diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2023-04-25 20:02:31 +0200 |
---|---|---|
committer | Peter Kjellerstedt <peter.kjellerstedt@gmail.com> | 2023-04-26 02:08:46 +0200 |
commit | edd1e47f107410d9e4edb691335410026ae5a534 (patch) | |
tree | 2b2a746b7544e75352fd8f70195f1020b6674861 | |
parent | c176fcf2eb3a20e989cd1c4439f76779f276f418 (diff) | |
download | glib-edd1e47f107410d9e4edb691335410026ae5a534.tar.gz |
Avoid having g_futex_simple() inadvertently modify errno
If both __NR_futex and __NR_futex_time64 are defined, g_futex_simple()
will first call futex_time64(). If that fails with ENOSYS, then
futex_time() is called instead. However, errno was not saved and
restored in this case, which would result in g_futex_simple()
returning with errno set to ENOSYS, even if futex_time() succeeded.
-rw-r--r-- | glib/gthreadprivate.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h index 9c847e039..74d37ba32 100644 --- a/glib/gthreadprivate.h +++ b/glib/gthreadprivate.h @@ -65,9 +65,13 @@ struct _GRealThread #define g_futex_simple(uaddr, futex_op, ...) \ G_STMT_START \ { \ + int saved_errno = errno; \ int res = syscall (__NR_futex_time64, uaddr, (gsize) futex_op, __VA_ARGS__); \ if (res < 0 && errno == ENOSYS) \ - syscall (__NR_futex, uaddr, (gsize) futex_op, __VA_ARGS__); \ + { \ + errno = saved_errno; \ + syscall (__NR_futex, uaddr, (gsize) futex_op, __VA_ARGS__); \ + } \ } \ G_STMT_END #elif defined(__NR_futex_time64) |