2020-06-15 14:18:57 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
2022-10-10 14:36:07 +00:00
|
|
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ 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. │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ 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. │
|
2020-06-15 14:18:57 +00:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2022-10-10 14:36:07 +00:00
|
|
|
#include "libc/calls/struct/siginfo.h"
|
|
|
|
#include "libc/calls/struct/siginfo.internal.h"
|
|
|
|
#include "libc/dce.h"
|
|
|
|
#include "libc/intrin/describeflags.h"
|
|
|
|
#include "libc/intrin/kprintf.h"
|
|
|
|
#include "libc/intrin/weaken.h"
|
2020-10-11 04:18:53 +00:00
|
|
|
#include "libc/str/str.h"
|
2022-06-09 03:01:28 +00:00
|
|
|
#include "libc/sysv/consts/sig.h"
|
2022-10-10 14:36:07 +00:00
|
|
|
|
|
|
|
#define N 300
|
|
|
|
|
|
|
|
#define append(...) i += ksnprintf(buf + i, N - i, __VA_ARGS__)
|
|
|
|
|
2024-08-25 01:10:22 +00:00
|
|
|
const char *_DescribeSiginfo(char buf[N], int rc, const siginfo_t *si) {
|
2022-10-10 14:36:07 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (rc == -1)
|
|
|
|
return "n/a";
|
|
|
|
if (!si)
|
|
|
|
return "NULL";
|
2024-06-22 12:45:49 +00:00
|
|
|
if (kisdangerous(si)) {
|
2022-10-10 14:36:07 +00:00
|
|
|
ksnprintf(buf, N, "%p", si);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
append("{.si_signo=%s, si_code=%s", strsignal(si->si_signo),
|
|
|
|
DescribeSiCode(si->si_signo, si->si_code));
|
|
|
|
|
|
|
|
if (si->si_errno) {
|
|
|
|
append(", .si_errno=%s", DescribeErrno(si->si_errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (si->si_signo == SIGILL || //
|
|
|
|
si->si_signo == SIGFPE || //
|
|
|
|
si->si_signo == SIGSEGV || //
|
|
|
|
si->si_signo == SIGBUS || //
|
|
|
|
si->si_signo == SIGTRAP) {
|
|
|
|
append(", .si_addr=%p, .si_addr_lsb=%d, .si_pkey=%u", si->si_addr,
|
|
|
|
si->si_addr_lsb, si->si_pkey);
|
|
|
|
} else if (si->si_signo == SIGALRM) {
|
|
|
|
append(", .si_timerid=%d, .si_overrun=%d", si->si_timerid, si->si_overrun);
|
|
|
|
} else {
|
|
|
|
if (si->si_pid) {
|
|
|
|
append(", .si_pid=%d", si->si_pid);
|
|
|
|
}
|
|
|
|
if (si->si_uid) {
|
|
|
|
append(", .si_uid=%d", si->si_uid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (si->si_status) {
|
|
|
|
append(", .si_status=%d", si->si_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (si->si_utime) {
|
|
|
|
append(", .si_utime=%d", si->si_utime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (si->si_stime) {
|
|
|
|
append(", .si_stime=%d", si->si_stime);
|
|
|
|
}
|
|
|
|
|
|
|
|
append("}");
|
|
|
|
|
|
|
|
return buf;
|
2020-06-15 14:18:57 +00:00
|
|
|
}
|