This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] Secure newlib stdio functions against thread cancellation (was Re: newlib stdio and thread cancellation)
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: newlib at sourceware dot org
- Date: Thu, 31 May 2012 07:56:39 +0200
- Subject: Re: [PATCH] Secure newlib stdio functions against thread cancellation (was Re: newlib stdio and thread cancellation)
On May 29 09:27, Corinna Vinschen wrote:
> * libc/stdio/local.h (_newlib_flockfile_start): New macro to
> secure stream related critical section against thread cancellation.
> (_newlib_flockfile_exit): Ditto.
> (_newlib_sfp_lock_end): Ditto.
> (_newlib_sfp_lock_start): Ditto for the list of streams.
> (_newlib_sfp_lock_exit): Ditto.
> (_newlib_sfp_lock_end): Ditto.
> Use aforementioned macros in place of _flockfile/_funlockfile
> and __sfp_lock_acquire/__sfp_lock_release throughout the code.
Looks like a typo: no _newlib_sfp_lock_exit definition in the
#else arm below, but two _newlib_sfp_lock_end.
> Index: libc/stdio/local.h
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/stdio/local.h,v
> retrieving revision 1.31
> diff -u -p -r1.31 local.h
> --- libc/stdio/local.h 14 Jun 2011 03:56:05 -0000 1.31
> +++ libc/stdio/local.h 29 May 2012 17:18:38 -0000
> @@ -32,6 +32,70 @@
> # include <io.h>
> #endif
>
> +#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS)
...
> +/* Exit from a stream list oriented critical section prematurely: */
> +# define _newlib_sfp_lock_exit() \
> + __sfp_lock_release (); \
> + pthread_setcancelstate (__oldcancel, &__oldcancel);
> +
> +/* End a stream list oriented critical section: */
> +# define _newlib_sfp_lock_end() \
> + __sfp_lock_release (); \
> + pthread_setcancelstate (__oldcancel, &__oldcancel); \
> + }
> +
> +#else /* __SINGLE_THREAD__ || !_POSIX_THREADS */
...
> +# define _newlib_sfp_lock_end() \
> + __sfp_lock_release ();
> +
> +# define _newlib_sfp_lock_end() \
> + __sfp_lock_release (); \
> + }
> +
> +#endif /* !__SINGLE_THREAD__ && _POSIX_THREADS */
This shows up in my gcc autotester when testing a newlib-update
candidate as follows:
/tmp/hpautotest-gcc47/gcc/newlib/libc/stdio/findfp.c:124:
undefined reference to `_newlib_sfp_lock_exit'
collect2: error: ld returned 1 exit status
Can you please fix? Thanks.
brgds, H-P