diff options
author | Matt Joyce <matthew.joyce@embedded-brains.de> | 2022-02-04 13:47:18 +0300 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-07-13 07:55:46 +0300 |
commit | db2123caf8501a6d2fe0a75a4d196492b68d99c6 (patch) | |
tree | b9ef8e83d487f6135ff77d53c20e498bd91c5af0 /newlib/libc | |
parent | 81352a9df9d7c8ce9f9dc63126e4cfbd8ff4a082 (diff) |
Add _REENT_SIG_FUNC(ptr)
Add a _REENT_SIG_FUNC() macro to encapsulate access to the
_sig_func member of struct reent. This will help to replace the
struct member with a thread-local storage object in a follow up
patch.
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/include/sys/reent.h | 1 | ||||
-rw-r--r-- | newlib/libc/reent/reent.c | 4 | ||||
-rw-r--r-- | newlib/libc/signal/signal.c | 26 |
3 files changed, 16 insertions, 15 deletions
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h index ef05dd8c9..fa9c6cf82 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -725,6 +725,7 @@ struct _reent #define _REENT_ERRNO(_ptr) ((_ptr)->_errno) #define _REENT_INC(_ptr) ((_ptr)->_inc) #define _REENT_LOCALE(_ptr) ((_ptr)->_locale) +#define _REENT_SIG_FUNC(_ptr) ((_ptr)->_sig_func) #define _REENT_STDIN(_ptr) ((_ptr)->_stdin) #define _REENT_STDOUT(_ptr) ((_ptr)->_stdout) #define _REENT_STDERR(_ptr) ((_ptr)->_stderr) diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c index 2cfec5363..4e9485c7a 100644 --- a/newlib/libc/reent/reent.c +++ b/newlib/libc/reent/reent.c @@ -83,8 +83,8 @@ _reclaim_reent (struct _reent *ptr) /* We should free _sig_func to avoid a memory leak, but how to do it safely considering that a signal may be delivered immediately after the free? - if (ptr->_sig_func) - _free_r (ptr, ptr->_sig_func);*/ + if (_REENT_SIG_FUNC(ptr)) + _free_r (ptr, _REENT_SIG_FUNC(ptr));*/ if (_REENT_CLEANUP(ptr)) { diff --git a/newlib/libc/signal/signal.c b/newlib/libc/signal/signal.c index a249e9f00..3f14b4712 100644 --- a/newlib/libc/signal/signal.c +++ b/newlib/libc/signal/signal.c @@ -93,14 +93,14 @@ _init_signal_r (struct _reent *ptr) { int i; - if (ptr->_sig_func == NULL) + if (_REENT_SIG_FUNC(ptr) == NULL) { - ptr->_sig_func = (_sig_func_ptr *)_malloc_r (ptr, sizeof (_sig_func_ptr) * NSIG); - if (ptr->_sig_func == NULL) + _REENT_SIG_FUNC(ptr) = (_sig_func_ptr *)_malloc_r (ptr, sizeof (_sig_func_ptr) * NSIG); + if (_REENT_SIG_FUNC(ptr) == NULL) return -1; for (i = 0; i < NSIG; i++) - ptr->_sig_func[i] = SIG_DFL; + _REENT_SIG_FUNC(ptr)[i] = SIG_DFL; } return 0; @@ -119,11 +119,11 @@ _signal_r (struct _reent *ptr, return SIG_ERR; } - if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0) + if (_REENT_SIG_FUNC(ptr) == NULL && _init_signal_r (ptr) != 0) return SIG_ERR; - old_func = ptr->_sig_func[sig]; - ptr->_sig_func[sig] = func; + old_func = _REENT_SIG_FUNC(ptr)[sig]; + _REENT_SIG_FUNC(ptr)[sig] = func; return old_func; } @@ -140,10 +140,10 @@ _raise_r (struct _reent *ptr, return -1; } - if (ptr->_sig_func == NULL) + if (_REENT_SIG_FUNC(ptr) == NULL) func = SIG_DFL; else - func = ptr->_sig_func[sig]; + func = _REENT_SIG_FUNC(ptr)[sig]; if (func == SIG_DFL) return _kill_r (ptr, _getpid_r (ptr), sig); @@ -156,7 +156,7 @@ _raise_r (struct _reent *ptr, } else { - ptr->_sig_func[sig] = SIG_DFL; + _REENT_SIG_FUNC(ptr)[sig] = SIG_DFL; func (sig); return 0; } @@ -173,10 +173,10 @@ __sigtramp_r (struct _reent *ptr, return -1; } - if (ptr->_sig_func == NULL && _init_signal_r (ptr) != 0) + if (_REENT_SIG_FUNC(ptr) == NULL && _init_signal_r (ptr) != 0) return -1; - func = ptr->_sig_func[sig]; + func = _REENT_SIG_FUNC(ptr)[sig]; if (func == SIG_DFL) return 1; else if (func == SIG_ERR) @@ -185,7 +185,7 @@ __sigtramp_r (struct _reent *ptr, return 3; else { - ptr->_sig_func[sig] = SIG_DFL; + _REENT_SIG_FUNC(ptr)[sig] = SIG_DFL; func (sig); return 0; } |