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:
Justine Tunney 2022-10-10 07:36:07 -07:00
parent 7ae556463a
commit 467a332e38
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
41 changed files with 887 additions and 345 deletions

View file

@ -16,154 +16,13 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/log/log.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/sig.h"
static bool IsSiUser(int si_code) {
if (!IsOpenbsd()) {
return si_code == SI_USER;
} else {
return si_code <= 0;
}
}
static void NameIt(char p[17], const char *s, int si_code) {
p = stpcpy(p, s);
FormatInt32(p, si_code);
}
/**
* Returns symbolic name for siginfo::si_code value.
*/
const char *GetSiCodeName(int sig, int si_code) {
static char b[17];
NameIt(b, "SI_", si_code);
if (si_code == SI_QUEUE) {
strcpy(b + 3, "QUEUE"); /* sent by sigqueue(2) */
} else if (si_code == SI_TIMER) {
strcpy(b + 3, "TIMER"); /* sent by setitimer(2) or clock_settime(2) */
} else if (si_code == SI_TKILL) {
strcpy(b + 3, "TKILL"); /* sent by tkill(2), etc. */
} else if (si_code == SI_MESGQ) {
strcpy(b + 3, "MESGQ"); /* sent by mq_notify(2) */
} else if (si_code == SI_MESGQ) {
strcpy(b + 3, "MESGQ"); /* aio completion */
} else if (si_code == SI_ASYNCNL) {
strcpy(b + 3, "ASYNCNL"); /* aio completion for dns; the horror */
} else if (si_code == SI_NOINFO) {
strcpy(b + 3, "NOINFO"); /* no signal specific info available */
} else if (si_code == SI_KERNEL) {
strcpy(b + 3, "KERNEL"); /* sent by kernel */
} else if (IsSiUser(si_code)) {
strcpy(b + 3, "USER"); /* sent by kill(2) i.e. from userspace */
} else if (sig == SIGCHLD) {
NameIt(b, "CLD_", si_code);
if (si_code == CLD_EXITED) {
strcpy(b + 4, "EXITED"); /* child exited */
} else if (si_code == CLD_KILLED) {
strcpy(b + 4, "KILLED"); /* child terminated w/o core */
} else if (si_code == CLD_DUMPED) {
strcpy(b + 4, "DUMPED"); /* child terminated w/ core */
} else if (si_code == CLD_TRAPPED) {
strcpy(b + 4, "TRAPPED"); /* traced child trapped */
} else if (si_code == CLD_STOPPED) {
strcpy(b + 4, "STOPPED"); /* child stopped */
} else if (si_code == CLD_CONTINUED) {
strcpy(b + 4, "CONTINUED"); /* stopped child continued */
}
} else if (sig == SIGTRAP) {
NameIt(b, "TRAP_", si_code);
if (si_code == TRAP_BRKPT) {
strcpy(b + 5, "BRKPT"); /* process breakpoint */
} else if (si_code == TRAP_TRACE) {
strcpy(b + 5, "TRACE"); /* process trace trap */
}
} else if (sig == SIGSEGV) {
NameIt(b, "SEGV_", si_code);
if (si_code == SEGV_MAPERR) {
strcpy(b + 5, "MAPERR"); /* address not mapped to object */
} else if (si_code == SEGV_ACCERR) {
strcpy(b + 5, "ACCERR"); /* invalid permissions for mapped object */
} else if (si_code == SEGV_PKUERR) {
strcpy(b + 5, "PKUERR"); /* FreeBSD: x86: PKU violation */
}
} else if (sig == SIGFPE) {
NameIt(b, "FPE_???", si_code);
if (si_code == FPE_INTDIV) {
strcpy(b + 4, "INTDIV"); /* integer divide by zero */
} else if (si_code == FPE_INTOVF) {
strcpy(b + 4, "INTOVF"); /* integer overflow */
} else if (si_code == FPE_FLTDIV) {
strcpy(b + 4, "FLTDIV"); /* floating point divide by zero */
} else if (si_code == FPE_FLTOVF) {
strcpy(b + 4, "FLTOVF"); /* floating point overflow */
} else if (si_code == FPE_FLTUND) {
strcpy(b + 4, "FLTUND"); /* floating point underflow */
} else if (si_code == FPE_FLTRES) {
strcpy(b + 4, "FLTRES"); /* floating point inexact */
} else if (si_code == FPE_FLTINV) {
strcpy(b + 4, "FLTINV"); /* invalid floating point operation */
} else if (si_code == FPE_FLTSUB) {
strcpy(b + 4, "FLTSUB"); /* subscript out of range */
}
} else if (sig == SIGILL) {
NameIt(b, "ILL_", si_code);
if (si_code == ILL_ILLOPC) {
strcpy(b + 4, "ILLOPC"); /* illegal opcode */
} else if (si_code == ILL_ILLOPN) {
strcpy(b + 4, "ILLOPN"); /* illegal operand */
} else if (si_code == ILL_ILLADR) {
strcpy(b + 4, "ILLADR"); /* illegal addressing mode */
} else if (si_code == ILL_ILLTRP) {
strcpy(b + 4, "ILLTRP"); /* illegal trap */
} else if (si_code == ILL_PRVOPC) {
strcpy(b + 4, "PRVOPC"); /* privileged opcode */
} else if (si_code == ILL_PRVREG) {
strcpy(b + 4, "PRVREG"); /* privileged register */
} else if (si_code == ILL_COPROC) {
strcpy(b + 4, "COPROC"); /* coprocessor error */
} else if (si_code == ILL_BADSTK) {
strcpy(b + 4, "BADSTK"); /* internal stack error */
}
} else if (sig == SIGBUS) {
NameIt(b, "BUS_", si_code);
if (si_code == BUS_ADRALN) {
strcpy(b + 4, "ADRALN"); /* invalid address alignment */
} else if (si_code == BUS_ADRERR) {
strcpy(b + 4, "ADRERR"); /* non-existent physical address */
} else if (si_code == BUS_OBJERR) {
strcpy(b + 4, "OBJERR"); /* object specific hardware error */
} else if (si_code == BUS_OOMERR) {
strcpy(b + 4, "OOMERR"); /* FreeBSD */
} else if (si_code == BUS_MCEERR_AR) {
strcpy(b + 4, "MCEERR_AR"); /* Linux 2.6.32+ */
} else if (si_code == BUS_MCEERR_AO) {
strcpy(b + 4, "MCEERR_AO"); /* Linux 2.6.32+ */
}
} else if (sig == SIGIO) {
NameIt(b, "POLL_", si_code);
if (si_code == POLL_IN) {
strcpy(b + 5, "IN"); /* data input available */
} else if (si_code == POLL_OUT) {
strcpy(b + 5, "OUT"); /* output buffer available */
} else if (si_code == POLL_MSG) {
strcpy(b + 5, "MSG"); /* input message available */
} else if (si_code == POLL_ERR) {
strcpy(b + 5, "ERR"); /* i/o error */
} else if (si_code == POLL_PRI) {
strcpy(b + 5, "PRI"); /* high priority input available */
} else if (si_code == POLL_HUP) {
strcpy(b + 5, "HUP"); /* device disconnected */
}
} else if (sig == SIGSYS) {
NameIt(b, "SYS_", si_code);
if (si_code == SYS_SECCOMP) {
strcpy(b + 4, "SECCOMP");
}
}
return b;
return (DescribeSiCode)(b, sig, si_code);
}