[PATCH] Fix problem with file locking used before initialised

Antony KING antony.king@st.com
Mon Jan 24 18:27:00 GMT 2005


Please find attached a patch against libc in newlib to fix I a problem I 
have encountered in the use of the _flockfile/_funlockfile API on the 
standard I/O streams (stderr, stdout and stdin).

The problems stems from the fact that the FILE objects for these I/O 
streams are initially statically allocated in the global re-entrancy 
structure (aka the "impure" pointer) and they are not 100% initialised 
by static initialisation. This is overcome by the use of the CHECK_INIT 
and _REENT_SMALL_CHECK_INIT macros which complete the initialisation of 
the standard FILE I/O objects in a re-entrancy structure. As part of the 
initialisation of the standard I/O FILE objects the file lock objects 
are initialised.

Unfortunately the _flockfile/_funlockfile functions are used before 
CHECK_INIT is called and therefore the FILE lock object could end up in 
an unknown state depending on the implementation of the FILE lock object 
and the method of initialisation. To solve this problem it is necessary 
to call CHECK_INIT before _flockfile/_funlockfile are called in any 
function that takes a FILE * object as an argument (which normally is a 
user level function). The attached patch attempts to fix this problem.

Note that I have modified some machine specific files unfortunately I am 
unable to test so you may not wish to commit these changes (powerpc and 
arm files).

Cheers,

Antony.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ChangeLog
URL: <http://sourceware.org/pipermail/newlib/attachments/20050124/1b9d1f2f/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: newlib.diffs.gz
Type: application/x-gzip
Size: 5405 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20050124/1b9d1f2f/attachment.bin>


More information about the Newlib mailing list