Add raw parameter to redbean lua compress

This commit is contained in:
Justine Tunney 2022-05-17 10:41:23 -07:00
parent f37524ef4f
commit 3d99ebb68c
4 changed files with 92 additions and 50 deletions

View file

@ -23,6 +23,7 @@
#include "libc/calls/ucontext.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sig.h"
@ -34,6 +35,7 @@ struct sigaction oldsa;
volatile bool gotsigint;
void OnSigInt(int sig) {
_checkstackalign();
gotsigint = true;
}
@ -46,11 +48,11 @@ void SetUp(void) {
TEST(sigaction, raise) {
struct sigaction saint = {.sa_handler = OnSigInt};
EXPECT_NE(-1, sigaction(SIGINT, &saint, &oldsa));
EXPECT_SYS(0, 0, sigaction(SIGINT, &saint, &oldsa));
ASSERT_FALSE(gotsigint);
EXPECT_NE(-1, raise(SIGINT));
ASSERT_TRUE(gotsigint);
EXPECT_NE(-1, sigaction(SIGINT, &oldsa, NULL));
EXPECT_SYS(0, 0, sigaction(SIGINT, &oldsa, NULL));
}
////////////////////////////////////////////////////////////////////////////////
@ -68,37 +70,36 @@ TEST(sigaction, testPingPongParentChildWithSigint) {
// kind of runner. todo(fixme!)
return;
}
EXPECT_NE(-1, sigemptyset(&blockint));
EXPECT_NE(-1, sigaddset(&blockint, SIGINT));
EXPECT_NE(-1, sigprocmask(SIG_BLOCK, &blockint, &oldmask));
EXPECT_NE(-1, sigaction(SIGINT, &catchint, &oldint));
EXPECT_SYS(0, 0, sigemptyset(&blockint));
EXPECT_SYS(0, 0, sigaddset(&blockint, SIGINT));
EXPECT_SYS(0, 0, sigprocmask(SIG_BLOCK, &blockint, &oldmask));
EXPECT_SYS(0, 0, sigaction(SIGINT, &catchint, &oldint));
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
// ping
EXPECT_NE(-1, kill(getppid(), SIGINT));
EXPECT_SYS(0, 0, kill(getppid(), SIGINT));
EXPECT_FALSE(gotsigint);
// pong
EXPECT_NE(-1, sigaction(SIGINT, &catchint, 0));
EXPECT_EQ(-1, sigsuspend(0));
EXPECT_EQ(EINTR, errno);
EXPECT_SYS(0, 0, sigaction(SIGINT, &catchint, 0));
EXPECT_SYS(EINTR, -1, sigsuspend(0));
EXPECT_TRUE(gotsigint);
_exit(0);
}
// pong
EXPECT_FALSE(gotsigint);
EXPECT_NE(-1, sigaction(SIGINT, &catchint, 0));
EXPECT_EQ(-1, sigsuspend(0));
EXPECT_SYS(0, 0, sigaction(SIGINT, &catchint, 0));
EXPECT_SYS(EINTR, -1, sigsuspend(0));
EXPECT_TRUE(gotsigint);
// ping
EXPECT_NE(-1, sigaction(SIGINT, &ignoreint, 0));
EXPECT_NE(-1, kill(pid, SIGINT));
EXPECT_SYS(0, 0, sigaction(SIGINT, &ignoreint, 0));
EXPECT_SYS(0, 0, kill(pid, SIGINT));
// cleanup
EXPECT_NE(-1, wait4(pid, &status, 0, 0));
EXPECT_EQ(1, WIFEXITED(status));
EXPECT_EQ(0, WEXITSTATUS(status));
EXPECT_EQ(0, WTERMSIG(status));
EXPECT_NE(-1, sigaction(SIGINT, &oldint, 0));
EXPECT_NE(-1, sigprocmask(SIG_BLOCK, &oldmask, 0));
EXPECT_SYS(0, 0, sigaction(SIGINT, &oldint, 0));
EXPECT_SYS(0, 0, sigprocmask(SIG_BLOCK, &oldmask, 0));
}
////////////////////////////////////////////////////////////////////////////////
@ -108,6 +109,7 @@ TEST(sigaction, testPingPongParentChildWithSigint) {
volatile int trapeax;
void OnTrap(int sig, struct siginfo *si, struct ucontext *ctx) {
_checkstackalign();
trapeax = ctx->uc_mcontext.rax;
}
@ -116,7 +118,7 @@ TEST(sigaction, debugBreak_handlerCanReadCpuState) {
EXPECT_NE(-1, sigaction(SIGTRAP, &saint, &oldsa));
asm("int3" : /* no outputs */ : "a"(0x31337));
EXPECT_EQ(0x31337, trapeax);
EXPECT_NE(-1, sigaction(SIGTRAP, &oldsa, NULL));
EXPECT_SYS(0, 0, sigaction(SIGTRAP, &oldsa, NULL));
}
////////////////////////////////////////////////////////////////////////////////
@ -124,6 +126,7 @@ TEST(sigaction, debugBreak_handlerCanReadCpuState) {
// test signal handler can modify cpu registers (now it's recoverable!)
void SkipOverFaultingInstruction(struct ucontext *ctx) {
_checkstackalign();
struct XedDecodedInst xedd;
xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64);
xed_instruction_length_decode(&xedd, (void *)ctx->uc_mcontext.rip, 15);
@ -131,6 +134,7 @@ void SkipOverFaultingInstruction(struct ucontext *ctx) {
}
void OnFpe(int sig, struct siginfo *si, struct ucontext *ctx) {
_checkstackalign();
SkipOverFaultingInstruction(ctx);
ctx->uc_mcontext.rax = 42;
ctx->uc_mcontext.rdx = 0;
@ -138,10 +142,10 @@ void OnFpe(int sig, struct siginfo *si, struct ucontext *ctx) {
noubsan void ubsanTrumpsSystemsEngineering(void) {
struct sigaction saint = {.sa_sigaction = OnFpe, .sa_flags = SA_SIGINFO};
EXPECT_NE(-1, sigaction(SIGFPE, &saint, &oldsa));
EXPECT_SYS(0, 0, sigaction(SIGFPE, &saint, &oldsa));
volatile long x = 0;
EXPECT_EQ(42, 666 / x); /* systems engineering trumps math */
EXPECT_NE(-1, sigaction(SIGFPE, &oldsa, NULL));
EXPECT_SYS(0, 0, sigaction(SIGFPE, &oldsa, NULL));
}
TEST(sigaction, sigFpe_handlerCanEditProcessStateAndRecoverExecution) {