Change sigaction_f to match sysv signature (#585)

This commit is contained in:
Gavin Hayes 2022-09-02 08:08:35 -04:00 committed by GitHub
parent 33b5b5b312
commit 263711965f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 46 additions and 35 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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);

View file

@ -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
* }

View file

@ -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 {

View file

@ -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;

View file

@ -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)));

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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

View file

@ -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;

View file

@ -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";

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;