1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

LibC: Add POSIX spec comments for signal APIs

This commit is contained in:
Brian Gianforcaro 2021-12-21 15:58:56 -08:00 committed by Brian Gianforcaro
parent ea355fbf17
commit 6fe71970f5

View file

@ -16,24 +16,28 @@
extern "C" { extern "C" {
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html
int kill(pid_t pid, int sig) int kill(pid_t pid, int sig)
{ {
int rc = syscall(SC_kill, pid, sig); int rc = syscall(SC_kill, pid, sig);
__RETURN_WITH_ERRNO(rc, rc, -1); __RETURN_WITH_ERRNO(rc, rc, -1);
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html
int killpg(int pgrp, int sig) int killpg(int pgrp, int sig)
{ {
int rc = syscall(SC_killpg, pgrp, sig); int rc = syscall(SC_killpg, pgrp, sig);
__RETURN_WITH_ERRNO(rc, rc, -1); __RETURN_WITH_ERRNO(rc, rc, -1);
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/raise.html
int raise(int sig) int raise(int sig)
{ {
// FIXME: Support multi-threaded programs. // FIXME: Support multi-threaded programs.
return kill(getpid(), sig); return kill(getpid(), sig);
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html
sighandler_t signal(int signum, sighandler_t handler) sighandler_t signal(int signum, sighandler_t handler)
{ {
struct sigaction new_act; struct sigaction new_act;
@ -47,24 +51,28 @@ sighandler_t signal(int signum, sighandler_t handler)
return old_act.sa_handler; return old_act.sa_handler;
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html
int sigaction(int signum, const struct sigaction* act, struct sigaction* old_act) int sigaction(int signum, const struct sigaction* act, struct sigaction* old_act)
{ {
int rc = syscall(SC_sigaction, signum, act, old_act); int rc = syscall(SC_sigaction, signum, act, old_act);
__RETURN_WITH_ERRNO(rc, rc, -1); __RETURN_WITH_ERRNO(rc, rc, -1);
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigemptyset.html
int sigemptyset(sigset_t* set) int sigemptyset(sigset_t* set)
{ {
*set = 0; *set = 0;
return 0; return 0;
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigfillset.html
int sigfillset(sigset_t* set) int sigfillset(sigset_t* set)
{ {
*set = 0xffffffff; *set = 0xffffffff;
return 0; return 0;
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaddset.html
int sigaddset(sigset_t* set, int sig) int sigaddset(sigset_t* set, int sig)
{ {
if (sig < 1 || sig > 32) { if (sig < 1 || sig > 32) {
@ -75,12 +83,14 @@ int sigaddset(sigset_t* set, int sig)
return 0; return 0;
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaltstack.html
int sigaltstack(const stack_t* ss, stack_t* old_ss) int sigaltstack(const stack_t* ss, stack_t* old_ss)
{ {
int rc = syscall(SC_sigaltstack, ss, old_ss); int rc = syscall(SC_sigaltstack, ss, old_ss);
__RETURN_WITH_ERRNO(rc, rc, -1); __RETURN_WITH_ERRNO(rc, rc, -1);
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigdelset.html
int sigdelset(sigset_t* set, int sig) int sigdelset(sigset_t* set, int sig)
{ {
if (sig < 1 || sig > 32) { if (sig < 1 || sig > 32) {
@ -91,6 +101,7 @@ int sigdelset(sigset_t* set, int sig)
return 0; return 0;
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigismember.html
int sigismember(const sigset_t* set, int sig) int sigismember(const sigset_t* set, int sig)
{ {
if (sig < 1 || sig > 32) { if (sig < 1 || sig > 32) {
@ -102,12 +113,14 @@ int sigismember(const sigset_t* set, int sig)
return 0; return 0;
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigprocmask.html
int sigprocmask(int how, const sigset_t* set, sigset_t* old_set) int sigprocmask(int how, const sigset_t* set, sigset_t* old_set)
{ {
int rc = syscall(SC_sigprocmask, how, set, old_set); int rc = syscall(SC_sigprocmask, how, set, old_set);
__RETURN_WITH_ERRNO(rc, rc, -1); __RETURN_WITH_ERRNO(rc, rc, -1);
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigpending.html
int sigpending(sigset_t* set) int sigpending(sigset_t* set)
{ {
int rc = syscall(SC_sigpending, set); int rc = syscall(SC_sigpending, set);
@ -149,6 +162,7 @@ const char* sys_siglist[NSIG] = {
"Bad system call", "Bad system call",
}; };
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/siglongjmp.html
void siglongjmp(jmp_buf env, int val) void siglongjmp(jmp_buf env, int val)
{ {
if (env->did_save_signal_mask) { if (env->did_save_signal_mask) {
@ -158,6 +172,7 @@ void siglongjmp(jmp_buf env, int val)
longjmp(env, val); longjmp(env, val);
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigsuspend.html
int sigsuspend(const sigset_t* set) int sigsuspend(const sigset_t* set)
{ {
return pselect(0, nullptr, nullptr, nullptr, nullptr, set); return pselect(0, nullptr, nullptr, nullptr, nullptr, set);
@ -180,6 +195,7 @@ int sigwaitinfo(sigset_t const* set, siginfo_t* info)
return sigtimedwait(set, info, nullptr); return sigtimedwait(set, info, nullptr);
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigtimedwait.html
int sigtimedwait(sigset_t const* set, siginfo_t* info, struct timespec const* timeout) int sigtimedwait(sigset_t const* set, siginfo_t* info, struct timespec const* timeout)
{ {
int rc = syscall(Syscall::SC_sigtimedwait, set, info, timeout); int rc = syscall(Syscall::SC_sigtimedwait, set, info, timeout);