This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: [PATCH] Fix problem with file locking used before initialised
- From: Antony KING <antony dot king at st dot com>
- To: newlib at sources dot redhat dot com
- Date: Tue, 01 Feb 2005 19:13:30 +0000
- Subject: Re: [PATCH] Fix problem with file locking used before initialised
- Organization: STMicroelectronics (R&D) Ltd
- References: <41F53DD1.3070506@st.com>
Please find attached a revised version of the following patch (replacing
the original submission) which adds some missing #includes of "local.h"
in files which had CHECK_INIT() calls added.
(I have also attached the patch file as text this time instead of as a
gzip'd attachment for easier perusal).
Cheers,
Antony.
Antony King wrote:
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.
Index: newlib/libc/include/sys/reent.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/reent.h,v
retrieving revision 1.33
diff -u -r1.33 reent.h
--- newlib/libc/include/sys/reent.h 15 Sep 2004 21:44:38 -0000 1.33
+++ newlib/libc/include/sys/reent.h 24 Jan 2005 12:01:24 -0000
@@ -158,9 +158,9 @@
struct _reent *_data;
};
/* CHECK_INIT() comes from stdio/local.h; be sure to include that. */
-# define _REENT_SMALL_CHECK_INIT(fp) CHECK_INIT(fp)
+# define _REENT_SMALL_CHECK_INIT(ptr) CHECK_INIT(ptr)
#else
-# define _REENT_SMALL_CHECK_INIT(fp) /* nothing */
+# define _REENT_SMALL_CHECK_INIT(ptr) /* nothing */
#endif
struct __sFILE {
Index: newlib/libc/machine/powerpc/vfprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/powerpc/vfprintf.c,v
retrieving revision 1.10
diff -u -r1.10 vfprintf.c
--- newlib/libc/machine/powerpc/vfprintf.c 18 Jan 2005 17:08:55 -0000 1.10
+++ newlib/libc/machine/powerpc/vfprintf.c 24 Jan 2005 12:14:13 -0000
@@ -239,7 +239,6 @@
unsigned char buf[BUFSIZ];
/* copy the important variables */
- fake._data = fp->_data;
fake._flags = fp->_flags & ~__SNBF;
fake._file = fp->_file;
fake._cookie = fp->_cookie;
@@ -322,6 +321,7 @@
_CONST char *fmt0 _AND
va_list ap)
{
+ CHECK_INIT (_REENT);
return _VFPRINTF_R (_REENT, fp, fmt0, ap);
}
Index: newlib/libc/machine/powerpc/vfscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/powerpc/vfscanf.c,v
retrieving revision 1.14
diff -u -r1.14 vfscanf.c
--- newlib/libc/machine/powerpc/vfscanf.c 24 Nov 2004 00:45:41 -0000 1.14
+++ newlib/libc/machine/powerpc/vfscanf.c 24 Jan 2005 12:01:21 -0000
@@ -224,8 +224,8 @@
_CONST char *fmt _AND
va_list ap)
{
- CHECK_INIT(fp);
- return __svfscanf_r (fp->_data, fp, fmt, ap);
+ CHECK_INIT(_REENT);
+ return __svfscanf_r (_REENT, fp, fmt, ap);
}
int
Index: newlib/libc/stdio/clearerr.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/clearerr.c,v
retrieving revision 1.3
diff -u -r1.3 clearerr.c
--- newlib/libc/stdio/clearerr.c 23 Apr 2004 20:01:54 -0000 1.3
+++ newlib/libc/stdio/clearerr.c 1 Feb 2005 18:28:37 -0000
@@ -54,12 +54,17 @@
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
+
+/* A subroutine version of the macro clearerr. */
+
#undef clearerr
_VOID
_DEFUN(clearerr, (fp),
FILE * fp)
{
+ CHECK_INIT(_REENT);
_flockfile (fp);
__sclearerr (fp);
_funlockfile (fp);
Index: newlib/libc/stdio/fclose.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fclose.c,v
retrieving revision 1.9
diff -u -r1.9 fclose.c
--- newlib/libc/stdio/fclose.c 11 Jun 2004 20:37:10 -0000 1.9
+++ newlib/libc/stdio/fclose.c 24 Jan 2005 12:01:21 -0000
@@ -76,10 +76,10 @@
__sfp_lock_acquire ();
+ CHECK_INIT (rptr);
+
_flockfile (fp);
- CHECK_INIT (fp);
-
if (fp->_flags == 0) /* not open! */
{
_funlockfile (fp);
Index: newlib/libc/stdio/feof.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/feof.c,v
retrieving revision 1.3
diff -u -r1.3 feof.c
--- newlib/libc/stdio/feof.c 23 Apr 2004 20:01:54 -0000 1.3
+++ newlib/libc/stdio/feof.c 1 Feb 2005 18:28:39 -0000
@@ -46,6 +46,9 @@
*/
#include <stdio.h>
+#include "local.h"
+
+/* A subroutine version of the macro feof. */
#undef feof
@@ -54,6 +57,7 @@
FILE * fp)
{
int result;
+ CHECK_INIT(_REENT);
_flockfile (fp);
result = __sfeof (fp);
_funlockfile (fp);
Index: newlib/libc/stdio/ferror.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/ferror.c,v
retrieving revision 1.3
diff -u -r1.3 ferror.c
--- newlib/libc/stdio/ferror.c 23 Apr 2004 20:01:54 -0000 1.3
+++ newlib/libc/stdio/ferror.c 1 Feb 2005 18:28:41 -0000
@@ -55,6 +55,7 @@
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
/* A subroutine version of the macro ferror. */
@@ -65,6 +66,7 @@
FILE * fp)
{
int result;
+ CHECK_INIT(_REENT);
_flockfile (fp);
result = __sferror (fp);
_funlockfile (fp);
Index: newlib/libc/stdio/fflush.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fflush.c,v
retrieving revision 1.4
diff -u -r1.4 fflush.c
--- newlib/libc/stdio/fflush.c 23 Apr 2004 20:01:54 -0000 1.4
+++ newlib/libc/stdio/fflush.c 24 Jan 2005 12:01:21 -0000
@@ -67,9 +67,9 @@
if (fp == NULL)
return _fwalk (_GLOBAL_REENT, fflush);
- _flockfile (fp);
+ CHECK_INIT (_REENT);
- CHECK_INIT (fp);
+ _flockfile (fp);
t = fp->_flags;
if ((t & __SWR) == 0 || (p = fp->_bf._base) == NULL)
Index: newlib/libc/stdio/fgetc.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fgetc.c,v
retrieving revision 1.3
diff -u -r1.3 fgetc.c
--- newlib/libc/stdio/fgetc.c 23 Apr 2004 20:01:54 -0000 1.3
+++ newlib/libc/stdio/fgetc.c 1 Feb 2005 18:28:43 -0000
@@ -55,12 +55,14 @@
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
int
_DEFUN(fgetc, (fp),
FILE * fp)
{
int result;
+ CHECK_INIT(_REENT);
_flockfile (fp);
result = __sgetc (fp);
_funlockfile (fp);
Index: newlib/libc/stdio/fgetpos.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fgetpos.c,v
retrieving revision 1.5
diff -u -r1.5 fgetpos.c
--- newlib/libc/stdio/fgetpos.c 23 Apr 2004 20:01:54 -0000 1.5
+++ newlib/libc/stdio/fgetpos.c 24 Jan 2005 12:01:21 -0000
@@ -81,15 +81,12 @@
FILE * fp _AND
_fpos_t * pos)
{
- _flockfile (fp);
*pos = _ftell_r (ptr, fp);
if (*pos != -1)
{
- _funlockfile (fp);
return 0;
}
- _funlockfile (fp);
return 1;
}
Index: newlib/libc/stdio/fgets.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fgets.c,v
retrieving revision 1.4
diff -u -r1.4 fgets.c
--- newlib/libc/stdio/fgets.c 23 Apr 2004 20:01:54 -0000 1.4
+++ newlib/libc/stdio/fgets.c 24 Jan 2005 12:01:21 -0000
@@ -80,6 +80,8 @@
s = buf;
+ CHECK_INIT(_REENT);
+
_flockfile (fp);
#ifdef __SCLE
if (fp->_flags & __SCLE)
Index: newlib/libc/stdio/fileno.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fileno.c,v
retrieving revision 1.3
diff -u -r1.3 fileno.c
--- newlib/libc/stdio/fileno.c 23 Apr 2004 20:01:54 -0000 1.3
+++ newlib/libc/stdio/fileno.c 24 Jan 2005 12:01:22 -0000
@@ -54,8 +54,8 @@
FILE * f)
{
int result;
+ CHECK_INIT (_REENT);
_flockfile (f);
- CHECK_INIT (f);
result = __sfileno (f);
_funlockfile (f);
return result;
Index: newlib/libc/stdio/fputc.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fputc.c,v
retrieving revision 1.3
diff -u -r1.3 fputc.c
--- newlib/libc/stdio/fputc.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/fputc.c 1 Feb 2005 18:28:48 -0000
@@ -59,6 +59,7 @@
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
int
_DEFUN(fputc, (ch, file),
@@ -66,6 +67,7 @@
FILE * file)
{
int result;
+ CHECK_INIT(_REENT);
_flockfile (file);
result = putc (ch, file);
_funlockfile (file);
Index: newlib/libc/stdio/fputs.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fputs.c,v
retrieving revision 1.3
diff -u -r1.3 fputs.c
--- newlib/libc/stdio/fputs.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/fputs.c 1 Feb 2005 18:28:50 -0000
@@ -51,6 +51,7 @@
#include <stdio.h>
#include <string.h>
#include "fvwrite.h"
+#include "local.h"
/*
* Write the given string to the given file.
@@ -69,6 +70,9 @@
iov.iov_len = uio.uio_resid = strlen (s);
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
+
+ CHECK_INIT(_REENT);
+
_flockfile (fp);
result = __sfvwrite (fp, &uio);
_funlockfile (fp);
Index: newlib/libc/stdio/fread.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fread.c,v
retrieving revision 1.9
diff -u -r1.9 fread.c
--- newlib/libc/stdio/fread.c 13 Dec 2004 19:42:16 -0000 1.9
+++ newlib/libc/stdio/fread.c 24 Jan 2005 12:01:22 -0000
@@ -125,6 +125,8 @@
if ((resid = count * size) == 0)
return 0;
+ CHECK_INIT(_REENT);
+
_flockfile (fp);
if (fp->_r < 0)
fp->_r = 0;
Index: newlib/libc/stdio/freopen.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/freopen.c,v
retrieving revision 1.11
diff -u -r1.11 freopen.c
--- newlib/libc/stdio/freopen.c 11 Jun 2004 20:37:10 -0000 1.11
+++ newlib/libc/stdio/freopen.c 24 Jan 2005 12:01:22 -0000
@@ -91,9 +91,9 @@
__sfp_lock_acquire ();
- _flockfile (fp);
+ CHECK_INIT (ptr);
- CHECK_INIT (fp);
+ _flockfile (fp);
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
Index: newlib/libc/stdio/fseek.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fseek.c,v
retrieving revision 1.10
diff -u -r1.10 fseek.c
--- newlib/libc/stdio/fseek.c 23 Apr 2004 20:01:55 -0000 1.10
+++ newlib/libc/stdio/fseek.c 24 Jan 2005 12:01:22 -0000
@@ -129,11 +129,11 @@
struct stat st;
int havepos;
- _flockfile (fp);
-
/* Make sure stdio is set up. */
- CHECK_INIT (fp);
+ CHECK_INIT (ptr);
+
+ _flockfile (fp);
/* If we've been doing some writing, and we're in append mode
then we don't really know where the filepos is. */
Index: newlib/libc/stdio/ftell.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/ftell.c,v
retrieving revision 1.8
diff -u -r1.8 ftell.c
--- newlib/libc/stdio/ftell.c 6 Jan 2005 20:10:56 -0000 1.8
+++ newlib/libc/stdio/ftell.c 24 Jan 2005 17:16:19 -0000
@@ -105,11 +105,11 @@
{
_fpos_t pos;
- _flockfile (fp);
-
/* Ensure stdio is set up. */
- CHECK_INIT (fp);
+ CHECK_INIT (ptr);
+
+ _flockfile (fp);
if (fp->_seek == NULL)
{
Index: newlib/libc/stdio/fwrite.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/fwrite.c,v
retrieving revision 1.3
diff -u -r1.3 fwrite.c
--- newlib/libc/stdio/fwrite.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/fwrite.c 24 Jan 2005 12:01:22 -0000
@@ -99,6 +99,8 @@
* generally slow and since this occurs whenever size==0.
*/
+ CHECK_INIT(_REENT);
+
_flockfile (fp);
if (__sfvwrite (fp, &uio) == 0)
{
Index: newlib/libc/stdio/getc.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/getc.c,v
retrieving revision 1.3
diff -u -r1.3 getc.c
--- newlib/libc/stdio/getc.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/getc.c 1 Feb 2005 18:28:57 -0000
@@ -64,6 +64,7 @@
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
/*
* A subroutine version of the macro getc.
@@ -76,8 +77,8 @@
register FILE *fp)
{
int result;
+ CHECK_INIT (_REENT);
_flockfile (fp);
- /* CHECK_INIT is called (eventually) by __srefill. */
result = __sgetc (fp);
_funlockfile (fp);
return result;
Index: newlib/libc/stdio/getchar.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/getchar.c,v
retrieving revision 1.3
diff -u -r1.3 getchar.c
--- newlib/libc/stdio/getchar.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/getchar.c 24 Jan 2005 12:01:22 -0000
@@ -82,7 +82,7 @@
_DEFUN(_getchar_r, (f),
struct _reent *f)
{
- _REENT_SMALL_CHECK_INIT (_stdin_r (f));
+ _REENT_SMALL_CHECK_INIT (f);
return getc (_stdin_r (f));
}
Index: newlib/libc/stdio/getdelim.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/getdelim.c,v
retrieving revision 1.3
diff -u -r1.3 getdelim.c
--- newlib/libc/stdio/getdelim.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/getdelim.c 24 Jan 2005 12:01:22 -0000
@@ -79,9 +79,9 @@
*n = DEFAULT_LINE_SIZE;
}
- _flockfile (fp);
+ CHECK_INIT (_REENT);
- CHECK_INIT (fp);
+ _flockfile (fp);
numbytes = *n;
ptr = buf;
Index: newlib/libc/stdio/iprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/iprintf.c,v
retrieving revision 1.6
diff -u -r1.6 iprintf.c
--- newlib/libc/stdio/iprintf.c 24 Nov 2004 00:45:41 -0000 1.6
+++ newlib/libc/stdio/iprintf.c 24 Jan 2005 12:01:22 -0000
@@ -40,7 +40,7 @@
int ret;
va_list ap;
- _REENT_SMALL_CHECK_INIT (_stdout_r (_REENT));
+ _REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
@@ -67,7 +67,7 @@
int ret;
va_list ap;
- _REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
Index: newlib/libc/stdio/iscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/iscanf.c,v
retrieving revision 1.1
diff -u -r1.1 iscanf.c
--- newlib/libc/stdio/iscanf.c 24 Nov 2004 00:45:41 -0000 1.1
+++ newlib/libc/stdio/iscanf.c 24 Jan 2005 12:01:22 -0000
@@ -39,7 +39,7 @@
int ret;
va_list ap;
- _REENT_SMALL_CHECK_INIT (_stdin_r (_REENT));
+ _REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
@@ -65,7 +65,7 @@
int ret;
va_list ap;
- _REENT_SMALL_CHECK_INIT (_stdin_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
Index: newlib/libc/stdio/local.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/local.h,v
retrieving revision 1.14
diff -u -r1.14 local.h
--- newlib/libc/stdio/local.h 24 Nov 2004 00:45:41 -0000 1.14
+++ newlib/libc/stdio/local.h 24 Jan 2005 12:01:22 -0000
@@ -49,11 +49,11 @@
/* Called by the main entry point fns to ensure stdio has been initialized. */
-#define CHECK_INIT(fp) \
+#define CHECK_INIT(ptr) \
do \
{ \
- if (_REENT && !_REENT->__sdidinit) \
- __sinit (_REENT); \
+ if ((ptr) && !(ptr)->__sdidinit) \
+ __sinit (ptr); \
} \
while (0)
Index: newlib/libc/stdio/perror.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/perror.c,v
retrieving revision 1.3
diff -u -r1.3 perror.c
--- newlib/libc/stdio/perror.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/perror.c 24 Jan 2005 12:01:22 -0000
@@ -74,7 +74,7 @@
{
char *error;
- _REENT_SMALL_CHECK_INIT (_stderr_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
if (s != NULL && *s != '\0')
{
fputs (s, _stderr_r (ptr));
Index: newlib/libc/stdio/printf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/printf.c,v
retrieving revision 1.4
diff -u -r1.4 printf.c
--- newlib/libc/stdio/printf.c 23 Apr 2004 20:01:55 -0000 1.4
+++ newlib/libc/stdio/printf.c 24 Jan 2005 12:01:22 -0000
@@ -39,7 +39,7 @@
int ret;
va_list ap;
- _REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
@@ -65,7 +65,7 @@
int ret;
va_list ap;
- _REENT_SMALL_CHECK_INIT (_stdout_r (_REENT));
+ _REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
Index: newlib/libc/stdio/putc.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/putc.c,v
retrieving revision 1.3
diff -u -r1.3 putc.c
--- newlib/libc/stdio/putc.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/putc.c 1 Feb 2005 18:29:07 -0000
@@ -67,6 +67,7 @@
#include <_ansi.h>
#include <stdio.h>
+#include "local.h"
/*
* A subroutine version of the macro putc.
@@ -80,8 +81,8 @@
register FILE *fp)
{
int result;
+ CHECK_INIT (_REENT);
_flockfile (fp);
- /* CHECK_INIT is (eventually) called by __swbuf. */
result = __sputc (c, fp);
_funlockfile (fp);
return result;
Index: newlib/libc/stdio/putchar.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/putchar.c,v
retrieving revision 1.5
diff -u -r1.5 putchar.c
--- newlib/libc/stdio/putchar.c 23 Apr 2004 20:01:55 -0000 1.5
+++ newlib/libc/stdio/putchar.c 24 Jan 2005 12:01:23 -0000
@@ -80,7 +80,7 @@
struct _reent *ptr _AND
int c)
{
- _REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
return putc (c, _stdout_r (ptr));
}
Index: newlib/libc/stdio/puts.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/puts.c,v
retrieving revision 1.3
diff -u -r1.3 puts.c
--- newlib/libc/stdio/puts.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/puts.c 24 Jan 2005 12:01:23 -0000
@@ -90,7 +90,7 @@
uio.uio_iov = &iov[0];
uio.uio_iovcnt = 2;
- _REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n');
}
Index: newlib/libc/stdio/refill.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/refill.c,v
retrieving revision 1.5
diff -u -r1.5 refill.c
--- newlib/libc/stdio/refill.c 17 Nov 2004 17:02:10 -0000 1.5
+++ newlib/libc/stdio/refill.c 24 Jan 2005 12:01:23 -0000
@@ -41,7 +41,7 @@
{
/* make sure stdio is set up */
- CHECK_INIT (fp);
+ CHECK_INIT (_REENT);
fp->_r = 0; /* largely a convenience for callers */
Index: newlib/libc/stdio/scanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/scanf.c,v
retrieving revision 1.5
diff -u -r1.5 scanf.c
--- newlib/libc/stdio/scanf.c 23 Apr 2004 20:01:55 -0000 1.5
+++ newlib/libc/stdio/scanf.c 24 Jan 2005 12:01:23 -0000
@@ -39,7 +39,7 @@
int ret;
va_list ap;
- _REENT_SMALL_CHECK_INIT (_stdin_r (_REENT));
+ _REENT_SMALL_CHECK_INIT (_REENT);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
@@ -65,7 +65,7 @@
int ret;
va_list ap;
- _REENT_SMALL_CHECK_INIT (_stdin_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
#ifdef _HAVE_STDC
va_start (ap, fmt);
#else
Index: newlib/libc/stdio/setvbuf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/setvbuf.c,v
retrieving revision 1.4
diff -u -r1.4 setvbuf.c
--- newlib/libc/stdio/setvbuf.c 23 Apr 2004 20:01:55 -0000 1.4
+++ newlib/libc/stdio/setvbuf.c 24 Jan 2005 12:01:23 -0000
@@ -104,9 +104,9 @@
{
int ret = 0;
- _flockfile (fp);
+ CHECK_INIT (_REENT);
- CHECK_INIT (fp);
+ _flockfile (fp);
/*
* Verify arguments. The `int' limit on `size' is due to this
Index: newlib/libc/stdio/ungetc.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/ungetc.c,v
retrieving revision 1.5
diff -u -r1.5 ungetc.c
--- newlib/libc/stdio/ungetc.c 3 May 2004 17:27:56 -0000 1.5
+++ newlib/libc/stdio/ungetc.c 24 Jan 2005 12:01:23 -0000
@@ -77,14 +77,14 @@
if (c == EOF)
return (EOF);
- _flockfile (fp);
-
/* Ensure stdio has been initialized.
??? Might be able to remove this as some other stdio routine should
have already been called to get the char we are un-getting. */
- CHECK_INIT (fp);
+ CHECK_INIT (rptr);
+ _flockfile (fp);
+
/* After ungetc, we won't be at eof anymore */
fp->_flags &= ~__SEOF;
Index: newlib/libc/stdio/vfprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
retrieving revision 1.37
diff -u -r1.37 vfprintf.c
--- newlib/libc/stdio/vfprintf.c 11 Jun 2004 20:37:10 -0000 1.37
+++ newlib/libc/stdio/vfprintf.c 24 Jan 2005 12:01:23 -0000
@@ -533,8 +533,8 @@
(u_long)GET_ARG (N, ap, u_int))
#endif
+ CHECK_INIT (data);
_flockfile (fp);
- CHECK_INIT (fp);
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
if (cantwrite (fp)) {
Index: newlib/libc/stdio/vfscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfscanf.c,v
retrieving revision 1.27
diff -u -r1.27 vfscanf.c
--- newlib/libc/stdio/vfscanf.c 6 Jan 2005 23:31:56 -0000 1.27
+++ newlib/libc/stdio/vfscanf.c 24 Jan 2005 12:57:15 -0000
@@ -231,7 +231,7 @@
_CONST char *fmt _AND
va_list ap)
{
- CHECK_INIT(fp);
+ CHECK_INIT(_REENT);
return __SVFSCANF_R (_REENT, fp, fmt, ap);
}
@@ -253,6 +253,7 @@
_CONST char *fmt _AND
va_list ap)
{
+ CHECK_INIT(data);
return __SVFSCANF_R (data, fp, fmt, ap);
}
Index: newlib/libc/stdio/viprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/viprintf.c,v
retrieving revision 1.1
diff -u -r1.1 viprintf.c
--- newlib/libc/stdio/viprintf.c 24 Nov 2004 00:45:41 -0000 1.1
+++ newlib/libc/stdio/viprintf.c 24 Jan 2005 12:01:23 -0000
@@ -145,7 +145,7 @@
_CONST char *fmt _AND
va_list ap)
{
- _REENT_SMALL_CHECK_INIT (_stdout_r (_REENT));
+ _REENT_SMALL_CHECK_INIT (_REENT);
return _vfiprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
}
@@ -157,6 +157,6 @@
_CONST char *fmt _AND
va_list ap)
{
- _REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
return _vfiprintf_r (ptr, _stdout_r (ptr), fmt, ap);
}
Index: newlib/libc/stdio/viscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/viscanf.c,v
retrieving revision 1.1
diff -u -r1.1 viscanf.c
--- newlib/libc/stdio/viscanf.c 24 Nov 2004 00:45:41 -0000 1.1
+++ newlib/libc/stdio/viscanf.c 24 Jan 2005 12:01:23 -0000
@@ -121,7 +121,7 @@
_CONST char *fmt _AND
va_list ap)
{
- _REENT_SMALL_CHECK_INIT (_stdin_r (_REENT));
+ _REENT_SMALL_CHECK_INIT (_REENT);
return __svfiscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
}
@@ -133,7 +133,7 @@
_CONST char *fmt _AND
va_list ap)
{
- _REENT_SMALL_CHECK_INIT (_stdin_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
return __svfiscanf_r (ptr, _stdin_r (ptr), fmt, ap);
}
Index: newlib/libc/stdio/vprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vprintf.c,v
retrieving revision 1.5
diff -u -r1.5 vprintf.c
--- newlib/libc/stdio/vprintf.c 23 Apr 2004 20:01:55 -0000 1.5
+++ newlib/libc/stdio/vprintf.c 24 Jan 2005 12:01:23 -0000
@@ -33,7 +33,7 @@
_CONST char *fmt _AND
va_list ap)
{
- _REENT_SMALL_CHECK_INIT (_stdout_r (_REENT));
+ _REENT_SMALL_CHECK_INIT (_REENT);
return _vfprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
}
@@ -45,6 +45,6 @@
_CONST char *fmt _AND
va_list ap)
{
- _REENT_SMALL_CHECK_INIT (_stdout_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
return _vfprintf_r (ptr, _stdout_r (ptr), fmt, ap);
}
Index: newlib/libc/stdio/vscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vscanf.c,v
retrieving revision 1.3
diff -u -r1.3 vscanf.c
--- newlib/libc/stdio/vscanf.c 23 Apr 2004 20:01:55 -0000 1.3
+++ newlib/libc/stdio/vscanf.c 24 Jan 2005 12:01:23 -0000
@@ -34,7 +34,7 @@
_CONST char *fmt _AND
va_list ap)
{
- _REENT_SMALL_CHECK_INIT (_stdin_r (_REENT));
+ _REENT_SMALL_CHECK_INIT (_REENT);
return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
}
@@ -46,7 +46,7 @@
_CONST char *fmt _AND
va_list ap)
{
- _REENT_SMALL_CHECK_INIT (_stdin_r (ptr));
+ _REENT_SMALL_CHECK_INIT (ptr);
return __svfscanf_r (ptr, _stdin_r (ptr), fmt, ap);
}
Index: newlib/libc/stdio/wbuf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/wbuf.c,v
retrieving revision 1.2
diff -u -r1.2 wbuf.c
--- newlib/libc/stdio/wbuf.c 23 Apr 2004 20:01:55 -0000 1.2
+++ newlib/libc/stdio/wbuf.c 24 Jan 2005 12:01:23 -0000
@@ -40,7 +40,7 @@
/* Ensure stdio has been initialized. */
- CHECK_INIT (fp);
+ CHECK_INIT (_REENT);
/*
* In case we cannot write, or longjmp takes us out early,
Index: newlib/libc/stdio/wsetup.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/wsetup.c,v
retrieving revision 1.2
diff -u -r1.2 wsetup.c
--- newlib/libc/stdio/wsetup.c 23 Apr 2004 20:01:55 -0000 1.2
+++ newlib/libc/stdio/wsetup.c 24 Jan 2005 12:01:23 -0000
@@ -34,7 +34,7 @@
{
/* Make sure stdio is set up. */
- CHECK_INIT (fp);
+ CHECK_INIT (_REENT);
/*
* If we are not writing, we had better be reading and writing.
Index: newlib/libc/stdio64/fgetpos64.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio64/fgetpos64.c,v
retrieving revision 1.3
diff -u -r1.3 fgetpos64.c
--- newlib/libc/stdio64/fgetpos64.c 22 Aug 2003 18:52:25 -0000 1.3
+++ newlib/libc/stdio64/fgetpos64.c 24 Jan 2005 12:01:23 -0000
@@ -60,15 +60,12 @@
FILE * fp _AND
_fpos64_t * pos)
{
- _flockfile(fp);
*pos = (_fpos64_t)_ftello64_r (ptr, fp);
if (*pos != -1)
{
- _funlockfile(fp);
return 0;
}
- _funlockfile(fp);
return 1;
}
Index: newlib/libc/stdio64/freopen64.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio64/freopen64.c,v
retrieving revision 1.6
diff -u -r1.6 freopen64.c
--- newlib/libc/stdio64/freopen64.c 16 Sep 2004 21:18:50 -0000 1.6
+++ newlib/libc/stdio64/freopen64.c 24 Jan 2005 12:01:23 -0000
@@ -91,9 +91,9 @@
__sfp_lock_acquire ();
- _flockfile(fp);
+ CHECK_INIT (ptr);
- CHECK_INIT (fp);
+ _flockfile(fp);
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
Index: newlib/libc/stdio64/fseeko64.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio64/fseeko64.c,v
retrieving revision 1.5
diff -u -r1.5 fseeko64.c
--- newlib/libc/stdio64/fseeko64.c 26 Aug 2003 18:09:43 -0000 1.5
+++ newlib/libc/stdio64/fseeko64.c 24 Jan 2005 12:01:23 -0000
@@ -111,11 +111,11 @@
struct stat64 st;
int havepos;
- _flockfile(fp);
-
/* Make sure stdio is set up. */
- CHECK_INIT (fp);
+ CHECK_INIT (ptr);
+
+ _flockfile(fp);
curoff = fp->_offset;
Index: newlib/libc/stdio64/ftello64.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio64/ftello64.c,v
retrieving revision 1.3
diff -u -r1.3 ftello64.c
--- newlib/libc/stdio64/ftello64.c 22 Aug 2003 18:52:25 -0000 1.3
+++ newlib/libc/stdio64/ftello64.c 24 Jan 2005 12:01:24 -0000
@@ -91,11 +91,11 @@
{
_fpos64_t pos;
- _flockfile(fp);
-
/* Ensure stdio is set up. */
- CHECK_INIT (fp);
+ CHECK_INIT (ptr);
+
+ _flockfile(fp);
if (fp->_seek64 == NULL)
{
Index: newlib/libc/stdlib/mallocr.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mallocr.c,v
retrieving revision 1.12
diff -u -r1.12 mallocr.c
--- newlib/libc/stdlib/mallocr.c 19 Aug 2003 18:09:54 -0000 1.12
+++ newlib/libc/stdlib/mallocr.c 24 Jan 2005 12:01:24 -0000
@@ -3484,7 +3484,7 @@
MALLOC_UNLOCK;
#ifdef INTERNAL_NEWLIB
- _REENT_SMALL_CHECK_INIT(_stderr_r (reent_ptr));
+ _REENT_SMALL_CHECK_INIT(reent_ptr);
fp = _stderr_r(reent_ptr);
#define fprintf fiprintf
#else
Index: newlib/libc/stdlib/mstats.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/mstats.c,v
retrieving revision 1.4
diff -u -r1.4 mstats.c
--- newlib/libc/stdlib/mstats.c 5 Sep 2003 00:13:15 -0000 1.4
+++ newlib/libc/stdlib/mstats.c 24 Jan 2005 12:01:24 -0000
@@ -140,7 +140,7 @@
struct _reent *ptr _AND
char *s)
{
- _REENT_SMALL_CHECK_INIT(_stderr_r (ptr));
+ _REENT_SMALL_CHECK_INIT(ptr);
fiprintf (_stderr_r (ptr), "Memory allocation statistics %s\n", s);
_malloc_stats_r (ptr);
}
Index: newlib/libc/sys/arm/syscalls.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/arm/syscalls.c,v
retrieving revision 1.9
diff -u -r1.9 syscalls.c
--- newlib/libc/sys/arm/syscalls.c 6 Jan 2004 19:27:21 -0000 1.9
+++ newlib/libc/sys/arm/syscalls.c 24 Jan 2005 12:01:24 -0000
@@ -55,20 +55,17 @@
/* following is copied from libc/stdio/local.h to check std streams */
extern void _EXFUN(__sinit,(struct _reent *));
-#define CHECK_INIT(fp) \
- do \
- { \
- if ((fp)->_data == 0) \
- (fp)->_data = _REENT; \
- if (!(fp)->_data->__sdidinit) \
- __sinit ((fp)->_data); \
- } \
+#define CHECK_INIT(ptr) \
+ do \
+ { \
+ if ((ptr) && !(ptr)->__sdidinit) \
+ __sinit (ptr); \
+ } \
while (0)
/* Adjust our internal handles to stay away from std* handles. */
#define FILE_HANDLE_OFFSET (0x20)
-static int std_files_checked;
static int monitor_stdin;
static int monitor_stdout;
static int monitor_stderr;
@@ -119,13 +116,8 @@
static int
remap_handle (int fh)
{
- if (!std_files_checked)
- {
- CHECK_INIT(stdin);
- CHECK_INIT(stdout);
- CHECK_INIT(stderr);
- std_files_checked = 1;
- }
+ CHECK_INIT(_REENT);
+
if (fh == STDIN_FILENO)
return monitor_stdin;
if (fh == STDOUT_FILENO)
2005-02-01 Antony King <antony.king@st.com>
* libc/stdio/clearerr.c (clearerr): Ensure CHECK_INIT() is
called before _flockfile to prevent lock object use before
initialisation. _REENT_SMALL_CHECK_INIT() and CHECK_INIT()
take a struct _reent * instead of a FILE *.
* libc/stdio/fclose.c (_fclose_r): Ditto.
* libc/stdio/feof.c (feof): Ditto.
* libc/stdio/ferror.c (ferror): Ditto.
* libc/stdio/fflush.c (fflush): Ditto.
* libc/stdio/fgetc.c (fgetc): Ditto.
* libc/stdio/fgets.c (fgets): Ditto.
* libc/stdio/fileno.c (fileno): Ditto.
* libc/stdio/fputc.c (fputc): Ditto.
* libc/stdio/fputs.c (fputs): Ditto.
* libc/stdio/fread.c (fread): Ditto.
* libc/stdio/freopen.c (_freopen_r): Ditto.
* libc/stdio/fseek.c (_fseek_r): Ditto.
* libc/stdio/ftell.c (_ftell_r): Ditto.
* libc/stdio/fwrite.c (fwrite): Ditto.
* libc/stdio/getc.c (getc): Ditto.
* libc/stdio/getdelim.c (__getdelim): Ditto.
* libc/stdio/putc.c (putc): Ditto.
* libc/stdio/setvbuf.c (setvbuf): Ditto.
* libc/stdio/ungetc.c (_ungetc_r): Ditto.
* libc/stdio/vfprintf.c (_VFPRINTF_R): Ditto.
* libc/stdio64/freopen64.c (_freopen64_r): Ditto.
* libc/stdio64/fseeko64.c (_fseeko64_r): Ditto.
* libc/stdio64/ftello64.c (_ftello64_r): Ditto.
* libc/stdio/local.h (CHECK_INIT): Argument is now a struct
_reent * instead of a FILE * and so replace incorrect use of
_REENT with argument.
* libc/sys/arm/syscalls.c (CHECK_INIT): Ditto.
* libc/stdio/getchar.c (getchar): _REENT_SMALL_CHECK_INIT() and
CHECK_INIT() take a struct _reent * instead of a FILE *.
* libc/stdio/iprintf.c (iprintf, _iprintf_r): Ditto.
* libc/stdio/iscanf.c (iscanf, _iscanf_r): Ditto.
* libc/stdio/perror.c (perror): Ditto.
* libc/stdio/printf.c (printf, _printf_r): Ditto.
* libc/stdio/putchar.c (putchar): Ditto.
* libc/stdio/puts.c (puts): Ditto.
* libc/stdio/refill.c (__srefill): Ditto.
* libc/stdio/scanf.c (scanf, _scanf_r): Ditto.
* libc/stdio/vfscanf.c (VFSCANF, _VFSCANF_R): Ditto.
* libc/stdio/viprintf.c (viprintf, _viprintf_r): Ditto.
* libc/stdio/viscanf.c (viscanf, _viscanf_r): Ditto.
* libc/stdio/vprintf.c (vprintf, _vprintf_r): Ditto.
* libc/stdio/vscanf.c (vscanf, _vscanf_r): Ditto.
* libc/stdio/wbuf.c (__swbuf): Ditto.
* libc/stdio/wsetup.c (__swsetup): Ditto.
* libc/stdlib/mallocr.c (malloc_stats): Ditto.
* libc/stdlib/mstats.c (_mstats_r): Ditto.
* libc/include/sys/reent.h (_REENT_SMALL_CHECK_INIT): Ditto.
* libc/machine/powerpc/vfscanf.c (vfscanf): Ditto.
* libc/stdio/fgetpos.c (_fgetpos_r): Removed unnecessary calls
to _flockfile and _funlockfile; rely on locking in _ftell_r.
* libc/stdio64/fgetpos64.c (_fgetpos64_r): Ditto (_ftello64_r).
* libc/machine/powerpc/vfprintf.c (__sbprintf): Removed unnecessary
initialision of _data field in FILE structure.
* libc/machine/powerpc/vfprintf.c (VFPRINTF): Added CHECK_INIT() call.