From feee98903cd8119d9a3db62589246a940f44a9f5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 17 Apr 2011 11:43:03 -0400 Subject: 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. --- src/fcntl/fcntl.c | 7 ++----- src/fcntl/open.c | 6 +----- src/fcntl/openat.c | 6 +----- 3 files changed, 4 insertions(+), 15 deletions(-) (limited to 'src/fcntl') diff --git a/src/fcntl/fcntl.c b/src/fcntl/fcntl.c index ab0ebecf..2c9fb6f3 100644 --- a/src/fcntl/fcntl.c +++ b/src/fcntl/fcntl.c @@ -6,17 +6,14 @@ int fcntl(int fd, int cmd, ...) { - int r; long arg; va_list ap; va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); if (cmd == F_SETFL) arg |= O_LARGEFILE; - if (cmd == F_SETLKW) CANCELPT_BEGIN; - r = syscall(SYS_fcntl, fd, cmd, arg); - if (cmd == F_SETLKW) CANCELPT_END; - return r; + if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, arg); + return syscall(SYS_fcntl, fd, cmd, arg); } LFS64(fcntl); diff --git a/src/fcntl/open.c b/src/fcntl/open.c index 064d298c..31d6744c 100644 --- a/src/fcntl/open.c +++ b/src/fcntl/open.c @@ -6,16 +6,12 @@ int open(const char *filename, int flags, ...) { - int r; mode_t mode; va_list ap; va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); - CANCELPT_BEGIN; - r = syscall(SYS_open, filename, flags|O_LARGEFILE, mode); - CANCELPT_END; - return r; + return syscall_cp(SYS_open, filename, flags|O_LARGEFILE, mode); } LFS64(open); diff --git a/src/fcntl/openat.c b/src/fcntl/openat.c index 1a2d9535..bdecb8c8 100644 --- a/src/fcntl/openat.c +++ b/src/fcntl/openat.c @@ -6,16 +6,12 @@ int openat(int fd, const char *filename, int flags, ...) { - int r; mode_t mode; va_list ap; va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); - CANCELPT_BEGIN; - r = syscall(SYS_openat, fd, filename, flags|O_LARGEFILE, mode); - CANCELPT_END; - return r; + return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode); } LFS64(openat); -- cgit v1.2.1