diff options
author | Matt Joyce <matthew.joyce@embedded-brains.de> | 2022-05-16 11:51:54 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-07-13 06:55:46 +0200 |
commit | ea99f21ce6c8a332845439ea87f792dbaf679d42 (patch) | |
tree | 94cfcaf461882955f7461b09d6c4c0e2f321e66e /newlib/libc/stdlib | |
parent | 1a0908203606527b6ac0ed438669b5bcd247a5f9 (diff) | |
download | newlib-ea99f21ce6c8a332845439ea87f792dbaf679d42.zip newlib-ea99f21ce6c8a332845439ea87f792dbaf679d42.tar.gz newlib-ea99f21ce6c8a332845439ea87f792dbaf679d42.tar.bz2 |
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.
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r-- | newlib/libc/stdlib/dtoa.c | 5 | ||||
-rw-r--r-- | newlib/libc/stdlib/ecvtbuf.c | 5 | ||||
-rw-r--r-- | newlib/libc/stdlib/l64a.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/lcong48.c | 8 | ||||
-rw-r--r-- | newlib/libc/stdlib/mblen.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbrlen.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbrtowc.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbsnrtowcs.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/mbtowc.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/mprec.c | 5 | ||||
-rw-r--r-- | newlib/libc/stdlib/rand.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/wcrtomb.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/wcsnrtombs.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdlib/wctomb.c | 4 |
14 files changed, 63 insertions, 0 deletions
diff --git a/newlib/libc/stdlib/dtoa.c b/newlib/libc/stdlib/dtoa.c index e47a8bc..198fa66 100644 --- a/newlib/libc/stdlib/dtoa.c +++ b/newlib/libc/stdlib/dtoa.c @@ -32,6 +32,11 @@ #include <string.h> #include "mprec.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local struct _Bigint *_tls_mp_result; +_Thread_local int _tls_mp_result_k; +#endif + static int quorem (_Bigint * b, _Bigint * S) { diff --git a/newlib/libc/stdlib/ecvtbuf.c b/newlib/libc/stdlib/ecvtbuf.c index 05f3151..5148966 100644 --- a/newlib/libc/stdlib/ecvtbuf.c +++ b/newlib/libc/stdlib/ecvtbuf.c @@ -57,6 +57,11 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #include "mprec.h" #include "local.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local char *_tls_cvtbuf; +_Thread_local int _tls_cvtlen; +#endif + static void print_f (struct _reent *ptr, char *buf, diff --git a/newlib/libc/stdlib/l64a.c b/newlib/libc/stdlib/l64a.c index 45282e3..6f12b61 100644 --- a/newlib/libc/stdlib/l64a.c +++ b/newlib/libc/stdlib/l64a.c @@ -24,6 +24,10 @@ #include <stdlib.h> #include <reent.h> +#ifdef _REENT_THREAD_LOCAL +_Thread_local char _tls_l64a_buf[8]; +#endif + static const char R64_ARRAY[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; char * diff --git a/newlib/libc/stdlib/lcong48.c b/newlib/libc/stdlib/lcong48.c index 78e9e57..d1109f0 100644 --- a/newlib/libc/stdlib/lcong48.c +++ b/newlib/libc/stdlib/lcong48.c @@ -13,6 +13,14 @@ #include "rand48.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local unsigned short _tls_rand48_seed[3] = {_RAND48_SEED_0, _RAND48_SEED_1, + _RAND48_SEED_2}; +_Thread_local unsigned short _tls_rand48_mult[3] = {_RAND48_MULT_0, _RAND48_MULT_1, + _RAND48_MULT_2}; +_Thread_local unsigned short _tls_rand48_add = _RAND48_ADD; +#endif + void _lcong48_r (struct _reent *r, unsigned short p[7]) diff --git a/newlib/libc/stdlib/mblen.c b/newlib/libc/stdlib/mblen.c index 3753d36..24df615 100644 --- a/newlib/libc/stdlib/mblen.c +++ b/newlib/libc/stdlib/mblen.c @@ -42,6 +42,10 @@ effects vary with the locale. #include <wchar.h> #include "local.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local _mbstate_t _tls_mblen_state; +#endif + int mblen (const char *s, size_t n) diff --git a/newlib/libc/stdlib/mbrlen.c b/newlib/libc/stdlib/mbrlen.c index 57a733f..39e175e 100644 --- a/newlib/libc/stdlib/mbrlen.c +++ b/newlib/libc/stdlib/mbrlen.c @@ -5,6 +5,10 @@ #include <stdio.h> #include <errno.h> +#ifdef _REENT_THREAD_LOCAL +_Thread_local _mbstate_t _tls_mbrlen_state; +#endif + size_t mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps) { diff --git a/newlib/libc/stdlib/mbrtowc.c b/newlib/libc/stdlib/mbrtowc.c index 521b7a5..e641b8c 100644 --- a/newlib/libc/stdlib/mbrtowc.c +++ b/newlib/libc/stdlib/mbrtowc.c @@ -7,6 +7,10 @@ #include <string.h> #include "local.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local _mbstate_t _tls_mbrtowc_state; +#endif + size_t _mbrtowc_r (struct _reent *ptr, wchar_t *pwc, diff --git a/newlib/libc/stdlib/mbsnrtowcs.c b/newlib/libc/stdlib/mbsnrtowcs.c index 8f94b1d..2effc50 100644 --- a/newlib/libc/stdlib/mbsnrtowcs.c +++ b/newlib/libc/stdlib/mbsnrtowcs.c @@ -70,6 +70,10 @@ PORTABILITY #include <stdio.h> #include <errno.h> +#ifdef _REENT_THREAD_LOCAL +_Thread_local _mbstate_t _tls_mbsrtowcs_state; +#endif + size_t _mbsnrtowcs_r (struct _reent *r, wchar_t *dst, diff --git a/newlib/libc/stdlib/mbtowc.c b/newlib/libc/stdlib/mbtowc.c index 2dc413f..fbd8df6 100644 --- a/newlib/libc/stdlib/mbtowc.c +++ b/newlib/libc/stdlib/mbtowc.c @@ -49,6 +49,10 @@ effects vary with the locale. #include <wchar.h> #include "local.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local _mbstate_t _tls_mbtowc_state; +#endif + int mbtowc (wchar_t *__restrict pwc, const char *__restrict s, diff --git a/newlib/libc/stdlib/mprec.c b/newlib/libc/stdlib/mprec.c index 930c984..1f534b0 100644 --- a/newlib/libc/stdlib/mprec.c +++ b/newlib/libc/stdlib/mprec.c @@ -86,6 +86,11 @@ #include <reent.h> #include "mprec.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local struct _Bigint *_tls_mp_p5s; +_Thread_local struct _Bigint **_tls_mp_freelist; +#endif + /* This is defined in sys/reent.h as (sizeof (size_t) << 3) now, as in NetBSD. The old value of 15 was wrong and made newlib vulnerable against buffer overrun attacks (CVE-2009-0689), same as other implementations of gdtoa diff --git a/newlib/libc/stdlib/rand.c b/newlib/libc/stdlib/rand.c index 209cb32..ba9cc80 100644 --- a/newlib/libc/stdlib/rand.c +++ b/newlib/libc/stdlib/rand.c @@ -58,6 +58,10 @@ on two different systems. #include <stdlib.h> #include <reent.h> +#ifdef _REENT_THREAD_LOCAL +_Thread_local unsigned long long _tls_rand_next = 1; +#endif + void srand (unsigned int seed) { diff --git a/newlib/libc/stdlib/wcrtomb.c b/newlib/libc/stdlib/wcrtomb.c index 6d670e2..1b84720 100644 --- a/newlib/libc/stdlib/wcrtomb.c +++ b/newlib/libc/stdlib/wcrtomb.c @@ -6,6 +6,10 @@ #include <errno.h> #include "local.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local _mbstate_t _tls_wcrtomb_state; +#endif + size_t _wcrtomb_r (struct _reent *ptr, char *s, diff --git a/newlib/libc/stdlib/wcsnrtombs.c b/newlib/libc/stdlib/wcsnrtombs.c index dfd974f..abef7ac 100644 --- a/newlib/libc/stdlib/wcsnrtombs.c +++ b/newlib/libc/stdlib/wcsnrtombs.c @@ -72,6 +72,10 @@ PORTABILITY #include "local.h" #include "../locale/setlocale.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local _mbstate_t _tls_wcsrtombs_state; +#endif + size_t _wcsnrtombs_l (struct _reent *r, char *dst, const wchar_t **src, size_t nwc, size_t len, mbstate_t *ps, struct __locale_t *loc) diff --git a/newlib/libc/stdlib/wctomb.c b/newlib/libc/stdlib/wctomb.c index e908d22..f56dccf 100644 --- a/newlib/libc/stdlib/wctomb.c +++ b/newlib/libc/stdlib/wctomb.c @@ -45,6 +45,10 @@ effects vary with the locale. #include <errno.h> #include "local.h" +#ifdef _REENT_THREAD_LOCAL +_Thread_local _mbstate_t _tls_wctomb_state; +#endif + int wctomb (char *s, wchar_t wchar) |