LibC: Implement pthread cancelation
This code is not tested at all but it looks correct xD
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
@@ -25,6 +26,7 @@ int munmap(void* addr, size_t len)
|
||||
|
||||
int msync(void* addr, size_t len, int flags)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return syscall(SYS_MSYNC, addr, len, flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include <pthread.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int pselect(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, fd_set* __restrict errorfds, const struct timespec* __restrict timeout, const sigset_t* __restrict sigmask)
|
||||
{
|
||||
pthread_testcancel();
|
||||
sys_pselect_t arguments {
|
||||
.nfds = nfds,
|
||||
.readfds = readfds,
|
||||
@@ -17,6 +19,7 @@ int pselect(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, f
|
||||
|
||||
int select(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, fd_set* __restrict errorfds, struct timeval* __restrict timeout)
|
||||
{
|
||||
pthread_testcancel();
|
||||
timespec* pts = nullptr;
|
||||
timespec ts;
|
||||
if (timeout)
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
#include <pthread.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return accept4(socket, address, address_len, 0);
|
||||
}
|
||||
|
||||
int accept4(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len, int flags)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return syscall(SYS_ACCEPT, socket, address, address_len, flags);
|
||||
}
|
||||
|
||||
@@ -19,6 +22,7 @@ int bind(int socket, const struct sockaddr* address, socklen_t address_len)
|
||||
|
||||
int connect(int socket, const struct sockaddr* address, socklen_t address_len)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return syscall(SYS_CONNECT, socket, address, address_len);
|
||||
}
|
||||
|
||||
@@ -29,11 +33,13 @@ int listen(int socket, int backlog)
|
||||
|
||||
ssize_t recv(int socket, void* __restrict buffer, size_t length, int flags)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return recvfrom(socket, buffer, length, flags, nullptr, nullptr);
|
||||
}
|
||||
|
||||
ssize_t recvfrom(int socket, void* __restrict buffer, size_t length, int flags, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
||||
{
|
||||
pthread_testcancel();
|
||||
sys_recvfrom_t arguments {
|
||||
.socket = socket,
|
||||
.buffer = buffer,
|
||||
@@ -47,11 +53,13 @@ ssize_t recvfrom(int socket, void* __restrict buffer, size_t length, int flags,
|
||||
|
||||
ssize_t send(int socket, const void* message, size_t length, int flags)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return sendto(socket, message, length, flags, nullptr, 0);
|
||||
}
|
||||
|
||||
ssize_t sendto(int socket, const void* message, size_t length, int flags, const struct sockaddr* dest_addr, socklen_t dest_len)
|
||||
{
|
||||
pthread_testcancel();
|
||||
sys_sendto_t arguments {
|
||||
.socket = socket,
|
||||
.message = message,
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include <pthread.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
ssize_t readv(int fildes, const struct iovec* iov, int iovcnt)
|
||||
{
|
||||
pthread_testcancel();
|
||||
|
||||
size_t result = 0;
|
||||
for (int i = 0; i < iovcnt; i++)
|
||||
{
|
||||
@@ -25,6 +28,8 @@ ssize_t readv(int fildes, const struct iovec* iov, int iovcnt)
|
||||
|
||||
ssize_t writev(int fildes, const struct iovec* iov, int iovcnt)
|
||||
{
|
||||
pthread_testcancel();
|
||||
|
||||
size_t result = 0;
|
||||
for (int i = 0; i < iovcnt; i++)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
#include <pthread.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
pid_t wait(int* stat_loc)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return waitpid(-1, stat_loc, 0);
|
||||
}
|
||||
|
||||
pid_t waitpid(pid_t pid, int* stat_loc, int options)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return (pid_t)syscall(SYS_WAIT, pid, stat_loc, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user