2000-02-18 03:39:52 +08:00
|
|
|
/* This header file provides the reentrancy. */
|
|
|
|
|
|
|
|
/* WARNING: All identifiers here must begin with an underscore. This file is
|
|
|
|
included by stdio.h and others and we therefore must only use identifiers
|
|
|
|
in the namespace allotted to us. */
|
|
|
|
|
|
|
|
#ifndef _SYS_REENT_H_
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
#define _SYS_REENT_H_
|
|
|
|
|
|
|
|
#include <_ansi.h>
|
2013-10-23 18:04:43 +08:00
|
|
|
#include <stddef.h>
|
2001-08-30 03:47:43 +08:00
|
|
|
#include <sys/_types.h>
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2006-09-27 05:22:19 +08:00
|
|
|
#define _NULL 0
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
#ifndef __Long
|
|
|
|
#if __LONG_MAX__ == 2147483647L
|
|
|
|
#define __Long long
|
|
|
|
typedef unsigned __Long __ULong;
|
|
|
|
#elif __INT_MAX__ == 2147483647
|
|
|
|
#define __Long int
|
|
|
|
typedef unsigned __Long __ULong;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2002-07-18 07:25:44 +08:00
|
|
|
#if !defined( __Long)
|
2002-06-25 04:03:38 +08:00
|
|
|
#include <sys/types.h>
|
2002-07-18 07:25:44 +08:00
|
|
|
#endif
|
|
|
|
|
2019-05-16 20:40:32 +08:00
|
|
|
#ifndef __machine_flock_t_defined
|
|
|
|
#include <sys/lock.h>
|
|
|
|
typedef _LOCK_RECURSIVE_T _flock_t;
|
|
|
|
#endif
|
|
|
|
|
2002-07-18 07:25:44 +08:00
|
|
|
#ifndef __Long
|
2000-02-18 03:39:52 +08:00
|
|
|
#define __Long __int32_t
|
|
|
|
typedef __uint32_t __ULong;
|
|
|
|
#endif
|
|
|
|
|
Implement funopen, fopencookie.
* libc/include/sys/reent.h (struct __sFILE, struct __sFILE64):
Switch to reentrant callbacks.
* libc/include/stdio.h (funopen): Fix declaration.
(fopencookie): Declare.
* libc/stdio/local.h (__sread, __swrite, __sseek, __sclose)
(__sseek64, __swrite64): Fix prototypes.
[__SCLE]: Pull in setmode declaration.
* libc/stdio/stdio.c (__sread, __swrite, __sseek, __sclose): Fix
reentrancy.
* libc/stdio64/stdio64.c (__sseek64_r, __swrite64_r): Delete.
(__sseek64, __swrite64): Fix reentrancy.
* libc/stdio/fseek.c (_fseek_r): Account for overflow, and fix
reentrancy.
* libc/stdio/ftell.c (_ftell_r): Likewise.
* libc/stdio/flags.c (__sflags): Don't lose __SAPP on "a+".
* libc/stdio/fclose.c (_fclose_r): Fix reentrancy.
* libc/stdio/freopen.c (_freopen_r): Likewise.
* libc/stdio/fvwrite.c (__sfvwrite_r): Likewise.
* libc/stdio/refill.c (__srefill_r): Likewise.
* libc/stdio/siscanf.c (eofread): Likewise.
* libc/stdio/sscanf.c (eofread): Likewise.
* libc/stdio/vsiscanf.c (eofread1): Likewise.
* libc/stdio/vsscanf.c (eofread1): Likewise.
* libc/stdio64/freopen64.c (_freopen64_r): Likewise.
* libc/stdio64/fseeko64.c (_fseeko64_r): Likewise.
* libc/stdio64/ftello64.c (_ftello64_r): Likewise.
* libc/stdio/fflush.c (fflush): Improve reentrancy, although more
could be fixed.
* libc/stdio/fopencookie.c (_fopencookie_r, fopencookie): New file.
* libc/stdio/funopen.c (_funopen_r, funopen): New file.
* libc/stdio/Makefile.am (ELIX_4_SOURCES, CHEWOUT_FILES): Build
new files.
* libc/stdio/Makefile.in: Regenerate.
2007-06-05 02:10:17 +08:00
|
|
|
struct _reent;
|
|
|
|
|
2016-07-22 02:49:42 +08:00
|
|
|
struct __locale_t;
|
2016-07-06 21:41:35 +08:00
|
|
|
|
2002-02-03 17:24:18 +08:00
|
|
|
/*
|
|
|
|
* If _REENT_SMALL is defined, we make struct _reent as small as possible,
|
|
|
|
* by having nearly everything possible allocated at first use.
|
|
|
|
*/
|
|
|
|
|
2008-10-03 00:43:23 +08:00
|
|
|
struct _Bigint
|
2000-02-18 03:39:52 +08:00
|
|
|
{
|
|
|
|
struct _Bigint *_next;
|
|
|
|
int _k, _maxwds, _sign, _wds;
|
|
|
|
__ULong _x[1];
|
|
|
|
};
|
|
|
|
|
2001-08-30 03:47:43 +08:00
|
|
|
/* needed by reentrant structure */
|
|
|
|
struct __tm
|
|
|
|
{
|
|
|
|
int __tm_sec;
|
|
|
|
int __tm_min;
|
|
|
|
int __tm_hour;
|
|
|
|
int __tm_mday;
|
|
|
|
int __tm_mon;
|
|
|
|
int __tm_year;
|
|
|
|
int __tm_wday;
|
|
|
|
int __tm_yday;
|
|
|
|
int __tm_isdst;
|
|
|
|
};
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
/*
|
2004-09-10 03:46:54 +08:00
|
|
|
* atexit() support.
|
2000-02-18 03:39:52 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
|
|
|
|
|
2003-06-06 23:36:31 +08:00
|
|
|
struct _on_exit_args {
|
2004-09-10 03:46:54 +08:00
|
|
|
void * _fnargs[_ATEXIT_SIZE]; /* user fn args */
|
|
|
|
void * _dso_handle[_ATEXIT_SIZE];
|
|
|
|
/* Bitmask is set if user function takes arguments. */
|
2003-06-06 23:36:31 +08:00
|
|
|
__ULong _fntypes; /* type of exit routine -
|
2004-09-10 03:46:54 +08:00
|
|
|
Must have at least _ATEXIT_SIZE bits */
|
|
|
|
/* Bitmask is set if function was registered via __cxa_atexit. */
|
|
|
|
__ULong _is_cxa;
|
2003-06-06 23:36:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef _REENT_SMALL
|
2000-02-18 03:39:52 +08:00
|
|
|
struct _atexit {
|
2004-09-10 03:46:54 +08:00
|
|
|
struct _atexit *_next; /* next in list */
|
2000-02-18 03:39:52 +08:00
|
|
|
int _ind; /* next index in this table */
|
|
|
|
void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
|
2003-06-06 23:36:31 +08:00
|
|
|
struct _on_exit_args * _on_exit_args_ptr;
|
2000-02-18 03:39:52 +08:00
|
|
|
};
|
2013-05-08 05:40:10 +08:00
|
|
|
# define _ATEXIT_INIT {_NULL, 0, {_NULL}, _NULL}
|
2002-02-03 17:24:18 +08:00
|
|
|
#else
|
|
|
|
struct _atexit {
|
2003-06-06 23:36:31 +08:00
|
|
|
struct _atexit *_next; /* next in list */
|
2002-02-03 17:24:18 +08:00
|
|
|
int _ind; /* next index in this table */
|
2004-09-10 03:46:54 +08:00
|
|
|
/* Some entries may already have been called, and will be NULL. */
|
2002-02-03 17:24:18 +08:00
|
|
|
void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
|
2003-06-06 23:36:31 +08:00
|
|
|
struct _on_exit_args _on_exit_args;
|
2002-02-03 17:24:18 +08:00
|
|
|
};
|
2013-05-08 05:40:10 +08:00
|
|
|
# define _ATEXIT_INIT {_NULL, 0, {_NULL}, {{_NULL}, {_NULL}, 0, 0}}
|
2002-02-03 17:24:18 +08:00
|
|
|
#endif
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stdio buffers.
|
|
|
|
*
|
2002-07-18 07:25:44 +08:00
|
|
|
* This and __FILE are defined here because we need them for struct _reent,
|
2000-02-18 03:39:52 +08:00
|
|
|
* but we don't want stdio.h included when stdlib.h is.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct __sbuf {
|
|
|
|
unsigned char *_base;
|
|
|
|
int _size;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stdio state variables.
|
|
|
|
*
|
|
|
|
* The following always hold:
|
|
|
|
*
|
|
|
|
* if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
|
|
|
|
* _lbfsize is -_bf._size, else _lbfsize is 0
|
|
|
|
* if _flags&__SRD, _w is 0
|
|
|
|
* if _flags&__SWR, _r is 0
|
|
|
|
*
|
|
|
|
* This ensures that the getc and putc macros (or inline functions) never
|
|
|
|
* try to write or read from a file that is in `read' or `write' mode.
|
|
|
|
* (Moreover, they can, and do, automatically switch from read mode to
|
|
|
|
* write mode, and back, on "r+" and "w+" files.)
|
|
|
|
*
|
|
|
|
* _lbfsize is used only to make the inline line-buffered output stream
|
|
|
|
* code as compact as possible.
|
|
|
|
*
|
|
|
|
* _ub, _up, and _ur are used when ungetc() pushes back more characters
|
|
|
|
* than fit in the current _bf, or when ungetc() pushes back a character
|
|
|
|
* that does not match the previous one in _bf. When this happens,
|
|
|
|
* _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
|
|
|
|
* _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
|
|
|
|
*/
|
|
|
|
|
Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722090fffd10869dbb15b879651c1370d in 2017. Since then it was enabled by
default for RTEMS. Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.
In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr. If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively. There are at least three problems with this:
(1) The thread-specific FILE objects are closed by _reclaim_reent(). This
leads to problems with language run-time libraries that provide wrappers to
the C/POSIX stdio streams (for example C++ and Ada), since they use the
thread-specific FILE objects of the initialization thread. In case the
initialization thread is deleted, then they use freed memory.
(2) Since thread-specific FILE objects are used with a common output device via
file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
atomicity of the output, e.g. a call to printf().
(3) There are resource managment issues, see:
https://sourceware.org/pipermail/newlib/2022/019558.html
https://bugs.linaro.org/show_bug.cgi?id=5841
This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option. This removes a couple of #ifdef blocks.
2022-05-18 00:28:52 +08:00
|
|
|
#define _REENT_SMALL_CHECK_INIT(ptr) /* nothing */
|
2002-02-03 17:24:18 +08:00
|
|
|
|
2022-12-08 23:03:06 +08:00
|
|
|
/* Cygwin must use __sFILE64 for backward compatibility, even though
|
|
|
|
it's not defining __LARGE64_FILES anymore. To make sure that __sFILE
|
|
|
|
is never defined, disable it here explicitely. */
|
|
|
|
#ifndef __CYGWIN__
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
struct __sFILE {
|
|
|
|
unsigned char *_p; /* current position in (some) buffer */
|
|
|
|
int _r; /* read space left for getc() */
|
|
|
|
int _w; /* write space left for putc() */
|
|
|
|
short _flags; /* flags, below; this FILE is free if 0 */
|
|
|
|
short _file; /* fileno, if Unix descriptor, else -1 */
|
|
|
|
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
|
|
|
|
int _lbfsize; /* 0 or -_bf._size, for inline putc */
|
|
|
|
|
2002-02-03 17:24:18 +08:00
|
|
|
#ifdef _REENT_SMALL
|
|
|
|
struct _reent *_data;
|
|
|
|
#endif
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
/* operations */
|
2017-12-04 10:53:22 +08:00
|
|
|
void * _cookie; /* cookie passed to io functions */
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2017-12-04 12:52:13 +08:00
|
|
|
_READ_WRITE_RETURN_TYPE (*_read) (struct _reent *, void *,
|
|
|
|
char *, _READ_WRITE_BUFSIZE_TYPE);
|
|
|
|
_READ_WRITE_RETURN_TYPE (*_write) (struct _reent *, void *,
|
2013-10-23 18:04:43 +08:00
|
|
|
const char *,
|
2017-12-04 12:52:13 +08:00
|
|
|
_READ_WRITE_BUFSIZE_TYPE);
|
|
|
|
_fpos_t (*_seek) (struct _reent *, void *, _fpos_t, int);
|
|
|
|
int (*_close) (struct _reent *, void *);
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/* separate buffer for long sequences of ungetc() */
|
|
|
|
struct __sbuf _ub; /* ungetc buffer */
|
|
|
|
unsigned char *_up; /* saved _p when _p is doing ungetc data */
|
|
|
|
int _ur; /* saved _r when _r is counting ungetc data */
|
|
|
|
|
|
|
|
/* tricks to meet minimum requirements even when malloc() fails */
|
|
|
|
unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
|
|
|
|
unsigned char _nbuf[1]; /* guarantee a getc() buffer */
|
|
|
|
|
|
|
|
/* separate buffer for fgetline() when line crosses buffer boundary */
|
|
|
|
struct __sbuf _lb; /* buffer for fgetline() */
|
|
|
|
|
|
|
|
/* Unix stdio files get aligned to block boundaries on fseek() */
|
|
|
|
int _blksize; /* stat.st_blksize (may be != _bf._size) */
|
2012-11-30 00:28:30 +08:00
|
|
|
_off_t _offset; /* current lseek offset */
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2002-02-03 17:24:18 +08:00
|
|
|
#ifndef _REENT_SMALL
|
2002-09-04 03:40:36 +08:00
|
|
|
struct _reent *_data; /* Here for binary compatibility? Remove? */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __SINGLE_THREAD__
|
|
|
|
_flock_t _lock; /* for thread-safety locking */
|
2002-02-03 17:24:18 +08:00
|
|
|
#endif
|
2008-12-10 Corinna Vinschen <corinna@vinschen.de>
Implement basic wide char stdio functionality, based on FreeBSD.
* libc/include/stdio.h (__SORD): Define.
(__SWID): Define.
* libc/include/wchar.h: Add declarations for new wide char functions.
(getwc): Define as macro.
(getwchar): Ditto.
(putwc): Ditto.
(putwchar): Ditto.
* libc/include/sys/reent.h (struct __sFILE): Add _mbstate member.
(struct __sFILE64): Ditto.
* libc/stdio/Makefile.am (ELIX_4_SOURCES): Add fgetwc.c, fgetws.c,
fputwc.c, fputws.c, fwide.c, getwc.c, getwchar.c, putwc.c, putwchar.c
and ungetwc.c.
(CHEWOUT_FILES): Add fgetwc.def, fgetws.def, fputwc.def, fputws.def,
fwide.def, getwc.def, getwchar.def, putwc.def, putwchar.def and
ungetwc.def.
Add header dependency rules for the new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fgetwc.c: New file, implementing fgetwc and _fgetwc_r.
* libc/stdio/fgetws.c: New file, implementing fgetws and _fgetws_r.
* libc/stdio/findfp.c (std): Initialize FILE's _mbstate member.
(__sfmoreglue): Ditto.
* libc/stdio/fputs.c (_fputs_r): Set stream orientation.
* libc/stdio/fputwc.c: New file, implementing fputwc and _fputwc_r.
* libc/stdio/fputws.c: New file, implementing fputws and _fputws_r.
* libc/stdio/fread.c (_fread_r): Set stream orientation.
* libc/stdio/freopen.c (_freopen_r): Reset stream orientation. Reset
_mbstate.
* libc/stdio/fseek.c (_fseek_r): Reset _mbstate.
* libc/stdio/fwide.c: New file, implementing fwide and _fwide_r.
* libc/stdio/fwrite.c (_fwrite_r): Set stream orientation.
* libc/stdio/getwc.c: New file, implementing getwc and _getwc_r.
* libc/stdio/getwchar.c: New file, implementing getwchar and
_getwchar_r.
* libc/stdio/local.h (ORIENT): New macro.
* libc/stdio/puts.c (_puts_r): Set stream orientation.
* libc/stdio/putwc.c: New file, implementing putwc and _putwc_r.
* libc/stdio/putwchar.c: New file, implementing putwchar and
_putwchar_r.
* libc/stdio/refill.c (__srefill_r): Set stream orientation.
* libc/stdio/stdio.tex: Add documentation for new functions.
* libc/stdio/ungetc.c (_ungetc_r): Set stream orientation.
* libc/stdio/ungetwc.c: New file, implementing ungetwc and _ungetwc_r.
* libc/stdio/vfscanf.c (__SVFSCANF_R): Set stream orientation.
* libc/stdio/wbuf.c (__swbuf_r): Ditto.
2008-12-11 07:43:12 +08:00
|
|
|
_mbstate_t _mbstate; /* for wide char stdio functions. */
|
2008-11-25 01:15:43 +08:00
|
|
|
int _flags2; /* for future use */
|
2000-02-18 03:39:52 +08:00
|
|
|
};
|
|
|
|
|
2022-12-08 23:03:06 +08:00
|
|
|
#endif /* !__CYGWIN__ */
|
|
|
|
|
2007-02-02 00:33:05 +08:00
|
|
|
#ifdef __CUSTOM_FILE_IO__
|
|
|
|
|
|
|
|
/* Get custom _FILE definition. */
|
|
|
|
#include <sys/custom_file.h>
|
|
|
|
|
|
|
|
#else /* !__CUSTOM_FILE_IO__ */
|
2022-12-08 23:03:06 +08:00
|
|
|
/* Cygwin must use __sFILE64 for backward compatibility, even though
|
|
|
|
it's not defining __LARGE64_FILES anymore. It also has to make
|
|
|
|
sure the name is the same to satisfy C++ name mangling. Overloading
|
|
|
|
_fpos64_t just fixes a build problem. The _seek64 function is
|
|
|
|
actually never used without __LARGE64_FILES being defined. */
|
|
|
|
#if defined (__LARGE64_FILES) || defined (__CYGWIN__)
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
#define _fpos64_t _fpos_t
|
|
|
|
#endif
|
|
|
|
|
2002-07-18 07:25:44 +08:00
|
|
|
struct __sFILE64 {
|
|
|
|
unsigned char *_p; /* current position in (some) buffer */
|
|
|
|
int _r; /* read space left for getc() */
|
|
|
|
int _w; /* write space left for putc() */
|
|
|
|
short _flags; /* flags, below; this FILE is free if 0 */
|
|
|
|
short _file; /* fileno, if Unix descriptor, else -1 */
|
|
|
|
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
|
|
|
|
int _lbfsize; /* 0 or -_bf._size, for inline putc */
|
|
|
|
|
|
|
|
struct _reent *_data;
|
|
|
|
|
|
|
|
/* operations */
|
2017-12-04 10:53:22 +08:00
|
|
|
void * _cookie; /* cookie passed to io functions */
|
2002-07-18 07:25:44 +08:00
|
|
|
|
2017-12-04 12:52:13 +08:00
|
|
|
_READ_WRITE_RETURN_TYPE (*_read) (struct _reent *, void *,
|
|
|
|
char *, _READ_WRITE_BUFSIZE_TYPE);
|
|
|
|
_READ_WRITE_RETURN_TYPE (*_write) (struct _reent *, void *,
|
2013-10-23 18:04:43 +08:00
|
|
|
const char *,
|
2017-12-04 12:52:13 +08:00
|
|
|
_READ_WRITE_BUFSIZE_TYPE);
|
|
|
|
_fpos_t (*_seek) (struct _reent *, void *, _fpos_t, int);
|
|
|
|
int (*_close) (struct _reent *, void *);
|
2002-07-18 07:25:44 +08:00
|
|
|
|
|
|
|
/* separate buffer for long sequences of ungetc() */
|
|
|
|
struct __sbuf _ub; /* ungetc buffer */
|
|
|
|
unsigned char *_up; /* saved _p when _p is doing ungetc data */
|
|
|
|
int _ur; /* saved _r when _r is counting ungetc data */
|
|
|
|
|
|
|
|
/* tricks to meet minimum requirements even when malloc() fails */
|
|
|
|
unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
|
|
|
|
unsigned char _nbuf[1]; /* guarantee a getc() buffer */
|
|
|
|
|
|
|
|
/* separate buffer for fgetline() when line crosses buffer boundary */
|
|
|
|
struct __sbuf _lb; /* buffer for fgetline() */
|
|
|
|
|
|
|
|
/* Unix stdio files get aligned to block boundaries on fseek() */
|
|
|
|
int _blksize; /* stat.st_blksize (may be != _bf._size) */
|
|
|
|
int _flags2; /* for future use */
|
2002-09-04 03:40:36 +08:00
|
|
|
|
2002-07-18 07:25:44 +08:00
|
|
|
_off64_t _offset; /* current lseek offset */
|
2017-12-04 12:52:13 +08:00
|
|
|
_fpos64_t (*_seek64) (struct _reent *, void *, _fpos64_t, int);
|
2002-09-04 03:40:36 +08:00
|
|
|
|
|
|
|
#ifndef __SINGLE_THREAD__
|
|
|
|
_flock_t _lock; /* for thread-safety locking */
|
|
|
|
#endif
|
2008-12-10 Corinna Vinschen <corinna@vinschen.de>
Implement basic wide char stdio functionality, based on FreeBSD.
* libc/include/stdio.h (__SORD): Define.
(__SWID): Define.
* libc/include/wchar.h: Add declarations for new wide char functions.
(getwc): Define as macro.
(getwchar): Ditto.
(putwc): Ditto.
(putwchar): Ditto.
* libc/include/sys/reent.h (struct __sFILE): Add _mbstate member.
(struct __sFILE64): Ditto.
* libc/stdio/Makefile.am (ELIX_4_SOURCES): Add fgetwc.c, fgetws.c,
fputwc.c, fputws.c, fwide.c, getwc.c, getwchar.c, putwc.c, putwchar.c
and ungetwc.c.
(CHEWOUT_FILES): Add fgetwc.def, fgetws.def, fputwc.def, fputws.def,
fwide.def, getwc.def, getwchar.def, putwc.def, putwchar.def and
ungetwc.def.
Add header dependency rules for the new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fgetwc.c: New file, implementing fgetwc and _fgetwc_r.
* libc/stdio/fgetws.c: New file, implementing fgetws and _fgetws_r.
* libc/stdio/findfp.c (std): Initialize FILE's _mbstate member.
(__sfmoreglue): Ditto.
* libc/stdio/fputs.c (_fputs_r): Set stream orientation.
* libc/stdio/fputwc.c: New file, implementing fputwc and _fputwc_r.
* libc/stdio/fputws.c: New file, implementing fputws and _fputws_r.
* libc/stdio/fread.c (_fread_r): Set stream orientation.
* libc/stdio/freopen.c (_freopen_r): Reset stream orientation. Reset
_mbstate.
* libc/stdio/fseek.c (_fseek_r): Reset _mbstate.
* libc/stdio/fwide.c: New file, implementing fwide and _fwide_r.
* libc/stdio/fwrite.c (_fwrite_r): Set stream orientation.
* libc/stdio/getwc.c: New file, implementing getwc and _getwc_r.
* libc/stdio/getwchar.c: New file, implementing getwchar and
_getwchar_r.
* libc/stdio/local.h (ORIENT): New macro.
* libc/stdio/puts.c (_puts_r): Set stream orientation.
* libc/stdio/putwc.c: New file, implementing putwc and _putwc_r.
* libc/stdio/putwchar.c: New file, implementing putwchar and
_putwchar_r.
* libc/stdio/refill.c (__srefill_r): Set stream orientation.
* libc/stdio/stdio.tex: Add documentation for new functions.
* libc/stdio/ungetc.c (_ungetc_r): Set stream orientation.
* libc/stdio/ungetwc.c: New file, implementing ungetwc and _ungetwc_r.
* libc/stdio/vfscanf.c (__SVFSCANF_R): Set stream orientation.
* libc/stdio/wbuf.c (__swbuf_r): Ditto.
2008-12-11 07:43:12 +08:00
|
|
|
_mbstate_t _mbstate; /* for wide char stdio functions. */
|
2002-07-18 07:25:44 +08:00
|
|
|
};
|
|
|
|
typedef struct __sFILE64 __FILE;
|
|
|
|
#else
|
|
|
|
typedef struct __sFILE __FILE;
|
|
|
|
#endif /* __LARGE64_FILES */
|
2007-02-02 00:33:05 +08:00
|
|
|
#endif /* !__CUSTOM_FILE_IO__ */
|
2002-07-18 07:25:44 +08:00
|
|
|
|
2022-05-02 15:25:44 +08:00
|
|
|
extern __FILE __sf[3];
|
|
|
|
|
2008-10-03 00:43:23 +08:00
|
|
|
struct _glue
|
2002-07-18 07:25:44 +08:00
|
|
|
{
|
|
|
|
struct _glue *_next;
|
|
|
|
int _niobs;
|
|
|
|
__FILE *_iobs;
|
|
|
|
};
|
|
|
|
|
2022-05-02 14:58:25 +08:00
|
|
|
extern struct _glue __sglue;
|
|
|
|
|
2001-02-14 Kazuhiro Fujieda <fujieda@jaist.ac.jp>
* libc/include/stdlib.h: Add declarations of rand48 functions and
their reentrant versions.
* libc/include/sys/reent.h: Move macros from rand48.h. Add
struct _rand48 for shared parameters of rand48 functions.
(struct _reent): Add a variable _r48 of struct _rand48.
(_REENT_INIT): Add _r48 initialization.
* libc/stdlib/Makefile.am (lib_a_SOURCES): Add rand48 functions.
(CHEWOUT_FILES): Add rand48.def.
* libc/stdlib/Makefile.am: Add dependencies for rand48 functions.
* libc/stdlib/Makefile.in: Regenerated.
* libc/stdlib/drand48.c (drand48, _drand48_r): Derived from the
NetBSD C library.
* libc/stdlib/erand48.c (erand48, _erand48_r): Ditto.
* libc/stdlib/jrand48.c (jrand48, _jrand48_r): Ditto.
* libc/stdlib/lcong48.c (lcong48, _lcong48_r): Ditto.
* libc/stdlib/lrand48.c (lrand48, _lrand48_r): Ditto.
* libc/stdlib/mrand48.c (mrand48, _mrand48_r): Ditto.
* libc/stdlib/nrand48.c (nrand48, _nrand48_r): Ditto.
* libc/stdlib/seed48.c (seed48, _seed48_r): Ditto.
* libc/stdlib/srand48.c (srand48, _srand48_r): Ditto.
* libc/stdlib/rand48.c (__dorand48): Ditto.
* libc/stdlib/rand48.h: Ditto, and modify declarations of global
parameters into macros referring them in the reentrant structure.
2001-02-15 10:04:55 +08:00
|
|
|
/*
|
|
|
|
* rand48 family support
|
|
|
|
*
|
|
|
|
* Copyright (c) 1993 Martin Birgmeier
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* You may redistribute unmodified or modified versions of this source
|
|
|
|
* code provided that the above copyright notice and this and the
|
|
|
|
* following conditions are retained.
|
|
|
|
*
|
|
|
|
* This software is provided ``as is'', and comes with no warranties
|
|
|
|
* of any kind. I shall in no event be liable for anything that happens
|
|
|
|
* to anyone/anything when using this software.
|
|
|
|
*/
|
|
|
|
#define _RAND48_SEED_0 (0x330e)
|
|
|
|
#define _RAND48_SEED_1 (0xabcd)
|
|
|
|
#define _RAND48_SEED_2 (0x1234)
|
|
|
|
#define _RAND48_MULT_0 (0xe66d)
|
|
|
|
#define _RAND48_MULT_1 (0xdeec)
|
|
|
|
#define _RAND48_MULT_2 (0x0005)
|
|
|
|
#define _RAND48_ADD (0x000b)
|
|
|
|
struct _rand48 {
|
|
|
|
unsigned short _seed[3];
|
|
|
|
unsigned short _mult[3];
|
|
|
|
unsigned short _add;
|
2002-02-03 17:24:18 +08:00
|
|
|
#ifdef _REENT_SMALL
|
|
|
|
/* Put this in here as well, for good luck. */
|
|
|
|
__extension__ unsigned long long _rand_next;
|
|
|
|
#endif
|
2001-02-14 Kazuhiro Fujieda <fujieda@jaist.ac.jp>
* libc/include/stdlib.h: Add declarations of rand48 functions and
their reentrant versions.
* libc/include/sys/reent.h: Move macros from rand48.h. Add
struct _rand48 for shared parameters of rand48 functions.
(struct _reent): Add a variable _r48 of struct _rand48.
(_REENT_INIT): Add _r48 initialization.
* libc/stdlib/Makefile.am (lib_a_SOURCES): Add rand48 functions.
(CHEWOUT_FILES): Add rand48.def.
* libc/stdlib/Makefile.am: Add dependencies for rand48 functions.
* libc/stdlib/Makefile.in: Regenerated.
* libc/stdlib/drand48.c (drand48, _drand48_r): Derived from the
NetBSD C library.
* libc/stdlib/erand48.c (erand48, _erand48_r): Ditto.
* libc/stdlib/jrand48.c (jrand48, _jrand48_r): Ditto.
* libc/stdlib/lcong48.c (lcong48, _lcong48_r): Ditto.
* libc/stdlib/lrand48.c (lrand48, _lrand48_r): Ditto.
* libc/stdlib/mrand48.c (mrand48, _mrand48_r): Ditto.
* libc/stdlib/nrand48.c (nrand48, _nrand48_r): Ditto.
* libc/stdlib/seed48.c (seed48, _seed48_r): Ditto.
* libc/stdlib/srand48.c (srand48, _srand48_r): Ditto.
* libc/stdlib/rand48.c (__dorand48): Ditto.
* libc/stdlib/rand48.h: Ditto, and modify declarations of global
parameters into macros referring them in the reentrant structure.
2001-02-15 10:04:55 +08:00
|
|
|
};
|
|
|
|
|
2002-02-03 17:24:18 +08:00
|
|
|
/* How big the some arrays are. */
|
|
|
|
#define _REENT_EMERGENCY_SIZE 25
|
|
|
|
#define _REENT_ASCTIME_SIZE 26
|
2002-06-06 04:58:59 +08:00
|
|
|
#define _REENT_SIGNAL_SIZE 24
|
2002-02-03 17:24:18 +08:00
|
|
|
|
Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store
thread-specific data. This object is returned by __getreent() if the
__DYNAMIC_REENT__ Newlib configuration option is defined.
The reentrancy structure contains for example errno and the standard input,
output, and error file streams. This means that if an application only uses
errno it has a dependency on the file stream support even if it does not use
it. This is an issue for lower end targets and applications which need to
qualify the software according to safety standards (for example ECSS-E-ST-40C,
ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333).
If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct
_reent is replaced by dedicated thread-local objects for each struct _reent
member. The thread-local objects are defined in translation units which use
the corresponding object.
2022-05-16 17:51:54 +08:00
|
|
|
#ifndef _REENT_THREAD_LOCAL
|
|
|
|
|
2022-05-13 20:40:07 +08:00
|
|
|
#ifdef _REENT_BACKWARD_BINARY_COMPAT
|
|
|
|
#define _REENT_INIT_RESERVED_0 0,
|
2022-05-13 20:53:13 +08:00
|
|
|
#define _REENT_INIT_RESERVED_1 0,
|
2022-05-13 21:21:34 +08:00
|
|
|
#define _REENT_INIT_RESERVED_2 0,
|
2022-05-13 19:44:13 +08:00
|
|
|
#define _REENT_INIT_RESERVED_6_7 _NULL, _ATEXIT_INIT,
|
Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722090fffd10869dbb15b879651c1370d in 2017. Since then it was enabled by
default for RTEMS. Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.
In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr. If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively. There are at least three problems with this:
(1) The thread-specific FILE objects are closed by _reclaim_reent(). This
leads to problems with language run-time libraries that provide wrappers to
the C/POSIX stdio streams (for example C++ and Ada), since they use the
thread-specific FILE objects of the initialization thread. In case the
initialization thread is deleted, then they use freed memory.
(2) Since thread-specific FILE objects are used with a common output device via
file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
atomicity of the output, e.g. a call to printf().
(3) There are resource managment issues, see:
https://sourceware.org/pipermail/newlib/2022/019558.html
https://bugs.linaro.org/show_bug.cgi?id=5841
This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option. This removes a couple of #ifdef blocks.
2022-05-18 00:28:52 +08:00
|
|
|
#define _REENT_INIT_RESERVED_8 {_NULL, 0, _NULL},
|
2022-05-13 20:40:07 +08:00
|
|
|
#else
|
|
|
|
#define _REENT_INIT_RESERVED_0 /* Nothing to initialize */
|
2022-05-13 20:53:13 +08:00
|
|
|
#define _REENT_INIT_RESERVED_1 /* Nothing to initialize */
|
2022-05-13 21:21:34 +08:00
|
|
|
#define _REENT_INIT_RESERVED_2 /* Nothing to initialize */
|
2022-05-13 19:44:13 +08:00
|
|
|
#define _REENT_INIT_RESERVED_6_7 /* Nothing to initialize */
|
Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722090fffd10869dbb15b879651c1370d in 2017. Since then it was enabled by
default for RTEMS. Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.
In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr. If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively. There are at least three problems with this:
(1) The thread-specific FILE objects are closed by _reclaim_reent(). This
leads to problems with language run-time libraries that provide wrappers to
the C/POSIX stdio streams (for example C++ and Ada), since they use the
thread-specific FILE objects of the initialization thread. In case the
initialization thread is deleted, then they use freed memory.
(2) Since thread-specific FILE objects are used with a common output device via
file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
atomicity of the output, e.g. a call to printf().
(3) There are resource managment issues, see:
https://sourceware.org/pipermail/newlib/2022/019558.html
https://bugs.linaro.org/show_bug.cgi?id=5841
This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option. This removes a couple of #ifdef blocks.
2022-05-18 00:28:52 +08:00
|
|
|
#define _REENT_INIT_RESERVED_8 /* Nothing to initialize */
|
2022-05-13 20:40:07 +08:00
|
|
|
#endif
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
* struct _reent
|
|
|
|
*
|
2022-06-08 16:41:05 +08:00
|
|
|
* This structure contains the thread-local objects needed by the library.
|
2000-02-18 03:39:52 +08:00
|
|
|
* It's raison d'etre is to facilitate threads by making all library routines
|
2022-06-08 16:41:05 +08:00
|
|
|
* reentrant. The exit handler support and FILE maintenance use dedicated
|
|
|
|
* global objects which are not included in this structure.
|
2000-02-18 03:39:52 +08:00
|
|
|
*/
|
|
|
|
|
2002-02-03 17:24:18 +08:00
|
|
|
#ifdef _REENT_SMALL
|
|
|
|
|
|
|
|
struct _mprec
|
|
|
|
{
|
|
|
|
/* used by mprec routines */
|
|
|
|
struct _Bigint *_result;
|
|
|
|
int _result_k;
|
|
|
|
struct _Bigint *_p5s;
|
|
|
|
struct _Bigint **_freelist;
|
|
|
|
};
|
|
|
|
|
2002-04-02 07:06:21 +08:00
|
|
|
|
|
|
|
struct _misc_reent
|
|
|
|
{
|
|
|
|
/* miscellaneous reentrant data */
|
|
|
|
char *_strtok_last;
|
2002-08-23 09:56:05 +08:00
|
|
|
_mbstate_t _mblen_state;
|
|
|
|
_mbstate_t _wctomb_state;
|
|
|
|
_mbstate_t _mbtowc_state;
|
2002-05-07 04:44:54 +08:00
|
|
|
char _l64a_buf[8];
|
2002-06-21 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/math.h: Add <sys/types.h> to get _uint32_t definition.
* libc/include/machine/types.h: Skip __off_t, __pid_t, and
__loff_t definitions if special _HAVE_SYSTYPES macro defined.
* libc/include/sys/config.h: Removed _uint*, _int* definitions.
* libc/include/sys/param.h: Remove i386 case which is handled
by default case.
(BIG_ENDIAN, LITTLE_ENDIAN): Protect
definitions in case they are already defined.
(BYTE_ORDER): Add default case using _IEEE_BIG_ENDIAN and
_IEEE_LITTLE_ENDIAN flags.
* libc/include/sys/reent.h: Change __uint32_t references to
use _ULong instead.
(_REENT_GETDATE_REENT_P): New macro.
* libc/include/sys/types.h (__int16_t, __uint16_t): Added.
(__int32_t, __uint32_t, __int64_t, __uint64_t): Ditto.
* libc/search/hash.h: Add default setting of BYTE_ORDER,
LITTLE_ENDIAN, and BIG_ENDIAN, if not already defined.
* libc/sys/linux/sys/types.h: Include <sys/_types.h>. Define
ssize_t based on _ssize_t. Remove __socklen_t, __uintptr_t,
pid_t, off_t, loff_t, caddr_t, and daddr_t type
definitions which are done by subsequent glibc headers.
Add macro definitions to prevent subsequent header files from
defining pid_t, off_t, ssize_t, and key_t. Move uintptr_t and
intptr_t to after glibc definitions of types they are based on.
2002-06-22 02:15:56 +08:00
|
|
|
int _getdate_err;
|
2002-09-10 05:42:14 +08:00
|
|
|
_mbstate_t _mbrlen_state;
|
|
|
|
_mbstate_t _mbrtowc_state;
|
|
|
|
_mbstate_t _mbsrtowcs_state;
|
|
|
|
_mbstate_t _wcrtomb_state;
|
|
|
|
_mbstate_t _wcsrtombs_state;
|
2002-04-02 07:06:21 +08:00
|
|
|
};
|
|
|
|
|
2013-07-03 03:26:20 +08:00
|
|
|
/* This version of _reent is laid out with "int"s in pairs, to help
|
2002-02-03 17:24:18 +08:00
|
|
|
* ports with 16-bit int's but 32-bit pointers, align nicely. */
|
|
|
|
struct _reent
|
|
|
|
{
|
2010-06-09 23:15:35 +08:00
|
|
|
/* As an exception to the above put _errno first for binary
|
|
|
|
compatibility with non _REENT_SMALL targets. */
|
|
|
|
int _errno; /* local copy of errno */
|
2002-02-03 17:24:18 +08:00
|
|
|
|
|
|
|
/* FILE is a big struct and may change over time. To try to achieve binary
|
|
|
|
compatibility with future versions, put stdin,stdout,stderr here.
|
|
|
|
These are pointers into member __sf defined below. */
|
2002-07-18 07:25:44 +08:00
|
|
|
__FILE *_stdin, *_stdout, *_stderr; /* XXX */
|
2002-02-03 17:24:18 +08:00
|
|
|
|
|
|
|
int _inc; /* used by tmpnam */
|
|
|
|
|
|
|
|
char *_emergency;
|
2008-10-03 00:43:23 +08:00
|
|
|
|
2022-05-13 20:40:07 +08:00
|
|
|
#ifdef _REENT_BACKWARD_BINARY_COMPAT
|
|
|
|
int _reserved_0;
|
2022-05-13 20:53:13 +08:00
|
|
|
int _reserved_1;
|
2022-05-13 20:40:07 +08:00
|
|
|
#endif
|
2016-07-22 02:49:42 +08:00
|
|
|
struct __locale_t *_locale;/* per-thread locale */
|
2002-02-03 17:24:18 +08:00
|
|
|
|
|
|
|
struct _mprec *_mp;
|
|
|
|
|
2017-12-04 12:52:13 +08:00
|
|
|
void (*__cleanup) (struct _reent *);
|
2002-02-03 17:24:18 +08:00
|
|
|
|
|
|
|
int _gamma_signgam;
|
|
|
|
|
|
|
|
/* used by some fp conversion routines */
|
|
|
|
int _cvtlen; /* should be size_t */
|
|
|
|
char *_cvtbuf;
|
|
|
|
|
|
|
|
struct _rand48 *_r48;
|
|
|
|
struct __tm *_localtime_buf;
|
|
|
|
char *_asctime_buf;
|
|
|
|
|
|
|
|
/* signal info */
|
2022-05-18 18:03:18 +08:00
|
|
|
void (** _sig_func)(int);
|
2002-02-03 17:24:18 +08:00
|
|
|
|
2022-05-13 19:44:13 +08:00
|
|
|
#ifdef _REENT_BACKWARD_BINARY_COMPAT
|
|
|
|
struct _atexit *_reserved_6;
|
|
|
|
struct _atexit _reserved_7;
|
Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722090fffd10869dbb15b879651c1370d in 2017. Since then it was enabled by
default for RTEMS. Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.
In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr. If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively. There are at least three problems with this:
(1) The thread-specific FILE objects are closed by _reclaim_reent(). This
leads to problems with language run-time libraries that provide wrappers to
the C/POSIX stdio streams (for example C++ and Ada), since they use the
thread-specific FILE objects of the initialization thread. In case the
initialization thread is deleted, then they use freed memory.
(2) Since thread-specific FILE objects are used with a common output device via
file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
atomicity of the output, e.g. a call to printf().
(3) There are resource managment issues, see:
https://sourceware.org/pipermail/newlib/2022/019558.html
https://bugs.linaro.org/show_bug.cgi?id=5841
This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option. This removes a couple of #ifdef blocks.
2022-05-18 00:28:52 +08:00
|
|
|
struct _glue _reserved_8;
|
2022-05-13 19:44:13 +08:00
|
|
|
#endif
|
2002-02-03 17:24:18 +08:00
|
|
|
|
2002-07-18 07:25:44 +08:00
|
|
|
__FILE *__sf; /* file descriptors */
|
2002-04-02 07:06:21 +08:00
|
|
|
struct _misc_reent *_misc; /* strtok, multibyte states */
|
2002-06-06 04:58:59 +08:00
|
|
|
char *_signal_buf; /* strsignal */
|
2002-02-03 17:24:18 +08:00
|
|
|
};
|
|
|
|
|
2018-02-28 20:31:48 +08:00
|
|
|
# define _REENT_INIT(var) \
|
|
|
|
{ 0, \
|
|
|
|
&__sf[0], \
|
|
|
|
&__sf[1], \
|
|
|
|
&__sf[2], \
|
|
|
|
0, \
|
|
|
|
_NULL, \
|
2022-05-13 20:40:07 +08:00
|
|
|
_REENT_INIT_RESERVED_0 \
|
2022-05-13 20:53:13 +08:00
|
|
|
_REENT_INIT_RESERVED_1 \
|
2018-02-28 20:31:48 +08:00
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
|
|
|
0, \
|
|
|
|
0, \
|
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
2022-05-13 19:44:13 +08:00
|
|
|
_REENT_INIT_RESERVED_6_7 \
|
Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722090fffd10869dbb15b879651c1370d in 2017. Since then it was enabled by
default for RTEMS. Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.
In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr. If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively. There are at least three problems with this:
(1) The thread-specific FILE objects are closed by _reclaim_reent(). This
leads to problems with language run-time libraries that provide wrappers to
the C/POSIX stdio streams (for example C++ and Ada), since they use the
thread-specific FILE objects of the initialization thread. In case the
initialization thread is deleted, then they use freed memory.
(2) Since thread-specific FILE objects are used with a common output device via
file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
atomicity of the output, e.g. a call to printf().
(3) There are resource managment issues, see:
https://sourceware.org/pipermail/newlib/2022/019558.html
https://bugs.linaro.org/show_bug.cgi?id=5841
This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option. This removes a couple of #ifdef blocks.
2022-05-18 00:28:52 +08:00
|
|
|
_REENT_INIT_RESERVED_8 \
|
2018-02-28 20:31:48 +08:00
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
|
|
|
_NULL \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _REENT_INIT_PTR_ZEROED(var) \
|
|
|
|
{ (var)->_stdin = &__sf[0]; \
|
|
|
|
(var)->_stdout = &__sf[1]; \
|
|
|
|
(var)->_stderr = &__sf[2]; \
|
|
|
|
}
|
|
|
|
|
2019-10-08 03:29:33 +08:00
|
|
|
/* Specify how to handle reent_check malloc failures. */
|
|
|
|
#ifdef _REENT_CHECK_VERIFY
|
2002-02-03 17:24:18 +08:00
|
|
|
#include <assert.h>
|
2019-10-08 03:29:33 +08:00
|
|
|
#define __reent_assert(x) ((x) ? (void)0 : __assert_func(__FILE__, __LINE__, (char *)0, "REENT malloc succeeded"))
|
2002-02-03 17:24:18 +08:00
|
|
|
#else
|
2006-09-23 03:33:11 +08:00
|
|
|
#define __reent_assert(x) ((void)0)
|
2002-02-03 17:24:18 +08:00
|
|
|
#endif
|
|
|
|
|
2007-02-02 00:33:05 +08:00
|
|
|
#ifdef __CUSTOM_FILE_IO__
|
|
|
|
#error Custom FILE I/O and _REENT_SMALL not currently supported.
|
|
|
|
#endif
|
|
|
|
|
2002-02-03 17:24:18 +08:00
|
|
|
/* Generic _REENT check macro. */
|
|
|
|
#define _REENT_CHECK(var, what, type, size, init) do { \
|
|
|
|
struct _reent *_r = (var); \
|
|
|
|
if (_r->what == NULL) { \
|
|
|
|
_r->what = (type)malloc(size); \
|
2006-09-23 03:33:11 +08:00
|
|
|
__reent_assert(_r->what); \
|
2002-02-03 17:24:18 +08:00
|
|
|
init; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define _REENT_CHECK_TM(var) \
|
|
|
|
_REENT_CHECK(var, _localtime_buf, struct __tm *, sizeof *((var)->_localtime_buf), \
|
|
|
|
/* nothing */)
|
|
|
|
|
|
|
|
#define _REENT_CHECK_ASCTIME_BUF(var) \
|
|
|
|
_REENT_CHECK(var, _asctime_buf, char *, _REENT_ASCTIME_SIZE, \
|
|
|
|
memset((var)->_asctime_buf, 0, _REENT_ASCTIME_SIZE))
|
|
|
|
|
|
|
|
/* Handle the dynamically allocated rand48 structure. */
|
|
|
|
#define _REENT_INIT_RAND48(var) do { \
|
|
|
|
struct _reent *_r = (var); \
|
|
|
|
_r->_r48->_seed[0] = _RAND48_SEED_0; \
|
|
|
|
_r->_r48->_seed[1] = _RAND48_SEED_1; \
|
|
|
|
_r->_r48->_seed[2] = _RAND48_SEED_2; \
|
|
|
|
_r->_r48->_mult[0] = _RAND48_MULT_0; \
|
|
|
|
_r->_r48->_mult[1] = _RAND48_MULT_1; \
|
|
|
|
_r->_r48->_mult[2] = _RAND48_MULT_2; \
|
|
|
|
_r->_r48->_add = _RAND48_ADD; \
|
2008-10-03 00:43:23 +08:00
|
|
|
_r->_r48->_rand_next = 1; \
|
2002-02-03 17:24:18 +08:00
|
|
|
} while (0)
|
|
|
|
#define _REENT_CHECK_RAND48(var) \
|
|
|
|
_REENT_CHECK(var, _r48, struct _rand48 *, sizeof *((var)->_r48), _REENT_INIT_RAND48((var)))
|
|
|
|
|
|
|
|
#define _REENT_INIT_MP(var) do { \
|
|
|
|
struct _reent *_r = (var); \
|
|
|
|
_r->_mp->_result_k = 0; \
|
|
|
|
_r->_mp->_result = _r->_mp->_p5s = _NULL; \
|
|
|
|
_r->_mp->_freelist = _NULL; \
|
|
|
|
} while (0)
|
|
|
|
#define _REENT_CHECK_MP(var) \
|
|
|
|
_REENT_CHECK(var, _mp, struct _mprec *, sizeof *((var)->_mp), _REENT_INIT_MP(var))
|
|
|
|
|
|
|
|
#define _REENT_CHECK_EMERGENCY(var) \
|
2002-02-09 21:01:46 +08:00
|
|
|
_REENT_CHECK(var, _emergency, char *, _REENT_EMERGENCY_SIZE, /* nothing */)
|
2002-02-03 17:24:18 +08:00
|
|
|
|
2002-04-02 07:06:21 +08:00
|
|
|
#define _REENT_INIT_MISC(var) do { \
|
|
|
|
struct _reent *_r = (var); \
|
|
|
|
_r->_misc->_strtok_last = _NULL; \
|
2002-08-23 09:56:05 +08:00
|
|
|
_r->_misc->_mblen_state.__count = 0; \
|
|
|
|
_r->_misc->_mblen_state.__value.__wch = 0; \
|
|
|
|
_r->_misc->_wctomb_state.__count = 0; \
|
|
|
|
_r->_misc->_wctomb_state.__value.__wch = 0; \
|
|
|
|
_r->_misc->_mbtowc_state.__count = 0; \
|
|
|
|
_r->_misc->_mbtowc_state.__value.__wch = 0; \
|
2002-09-10 05:42:14 +08:00
|
|
|
_r->_misc->_mbrlen_state.__count = 0; \
|
|
|
|
_r->_misc->_mbrlen_state.__value.__wch = 0; \
|
|
|
|
_r->_misc->_mbrtowc_state.__count = 0; \
|
|
|
|
_r->_misc->_mbrtowc_state.__value.__wch = 0; \
|
|
|
|
_r->_misc->_mbsrtowcs_state.__count = 0; \
|
|
|
|
_r->_misc->_mbsrtowcs_state.__value.__wch = 0; \
|
|
|
|
_r->_misc->_wcrtomb_state.__count = 0; \
|
|
|
|
_r->_misc->_wcrtomb_state.__value.__wch = 0; \
|
|
|
|
_r->_misc->_wcsrtombs_state.__count = 0; \
|
|
|
|
_r->_misc->_wcsrtombs_state.__value.__wch = 0; \
|
2002-05-07 04:44:54 +08:00
|
|
|
_r->_misc->_l64a_buf[0] = '\0'; \
|
2002-06-21 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/math.h: Add <sys/types.h> to get _uint32_t definition.
* libc/include/machine/types.h: Skip __off_t, __pid_t, and
__loff_t definitions if special _HAVE_SYSTYPES macro defined.
* libc/include/sys/config.h: Removed _uint*, _int* definitions.
* libc/include/sys/param.h: Remove i386 case which is handled
by default case.
(BIG_ENDIAN, LITTLE_ENDIAN): Protect
definitions in case they are already defined.
(BYTE_ORDER): Add default case using _IEEE_BIG_ENDIAN and
_IEEE_LITTLE_ENDIAN flags.
* libc/include/sys/reent.h: Change __uint32_t references to
use _ULong instead.
(_REENT_GETDATE_REENT_P): New macro.
* libc/include/sys/types.h (__int16_t, __uint16_t): Added.
(__int32_t, __uint32_t, __int64_t, __uint64_t): Ditto.
* libc/search/hash.h: Add default setting of BYTE_ORDER,
LITTLE_ENDIAN, and BIG_ENDIAN, if not already defined.
* libc/sys/linux/sys/types.h: Include <sys/_types.h>. Define
ssize_t based on _ssize_t. Remove __socklen_t, __uintptr_t,
pid_t, off_t, loff_t, caddr_t, and daddr_t type
definitions which are done by subsequent glibc headers.
Add macro definitions to prevent subsequent header files from
defining pid_t, off_t, ssize_t, and key_t. Move uintptr_t and
intptr_t to after glibc definitions of types they are based on.
2002-06-22 02:15:56 +08:00
|
|
|
_r->_misc->_getdate_err = 0; \
|
2002-04-02 07:06:21 +08:00
|
|
|
} while (0)
|
|
|
|
#define _REENT_CHECK_MISC(var) \
|
|
|
|
_REENT_CHECK(var, _misc, struct _misc_reent *, sizeof *((var)->_misc), _REENT_INIT_MISC(var))
|
|
|
|
|
2002-06-06 04:58:59 +08:00
|
|
|
#define _REENT_CHECK_SIGNAL_BUF(var) \
|
|
|
|
_REENT_CHECK(var, _signal_buf, char *, _REENT_SIGNAL_SIZE, /* nothing */)
|
|
|
|
|
2002-02-03 17:24:18 +08:00
|
|
|
#define _REENT_SIGNGAM(ptr) ((ptr)->_gamma_signgam)
|
|
|
|
#define _REENT_RAND_NEXT(ptr) ((ptr)->_r48->_rand_next)
|
|
|
|
#define _REENT_RAND48_SEED(ptr) ((ptr)->_r48->_seed)
|
|
|
|
#define _REENT_RAND48_MULT(ptr) ((ptr)->_r48->_mult)
|
|
|
|
#define _REENT_RAND48_ADD(ptr) ((ptr)->_r48->_add)
|
|
|
|
#define _REENT_MP_RESULT(ptr) ((ptr)->_mp->_result)
|
|
|
|
#define _REENT_MP_RESULT_K(ptr) ((ptr)->_mp->_result_k)
|
|
|
|
#define _REENT_MP_P5S(ptr) ((ptr)->_mp->_p5s)
|
|
|
|
#define _REENT_MP_FREELIST(ptr) ((ptr)->_mp->_freelist)
|
|
|
|
#define _REENT_ASCTIME_BUF(ptr) ((ptr)->_asctime_buf)
|
|
|
|
#define _REENT_TM(ptr) ((ptr)->_localtime_buf)
|
2002-04-02 07:06:21 +08:00
|
|
|
#define _REENT_STRTOK_LAST(ptr) ((ptr)->_misc->_strtok_last)
|
|
|
|
#define _REENT_MBLEN_STATE(ptr) ((ptr)->_misc->_mblen_state)
|
|
|
|
#define _REENT_MBTOWC_STATE(ptr)((ptr)->_misc->_mbtowc_state)
|
|
|
|
#define _REENT_WCTOMB_STATE(ptr)((ptr)->_misc->_wctomb_state)
|
2002-09-10 05:42:14 +08:00
|
|
|
#define _REENT_MBRLEN_STATE(ptr) ((ptr)->_misc->_mbrlen_state)
|
|
|
|
#define _REENT_MBRTOWC_STATE(ptr) ((ptr)->_misc->_mbrtowc_state)
|
|
|
|
#define _REENT_MBSRTOWCS_STATE(ptr) ((ptr)->_misc->_mbsrtowcs_state)
|
|
|
|
#define _REENT_WCRTOMB_STATE(ptr) ((ptr)->_misc->_wcrtomb_state)
|
|
|
|
#define _REENT_WCSRTOMBS_STATE(ptr) ((ptr)->_misc->_wcsrtombs_state)
|
2002-05-07 04:44:54 +08:00
|
|
|
#define _REENT_L64A_BUF(ptr) ((ptr)->_misc->_l64a_buf)
|
2002-06-21 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/math.h: Add <sys/types.h> to get _uint32_t definition.
* libc/include/machine/types.h: Skip __off_t, __pid_t, and
__loff_t definitions if special _HAVE_SYSTYPES macro defined.
* libc/include/sys/config.h: Removed _uint*, _int* definitions.
* libc/include/sys/param.h: Remove i386 case which is handled
by default case.
(BIG_ENDIAN, LITTLE_ENDIAN): Protect
definitions in case they are already defined.
(BYTE_ORDER): Add default case using _IEEE_BIG_ENDIAN and
_IEEE_LITTLE_ENDIAN flags.
* libc/include/sys/reent.h: Change __uint32_t references to
use _ULong instead.
(_REENT_GETDATE_REENT_P): New macro.
* libc/include/sys/types.h (__int16_t, __uint16_t): Added.
(__int32_t, __uint32_t, __int64_t, __uint64_t): Ditto.
* libc/search/hash.h: Add default setting of BYTE_ORDER,
LITTLE_ENDIAN, and BIG_ENDIAN, if not already defined.
* libc/sys/linux/sys/types.h: Include <sys/_types.h>. Define
ssize_t based on _ssize_t. Remove __socklen_t, __uintptr_t,
pid_t, off_t, loff_t, caddr_t, and daddr_t type
definitions which are done by subsequent glibc headers.
Add macro definitions to prevent subsequent header files from
defining pid_t, off_t, ssize_t, and key_t. Move uintptr_t and
intptr_t to after glibc definitions of types they are based on.
2002-06-22 02:15:56 +08:00
|
|
|
#define _REENT_GETDATE_ERR_P(ptr) (&((ptr)->_misc->_getdate_err))
|
2002-06-06 04:58:59 +08:00
|
|
|
#define _REENT_SIGNAL_BUF(ptr) ((ptr)->_signal_buf)
|
2002-02-03 17:24:18 +08:00
|
|
|
|
|
|
|
#else /* !_REENT_SMALL */
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
struct _reent
|
|
|
|
{
|
2002-02-03 17:24:18 +08:00
|
|
|
int _errno; /* local copy of errno */
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/* FILE is a big struct and may change over time. To try to achieve binary
|
|
|
|
compatibility with future versions, put stdin,stdout,stderr here.
|
|
|
|
These are pointers into member __sf defined below. */
|
2002-07-18 07:25:44 +08:00
|
|
|
__FILE *_stdin, *_stdout, *_stderr;
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
int _inc; /* used by tmpnam */
|
2002-02-03 17:24:18 +08:00
|
|
|
char _emergency[_REENT_EMERGENCY_SIZE];
|
2008-10-03 00:43:23 +08:00
|
|
|
|
2022-05-13 20:53:13 +08:00
|
|
|
#ifdef _REENT_BACKWARD_BINARY_COMPAT
|
|
|
|
int _reserved_1;
|
|
|
|
#endif
|
2016-07-22 02:49:42 +08:00
|
|
|
struct __locale_t *_locale;/* per-thread locale */
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2022-05-13 20:40:07 +08:00
|
|
|
#ifdef _REENT_BACKWARD_BINARY_COMPAT
|
|
|
|
int _reserved_0;
|
|
|
|
#endif
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2017-12-04 12:52:13 +08:00
|
|
|
void (*__cleanup) (struct _reent *);
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/* used by mprec routines */
|
|
|
|
struct _Bigint *_result;
|
|
|
|
int _result_k;
|
|
|
|
struct _Bigint *_p5s;
|
|
|
|
struct _Bigint **_freelist;
|
|
|
|
|
|
|
|
/* used by some fp conversion routines */
|
|
|
|
int _cvtlen; /* should be size_t */
|
|
|
|
char *_cvtbuf;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2022-05-13 21:21:34 +08:00
|
|
|
#ifdef _REENT_BACKWARD_BINARY_COMPAT
|
|
|
|
unsigned int _reserved_2;
|
|
|
|
#endif
|
2002-04-02 07:06:21 +08:00
|
|
|
char * _strtok_last;
|
2002-06-06 04:58:59 +08:00
|
|
|
char _asctime_buf[_REENT_ASCTIME_SIZE];
|
2001-08-30 03:47:43 +08:00
|
|
|
struct __tm _localtime_buf;
|
2000-02-18 03:39:52 +08:00
|
|
|
int _gamma_signgam;
|
2000-06-21 02:34:57 +08:00
|
|
|
__extension__ unsigned long long _rand_next;
|
2001-02-14 Kazuhiro Fujieda <fujieda@jaist.ac.jp>
* libc/include/stdlib.h: Add declarations of rand48 functions and
their reentrant versions.
* libc/include/sys/reent.h: Move macros from rand48.h. Add
struct _rand48 for shared parameters of rand48 functions.
(struct _reent): Add a variable _r48 of struct _rand48.
(_REENT_INIT): Add _r48 initialization.
* libc/stdlib/Makefile.am (lib_a_SOURCES): Add rand48 functions.
(CHEWOUT_FILES): Add rand48.def.
* libc/stdlib/Makefile.am: Add dependencies for rand48 functions.
* libc/stdlib/Makefile.in: Regenerated.
* libc/stdlib/drand48.c (drand48, _drand48_r): Derived from the
NetBSD C library.
* libc/stdlib/erand48.c (erand48, _erand48_r): Ditto.
* libc/stdlib/jrand48.c (jrand48, _jrand48_r): Ditto.
* libc/stdlib/lcong48.c (lcong48, _lcong48_r): Ditto.
* libc/stdlib/lrand48.c (lrand48, _lrand48_r): Ditto.
* libc/stdlib/mrand48.c (mrand48, _mrand48_r): Ditto.
* libc/stdlib/nrand48.c (nrand48, _nrand48_r): Ditto.
* libc/stdlib/seed48.c (seed48, _seed48_r): Ditto.
* libc/stdlib/srand48.c (srand48, _srand48_r): Ditto.
* libc/stdlib/rand48.c (__dorand48): Ditto.
* libc/stdlib/rand48.h: Ditto, and modify declarations of global
parameters into macros referring them in the reentrant structure.
2001-02-15 10:04:55 +08:00
|
|
|
struct _rand48 _r48;
|
2002-08-23 09:56:05 +08:00
|
|
|
_mbstate_t _mblen_state;
|
|
|
|
_mbstate_t _mbtowc_state;
|
|
|
|
_mbstate_t _wctomb_state;
|
2002-05-07 04:44:54 +08:00
|
|
|
char _l64a_buf[8];
|
2002-06-06 04:58:59 +08:00
|
|
|
char _signal_buf[_REENT_SIGNAL_SIZE];
|
2008-10-03 00:43:23 +08:00
|
|
|
int _getdate_err;
|
2002-09-10 05:42:14 +08:00
|
|
|
_mbstate_t _mbrlen_state;
|
|
|
|
_mbstate_t _mbrtowc_state;
|
|
|
|
_mbstate_t _mbsrtowcs_state;
|
|
|
|
_mbstate_t _wcrtomb_state;
|
|
|
|
_mbstate_t _wcsrtombs_state;
|
2008-05-23 05:30:28 +08:00
|
|
|
int _h_errno;
|
2023-08-16 04:30:59 +08:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
_mbstate_t _c8rtomb_state;
|
|
|
|
_mbstate_t _c16rtomb_state;
|
|
|
|
_mbstate_t _c32rtomb_state;
|
|
|
|
_mbstate_t _mbrtoc8_state;
|
|
|
|
_mbstate_t _mbrtoc16_state;
|
|
|
|
_mbstate_t _mbrtoc32_state;
|
|
|
|
#endif
|
2000-02-18 03:39:52 +08:00
|
|
|
} _reent;
|
2022-05-13 20:56:24 +08:00
|
|
|
#ifdef _REENT_BACKWARD_BINARY_COMPAT
|
2000-02-18 03:39:52 +08:00
|
|
|
struct
|
|
|
|
{
|
2022-05-13 20:56:24 +08:00
|
|
|
unsigned char * _reserved_3[30];
|
|
|
|
unsigned int _reserved_4[30];
|
|
|
|
} _reserved_5;
|
|
|
|
#endif
|
2000-02-18 03:39:52 +08:00
|
|
|
} _new;
|
|
|
|
|
2022-05-13 19:44:13 +08:00
|
|
|
#ifdef _REENT_BACKWARD_BINARY_COMPAT
|
|
|
|
struct _atexit *_reserved_6;
|
|
|
|
struct _atexit _reserved_7;
|
|
|
|
#endif
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/* signal info */
|
2021-07-23 05:41:42 +08:00
|
|
|
void (**_sig_func)(int);
|
2000-02-18 03:39:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define _REENT_INIT(var) \
|
2004-06-12 04:37:10 +08:00
|
|
|
{ 0, \
|
Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722090fffd10869dbb15b879651c1370d in 2017. Since then it was enabled by
default for RTEMS. Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.
In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr. If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively. There are at least three problems with this:
(1) The thread-specific FILE objects are closed by _reclaim_reent(). This
leads to problems with language run-time libraries that provide wrappers to
the C/POSIX stdio streams (for example C++ and Ada), since they use the
thread-specific FILE objects of the initialization thread. In case the
initialization thread is deleted, then they use freed memory.
(2) Since thread-specific FILE objects are used with a common output device via
file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
atomicity of the output, e.g. a call to printf().
(3) There are resource managment issues, see:
https://sourceware.org/pipermail/newlib/2022/019558.html
https://bugs.linaro.org/show_bug.cgi?id=5841
This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option. This removes a couple of #ifdef blocks.
2022-05-18 00:28:52 +08:00
|
|
|
&__sf[0], \
|
|
|
|
&__sf[1], \
|
|
|
|
&__sf[2], \
|
2004-06-12 04:37:10 +08:00
|
|
|
0, \
|
|
|
|
"", \
|
2022-05-13 20:53:13 +08:00
|
|
|
_REENT_INIT_RESERVED_1 \
|
2016-07-26 21:42:04 +08:00
|
|
|
_NULL, \
|
2022-05-13 20:40:07 +08:00
|
|
|
_REENT_INIT_RESERVED_0 \
|
2004-06-12 04:37:10 +08:00
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
|
|
|
0, \
|
|
|
|
_NULL, \
|
|
|
|
_NULL, \
|
|
|
|
0, \
|
|
|
|
_NULL, \
|
|
|
|
{ \
|
|
|
|
{ \
|
2022-05-13 21:21:34 +08:00
|
|
|
_REENT_INIT_RESERVED_2 \
|
2004-06-12 04:37:10 +08:00
|
|
|
_NULL, \
|
|
|
|
"", \
|
|
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0}, \
|
|
|
|
0, \
|
|
|
|
1, \
|
|
|
|
{ \
|
|
|
|
{_RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2}, \
|
|
|
|
{_RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2}, \
|
|
|
|
_RAND48_ADD \
|
|
|
|
}, \
|
|
|
|
{0, {0}}, \
|
|
|
|
{0, {0}}, \
|
|
|
|
{0, {0}}, \
|
|
|
|
"", \
|
|
|
|
"", \
|
|
|
|
0, \
|
|
|
|
{0, {0}}, \
|
|
|
|
{0, {0}}, \
|
|
|
|
{0, {0}}, \
|
|
|
|
{0, {0}}, \
|
|
|
|
{0, {0}} \
|
|
|
|
} \
|
|
|
|
}, \
|
2022-05-13 19:44:13 +08:00
|
|
|
_REENT_INIT_RESERVED_6_7 \
|
2022-05-02 15:00:12 +08:00
|
|
|
_NULL \
|
2004-06-12 04:37:10 +08:00
|
|
|
}
|
2002-04-02 07:06:21 +08:00
|
|
|
|
2015-12-14 16:57:54 +08:00
|
|
|
#define _REENT_INIT_PTR_ZEROED(var) \
|
Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722090fffd10869dbb15b879651c1370d in 2017. Since then it was enabled by
default for RTEMS. Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.
In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr. If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively. There are at least three problems with this:
(1) The thread-specific FILE objects are closed by _reclaim_reent(). This
leads to problems with language run-time libraries that provide wrappers to
the C/POSIX stdio streams (for example C++ and Ada), since they use the
thread-specific FILE objects of the initialization thread. In case the
initialization thread is deleted, then they use freed memory.
(2) Since thread-specific FILE objects are used with a common output device via
file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
atomicity of the output, e.g. a call to printf().
(3) There are resource managment issues, see:
https://sourceware.org/pipermail/newlib/2022/019558.html
https://bugs.linaro.org/show_bug.cgi?id=5841
This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option. This removes a couple of #ifdef blocks.
2022-05-18 00:28:52 +08:00
|
|
|
{ (var)->_stdin = &__sf[0]; \
|
|
|
|
(var)->_stdout = &__sf[1]; \
|
|
|
|
(var)->_stderr = &__sf[2]; \
|
2008-05-15 06:09:10 +08:00
|
|
|
(var)->_new._reent._rand_next = 1; \
|
|
|
|
(var)->_new._reent._r48._seed[0] = _RAND48_SEED_0; \
|
|
|
|
(var)->_new._reent._r48._seed[1] = _RAND48_SEED_1; \
|
|
|
|
(var)->_new._reent._r48._seed[2] = _RAND48_SEED_2; \
|
|
|
|
(var)->_new._reent._r48._mult[0] = _RAND48_MULT_0; \
|
|
|
|
(var)->_new._reent._r48._mult[1] = _RAND48_MULT_1; \
|
|
|
|
(var)->_new._reent._r48._mult[2] = _RAND48_MULT_2; \
|
|
|
|
(var)->_new._reent._r48._add = _RAND48_ADD; \
|
2002-04-02 07:06:21 +08:00
|
|
|
}
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2002-02-03 17:24:18 +08:00
|
|
|
#define _REENT_CHECK_RAND48(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_MP(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_TM(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_ASCTIME_BUF(ptr) /* nothing */
|
2002-02-05 02:38:44 +08:00
|
|
|
#define _REENT_CHECK_EMERGENCY(ptr) /* nothing */
|
2002-04-02 07:06:21 +08:00
|
|
|
#define _REENT_CHECK_MISC(ptr) /* nothing */
|
2002-06-06 04:58:59 +08:00
|
|
|
#define _REENT_CHECK_SIGNAL_BUF(ptr) /* nothing */
|
2002-02-03 17:24:18 +08:00
|
|
|
|
|
|
|
#define _REENT_SIGNGAM(ptr) ((ptr)->_new._reent._gamma_signgam)
|
|
|
|
#define _REENT_RAND_NEXT(ptr) ((ptr)->_new._reent._rand_next)
|
|
|
|
#define _REENT_RAND48_SEED(ptr) ((ptr)->_new._reent._r48._seed)
|
|
|
|
#define _REENT_RAND48_MULT(ptr) ((ptr)->_new._reent._r48._mult)
|
|
|
|
#define _REENT_RAND48_ADD(ptr) ((ptr)->_new._reent._r48._add)
|
|
|
|
#define _REENT_MP_RESULT(ptr) ((ptr)->_result)
|
|
|
|
#define _REENT_MP_RESULT_K(ptr) ((ptr)->_result_k)
|
|
|
|
#define _REENT_MP_P5S(ptr) ((ptr)->_p5s)
|
|
|
|
#define _REENT_MP_FREELIST(ptr) ((ptr)->_freelist)
|
2004-01-09 03:33:13 +08:00
|
|
|
#define _REENT_ASCTIME_BUF(ptr) ((ptr)->_new._reent._asctime_buf)
|
2002-02-03 17:24:18 +08:00
|
|
|
#define _REENT_TM(ptr) (&(ptr)->_new._reent._localtime_buf)
|
2002-04-02 07:06:21 +08:00
|
|
|
#define _REENT_STRTOK_LAST(ptr) ((ptr)->_new._reent._strtok_last)
|
|
|
|
#define _REENT_MBLEN_STATE(ptr) ((ptr)->_new._reent._mblen_state)
|
|
|
|
#define _REENT_MBTOWC_STATE(ptr)((ptr)->_new._reent._mbtowc_state)
|
|
|
|
#define _REENT_WCTOMB_STATE(ptr)((ptr)->_new._reent._wctomb_state)
|
2002-09-10 05:42:14 +08:00
|
|
|
#define _REENT_MBRLEN_STATE(ptr)((ptr)->_new._reent._mbrlen_state)
|
|
|
|
#define _REENT_MBRTOWC_STATE(ptr)((ptr)->_new._reent._mbrtowc_state)
|
|
|
|
#define _REENT_MBSRTOWCS_STATE(ptr)((ptr)->_new._reent._mbsrtowcs_state)
|
|
|
|
#define _REENT_WCRTOMB_STATE(ptr)((ptr)->_new._reent._wcrtomb_state)
|
|
|
|
#define _REENT_WCSRTOMBS_STATE(ptr)((ptr)->_new._reent._wcsrtombs_state)
|
2023-08-16 04:30:59 +08:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
# define _REENT_C8RTOMB_STATE(ptr)((ptr)->_new._reent._c8rtomb_state)
|
|
|
|
# define _REENT_C16RTOMB_STATE(ptr)((ptr)->_new._reent._c16rtomb_state)
|
|
|
|
# define _REENT_C32RTOMB_STATE(ptr)((ptr)->_new._reent._c32rtomb_state)
|
|
|
|
# define _REENT_MBRTOC8_STATE(ptr)((ptr)->_new._reent._mbrtoc8_state)
|
|
|
|
# define _REENT_MBRTOC16_STATE(ptr)((ptr)->_new._reent._mbrtoc16_state)
|
|
|
|
# define _REENT_MBRTOC32_STATE(ptr)((ptr)->_new._reent._mbrtoc32_state)
|
|
|
|
#endif
|
2002-05-07 04:44:54 +08:00
|
|
|
#define _REENT_L64A_BUF(ptr) ((ptr)->_new._reent._l64a_buf)
|
2002-06-06 04:58:59 +08:00
|
|
|
#define _REENT_SIGNAL_BUF(ptr) ((ptr)->_new._reent._signal_buf)
|
2002-06-21 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/math.h: Add <sys/types.h> to get _uint32_t definition.
* libc/include/machine/types.h: Skip __off_t, __pid_t, and
__loff_t definitions if special _HAVE_SYSTYPES macro defined.
* libc/include/sys/config.h: Removed _uint*, _int* definitions.
* libc/include/sys/param.h: Remove i386 case which is handled
by default case.
(BIG_ENDIAN, LITTLE_ENDIAN): Protect
definitions in case they are already defined.
(BYTE_ORDER): Add default case using _IEEE_BIG_ENDIAN and
_IEEE_LITTLE_ENDIAN flags.
* libc/include/sys/reent.h: Change __uint32_t references to
use _ULong instead.
(_REENT_GETDATE_REENT_P): New macro.
* libc/include/sys/types.h (__int16_t, __uint16_t): Added.
(__int32_t, __uint32_t, __int64_t, __uint64_t): Ditto.
* libc/search/hash.h: Add default setting of BYTE_ORDER,
LITTLE_ENDIAN, and BIG_ENDIAN, if not already defined.
* libc/sys/linux/sys/types.h: Include <sys/_types.h>. Define
ssize_t based on _ssize_t. Remove __socklen_t, __uintptr_t,
pid_t, off_t, loff_t, caddr_t, and daddr_t type
definitions which are done by subsequent glibc headers.
Add macro definitions to prevent subsequent header files from
defining pid_t, off_t, ssize_t, and key_t. Move uintptr_t and
intptr_t to after glibc definitions of types they are based on.
2002-06-22 02:15:56 +08:00
|
|
|
#define _REENT_GETDATE_ERR_P(ptr) (&((ptr)->_new._reent._getdate_err))
|
2002-02-03 17:24:18 +08:00
|
|
|
|
|
|
|
#endif /* !_REENT_SMALL */
|
|
|
|
|
2022-02-03 17:18:53 +08:00
|
|
|
#define _REENT_CLEANUP(_ptr) ((_ptr)->__cleanup)
|
2022-02-03 19:24:26 +08:00
|
|
|
#define _REENT_CVTBUF(_ptr) ((_ptr)->_cvtbuf)
|
2022-02-03 18:19:14 +08:00
|
|
|
#define _REENT_CVTLEN(_ptr) ((_ptr)->_cvtlen)
|
2022-05-16 16:54:31 +08:00
|
|
|
#define _REENT_EMERGENCY(_ptr) ((_ptr)->_emergency)
|
2022-01-18 17:13:04 +08:00
|
|
|
#define _REENT_ERRNO(_ptr) ((_ptr)->_errno)
|
2022-02-02 16:49:00 +08:00
|
|
|
#define _REENT_INC(_ptr) ((_ptr)->_inc)
|
2022-02-02 19:47:30 +08:00
|
|
|
#define _REENT_LOCALE(_ptr) ((_ptr)->_locale)
|
2022-02-04 18:47:18 +08:00
|
|
|
#define _REENT_SIG_FUNC(_ptr) ((_ptr)->_sig_func)
|
2022-01-28 17:58:36 +08:00
|
|
|
#define _REENT_STDIN(_ptr) ((_ptr)->_stdin)
|
2022-02-01 19:37:46 +08:00
|
|
|
#define _REENT_STDOUT(_ptr) ((_ptr)->_stdout)
|
2022-02-01 20:05:53 +08:00
|
|
|
#define _REENT_STDERR(_ptr) ((_ptr)->_stderr)
|
2022-05-16 16:54:31 +08:00
|
|
|
|
2015-12-14 16:57:54 +08:00
|
|
|
#define _REENT_INIT_PTR(var) \
|
|
|
|
{ memset((var), 0, sizeof(*(var))); \
|
|
|
|
_REENT_INIT_PTR_ZEROED(var); \
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
/*
|
|
|
|
* All references to struct _reent are via this pointer.
|
|
|
|
* Internally, newlib routines that need to reference it should use _REENT.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ATTRIBUTE_IMPURE_PTR__
|
|
|
|
#define __ATTRIBUTE_IMPURE_PTR__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
|
2022-05-03 20:51:55 +08:00
|
|
|
|
|
|
|
#ifndef __ATTRIBUTE_IMPURE_DATA__
|
|
|
|
#define __ATTRIBUTE_IMPURE_DATA__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern struct _reent _impure_data __ATTRIBUTE_IMPURE_DATA__;
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/* #define _REENT_ONLY define this to get only reentrant routines */
|
|
|
|
|
2002-05-17 Jeff Johnston <jjohnstn@redhat.com>
* Makefile.am: Copy and install headers from sys/machine/include
directory. Also pass $toollibdir to lower-level directories.
* Makefile.in: Regenerated.
* libc/include/stdio.h[!_REENT_ONLY]: Change stdin, stdout, and
stderr to use _REENT macro instead of _impure_ptr directly.
* libc/include/sys/config.h[__i386__][__linux__]: Define
__DYNAMIC_REENT__.
* libc/include/sys/reent.h[!_REENT_ONLY]: Change _REENT macro to be
call to __getreent() function if !__SINGLE_THREAD__ and
__DYNAMIC_REENT__ is set.
* libc/reent/Makefile.am: Add support for getreent.c.
* libc/reent/Makefile.in: Regenerated.
* libc/string/strerror.c: Add check if EOPNOTSUPP and ENOTSUP are same.
* libc/sys/linux/Makefile.am: Add support for new files.
* libc/sys/linux/configure.in: Add $EXTRA_DIRS variable.
* libc/sys/linux/Makefile.in: Regenerated.
* libc/sys/linux/configure: Ditto.
* libc/sys/linux/io.c: Add poll syscall. Also weak-alias
__close, __read, __write, __poll, __open, __lseek, __fcntl from
their __libc_ counterparts.
* libc/sys/linux/io64.c: Add __libc_ prefix to lseek64 and open64
and weak-alias to regular names.
* libc/sys/linux/pread64.c: Rename to __libc_pread64 and weak-alias
to pread64 and __pread64.
* libc/sys/linux/process.c: Weak_alias __libc_getpid to __getpid.
* libc/sys/linux/pwrite64.c: Rename to __libc_pwrite64 and
weak-alias to pwrite64.
* libc/sys/linux/sched.c: Weak-alias __libc_sched_getparam,
__libc_sched_getscheduler, __libc_sched_get_priority_max,
__libc_sched_get_priority_min, and __libc_sched_setschedule to
name with __ instead of __libc_.
* libc/sys/linux/siglongjmp.c: Include <machine/weakalias.h>.
Rename siglongjmp to __libc_siglongjmp and weak-alias to siglongjmp.
Call __libc_longjmp instead of longjmp, from __libc_siglongjmp.
* libc/sys/linux/signal.c: Rename raise to __libc_raise and weak-alias
to raise.
* libc/sys/linux/socket.c: Weak-alias __libc_connect to __connect and
__libc_send to __send.
* libc/sys/linux/time.c: Weak-alias __libc_gettimeofday to
__gettimeofday.
* libc/sys/linux/wait.c: Rename wait to __libc_wait and weak-alias
it to wait. Rename wait3 to __libc_wait3 and weak-alias it to wait3.
* libc/sys/linux/include/setjmp.h: Use __jmp_buf in sigjmp_buf
type and typedef __jmp_buf to jmp_buf.
* libc/sys/linux/machine/i386/Makefile.am: Add syscalls.c and
setjmp.S.
* libc/sys/linux/machine/i386/Makefile.in: Regenerated.
* libc/sys/linux/machine/i386/crt0.c: Add support to clear .bss
section.
* libc/sys/linux/machine/i386/socketcall.h: Change to use __libc_
prefix for function macros and then use weak_alias() to regular names.
* libc/sys/linux/machine/i386/syscall.h: Ditto.
* libc/sys/linux/sys/errno.h: Define EOPNOTSUP to be ENOTSUP.
* libc/sys/linux/sys/stdio.h: Define _flockfile and _funlockfile
to be flockfile() and funlockfile() respectively.
* libc/sys/linux/sys/types.h
* libc/reent/getreent.c: New file.
* libc/sys/linux/flockfile.c: Ditto.
* libc/sys/linux/funlockfile.c: Ditto.
* libc/sys/linux/getreent.c: Ditto.
* libc/sys/linux/pread.c: Ditto.
* libc/sys/linux/pwrite.c: Ditto.
* libc/sys/linux/raise.c: Ditto.
* libc/sys/linux/system.c: Ditto.
* libc/sys/linux/tcdrain.c: Ditto.
* libc/sys/linux/machine/i386/i386mach.h: Ditto.
* libc/sys/linux/machine/i386/setjmp.S: Ditto.
* libc/sys/linux/machine/i386/syscalls.c: Ditto.
* libc/sys/linux/machine/i386/weakalias.h: Ditto.
* libc/sys/linux/machine/i386/include/setjmp.h: Ditto.
2002-05-18 07:39:39 +08:00
|
|
|
#if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__)
|
2004-02-09 10:22:01 +08:00
|
|
|
#ifndef __getreent
|
2017-12-04 13:54:48 +08:00
|
|
|
struct _reent * __getreent (void);
|
2004-02-09 10:22:01 +08:00
|
|
|
#endif
|
2002-05-17 Jeff Johnston <jjohnstn@redhat.com>
* Makefile.am: Copy and install headers from sys/machine/include
directory. Also pass $toollibdir to lower-level directories.
* Makefile.in: Regenerated.
* libc/include/stdio.h[!_REENT_ONLY]: Change stdin, stdout, and
stderr to use _REENT macro instead of _impure_ptr directly.
* libc/include/sys/config.h[__i386__][__linux__]: Define
__DYNAMIC_REENT__.
* libc/include/sys/reent.h[!_REENT_ONLY]: Change _REENT macro to be
call to __getreent() function if !__SINGLE_THREAD__ and
__DYNAMIC_REENT__ is set.
* libc/reent/Makefile.am: Add support for getreent.c.
* libc/reent/Makefile.in: Regenerated.
* libc/string/strerror.c: Add check if EOPNOTSUPP and ENOTSUP are same.
* libc/sys/linux/Makefile.am: Add support for new files.
* libc/sys/linux/configure.in: Add $EXTRA_DIRS variable.
* libc/sys/linux/Makefile.in: Regenerated.
* libc/sys/linux/configure: Ditto.
* libc/sys/linux/io.c: Add poll syscall. Also weak-alias
__close, __read, __write, __poll, __open, __lseek, __fcntl from
their __libc_ counterparts.
* libc/sys/linux/io64.c: Add __libc_ prefix to lseek64 and open64
and weak-alias to regular names.
* libc/sys/linux/pread64.c: Rename to __libc_pread64 and weak-alias
to pread64 and __pread64.
* libc/sys/linux/process.c: Weak_alias __libc_getpid to __getpid.
* libc/sys/linux/pwrite64.c: Rename to __libc_pwrite64 and
weak-alias to pwrite64.
* libc/sys/linux/sched.c: Weak-alias __libc_sched_getparam,
__libc_sched_getscheduler, __libc_sched_get_priority_max,
__libc_sched_get_priority_min, and __libc_sched_setschedule to
name with __ instead of __libc_.
* libc/sys/linux/siglongjmp.c: Include <machine/weakalias.h>.
Rename siglongjmp to __libc_siglongjmp and weak-alias to siglongjmp.
Call __libc_longjmp instead of longjmp, from __libc_siglongjmp.
* libc/sys/linux/signal.c: Rename raise to __libc_raise and weak-alias
to raise.
* libc/sys/linux/socket.c: Weak-alias __libc_connect to __connect and
__libc_send to __send.
* libc/sys/linux/time.c: Weak-alias __libc_gettimeofday to
__gettimeofday.
* libc/sys/linux/wait.c: Rename wait to __libc_wait and weak-alias
it to wait. Rename wait3 to __libc_wait3 and weak-alias it to wait3.
* libc/sys/linux/include/setjmp.h: Use __jmp_buf in sigjmp_buf
type and typedef __jmp_buf to jmp_buf.
* libc/sys/linux/machine/i386/Makefile.am: Add syscalls.c and
setjmp.S.
* libc/sys/linux/machine/i386/Makefile.in: Regenerated.
* libc/sys/linux/machine/i386/crt0.c: Add support to clear .bss
section.
* libc/sys/linux/machine/i386/socketcall.h: Change to use __libc_
prefix for function macros and then use weak_alias() to regular names.
* libc/sys/linux/machine/i386/syscall.h: Ditto.
* libc/sys/linux/sys/errno.h: Define EOPNOTSUP to be ENOTSUP.
* libc/sys/linux/sys/stdio.h: Define _flockfile and _funlockfile
to be flockfile() and funlockfile() respectively.
* libc/sys/linux/sys/types.h
* libc/reent/getreent.c: New file.
* libc/sys/linux/flockfile.c: Ditto.
* libc/sys/linux/funlockfile.c: Ditto.
* libc/sys/linux/getreent.c: Ditto.
* libc/sys/linux/pread.c: Ditto.
* libc/sys/linux/pwrite.c: Ditto.
* libc/sys/linux/raise.c: Ditto.
* libc/sys/linux/system.c: Ditto.
* libc/sys/linux/tcdrain.c: Ditto.
* libc/sys/linux/machine/i386/i386mach.h: Ditto.
* libc/sys/linux/machine/i386/setjmp.S: Ditto.
* libc/sys/linux/machine/i386/syscalls.c: Ditto.
* libc/sys/linux/machine/i386/weakalias.h: Ditto.
* libc/sys/linux/machine/i386/include/setjmp.h: Ditto.
2002-05-18 07:39:39 +08:00
|
|
|
# define _REENT (__getreent())
|
|
|
|
#else /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */
|
|
|
|
# define _REENT _impure_ptr
|
|
|
|
#endif /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */
|
|
|
|
|
2022-05-23 17:29:57 +08:00
|
|
|
#define _REENT_IS_NULL(_ptr) ((_ptr) == NULL)
|
|
|
|
|
2022-05-03 20:51:55 +08:00
|
|
|
#define _GLOBAL_REENT (&_impure_data)
|
2003-08-23 02:52:25 +08:00
|
|
|
|
Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store
thread-specific data. This object is returned by __getreent() if the
__DYNAMIC_REENT__ Newlib configuration option is defined.
The reentrancy structure contains for example errno and the standard input,
output, and error file streams. This means that if an application only uses
errno it has a dependency on the file stream support even if it does not use
it. This is an issue for lower end targets and applications which need to
qualify the software according to safety standards (for example ECSS-E-ST-40C,
ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333).
If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct
_reent is replaced by dedicated thread-local objects for each struct _reent
member. The thread-local objects are defined in translation units which use
the corresponding object.
2022-05-16 17:51:54 +08:00
|
|
|
#else /* _REENT_THREAD_LOCAL */
|
|
|
|
|
|
|
|
#define _REENT NULL
|
|
|
|
#define _GLOBAL_REENT NULL
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since _REENT is defined as NULL, this macro ensures that calls to
|
|
|
|
* CHECK_INIT() do not automatically fail.
|
|
|
|
*/
|
|
|
|
#define _REENT_IS_NULL(_ptr) 0
|
|
|
|
|
|
|
|
#define _REENT_CHECK_RAND48(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_MP(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_TM(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_ASCTIME_BUF(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_EMERGENCY(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_MISC(ptr) /* nothing */
|
|
|
|
#define _REENT_CHECK_SIGNAL_BUF(ptr) /* nothing */
|
|
|
|
|
|
|
|
extern _Thread_local char _tls_asctime_buf[_REENT_ASCTIME_SIZE];
|
|
|
|
#define _REENT_ASCTIME_BUF(_ptr) (_tls_asctime_buf)
|
|
|
|
extern _Thread_local char *_tls_cvtbuf;
|
|
|
|
#define _REENT_CVTBUF(_ptr) (_tls_cvtbuf)
|
|
|
|
extern _Thread_local int _tls_cvtlen;
|
|
|
|
#define _REENT_CVTLEN(_ptr) (_tls_cvtlen)
|
|
|
|
extern _Thread_local void (*_tls_cleanup)(struct _reent *);
|
|
|
|
#define _REENT_CLEANUP(_ptr) (_tls_cleanup)
|
2023-04-26 14:23:04 +08:00
|
|
|
extern _Thread_local char _tls_emergency[_REENT_EMERGENCY_SIZE];
|
Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store
thread-specific data. This object is returned by __getreent() if the
__DYNAMIC_REENT__ Newlib configuration option is defined.
The reentrancy structure contains for example errno and the standard input,
output, and error file streams. This means that if an application only uses
errno it has a dependency on the file stream support even if it does not use
it. This is an issue for lower end targets and applications which need to
qualify the software according to safety standards (for example ECSS-E-ST-40C,
ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333).
If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct
_reent is replaced by dedicated thread-local objects for each struct _reent
member. The thread-local objects are defined in translation units which use
the corresponding object.
2022-05-16 17:51:54 +08:00
|
|
|
#define _REENT_EMERGENCY(_ptr) (_tls_emergency)
|
|
|
|
extern _Thread_local int _tls_errno;
|
|
|
|
#define _REENT_ERRNO(_ptr) (_tls_errno)
|
|
|
|
extern _Thread_local int _tls_getdate_err;
|
|
|
|
#define _REENT_GETDATE_ERR_P(_ptr) (&_tls_getdate_err)
|
|
|
|
extern _Thread_local int _tls_inc;
|
|
|
|
#define _REENT_INC(_ptr) (_tls_inc)
|
|
|
|
extern _Thread_local char _tls_l64a_buf[8];
|
|
|
|
#define _REENT_L64A_BUF(_ptr) (_tls_l64a_buf)
|
|
|
|
extern _Thread_local struct __locale_t *_tls_locale;
|
|
|
|
#define _REENT_LOCALE(_ptr) (_tls_locale)
|
|
|
|
extern _Thread_local _mbstate_t _tls_mblen_state;
|
|
|
|
#define _REENT_MBLEN_STATE(_ptr) (_tls_mblen_state)
|
|
|
|
extern _Thread_local _mbstate_t _tls_mbrlen_state;
|
|
|
|
#define _REENT_MBRLEN_STATE(_ptr) (_tls_mbrlen_state)
|
|
|
|
extern _Thread_local _mbstate_t _tls_mbrtowc_state;
|
|
|
|
#define _REENT_MBRTOWC_STATE(_ptr) (_tls_mbrtowc_state)
|
|
|
|
extern _Thread_local _mbstate_t _tls_mbsrtowcs_state;
|
|
|
|
#define _REENT_MBSRTOWCS_STATE(_ptr) (_tls_mbsrtowcs_state)
|
|
|
|
extern _Thread_local _mbstate_t _tls_mbtowc_state;
|
|
|
|
#define _REENT_MBTOWC_STATE(_ptr) (_tls_mbtowc_state)
|
|
|
|
extern _Thread_local struct _Bigint **_tls_mp_freelist;
|
|
|
|
#define _REENT_MP_FREELIST(_ptr) (_tls_mp_freelist)
|
|
|
|
extern _Thread_local struct _Bigint *_tls_mp_p5s;
|
|
|
|
#define _REENT_MP_P5S(_ptr) (_tls_mp_p5s)
|
|
|
|
extern _Thread_local struct _Bigint *_tls_mp_result;
|
|
|
|
#define _REENT_MP_RESULT(_ptr) (_tls_mp_result)
|
|
|
|
extern _Thread_local int _tls_mp_result_k;
|
|
|
|
#define _REENT_MP_RESULT_K(_ptr) (_tls_mp_result_k)
|
|
|
|
extern _Thread_local unsigned short _tls_rand48_add;
|
|
|
|
#define _REENT_RAND48_ADD(_ptr) (_tls_rand48_add)
|
|
|
|
extern _Thread_local unsigned short _tls_rand48_mult[3];
|
|
|
|
#define _REENT_RAND48_MULT(_ptr) (_tls_rand48_mult)
|
|
|
|
extern _Thread_local unsigned short _tls_rand48_seed[3];
|
|
|
|
#define _REENT_RAND48_SEED(_ptr) (_tls_rand48_seed)
|
|
|
|
extern _Thread_local unsigned long long _tls_rand_next;
|
|
|
|
#define _REENT_RAND_NEXT(_ptr) (_tls_rand_next)
|
|
|
|
extern _Thread_local void (**_tls_sig_func)(int);
|
|
|
|
#define _REENT_SIG_FUNC(_ptr) (_tls_sig_func)
|
|
|
|
extern _Thread_local char _tls_signal_buf[_REENT_SIGNAL_SIZE];
|
|
|
|
#define _REENT_SIGNAL_BUF(_ptr) (_tls_signal_buf)
|
|
|
|
extern _Thread_local int _tls_gamma_signgam;
|
|
|
|
#define _REENT_SIGNGAM(_ptr) (_tls_gamma_signgam)
|
|
|
|
extern _Thread_local __FILE *_tls_stdin;
|
|
|
|
#define _REENT_STDIN(_ptr) (_tls_stdin)
|
|
|
|
extern _Thread_local __FILE *_tls_stdout;
|
|
|
|
#define _REENT_STDOUT(_ptr) (_tls_stdout)
|
|
|
|
extern _Thread_local __FILE *_tls_stderr;
|
|
|
|
#define _REENT_STDERR(_ptr) (_tls_stderr)
|
|
|
|
extern _Thread_local char *_tls_strtok_last;
|
|
|
|
#define _REENT_STRTOK_LAST(_ptr) (_tls_strtok_last)
|
|
|
|
extern _Thread_local struct __tm _tls_localtime_buf;
|
|
|
|
#define _REENT_TM(_ptr) (&_tls_localtime_buf)
|
|
|
|
extern _Thread_local _mbstate_t _tls_wctomb_state;
|
|
|
|
#define _REENT_WCTOMB_STATE(_ptr) (_tls_wctomb_state)
|
|
|
|
extern _Thread_local _mbstate_t _tls_wcrtomb_state;
|
|
|
|
#define _REENT_WCRTOMB_STATE(_ptr) (_tls_wcrtomb_state)
|
|
|
|
extern _Thread_local _mbstate_t _tls_wcsrtombs_state;
|
|
|
|
#define _REENT_WCSRTOMBS_STATE(_ptr) (_tls_wcsrtombs_state)
|
|
|
|
|
|
|
|
#endif /* !_REENT_THREAD_LOCAL */
|
|
|
|
|
2022-05-19 01:21:44 +08:00
|
|
|
/* This value is used in stdlib/misc.c. reent/reent.c has to know it
|
|
|
|
as well to make sure the freelist is correctly free'd. Therefore
|
|
|
|
we define it here, rather than in stdlib/misc.c, as before. */
|
|
|
|
#define _Kmax (sizeof (size_t) << 3)
|
|
|
|
|
2022-05-13 19:44:13 +08:00
|
|
|
extern struct _atexit *__atexit; /* points to head of LIFO stack */
|
|
|
|
extern struct _atexit __atexit0; /* one guaranteed table, required by ANSI */
|
2013-05-08 05:40:10 +08:00
|
|
|
|
2022-05-19 01:21:44 +08:00
|
|
|
extern void (*__stdio_exit_handler) (void);
|
|
|
|
|
|
|
|
void _reclaim_reent (struct _reent *);
|
|
|
|
|
|
|
|
extern int _fwalk_sglue (struct _reent *, int (*)(struct _reent *, __FILE *),
|
|
|
|
struct _glue *);
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* _SYS_REENT_H_ */
|