summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2022-06-12 15:15:09 +0200
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-07-22 10:07:15 -0700
commitc85f307e6233397993e18b31d0034ed77bed73d9 (patch)
tree9a9e344799bb9588b848273d0fecbffe1957e3d4 /Userland/Libraries
parent899fd74f8ecc7c0b57a555babbad445f87ac36b4 (diff)
downloadserenity-c85f307e6233397993e18b31d0034ed77bed73d9.zip
LibC: Mark a bunch of functions as cancellation points
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibC/fcntl.cpp9
-rw-r--r--Userland/Libraries/LibC/poll.cpp3
-rw-r--r--Userland/Libraries/LibC/pthread.cpp2
-rw-r--r--Userland/Libraries/LibC/pthread_cond.cpp3
-rw-r--r--Userland/Libraries/LibC/semaphore.cpp3
-rw-r--r--Userland/Libraries/LibC/signal.cpp7
-rw-r--r--Userland/Libraries/LibC/stdlib.cpp3
-rw-r--r--Userland/Libraries/LibC/sys/mman.cpp3
-rw-r--r--Userland/Libraries/LibC/sys/select.cpp5
-rw-r--r--Userland/Libraries/LibC/sys/socket.cpp11
-rw-r--r--Userland/Libraries/LibC/sys/uio.cpp5
-rw-r--r--Userland/Libraries/LibC/sys/wait.cpp5
-rw-r--r--Userland/Libraries/LibC/termios.cpp3
-rw-r--r--Userland/Libraries/LibC/time.cpp3
-rw-r--r--Userland/Libraries/LibC/unistd.cpp13
15 files changed, 78 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/fcntl.cpp b/Userland/Libraries/LibC/fcntl.cpp
index 97fe440606..7927845678 100644
--- a/Userland/Libraries/LibC/fcntl.cpp
+++ b/Userland/Libraries/LibC/fcntl.cpp
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -17,6 +18,8 @@ extern "C" {
int fcntl(int fd, int cmd, ...)
{
+ __pthread_maybe_cancel();
+
va_list ap;
va_start(ap, cmd);
uintptr_t extra_arg = va_arg(ap, uintptr_t);
@@ -46,11 +49,15 @@ int inode_watcher_remove_watch(int fd, int wd)
int creat(char const* path, mode_t mode)
{
+ __pthread_maybe_cancel();
+
return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
}
int open(char const* path, int options, ...)
{
+ __pthread_maybe_cancel();
+
if (!path) {
errno = EFAULT;
return -1;
@@ -71,6 +78,8 @@ int open(char const* path, int options, ...)
int openat(int dirfd, char const* path, int options, ...)
{
+ __pthread_maybe_cancel();
+
if (!path) {
errno = EFAULT;
return -1;
diff --git a/Userland/Libraries/LibC/poll.cpp b/Userland/Libraries/LibC/poll.cpp
index 7491346d5b..2d80d13cce 100644
--- a/Userland/Libraries/LibC/poll.cpp
+++ b/Userland/Libraries/LibC/poll.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <poll.h>
#include <sys/time.h>
@@ -14,6 +15,8 @@ extern "C" {
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html
int poll(pollfd* fds, nfds_t nfds, int timeout_ms)
{
+ __pthread_maybe_cancel();
+
timespec timeout;
timespec* timeout_ts = &timeout;
if (timeout_ms < 0)
diff --git a/Userland/Libraries/LibC/pthread.cpp b/Userland/Libraries/LibC/pthread.cpp
index 29aecba78e..5f9d981096 100644
--- a/Userland/Libraries/LibC/pthread.cpp
+++ b/Userland/Libraries/LibC/pthread.cpp
@@ -192,6 +192,8 @@ void pthread_cleanup_pop(int execute)
// https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_join.html
int pthread_join(pthread_t thread, void** exit_value_ptr)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_join_thread, thread, exit_value_ptr);
__RETURN_PTHREAD_ERROR(rc);
}
diff --git a/Userland/Libraries/LibC/pthread_cond.cpp b/Userland/Libraries/LibC/pthread_cond.cpp
index 0ff377bfac..8c15579391 100644
--- a/Userland/Libraries/LibC/pthread_cond.cpp
+++ b/Userland/Libraries/LibC/pthread_cond.cpp
@@ -8,6 +8,7 @@
#include <AK/Assertions.h>
#include <AK/Atomic.h>
#include <AK/Types.h>
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <pthread.h>
#include <serenity.h>
@@ -87,6 +88,8 @@ int pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html
int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const struct timespec* abstime)
{
+ __pthread_maybe_cancel();
+
// Save the mutex this condition variable is associated with. We don't (yet)
// support changing this mutex once set.
pthread_mutex_t* old_mutex = AK::atomic_exchange(&cond->mutex, mutex, AK::memory_order_relaxed);
diff --git a/Userland/Libraries/LibC/semaphore.cpp b/Userland/Libraries/LibC/semaphore.cpp
index 355500730f..cebee805e8 100644
--- a/Userland/Libraries/LibC/semaphore.cpp
+++ b/Userland/Libraries/LibC/semaphore.cpp
@@ -12,6 +12,7 @@
#include <AK/ScopeGuard.h>
#include <AK/String.h>
#include <AK/Types.h>
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
@@ -310,6 +311,8 @@ int sem_wait(sem_t* sem)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_timedwait.html
int sem_timedwait(sem_t* sem, const struct timespec* abstime)
{
+ __pthread_maybe_cancel();
+
if (sem->magic != SEM_MAGIC) {
errno = EINVAL;
return -1;
diff --git a/Userland/Libraries/LibC/signal.cpp b/Userland/Libraries/LibC/signal.cpp
index 850dd48caa..f15a313d75 100644
--- a/Userland/Libraries/LibC/signal.cpp
+++ b/Userland/Libraries/LibC/signal.cpp
@@ -6,6 +6,7 @@
#include <AK/Format.h>
#include <assert.h>
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <setjmp.h>
#include <signal.h>
@@ -175,6 +176,8 @@ void siglongjmp(jmp_buf env, int val)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigsuspend.html
int sigsuspend(sigset_t const* set)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_sigsuspend, set);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -182,6 +185,8 @@ int sigsuspend(sigset_t const* set)
// https://pubs.opengroup.org/onlinepubs/009604499/functions/sigwait.html
int sigwait(sigset_t const* set, int* sig)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(Syscall::SC_sigtimedwait, set, nullptr, nullptr);
VERIFY(rc != 0);
if (rc < 0)
@@ -199,6 +204,8 @@ int sigwaitinfo(sigset_t const* set, siginfo_t* info)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigtimedwait.html
int sigtimedwait(sigset_t const* set, siginfo_t* info, struct timespec const* timeout)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(Syscall::SC_sigtimedwait, set, info, timeout);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/Userland/Libraries/LibC/stdlib.cpp b/Userland/Libraries/LibC/stdlib.cpp
index 69ea92f790..39069a93e0 100644
--- a/Userland/Libraries/LibC/stdlib.cpp
+++ b/Userland/Libraries/LibC/stdlib.cpp
@@ -14,6 +14,7 @@
#include <LibELF/AuxiliaryVector.h>
#include <alloca.h>
#include <assert.h>
+#include <bits/pthread_cancel.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -810,6 +811,8 @@ void srandom(unsigned seed)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/system.html
int system(char const* command)
{
+ __pthread_maybe_cancel();
+
if (!command)
return 1;
diff --git a/Userland/Libraries/LibC/sys/mman.cpp b/Userland/Libraries/LibC/sys/mman.cpp
index 9dd9d4ef3a..20c0db4c45 100644
--- a/Userland/Libraries/LibC/sys/mman.cpp
+++ b/Userland/Libraries/LibC/sys/mman.cpp
@@ -5,6 +5,7 @@
*/
#include <AK/Format.h>
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -110,6 +111,8 @@ int munlock(void const*, size_t)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/msync.html
int msync(void* address, size_t size, int flags)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_msync, address, size, flags);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/Userland/Libraries/LibC/sys/select.cpp b/Userland/Libraries/LibC/sys/select.cpp
index b3441a4910..2669a0832f 100644
--- a/Userland/Libraries/LibC/sys/select.cpp
+++ b/Userland/Libraries/LibC/sys/select.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <stdio.h>
#include <sys/poll.h>
@@ -18,6 +19,8 @@ extern "C" {
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, timeval* timeout_tv)
{
+ __pthread_maybe_cancel();
+
timespec* timeout_ts = nullptr;
timespec timeout;
if (timeout_tv) {
@@ -30,6 +33,8 @@ int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, timev
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/pselect.html
int pselect(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, timespec const* timeout, sigset_t const* sigmask)
{
+ __pthread_maybe_cancel();
+
Vector<pollfd, FD_SETSIZE> fds;
if (nfds < 0 || static_cast<size_t>(nfds) >= fds.capacity())
diff --git a/Userland/Libraries/LibC/sys/socket.cpp b/Userland/Libraries/LibC/sys/socket.cpp
index 6cfedc0c0e..54d67403b0 100644
--- a/Userland/Libraries/LibC/sys/socket.cpp
+++ b/Userland/Libraries/LibC/sys/socket.cpp
@@ -5,6 +5,7 @@
*/
#include <AK/Assertions.h>
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -38,6 +39,8 @@ int listen(int sockfd, int backlog)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html
int accept(int sockfd, sockaddr* addr, socklen_t* addrlen)
{
+ __pthread_maybe_cancel();
+
return accept4(sockfd, addr, addrlen, 0);
}
@@ -51,6 +54,8 @@ int accept4(int sockfd, sockaddr* addr, socklen_t* addrlen, int flags)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html
int connect(int sockfd, sockaddr const* addr, socklen_t addrlen)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_connect, sockfd, addr, addrlen);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -65,6 +70,8 @@ int shutdown(int sockfd, int how)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html
ssize_t sendmsg(int sockfd, const struct msghdr* msg, int flags)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_sendmsg, sockfd, msg, flags);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -86,6 +93,8 @@ ssize_t send(int sockfd, void const* data, size_t data_length, int flags)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html
ssize_t recvmsg(int sockfd, struct msghdr* msg, int flags)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_recvmsg, sockfd, msg, flags);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -93,6 +102,8 @@ ssize_t recvmsg(int sockfd, struct msghdr* msg, int flags)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html
ssize_t recvfrom(int sockfd, void* buffer, size_t buffer_length, int flags, struct sockaddr* addr, socklen_t* addr_length)
{
+ __pthread_maybe_cancel();
+
if (!addr_length && addr) {
errno = EINVAL;
return -1;
diff --git a/Userland/Libraries/LibC/sys/uio.cpp b/Userland/Libraries/LibC/sys/uio.cpp
index 6e7bdce91a..24be56d284 100644
--- a/Userland/Libraries/LibC/sys/uio.cpp
+++ b/Userland/Libraries/LibC/sys/uio.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <sys/uio.h>
#include <syscall.h>
@@ -12,12 +13,16 @@ extern "C" {
ssize_t writev(int fd, const struct iovec* iov, int iov_count)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_writev, fd, iov, iov_count);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
ssize_t readv(int fd, const struct iovec* iov, int iov_count)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_readv, fd, iov, iov_count);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/Userland/Libraries/LibC/sys/wait.cpp b/Userland/Libraries/LibC/sys/wait.cpp
index 0a613352f7..dab010de60 100644
--- a/Userland/Libraries/LibC/sys/wait.cpp
+++ b/Userland/Libraries/LibC/sys/wait.cpp
@@ -5,6 +5,7 @@
*/
#include <assert.h>
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <sys/wait.h>
#include <syscall.h>
@@ -21,6 +22,8 @@ pid_t wait(int* wstatus)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/waitpid.html
pid_t waitpid(pid_t waitee, int* wstatus, int options)
{
+ __pthread_maybe_cancel();
+
siginfo_t siginfo;
idtype_t idtype;
id_t id;
@@ -78,6 +81,8 @@ pid_t waitpid(pid_t waitee, int* wstatus, int options)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/waitid.html
int waitid(idtype_t idtype, id_t id, siginfo_t* infop, int options)
{
+ __pthread_maybe_cancel();
+
Syscall::SC_waitid_params params { idtype, id, infop, options };
int rc = syscall(SC_waitid, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
diff --git a/Userland/Libraries/LibC/termios.cpp b/Userland/Libraries/LibC/termios.cpp
index 291dafa659..328424ef9d 100644
--- a/Userland/Libraries/LibC/termios.cpp
+++ b/Userland/Libraries/LibC/termios.cpp
@@ -5,6 +5,7 @@
*/
#include <assert.h>
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <termios.h>
@@ -51,6 +52,8 @@ int tcflush(int fd, int queue_selector)
// https://pubs.opengroup.org/onlinepubs/009695399/functions/tcdrain.html
int tcdrain([[maybe_unused]] int fd)
{
+ __pthread_maybe_cancel();
+
// FIXME: Implement this for real.
return 0;
}
diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp
index 163c75fa4c..9ee6e89a37 100644
--- a/Userland/Libraries/LibC/time.cpp
+++ b/Userland/Libraries/LibC/time.cpp
@@ -11,6 +11,7 @@
#include <Kernel/API/TimePage.h>
#include <LibTimeZone/TimeZone.h>
#include <assert.h>
+#include <bits/pthread_cancel.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
@@ -458,6 +459,8 @@ int clock_settime(clockid_t clock_id, struct timespec* ts)
int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec* requested_sleep, struct timespec* remaining_sleep)
{
+ __pthread_maybe_cancel();
+
Syscall::SC_clock_nanosleep_params params { clock_id, flags, requested_sleep, remaining_sleep };
int rc = syscall(SC_clock_nanosleep, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp
index b305185249..78dcb42e5f 100644
--- a/Userland/Libraries/LibC/unistd.cpp
+++ b/Userland/Libraries/LibC/unistd.cpp
@@ -10,6 +10,7 @@
#include <AK/Vector.h>
#include <alloca.h>
#include <assert.h>
+#include <bits/pthread_cancel.h>
#include <bits/pthread_integration.h>
#include <dirent.h>
#include <errno.h>
@@ -374,6 +375,8 @@ pid_t getpgrp()
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
ssize_t read(int fd, void* buf, size_t count)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_read, fd, buf, count);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -381,6 +384,8 @@ ssize_t read(int fd, void* buf, size_t count)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html
ssize_t pread(int fd, void* buf, size_t count, off_t offset)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_pread, fd, buf, count, &offset);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -388,6 +393,8 @@ ssize_t pread(int fd, void* buf, size_t count, off_t offset)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html
ssize_t write(int fd, void const* buf, size_t count)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_write, fd, buf, count);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -395,6 +402,8 @@ ssize_t write(int fd, void const* buf, size_t count)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html
ssize_t pwrite(int fd, void const* buf, size_t count, off_t offset)
{
+ __pthread_maybe_cancel();
+
// FIXME: This is not thread safe and should be implemented in the kernel instead.
off_t old_offset = lseek(fd, 0, SEEK_CUR);
lseek(fd, offset, SEEK_SET);
@@ -484,6 +493,8 @@ char* ttyname(int fd)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
int close(int fd)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_close, fd);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -891,6 +902,8 @@ int sysbeep()
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html
int fsync(int fd)
{
+ __pthread_maybe_cancel();
+
int rc = syscall(SC_fsync, fd);
__RETURN_WITH_ERRNO(rc, rc, -1);
}