mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-27 04:50:28 +00:00
Introduce sigtimedwait() and sigwaitinfo()
This change also invents sigcountset() and strsignal_r() and improves the quality of siginfo_t handling.
This commit is contained in:
parent
7ae556463a
commit
467a332e38
41 changed files with 887 additions and 345 deletions
|
@ -65,6 +65,13 @@ $(LIBC_CALLS_A).pkg: \
|
|||
$(LIBC_CALLS_A_OBJS) \
|
||||
$(foreach x,$(LIBC_CALLS_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
# we can't use asan because:
|
||||
# siginfo_t memory is owned by kernels
|
||||
o/$(MODE)/libc/calls/siginfo2cosmo.o: private \
|
||||
OVERRIDE_COPTS += \
|
||||
-ffreestanding \
|
||||
-fno-sanitize=address
|
||||
|
||||
# we can't use asan because:
|
||||
# ucontext_t memory is owned by xnu kernel
|
||||
o/$(MODE)/libc/calls/sigenter-xnu.o: private \
|
||||
|
|
|
@ -556,6 +556,7 @@ static const uint16_t kPledgeStdio[] = {
|
|||
__NR_linux_prlimit | STDIO, //
|
||||
__NR_linux_sched_getaffinity, //
|
||||
__NR_linux_sched_setaffinity, //
|
||||
__NR_linux_sigtimedwait, //
|
||||
};
|
||||
|
||||
static const uint16_t kPledgeFlock[] = {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "libc/calls/struct/sigaction-freebsd.internal.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo-freebsd.internal.h"
|
||||
#include "libc/calls/struct/siginfo-meta.internal.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/struct/ucontext-freebsd.internal.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
|
@ -75,16 +76,7 @@ privileged void __sigenter_freebsd(int sig, struct siginfo_freebsd *freebsdinfo,
|
|||
g.uc.uc_mcontext.err = ctx->uc_mcontext.mc_err;
|
||||
g.uc.uc_mcontext.trapno = ctx->uc_mcontext.mc_trapno;
|
||||
__repmovsb(&g.uc.__fpustate, &ctx->uc_mcontext.mc_fpstate, 512);
|
||||
g.si.si_signo = freebsdinfo->si_signo;
|
||||
g.si.si_errno = freebsdinfo->si_errno;
|
||||
g.si.si_code = freebsdinfo->si_code;
|
||||
if (freebsdinfo->si_pid) {
|
||||
g.si.si_pid = freebsdinfo->si_pid;
|
||||
g.si.si_uid = freebsdinfo->si_uid;
|
||||
} else {
|
||||
g.si.si_addr = (void *)freebsdinfo->si_addr;
|
||||
}
|
||||
g.si.si_value = freebsdinfo->si_value;
|
||||
__siginfo2cosmo(&g.si, (void *)freebsdinfo);
|
||||
((sigaction_f)(_base + rva))(sig, &g.si, &g.uc);
|
||||
ctx->uc_stack.ss_sp = g.uc.uc_stack.ss_sp;
|
||||
ctx->uc_stack.ss_size = g.uc.uc_stack.ss_size;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/struct/sigaction-freebsd.internal.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo-meta.internal.h"
|
||||
#include "libc/calls/struct/siginfo-netbsd.internal.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/struct/ucontext-netbsd.internal.h"
|
||||
|
@ -43,13 +44,7 @@ privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
|
|||
((sigaction_f)(_base + rva))(sig, 0, 0);
|
||||
} else {
|
||||
__repstosb(&uc, 0, sizeof(uc));
|
||||
__repstosb(&si2, 0, sizeof(si2));
|
||||
si2.si_signo = si->si_signo;
|
||||
si2.si_code = si->si_code;
|
||||
si2.si_errno = si->si_errno;
|
||||
si2.si_pid = si->si_pid;
|
||||
si2.si_uid = si->si_uid;
|
||||
si2.si_value = si->si_value;
|
||||
__siginfo2cosmo(&si2, (void *)si);
|
||||
uc.uc_mcontext.fpregs = &uc.__fpustate;
|
||||
uc.uc_flags = ctx->uc_flags;
|
||||
uc.uc_stack.ss_sp = ctx->uc_stack.ss_sp;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/struct/sigaction-freebsd.internal.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo-meta.internal.h"
|
||||
#include "libc/calls/struct/siginfo-openbsd.internal.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/struct/ucontext-openbsd.internal.h"
|
||||
|
@ -44,17 +45,8 @@ privileged void __sigenter_openbsd(int sig, struct siginfo_openbsd *openbsdinfo,
|
|||
if (~flags & SA_SIGINFO) {
|
||||
((sigaction_f)(_base + rva))(sig, 0, 0);
|
||||
} else {
|
||||
__repstosb(&g, 0, sizeof(g));
|
||||
g.si.si_signo = openbsdinfo->si_signo;
|
||||
g.si.si_code = openbsdinfo->si_code;
|
||||
g.si.si_errno = openbsdinfo->si_errno;
|
||||
if (openbsdinfo->si_pid) {
|
||||
g.si.si_pid = openbsdinfo->si_pid;
|
||||
g.si.si_uid = openbsdinfo->si_uid;
|
||||
} else {
|
||||
g.si.si_addr = (void *)openbsdinfo->si_addr;
|
||||
}
|
||||
g.si.si_value = openbsdinfo->si_value;
|
||||
__repstosb(&g.uc, 0, sizeof(g.uc));
|
||||
__siginfo2cosmo(&g.si, (void *)openbsdinfo);
|
||||
g.uc.uc_mcontext.fpregs = &g.uc.__fpustate;
|
||||
__repmovsb(&g.uc.uc_sigmask, &ctx->sc_mask,
|
||||
MIN(sizeof(g.uc.uc_sigmask), sizeof(ctx->sc_mask)));
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/struct/metasigaltstack.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/siginfo-meta.internal.h"
|
||||
#include "libc/calls/struct/siginfo-xnu.internal.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/ucontext.h"
|
||||
|
@ -492,16 +493,7 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
|
|||
}
|
||||
}
|
||||
if (xnuinfo) {
|
||||
g.si.si_signo = xnuinfo->si_signo;
|
||||
g.si.si_errno = xnuinfo->si_errno;
|
||||
g.si.si_code = xnuinfo->si_code;
|
||||
if (xnuinfo->si_pid) {
|
||||
g.si.si_pid = xnuinfo->si_pid;
|
||||
g.si.si_uid = xnuinfo->si_uid;
|
||||
} else {
|
||||
g.si.si_addr = (void *)xnuinfo->si_addr;
|
||||
}
|
||||
g.si.si_value = xnuinfo->si_value;
|
||||
__siginfo2cosmo(&g.si, (void *)xnuinfo);
|
||||
}
|
||||
((sigaction_f)(_base + rva))(sig, &g.si, &g.uc);
|
||||
if (xnuctx) {
|
||||
|
|
106
libc/calls/siginfo2cosmo.c
Normal file
106
libc/calls/siginfo2cosmo.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/siginfo-meta.internal.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
|
||||
privileged void __siginfo2cosmo(struct siginfo *si,
|
||||
const union siginfo_meta *m) {
|
||||
void *si_addr;
|
||||
int32_t si_signo;
|
||||
int32_t si_errno;
|
||||
int32_t si_code;
|
||||
int32_t si_pid;
|
||||
int32_t si_uid;
|
||||
int32_t si_status;
|
||||
int32_t si_timerid;
|
||||
int32_t si_overrun;
|
||||
union sigval si_value;
|
||||
|
||||
if (IsLinux()) {
|
||||
*si = m->linux;
|
||||
return;
|
||||
} else if (IsFreebsd()) {
|
||||
si_signo = m->freebsd.si_signo;
|
||||
si_errno = m->freebsd.si_errno;
|
||||
si_code = m->freebsd.si_code;
|
||||
si_pid = m->freebsd.si_pid;
|
||||
si_uid = m->freebsd.si_uid;
|
||||
si_status = m->freebsd.si_status;
|
||||
si_timerid = m->freebsd.si_timerid;
|
||||
si_overrun = m->freebsd.si_overrun;
|
||||
si_addr = m->freebsd.si_addr;
|
||||
si_value = m->freebsd.si_value;
|
||||
} else if (IsXnu()) {
|
||||
si_signo = m->xnu.si_signo;
|
||||
si_errno = m->xnu.si_errno;
|
||||
si_code = m->xnu.si_code;
|
||||
si_pid = m->xnu.si_pid;
|
||||
si_uid = m->xnu.si_uid;
|
||||
si_status = m->xnu.si_status;
|
||||
si_timerid = 0;
|
||||
si_overrun = 0;
|
||||
si_addr = m->xnu.si_addr;
|
||||
si_value = m->xnu.si_value;
|
||||
} else if (IsOpenbsd()) {
|
||||
si_signo = m->openbsd.si_signo;
|
||||
si_errno = m->openbsd.si_errno;
|
||||
si_code = m->openbsd.si_code;
|
||||
si_pid = m->openbsd.si_pid;
|
||||
si_uid = m->openbsd.si_uid;
|
||||
si_status = m->openbsd.si_status;
|
||||
si_timerid = 0;
|
||||
si_overrun = 0;
|
||||
si_addr = m->openbsd.si_addr;
|
||||
si_value = m->openbsd.si_value;
|
||||
} else if (IsNetbsd()) {
|
||||
si_signo = m->netbsd.si_signo;
|
||||
si_errno = m->netbsd.si_errno;
|
||||
si_code = m->netbsd.si_code;
|
||||
si_pid = m->netbsd.si_pid;
|
||||
si_uid = m->netbsd.si_uid;
|
||||
si_status = m->netbsd.si_status;
|
||||
si_timerid = 0;
|
||||
si_overrun = 0;
|
||||
si_addr = m->netbsd.si_addr;
|
||||
si_value = m->netbsd.si_value;
|
||||
} else {
|
||||
notpossible;
|
||||
}
|
||||
|
||||
*si = (struct siginfo){0};
|
||||
si->si_signo = si_signo;
|
||||
si->si_errno = si_errno;
|
||||
si->si_code = si_code;
|
||||
si->si_value = si_value;
|
||||
if (si_signo == SIGILL || //
|
||||
si_signo == SIGFPE || //
|
||||
si_signo == SIGSEGV || //
|
||||
si_signo == SIGBUS || //
|
||||
si_signo == SIGTRAP) {
|
||||
si->si_addr = si_addr;
|
||||
} else if (si_signo == SIGALRM) {
|
||||
si->si_timerid = si_timerid;
|
||||
si->si_overrun = si_overrun;
|
||||
} else {
|
||||
si->si_pid = si_pid;
|
||||
si->si_uid = si_uid;
|
||||
}
|
||||
}
|
|
@ -17,37 +17,44 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/sig.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/calls/struct/sigset.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Determines the blocked pending signals
|
||||
*
|
||||
* @param pending is where the bitset of pending signals is returned,
|
||||
* may not be NULL.
|
||||
* @return -1 w/ EFAULT
|
||||
* which may not be null
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
* @raise EFAULT if `pending` points to invalid memory
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
int sigpending(sigset_t *pending) {
|
||||
int rc;
|
||||
if (IsAsan() && !__asan_is_valid(pending, sizeof(*pending))) {
|
||||
if (!pending || (IsAsan() && !__asan_is_valid(pending, sizeof(*pending)))) {
|
||||
rc = efault();
|
||||
} else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
|
||||
// 128 signals on NetBSD and FreeBSD, 64 on Linux, 32 on OpenBSD and XNU
|
||||
rc = sys_sigpending(pending, 8);
|
||||
// 128 signals on NetBSD and FreeBSD, 64 on Linux, 32 on OpenBSD and XNU.
|
||||
// OpenBSD passes signal sets in words rather than pointers
|
||||
if (IsOpenbsd()) {
|
||||
pending->__bits[0] = (unsigned)rc;
|
||||
rc = 0;
|
||||
} else if (IsXnu()) {
|
||||
pending->__bits[0] &= 0xFFFFFFFF;
|
||||
}
|
||||
if (IsLinux() || IsOpenbsd() || IsXnu()) {
|
||||
pending->__bits[1] = 0;
|
||||
// only modify memory on success
|
||||
if (!rc) {
|
||||
// clear unsupported bits
|
||||
if (IsXnu()) {
|
||||
pending->__bits[0] &= 0xFFFFFFFF;
|
||||
}
|
||||
if (IsLinux() || IsOpenbsd() || IsXnu()) {
|
||||
pending->__bits[1] = 0;
|
||||
}
|
||||
}
|
||||
} else if (IsWindows()) {
|
||||
sigemptyset(pending);
|
||||
|
|
75
libc/calls/sigtimedwait.c
Normal file
75
libc/calls/sigtimedwait.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/asan.internal.h"
|
||||
#include "libc/calls/sigtimedwait.h"
|
||||
#include "libc/calls/sigtimedwait.internal.h"
|
||||
#include "libc/calls/struct/siginfo.internal.h"
|
||||
#include "libc/calls/struct/sigset.internal.h"
|
||||
#include "libc/calls/struct/timespec.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Waits for signal synchronously, w/ timeout.
|
||||
*
|
||||
* @param set is signals for which we'll be waiting
|
||||
* @param info if not null shall receive info about signal
|
||||
* @param timeout is relative deadline and null means wait forever
|
||||
* @return signal number on success, or -1 w/ errno
|
||||
* @raise EINTR if an asynchronous signal was delivered instead
|
||||
* @raise EINVAL if nanoseconds parameter was out of range
|
||||
* @raise EAGAIN if deadline expired
|
||||
* @raise ENOSYS on Windows, XNU, OpenBSD, Metal
|
||||
* @raise EFAULT if invalid memory was supplied
|
||||
*/
|
||||
int sigtimedwait(const sigset_t *set, siginfo_t *info,
|
||||
const struct timespec *timeout) {
|
||||
int rc;
|
||||
char strsig[15];
|
||||
struct timespec ts;
|
||||
union siginfo_meta si = {0};
|
||||
|
||||
if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) ||
|
||||
(info && !__asan_is_valid(info, sizeof(*info))) ||
|
||||
(timeout && !__asan_is_valid_timespec(timeout)))) {
|
||||
rc = efault();
|
||||
} else if (IsLinux() || IsFreebsd() || IsNetbsd()) {
|
||||
if (timeout) {
|
||||
// 1. Linux needs its size parameter
|
||||
// 2. NetBSD modifies timeout argument
|
||||
ts = *timeout;
|
||||
rc = sys_sigtimedwait(set, &si, &ts, 8);
|
||||
} else {
|
||||
rc = sys_sigtimedwait(set, &si, 0, 8);
|
||||
}
|
||||
if (rc != -1 && info) {
|
||||
__siginfo2cosmo(info, &si);
|
||||
}
|
||||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
|
||||
STRACE("sigtimedwait(%s, [%s], %s) → %s% m", DescribeSigset(0, set),
|
||||
DescribeSiginfo(rc, info), DescribeTimespec(0, timeout),
|
||||
strsignal_r(rc, strsig));
|
||||
return rc;
|
||||
}
|
14
libc/calls/sigtimedwait.h
Normal file
14
libc/calls/sigtimedwait.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_H_
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *);
|
||||
int sigwaitinfo(const sigset_t *, siginfo_t *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_H_ */
|
14
libc/calls/sigtimedwait.internal.h
Normal file
14
libc/calls/sigtimedwait.internal.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_INTERNAL_H_
|
||||
#include "libc/calls/struct/siginfo-meta.internal.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int sys_sigtimedwait(const sigset_t *, union siginfo_meta *,
|
||||
const struct timespec *, size_t) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_INTERNAL_H_ */
|
33
libc/calls/sigwaitinfo.c
Normal file
33
libc/calls/sigwaitinfo.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/sigtimedwait.h"
|
||||
|
||||
/**
|
||||
* Waits for signal synchronously.
|
||||
*
|
||||
* @param set is signals for which we'll be waiting
|
||||
* @param info if not null shall receive info about signal
|
||||
* @return signal number on success, or -1 w/ errno
|
||||
* @raise EINTR if an asynchronous signal was delivered instead
|
||||
* @raise ENOSYS on OpenBSD, XNU, and Windows
|
||||
* @see sigtimedwait()
|
||||
*/
|
||||
int sigwaitinfo(const sigset_t *mask, siginfo_t *si) {
|
||||
return sigtimedwait(mask, si, 0);
|
||||
}
|
23
libc/calls/struct/siginfo-meta.internal.h
Normal file
23
libc/calls/struct/siginfo-meta.internal.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_META_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_META_INTERNAL_H_
|
||||
#include "libc/calls/struct/siginfo-freebsd.internal.h"
|
||||
#include "libc/calls/struct/siginfo-netbsd.internal.h"
|
||||
#include "libc/calls/struct/siginfo-openbsd.internal.h"
|
||||
#include "libc/calls/struct/siginfo-xnu.internal.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
union siginfo_meta {
|
||||
struct siginfo linux;
|
||||
struct siginfo_xnu xnu;
|
||||
struct siginfo_freebsd freebsd;
|
||||
struct siginfo_openbsd openbsd;
|
||||
struct siginfo_netbsd netbsd;
|
||||
};
|
||||
|
||||
void __siginfo2cosmo(struct siginfo *, const union siginfo_meta *) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_META_INTERNAL_H_ */
|
|
@ -12,11 +12,13 @@ struct siginfo {
|
|||
struct {
|
||||
union {
|
||||
struct {
|
||||
/* signals sent by kill() and sigqueue() set these */
|
||||
int32_t si_pid;
|
||||
uint32_t si_uid;
|
||||
};
|
||||
struct {
|
||||
int32_t si_timerid; /* SIGALRM */
|
||||
/* SIGALRM sets these */
|
||||
int32_t si_timerid;
|
||||
int32_t si_overrun;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "libc/calls/struct/sigaction-xnu.internal.h"
|
||||
#include "libc/calls/struct/siginfo-xnu.internal.h"
|
||||
#include "libc/calls/struct/siginfo.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
@ -10,6 +11,9 @@ int sys_sigqueueinfo(int, const siginfo_t *) hidden;
|
|||
void __sigenter_xnu(void *, int, int, struct siginfo_xnu *,
|
||||
struct __darwin_ucontext *) hidden;
|
||||
|
||||
const char *DescribeSiginfo(char[300], int, const siginfo_t *);
|
||||
#define DescribeSiginfo(x, y) DescribeSiginfo(alloca(300), x, y)
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_INTERNAL_H_ */
|
||||
|
|
|
@ -13,11 +13,12 @@ int sigemptyset(sigset_t *) paramsnonnull();
|
|||
int sigfillset(sigset_t *) paramsnonnull();
|
||||
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
|
||||
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
|
||||
int sigisemptyset(const sigset_t *) paramsnonnull();
|
||||
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect;
|
||||
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
|
||||
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect;
|
||||
int sigprocmask(int, const sigset_t *, sigset_t *);
|
||||
int sigsuspend(const sigset_t *);
|
||||
int sigpending(sigset_t *) paramsnonnull() nosideeffect;
|
||||
int sigpending(sigset_t *);
|
||||
int pthread_sigmask(int, const sigset_t *, sigset_t *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue