From 263711965f5511aabf73a4a7e5661f41721fd67a Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 2 Sep 2022 08:08:35 -0400 Subject: [PATCH] Change sigaction_f to match sysv signature (#585) --- examples/setitimer.c | 2 +- examples/ucontext-sigfpe-recovery.c | 3 ++- libc/calls/pledge-linux.c | 3 ++- libc/calls/sigaction.c | 14 ++++++++------ libc/calls/struct/sigaction.h | 3 ++- libc/log/onkill.c | 5 ++--- test/libc/calls/reservefd_test.c | 2 +- test/libc/calls/setitimer_test.c | 2 +- test/libc/calls/sigaction_test.c | 6 ++++-- test/libc/calls/signal_test.c | 5 +++-- test/libc/calls/sigprocmask_test.c | 2 +- test/libc/calls/sigsuspend_test.c | 2 +- test/libc/runtime/mprotect_test.c | 6 ++++-- test/libc/runtime/munmap_test.c | 3 ++- third_party/awk/main.c | 2 +- third_party/chibicc/chibicc.c | 2 +- third_party/lua/lunix.c | 2 +- tool/build/blinkenlights.c | 2 +- tool/build/compile.c | 2 +- tool/build/deltaify.c | 2 +- tool/viz/life.c | 4 ++-- tool/viz/memzoom.c | 4 ++-- tool/viz/vdsodump.c | 3 ++- 23 files changed, 46 insertions(+), 35 deletions(-) diff --git a/examples/setitimer.c b/examples/setitimer.c index 28d1d30e8..456d73433 100644 --- a/examples/setitimer.c +++ b/examples/setitimer.c @@ -21,7 +21,7 @@ volatile bool gotalrm; -void OnSigAlrm(int sig, siginfo_t *si, ucontext_t *ctx) { +void OnSigAlrm(int sig, siginfo_t *si, void *ctx) { gotalrm = true; } diff --git a/examples/ucontext-sigfpe-recovery.c b/examples/ucontext-sigfpe-recovery.c index 30965799f..ccfbad46d 100644 --- a/examples/ucontext-sigfpe-recovery.c +++ b/examples/ucontext-sigfpe-recovery.c @@ -26,8 +26,9 @@ * and this example should work on all supported platforms even Windows */ -void handler(int sig, siginfo_t *si, ucontext_t *ctx) { +void handler(int sig, siginfo_t *si, void *vctx) { struct XedDecodedInst xedd; + struct ucontext *ctx = vctx; xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64); xed_instruction_length_decode(&xedd, (void *)ctx->uc_mcontext.rip, 15); ctx->uc_mcontext.rip += xedd.length; diff --git a/libc/calls/pledge-linux.c b/libc/calls/pledge-linux.c index 2ba7f51c2..db6b4ee10 100644 --- a/libc/calls/pledge-linux.c +++ b/libc/calls/pledge-linux.c @@ -966,10 +966,11 @@ static privileged int HasSyscall(struct Pledges *p, uint16_t n) { return 0; } -static privileged void OnSigSys(int sig, siginfo_t *si, ucontext_t *ctx) { +static privileged void OnSigSys(int sig, siginfo_t *si, void *vctx) { bool found; char ord[17], rip[17]; int i, ok, mode = si->si_errno; + ucontext_t *ctx = vctx; ctx->uc_mcontext.rax = -Eperm; FixCpy(ord, si->si_syscall, 12); HexCpy(rip, ctx->uc_mcontext.rip); diff --git a/libc/calls/sigaction.c b/libc/calls/sigaction.c index b65e8ef51..4a647aac8 100644 --- a/libc/calls/sigaction.c +++ b/libc/calls/sigaction.c @@ -251,7 +251,7 @@ static int __sigaction(int sig, const struct sigaction *act, /** * Installs handler for kernel interrupt to thread, e.g.: * - * void GotCtrlC(int sig, siginfo_t *si, ucontext_t *ctx); + * void GotCtrlC(int sig, siginfo_t *si, void *ctx); * struct sigaction sa = {.sa_sigaction = GotCtrlC, * .sa_flags = SA_RESETHAND|SA_RESTART|SA_SIGINFO}; * CHECK_NE(-1, sigaction(SIGINT, &sa, NULL)); @@ -259,10 +259,11 @@ static int __sigaction(int sig, const struct sigaction *act, * The following flags are supported across platforms: * * - `SA_SIGINFO`: Causes the `siginfo_t` and `ucontext_t` parameters to - * be passed. This not only gives you more information about the - * signal, but also allows your signal handler to change the CPU - * registers. That's useful for recovering from crashes. If you don't - * use this attribute, then signal delivery will go a little faster. + * be passed. `void *ctx` actually refers to `struct ucontext *`. + * This not only gives you more information about the signal, but also + * allows your signal handler to change the CPU registers. That's + * useful for recovering from crashes. If you don't use this attribute, + * then signal delivery will go a little faster. * * - `SA_RESTART`: Enables BSD signal handling semantics. Normally i/o * entrypoints check for pending signals to deliver. If one gets @@ -371,7 +372,8 @@ static int __sigaction(int sig, const struct sigaction *act, * ctx->uc_mcontext.rip += xedd.length; * } * - * void OnCrash(int sig, struct siginfo *si, struct ucontext *ctx) { + * void OnCrash(int sig, struct siginfo *si, void *vctx) { + * struct ucontext *ctx = vctx; * SkipOverFaultingInstruction(ctx); * ContinueOnCrash(); // reinstall here in case *rip faults * } diff --git a/libc/calls/struct/sigaction.h b/libc/calls/struct/sigaction.h index 2e97ad114..4c10d64f6 100644 --- a/libc/calls/struct/sigaction.h +++ b/libc/calls/struct/sigaction.h @@ -9,7 +9,8 @@ COSMOPOLITAN_C_START_ typedef void (*sighandler_t)(int); -typedef void (*sigaction_f)(int, struct siginfo *, struct ucontext *); +typedef void (*sigaction_f)(int, struct siginfo *, + void * /*struct ucontext **/); struct sigaction { /* cosmo abi */ union { diff --git a/libc/log/onkill.c b/libc/log/onkill.c index 0be0c1300..3959bf273 100644 --- a/libc/log/onkill.c +++ b/libc/log/onkill.c @@ -16,12 +16,12 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/siginfo.h" #include "libc/calls/ucontext.h" #include "libc/dce.h" +#include "libc/intrin/bits.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/runtime/runtime.h" @@ -41,8 +41,7 @@ static const int sigs[] = { SIGTERM /* kill (default signal) */ }; -textexit static void __onkill(int sig, struct siginfo *si, - struct ucontext *context) { +textexit static void __onkill(int sig, struct siginfo *si, void *context) { /* https://www.tldp.org/LDP/abs/html/exitcodes.html */ exit(128 + sig); unreachable; diff --git a/test/libc/calls/reservefd_test.c b/test/libc/calls/reservefd_test.c index c0054063a..4e3062b03 100644 --- a/test/libc/calls/reservefd_test.c +++ b/test/libc/calls/reservefd_test.c @@ -74,7 +74,7 @@ TEST(reservefd, testGrowthOfFdsDataStructure) { } } -void OnSigAlrm(int sig, siginfo_t *si, ucontext_t *ctx) { +void OnSigAlrm(int sig, siginfo_t *si, void *ctx) { int rc, fd; char buf[64]; ASSERT_NE(-1, (fd = open("/zip/libc/testlib/hyperion.txt", O_RDONLY))); diff --git a/test/libc/calls/setitimer_test.c b/test/libc/calls/setitimer_test.c index c568e7541..2f6a5e66d 100644 --- a/test/libc/calls/setitimer_test.c +++ b/test/libc/calls/setitimer_test.c @@ -35,7 +35,7 @@ void SetUpOnce(void) { ASSERT_SYS(0, 0, pledge("stdio", 0)); } -void OnSigAlrm(int sig, siginfo_t *si, ucontext_t *ctx) { +void OnSigAlrm(int sig, siginfo_t *si, void *ctx) { EXPECT_EQ(SIGALRM, sig); EXPECT_EQ(SIGALRM, si->si_signo); gotsig = true; diff --git a/test/libc/calls/sigaction_test.c b/test/libc/calls/sigaction_test.c index 93d983b9c..8beb9e316 100644 --- a/test/libc/calls/sigaction_test.c +++ b/test/libc/calls/sigaction_test.c @@ -111,7 +111,8 @@ TEST(sigaction, testPingPongParentChildWithSigint) { volatile int trapeax; -void OnTrap(int sig, struct siginfo *si, struct ucontext *ctx) { +void OnTrap(int sig, struct siginfo *si, void *vctx) { + struct ucontext *ctx = vctx; CheckStackIsAligned(); trapeax = ctx->uc_mcontext.rax; } @@ -136,7 +137,8 @@ void SkipOverFaultingInstruction(struct ucontext *ctx) { ctx->uc_mcontext.rip += xedd.length; } -void OnFpe(int sig, struct siginfo *si, struct ucontext *ctx) { +void OnFpe(int sig, struct siginfo *si, void *vctx) { + struct ucontext *ctx = vctx; CheckStackIsAligned(); SkipOverFaultingInstruction(ctx); ctx->uc_mcontext.rax = 42; diff --git a/test/libc/calls/signal_test.c b/test/libc/calls/signal_test.c index 100880b91..deef09aa7 100644 --- a/test/libc/calls/signal_test.c +++ b/test/libc/calls/signal_test.c @@ -43,7 +43,7 @@ TEST(signal, test) { //////////////////////////////////////////////////////////////////////////////// // signal round-trip delivery takes about 1µs -void OnSigTrap(int sig, struct siginfo *si, struct ucontext *ctx) { +void OnSigTrap(int sig, struct siginfo *si, void *ctx) { } void TrapBench(int n) { @@ -72,7 +72,8 @@ BENCH(signal, trapBenchSiginfo) { sigaction(SIGTRAP, &old, 0); } -void OnSigHlt(int sig, struct siginfo *si, struct ucontext *ctx) { +void OnSigHlt(int sig, struct siginfo *si, void *vctx) { + struct ucontext *ctx = vctx; ctx->uc_mcontext.rip += 1; } diff --git a/test/libc/calls/sigprocmask_test.c b/test/libc/calls/sigprocmask_test.c index 129bf3b60..1b155fbc5 100644 --- a/test/libc/calls/sigprocmask_test.c +++ b/test/libc/calls/sigprocmask_test.c @@ -32,7 +32,7 @@ void SetUpOnce(void) { ASSERT_SYS(0, 0, pledge("stdio proc", 0)); } -void OnSig(int sig, siginfo_t *si, ucontext_t *ctx) { +void OnSig(int sig, siginfo_t *si, void *ctx) { ++n; } diff --git a/test/libc/calls/sigsuspend_test.c b/test/libc/calls/sigsuspend_test.c index 17fd8fa06..bf0a29504 100644 --- a/test/libc/calls/sigsuspend_test.c +++ b/test/libc/calls/sigsuspend_test.c @@ -31,7 +31,7 @@ volatile bool gotsig1; volatile bool gotsig2; volatile bool finished; -void OnSigQueuing(int sig, siginfo_t *si, ucontext_t *ctx) { +void OnSigQueuing(int sig, siginfo_t *si, void *ctx) { if (!finished) { EXPECT_EQ(SIGUSR2, sig); EXPECT_EQ(SIGUSR2, si->si_signo); diff --git a/test/libc/runtime/mprotect_test.c b/test/libc/runtime/mprotect_test.c index e01f4ba2d..8559f72f3 100644 --- a/test/libc/runtime/mprotect_test.c +++ b/test/libc/runtime/mprotect_test.c @@ -47,12 +47,14 @@ void SkipOverFaultingInstruction(struct ucontext *ctx) { ctx->uc_mcontext.rip += xedd.length; } -void OnSigSegv(int sig, struct siginfo *si, struct ucontext *ctx) { +void OnSigSegv(int sig, struct siginfo *si, void *vctx) { + struct ucontext *ctx = vctx; gotsegv = true; SkipOverFaultingInstruction(ctx); } -void OnSigBus(int sig, struct siginfo *si, struct ucontext *ctx) { +void OnSigBus(int sig, struct siginfo *si, void *vctx) { + struct ucontext *ctx = vctx; gotbusted = true; SkipOverFaultingInstruction(ctx); #if 0 diff --git a/test/libc/runtime/munmap_test.c b/test/libc/runtime/munmap_test.c index ac5218f03..c39ef6bb8 100644 --- a/test/libc/runtime/munmap_test.c +++ b/test/libc/runtime/munmap_test.c @@ -35,8 +35,9 @@ volatile int gotsignal; char testlib_enable_tmp_setup_teardown; -void ContinueOnError(int sig, siginfo_t *si, ucontext_t *ctx) { +void ContinueOnError(int sig, siginfo_t *si, void *vctx) { struct XedDecodedInst xedd; + struct ucontext *ctx = vctx; xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64); xed_instruction_length_decode(&xedd, (void *)ctx->uc_mcontext.rip, 15); ctx->uc_mcontext.rip += xedd.length; diff --git a/third_party/awk/main.c b/third_party/awk/main.c index df25804ab..07b8921b7 100644 --- a/third_party/awk/main.c +++ b/third_party/awk/main.c @@ -82,7 +82,7 @@ static size_t curpfile; /* current filename */ bool safe = false; /* true => "safe" mode */ -static wontreturn void fpecatch(int n, siginfo_t *si, ucontext_t *uc) +static wontreturn void fpecatch(int n, siginfo_t *si, void *uc) { const char *emsg[10]; emsg[0] = "Unknown error"; diff --git a/third_party/chibicc/chibicc.c b/third_party/chibicc/chibicc.c index a50108441..f92e9d71e 100644 --- a/third_party/chibicc/chibicc.c +++ b/third_party/chibicc/chibicc.c @@ -681,7 +681,7 @@ static void run_linker(StringArray *inputs, char *output) { handle_exit(run_subprocess(arr.data)); } -static void OnCtrlC(int sig, siginfo_t *si, ucontext_t *ctx) { +static void OnCtrlC(int sig, siginfo_t *si, void *ctx) { exit(1); } diff --git a/third_party/lua/lunix.c b/third_party/lua/lunix.c index 9c4f4d431..d5ded4b6e 100644 --- a/third_party/lua/lunix.c +++ b/third_party/lua/lunix.c @@ -1687,7 +1687,7 @@ static int LuaUnixSigprocmask(lua_State *L) { } } -static void LuaUnixOnSignal(int sig, siginfo_t *si, ucontext_t *ctx) { +static void LuaUnixOnSignal(int sig, siginfo_t *si, void *ctx) { int type; lua_State *L = GL; STRACE("LuaUnixOnSignal(%G)", sig); diff --git a/tool/build/blinkenlights.c b/tool/build/blinkenlights.c index d9d04d94c..3a932305d 100644 --- a/tool/build/blinkenlights.c +++ b/tool/build/blinkenlights.c @@ -3127,7 +3127,7 @@ static void OnlyRunOnFirstCpu(void) { sched_setaffinity(0, sizeof(bs), &bs); } -static void OnSignal(int sig, siginfo_t *si, ucontext_t *uc) { +static void OnSignal(int sig, siginfo_t *si, void *uc) { EnqueueSignal(m, sig, si->si_code); } diff --git a/tool/build/compile.c b/tool/build/compile.c index 483869eb3..e42271981 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -269,7 +269,7 @@ void OnAlrm(int sig) { ++gotalrm; } -void OnChld(int sig, siginfo_t *si, ucontext_t *ctx) { +void OnChld(int sig, siginfo_t *si, void *ctx) { if (!gotchld++) { clock_gettime(CLOCK_MONOTONIC, &signalled); } diff --git a/tool/build/deltaify.c b/tool/build/deltaify.c index f9384a894..66b914783 100644 --- a/tool/build/deltaify.c +++ b/tool/build/deltaify.c @@ -32,7 +32,7 @@ static int pid; -static void RelaySig(int sig, struct siginfo *si, struct ucontext *uc) { +static void RelaySig(int sig, struct siginfo *si, void *uc) { kill(pid, sig); } diff --git a/tool/viz/life.c b/tool/viz/life.c index 6fccdc0f9..703e99af0 100644 --- a/tool/viz/life.c +++ b/tool/viz/life.c @@ -760,11 +760,11 @@ static void OnExit(void) { ioctl(out, TCSETS, &oldterm); } -static void OnSigInt(int sig, struct siginfo *sa, struct ucontext *uc) { +static void OnSigInt(int sig, struct siginfo *sa, void *uc) { action |= INTERRUPTED; } -static void OnSigWinch(int sig, struct siginfo *sa, struct ucontext *uc) { +static void OnSigWinch(int sig, struct siginfo *sa, void *uc) { action |= RESIZED; } diff --git a/tool/viz/memzoom.c b/tool/viz/memzoom.c index 487dd1386..9f2266280 100644 --- a/tool/viz/memzoom.c +++ b/tool/viz/memzoom.c @@ -219,11 +219,11 @@ static void OnExit(void) { ioctl(out, TCSETS, &oldterm); } -static void OnSigInt(int sig, struct siginfo *sa, struct ucontext *uc) { +static void OnSigInt(int sig, struct siginfo *sa, void *uc) { action |= INTERRUPTED; } -static void OnSigWinch(int sig, struct siginfo *sa, struct ucontext *uc) { +static void OnSigWinch(int sig, struct siginfo *sa, void *uc) { action |= RESIZED; } diff --git a/tool/viz/vdsodump.c b/tool/viz/vdsodump.c index f5042a241..b10398fd7 100644 --- a/tool/viz/vdsodump.c +++ b/tool/viz/vdsodump.c @@ -30,8 +30,9 @@ volatile bool finished; -void OnSegmentationFault(int sig, siginfo_t *si, ucontext_t *ctx) { +void OnSegmentationFault(int sig, siginfo_t *si, void *vctx) { struct XedDecodedInst xedd; + ucontext_t *ctx = vctx; xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64); xed_instruction_length_decode(&xedd, (void *)ctx->uc_mcontext.rip, 15); ctx->uc_mcontext.rip += xedd.length;