diff options
author | Rich Felker <dalias@aerifal.cx> | 2013-08-03 13:20:42 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-08-03 13:20:42 -0400 |
commit | 7356c2554e33cf16768616e8e3ae4a4f5a5aac17 (patch) | |
tree | 9510cb631685508d9ece852b7ce865e91a903589 /src/time/timer_delete.c | |
parent | 14012b91f2b52f70fd3f3bb807fb880654337da5 (diff) | |
download | musl-7356c2554e33cf16768616e8e3ae4a4f5a5aac17.tar.gz musl-7356c2554e33cf16768616e8e3ae4a4f5a5aac17.tar.bz2 musl-7356c2554e33cf16768616e8e3ae4a4f5a5aac17.tar.xz musl-7356c2554e33cf16768616e8e3ae4a4f5a5aac17.zip |
fix multiple bugs in SIGEV_THREAD timers
1. the thread result field was reused for storing a kernel timer id,
but would be overwritten if the application code exited or cancelled
the thread.
2. low pointer values were used as the indicator that the timer id is
a kernel timer id rather than a thread id. this is not portable, as
mmap may return low pointers on some conditions. instead, use the fact
that pointers must be aligned and kernel timer ids must be
non-negative to map pointers into the negative integer space.
3. signals were not blocked until after the timer thread started, so a
race condition could allow a signal handler to run in the timer thread
when it's not supposed to exist. this is mainly problematic if the
calling thread was the only thread where the signal was unblocked and
the signal handler assumes it runs in that thread.
Diffstat (limited to 'src/time/timer_delete.c')
-rw-r--r-- | src/time/timer_delete.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/time/timer_delete.c b/src/time/timer_delete.c index b5f8ca19..c81f921a 100644 --- a/src/time/timer_delete.c +++ b/src/time/timer_delete.c @@ -1,12 +1,13 @@ #include <time.h> +#include <limits.h> #include "pthread_impl.h" int timer_delete(timer_t t) { - if ((uintptr_t)t >= 0x100000) { - pthread_t td = t; - td->delete_timer = 1; - __wake(&td->delete_timer, 1, 1); + if ((intptr_t)t < 0) { + pthread_t td = (void *)((uintptr_t)t << 1); + a_store(&td->timer_id, td->timer_id | INT_MIN); + __wake(&td->timer_id, 1, 1); return 0; } return __syscall(SYS_timer_delete, (long)t); |