aboutsummaryrefslogtreecommitdiff
path: root/src/unistd
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-17 11:43:03 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-17 11:43:03 -0400
commitfeee98903cd8119d9a3db62589246a940f44a9f5 (patch)
tree37922ce54f00145d7fc0ac795216fce611e0806a /src/unistd
parent90f09a0dde3b37ebfabc4d3f6e2bb64086b7e804 (diff)
downloadmusl-feee98903cd8119d9a3db62589246a940f44a9f5.zip
musl-feee98903cd8119d9a3db62589246a940f44a9f5.tar.gz
musl-feee98903cd8119d9a3db62589246a940f44a9f5.tar.bz2
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.
Diffstat (limited to 'src/unistd')
-rw-r--r--src/unistd/close.c5
-rw-r--r--src/unistd/pause.c6
-rw-r--r--src/unistd/pread.c6
-rw-r--r--src/unistd/pwrite.c6
-rw-r--r--src/unistd/read.c6
-rw-r--r--src/unistd/readv.c6
-rw-r--r--src/unistd/write.c6
-rw-r--r--src/unistd/writev.c6
8 files changed, 9 insertions, 38 deletions
diff --git a/src/unistd/close.c b/src/unistd/close.c
index f52c0ef..231f79e 100644
--- a/src/unistd/close.c
+++ b/src/unistd/close.c
@@ -4,8 +4,7 @@
int close(int fd)
{
- int ret = syscall(SYS_close, fd);
- CANCELPT_BEGIN;
- CANCELPT_END;
+ int ret = syscall_cp(SYS_close, fd);
+ if (libc.testcancel) libc.testcancel();
return ret;
}
diff --git a/src/unistd/pause.c b/src/unistd/pause.c
index 57ed25e..f7ed17d 100644
--- a/src/unistd/pause.c
+++ b/src/unistd/pause.c
@@ -4,9 +4,5 @@
int pause(void)
{
- int r;
- CANCELPT_BEGIN;
- r = syscall(SYS_pause);
- CANCELPT_END;
- return r;
+ return syscall_cp(SYS_pause);
}
diff --git a/src/unistd/pread.c b/src/unistd/pread.c
index 0a04501..1bf0c75 100644
--- a/src/unistd/pread.c
+++ b/src/unistd/pread.c
@@ -4,11 +4,7 @@
ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
{
- ssize_t r;
- CANCELPT_BEGIN;
- r = syscall(SYS_pread, fd, buf, size, __SYSCALL_LL(ofs));
- CANCELPT_END;
- return r;
+ return syscall_cp(SYS_pread, fd, buf, size, __SYSCALL_LL(ofs));
}
LFS64(pread);
diff --git a/src/unistd/pwrite.c b/src/unistd/pwrite.c
index f878bb6..224eacd 100644
--- a/src/unistd/pwrite.c
+++ b/src/unistd/pwrite.c
@@ -4,11 +4,7 @@
ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
{
- ssize_t r;
- CANCELPT_BEGIN;
- r = syscall(SYS_pwrite, fd, buf, size, __SYSCALL_LL(ofs));
- CANCELPT_END;
- return r;
+ return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL(ofs));
}
LFS64(pwrite);
diff --git a/src/unistd/read.c b/src/unistd/read.c
index 194b389..eb882fc 100644
--- a/src/unistd/read.c
+++ b/src/unistd/read.c
@@ -4,9 +4,5 @@
ssize_t read(int fd, void *buf, size_t count)
{
- ssize_t r;
- CANCELPT_BEGIN;
- r = syscall(SYS_read, fd, buf, count);
- CANCELPT_END;
- return r;
+ return syscall_cp(SYS_read, fd, buf, count);
}
diff --git a/src/unistd/readv.c b/src/unistd/readv.c
index 9b87728..e45cb48 100644
--- a/src/unistd/readv.c
+++ b/src/unistd/readv.c
@@ -4,9 +4,5 @@
ssize_t readv(int fd, const struct iovec *iov, int count)
{
- ssize_t r;
- CANCELPT_BEGIN;
- r = syscall(SYS_readv, fd, iov, count);
- CANCELPT_END;
- return r;
+ return syscall_cp(SYS_readv, fd, iov, count);
}
diff --git a/src/unistd/write.c b/src/unistd/write.c
index a8284b3..e2f7e1f 100644
--- a/src/unistd/write.c
+++ b/src/unistd/write.c
@@ -4,9 +4,5 @@
ssize_t write(int fd, const void *buf, size_t count)
{
- int r;
- CANCELPT_BEGIN;
- r = syscall(SYS_write, fd, buf, count);
- CANCELPT_END;
- return r;
+ return syscall_cp(SYS_write, fd, buf, count);
}
diff --git a/src/unistd/writev.c b/src/unistd/writev.c
index a45afeb..ef300dd 100644
--- a/src/unistd/writev.c
+++ b/src/unistd/writev.c
@@ -4,9 +4,5 @@
ssize_t writev(int fd, const struct iovec *iov, int count)
{
- ssize_t r;
- CANCELPT_BEGIN;
- r = syscall(SYS_writev, fd, iov, count);
- CANCELPT_END;
- return r;
+ return syscall_cp(SYS_writev, fd, iov, count);
}