Kenrel: Separate pthread API from kernel API

It didn't really make sense for the syscalls to be named as the pthread
equivalents. Now the kernel just uses thread ids
This commit is contained in:
2026-07-02 19:11:49 +03:00
parent 5540bc4147
commit f449ca8161
10 changed files with 58 additions and 62 deletions

View File

@@ -100,12 +100,12 @@ __BEGIN_DECLS
O(SYS_GET_FSBASE, get_fsbase) \
O(SYS_SET_GSBASE, set_gsbase) \
O(SYS_GET_GSBASE, get_gsbase) \
O(SYS_PTHREAD_CREATE, pthread_create) \
O(SYS_PTHREAD_EXIT, pthread_exit) \
O(SYS_PTHREAD_JOIN, pthread_join) \
O(SYS_PTHREAD_SELF, pthread_self) \
O(SYS_PTHREAD_KILL, pthread_kill) \
O(SYS_PTHREAD_DETACH, pthread_detach) \
O(SYS_THREAD_CREATE, thread_create) \
O(SYS_THREAD_EXIT, thread_exit) \
O(SYS_THREAD_JOIN, thread_join) \
O(SYS_THREAD_GETID, thread_getid) \
O(SYS_THREAD_KILL, thread_kill) \
O(SYS_THREAD_DETACH, thread_detach) \
O(SYS_EPOLL_CREATE1, epoll_create1) \
O(SYS_EPOLL_CTL, epoll_ctl) \
O(SYS_EPOLL_PWAIT2, epoll_pwait2) \

View File

@@ -62,7 +62,7 @@ asm(
extern "C" void _pthread_trampoline_cpp(void* arg)
{
auto info = *reinterpret_cast<pthread_trampoline_info_t*>(arg);
info.uthread->id = syscall(SYS_PTHREAD_SELF);
info.uthread->id = syscall(SYS_THREAD_GETID);
#if defined(__x86_64__)
syscall(SYS_SET_FSBASE, info.uthread);
#elif defined(__i686__)
@@ -432,7 +432,7 @@ int pthread_create(pthread_t* __restrict thread_id, const pthread_attr_t* __rest
info->uthread = uthread;
}
syscall_ret = syscall(SYS_PTHREAD_CREATE, attr, _pthread_trampoline, info);
syscall_ret = syscall(SYS_THREAD_CREATE, _pthread_trampoline, info);
if (syscall_ret == -1)
goto pthread_create_error;
@@ -450,7 +450,7 @@ pthread_create_error:
int pthread_detach(pthread_t thread)
{
return syscall(SYS_PTHREAD_DETACH, thread);
return syscall(SYS_THREAD_DETACH, thread);
}
void pthread_exit(void* value_ptr)
@@ -486,7 +486,7 @@ void pthread_exit(void* value_ptr)
}
free_uthread(uthread);
syscall(SYS_PTHREAD_EXIT, value_ptr);
syscall(SYS_THREAD_EXIT, value_ptr);
ASSERT_NOT_REACHED();
}
@@ -495,7 +495,7 @@ int pthread_join(pthread_t thread, void** value_ptr)
do {
pthread_testcancel();
errno = 0;
} while (syscall(SYS_PTHREAD_JOIN, thread, value_ptr) == -1 && errno == EINTR);
} while (syscall(SYS_THREAD_JOIN, thread, value_ptr) == -1 && errno == EINTR);
return errno;
}
@@ -528,7 +528,7 @@ static pthread_mutex_t s_atfork_mutex = PTHREAD_MUTEX_INITIALIZER;
void _pthread_call_atfork(int state)
{
if (state == _PTHREAD_ATFORK_CHILD)
_get_uthread()->id = syscall(SYS_PTHREAD_SELF);
_get_uthread()->id = syscall(SYS_THREAD_GETID);
pthread_mutex_lock(&s_atfork_mutex);

View File

@@ -1,5 +1,6 @@
#include <BAN/Assert.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <string.h>
#include <sys/syscall.h>
@@ -40,7 +41,7 @@ void psignal(int signum, const char* message)
int pthread_kill(pthread_t thread, int sig)
{
if (syscall(SYS_PTHREAD_KILL, thread, sig) == -1)
if (syscall(SYS_THREAD_KILL, thread, sig) == -1)
return errno;
return 0;
}
@@ -54,8 +55,7 @@ int pthread_sigmask(int how, const sigset_t* __restrict set, sigset_t* __restric
int raise(int sig)
{
// FIXME: won't work after multithreaded
return kill(getpid(), sig);
return pthread_kill(pthread_self(), sig);
}
int sigaction(int sig, const struct sigaction* __restrict act, struct sigaction* __restrict oact)

View File

@@ -66,7 +66,7 @@ extern "C" void _init_libc(char** environ, init_funcs_t init_funcs, init_funcs_t
#endif
{
self->cleanup_stack = nullptr;
self->id = syscall(SYS_PTHREAD_SELF);
self->id = syscall(SYS_THREAD_GETID);
self->errno_ = 0;
self->cancel_type = PTHREAD_CANCEL_DEFERRED;
self->cancel_state = PTHREAD_CANCEL_ENABLE;
@@ -84,7 +84,7 @@ extern "C" void _init_libc(char** environ, init_funcs_t init_funcs, init_funcs_t
.master_tls_module_count = 1,
.dynamic_tls = nullptr,
.cleanup_stack = nullptr,
.id = static_cast<pthread_t>(syscall(SYS_PTHREAD_SELF)),
.id = static_cast<pthread_t>(syscall(SYS_THREAD_GETID)),
.errno_ = 0,
.cancel_type = PTHREAD_CANCEL_DEFERRED,
.cancel_state = PTHREAD_CANCEL_ENABLE,

View File

@@ -223,7 +223,7 @@ constexpr uintptr_t SYM_NOT_FOUND = -1;
static void lock_global_lock()
{
const pthread_t tid = syscall(SYS_PTHREAD_SELF);
const pthread_t tid = syscall(SYS_THREAD_GETID);
pthread_t expected = 0;
while (!s_global_locker.compare_exchange(expected, tid))
@@ -1359,7 +1359,7 @@ static void initialize_tls(MasterTLS master_tls)
.master_tls_module_count = master_tls.module_count,
.dynamic_tls = s_dynamic_tls,
.cleanup_stack = nullptr,
.id = static_cast<pthread_t>(syscall(SYS_PTHREAD_SELF)),
.id = static_cast<pthread_t>(syscall(SYS_THREAD_GETID)),
.errno_ = 0,
.cancel_type = PTHREAD_CANCEL_DEFERRED,
.cancel_state = PTHREAD_CANCEL_ENABLE,