Kernel/LibC: Implement pthread_kill

This commit is contained in:
Bananymous 2025-06-01 00:56:23 +03:00
parent c957f1ddca
commit 56fdf6002c
4 changed files with 37 additions and 2 deletions

View File

@ -194,6 +194,7 @@ namespace Kernel
BAN::ErrorOr<long> sys_pthread_exit(void* value); BAN::ErrorOr<long> sys_pthread_exit(void* value);
BAN::ErrorOr<long> sys_pthread_join(pthread_t thread, void** value); BAN::ErrorOr<long> sys_pthread_join(pthread_t thread, void** value);
BAN::ErrorOr<long> sys_pthread_self(); BAN::ErrorOr<long> sys_pthread_self();
BAN::ErrorOr<long> sys_pthread_kill(pthread_t thread, int signal);
BAN::ErrorOr<long> sys_tcgetpgrp(int fd); BAN::ErrorOr<long> sys_tcgetpgrp(int fd);
BAN::ErrorOr<long> sys_tcsetpgrp(int fd, pid_t pgid); BAN::ErrorOr<long> sys_tcsetpgrp(int fd, pid_t pgid);

View File

@ -2557,6 +2557,25 @@ namespace Kernel
return Thread::current().tid(); return Thread::current().tid();
} }
BAN::ErrorOr<long> Process::sys_pthread_kill(pthread_t tid, int signal)
{
if (signal != 0 && (signal < _SIGMIN || signal > _SIGMAX))
return BAN::Error::from_errno(EINVAL);
LockGuard _(m_process_lock);
for (auto* thread : m_threads)
{
if (thread->tid() != tid)
continue;
if (signal != 0)
thread->add_signal(signal);
return 0;
}
return BAN::Error::from_errno(ESRCH);
}
BAN::ErrorOr<long> Process::sys_tcgetpgrp(int fd) BAN::ErrorOr<long> Process::sys_tcgetpgrp(int fd)
{ {
LockGuard _(m_process_lock); LockGuard _(m_process_lock);

View File

@ -103,6 +103,7 @@ __BEGIN_DECLS
O(SYS_PTHREAD_EXIT, pthread_exit) \ O(SYS_PTHREAD_EXIT, pthread_exit) \
O(SYS_PTHREAD_JOIN, pthread_join) \ O(SYS_PTHREAD_JOIN, pthread_join) \
O(SYS_PTHREAD_SELF, pthread_self) \ O(SYS_PTHREAD_SELF, pthread_self) \
O(SYS_PTHREAD_KILL, pthread_kill) \
O(SYS_EPOLL_CREATE1, epoll_create1) \ O(SYS_EPOLL_CREATE1, epoll_create1) \
O(SYS_EPOLL_CTL, epoll_ctl) \ O(SYS_EPOLL_CTL, epoll_ctl) \
O(SYS_EPOLL_PWAIT2, epoll_pwait2) \ O(SYS_EPOLL_PWAIT2, epoll_pwait2) \

View File

@ -38,9 +38,18 @@ void psignal(int signum, const char* message)
fprintf(stderr, "%s\n", strsignal(signum)); fprintf(stderr, "%s\n", strsignal(signum));
} }
int pthread_kill(pthread_t thread, int sig)
{
if (syscall(SYS_PTHREAD_KILL, thread, sig) == -1)
return errno;
return 0;
}
int pthread_sigmask(int how, const sigset_t* __restrict set, sigset_t* __restrict oset) int pthread_sigmask(int how, const sigset_t* __restrict set, sigset_t* __restrict oset)
{ {
return syscall(SYS_SIGPROCMASK, how, set, oset); if (syscall(SYS_SIGPROCMASK, how, set, oset) == -1)
return errno;
return 0;
} }
int raise(int sig) int raise(int sig)
@ -138,7 +147,12 @@ int sigpending(sigset_t* set)
int sigprocmask(int how, const sigset_t* __restrict set, sigset_t* __restrict oset) int sigprocmask(int how, const sigset_t* __restrict set, sigset_t* __restrict oset)
{ {
return pthread_sigmask(how, set, oset); if (int error = pthread_sigmask(how, set, oset))
{
errno = error;
return -1;
}
return 0;
} }
int sigrelse(int sig) int sigrelse(int sig)