Implement raise() with getcontext() / setcontext()

This commit is contained in:
Justine Tunney 2023-11-05 17:52:30 -08:00
parent dd83db9567
commit 736fdb757a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 73 additions and 97 deletions

View file

@ -54,7 +54,6 @@ TEST(getcontext, test) {
TEST(getcontext, canReadAndWriteSignalMask) {
sigset_t ss, old;
volatile int n = 0;
__interruptible = true;
sigemptyset(&ss);
sigaddset(&ss, SIGUSR1);
sigprocmask(SIG_SETMASK, &ss, &old);
@ -72,8 +71,7 @@ TEST(getcontext, canReadAndWriteSignalMask) {
}
void SetGetContext(void) {
static int a;
a = 0;
int a = 0;
getcontext(&context);
if (!a) {
a = 1;
@ -82,9 +80,6 @@ void SetGetContext(void) {
}
BENCH(getcontext, bench) {
__interruptible = false;
EZBENCH2("getsetcontext nosig", donothing, SetGetContext());
__interruptible = true;
EZBENCH2("getsetcontext", donothing, SetGetContext());
}
@ -99,10 +94,6 @@ BENCH(swapcontext, bench) {
}
} else {
ready = true;
__interruptible = false;
EZBENCH2("swapcontextx2 nosig", donothing, swapcontext(&loop, &main));
// kprintf("dollar\n");
__interruptible = true;
EZBENCH2("swapcontextx2", donothing, swapcontext(&loop, &main));
// kprintf("dollar\n");
}

View file

@ -20,10 +20,12 @@
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/subprocess.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"
@ -67,9 +69,19 @@ void *Worker(void *arg) {
}
TEST(raise, threaded) {
SPAWN(fork);
signal(SIGILL, SIG_DFL);
pthread_t worker;
ASSERT_EQ(0, pthread_create(&worker, 0, Worker, 0));
ASSERT_EQ(0, pthread_join(worker, 0));
pthread_exit(0);
EXITS(0);
}
void OnRaise(int sig) {
}
BENCH(raise, bench) {
signal(SIGUSR1, OnRaise);
EZBENCH2("raise", donothing, raise(SIGUSR1));
}

View file

@ -116,3 +116,8 @@ TEST(poll, interrupt) {
ASSERT_TRUE(gotsig);
ASSERT_TRUE(didit);
}
TEST(raise, zero) {
ASSERT_SYS(0, 0, raise(0));
ASSERT_SYS(EINVAL, -1, raise(-1));
}

View file

@ -64,7 +64,6 @@ void check_args(long x0, long x1, long x2, long x3, long x4, long x5, double f0,
TEST(makecontext, args) {
char stack[1024];
__interruptible = false;
getcontext(&uc);
uc.uc_link = &goback;
uc.uc_stack.ss_sp = stack;