overhaul pthread cancellation
authorRich Felker <dalias@aerifal.cx>
Sun, 17 Apr 2011 15:43:03 +0000 (11:43 -0400)
committerRich Felker <dalias@aerifal.cx>
Sun, 17 Apr 2011 15:43:03 +0000 (11:43 -0400)
commitfeee98903cd8119d9a3db62589246a940f44a9f5
tree37922ce54f00145d7fc0ac795216fce611e0806a
parent90f09a0dde3b37ebfabc4d3f6e2bb64086b7e804
overhaul pthread cancellation

this patch improves the correctness, simplicity, and size of
cancellation-related code. modulo any small errors, it should now be
completely conformant, safe, and resource-leak free.

the notion of entering and exiting cancellation-point context has been
completely eliminated and replaced with alternative syscall assembly
code for cancellable syscalls. the assembly is responsible for setting
up execution context information (stack pointer and address of the
syscall instruction) which the cancellation signal handler can use to
determine whether the interrupted code was in a cancellable state.

these changes eliminate race conditions in the previous generation of
cancellation handling code (whereby a cancellation request received
just prior to the syscall would not be processed, leaving the syscall
to block, potentially indefinitely), and remedy an issue where
non-cancellable syscalls made from signal handlers became cancellable
if the signal handler interrupted a cancellation point.

x86_64 asm is untested and may need a second try to get it right.
50 files changed:
arch/i386/bits/pthread.h
arch/i386/bits/syscall.h
arch/i386/pthread_arch.h
arch/x86_64/bits/syscall.h
arch/x86_64/pthread_arch.h
src/fcntl/fcntl.c
src/fcntl/open.c
src/fcntl/openat.c
src/internal/libc.h
src/internal/pthread_impl.h
src/internal/syscall.h
src/ipc/msgrcv.c
src/ipc/msgsnd.c
src/network/accept.c
src/network/connect.c
src/network/recvfrom.c
src/network/recvmsg.c
src/network/sendmsg.c
src/network/sendto.c
src/process/waitid.c
src/process/waitpid.c
src/select/poll.c
src/select/pselect.c
src/select/select.c
src/signal/sigsuspend.c
src/signal/sigtimedwait.c
src/termios/tcdrain.c
src/thread/__timedwait.c
src/thread/__timedwait_cp.c [new file with mode: 0644]
src/thread/cancel_dummy.c [new file with mode: 0644]
src/thread/cancel_impl.c [new file with mode: 0644]
src/thread/i386/syscall_cp.s [new file with mode: 0644]
src/thread/pthread_cancel.c [deleted file]
src/thread/pthread_cond_timedwait.c
src/thread/pthread_create.c
src/thread/pthread_join.c
src/thread/pthread_testcancel.c
src/thread/sem_timedwait.c
src/thread/syscall_cp.c [new file with mode: 0644]
src/thread/x86_64/syscall_cp.s [new file with mode: 0644]
src/time/clock_nanosleep.c
src/time/nanosleep.c
src/unistd/close.c
src/unistd/pause.c
src/unistd/pread.c
src/unistd/pwrite.c
src/unistd/read.c
src/unistd/readv.c
src/unistd/write.c
src/unistd/writev.c