mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
111 lines
5.7 KiB
C
111 lines
5.7 KiB
C
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
|
│ │
|
|
│ 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. │
|
|
│ │
|
|
│ 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. │
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
#include "libc/calls/calls.h"
|
|
#include "libc/calls/internal.h"
|
|
#include "libc/calls/state.internal.h"
|
|
#include "libc/calls/struct/sigaction-freebsd.internal.h"
|
|
#include "libc/calls/struct/siginfo-netbsd.internal.h"
|
|
#include "libc/calls/struct/siginfo.h"
|
|
#include "libc/calls/struct/ucontext-netbsd.internal.h"
|
|
#include "libc/calls/typedef/sigaction_f.h"
|
|
#include "libc/calls/ucontext.h"
|
|
#include "libc/log/libfatal.internal.h"
|
|
#include "libc/macros.internal.h"
|
|
#include "libc/str/str.h"
|
|
#include "libc/sysv/consts/sa.h"
|
|
|
|
privileged void __sigenter_netbsd(int sig, struct siginfo_netbsd *si,
|
|
struct ucontext_netbsd *ctx) {
|
|
int rva, flags;
|
|
ucontext_t uc;
|
|
struct siginfo si2;
|
|
rva = __sighandrvas[sig & (NSIG - 1)];
|
|
if (rva >= kSigactionMinRva) {
|
|
flags = __sighandflags[sig & (NSIG - 1)];
|
|
if (~flags & SA_SIGINFO) {
|
|
((sigaction_f)(_base + rva))(sig, 0, 0);
|
|
} else {
|
|
__repstosb(&uc, 0, sizeof(uc));
|
|
__repstosb(&si2, 0, sizeof(si2));
|
|
si2.si_signo = si->si_signo;
|
|
si2.si_code = si->si_code;
|
|
si2.si_errno = si->si_errno;
|
|
si2.si_pid = si->si_pid;
|
|
si2.si_uid = si->si_uid;
|
|
si2.si_value = si->si_value;
|
|
uc.uc_mcontext.fpregs = &uc.__fpustate;
|
|
uc.uc_flags = ctx->uc_flags;
|
|
uc.uc_stack.ss_sp = ctx->uc_stack.ss_sp;
|
|
uc.uc_stack.ss_size = ctx->uc_stack.ss_size;
|
|
uc.uc_stack.ss_flags = ctx->uc_stack.ss_flags;
|
|
__repmovsb(&uc.uc_sigmask, &ctx->uc_sigmask,
|
|
MIN(sizeof(uc.uc_sigmask), sizeof(ctx->uc_sigmask)));
|
|
uc.uc_mcontext.rdi = ctx->uc_mcontext.rdi;
|
|
uc.uc_mcontext.rsi = ctx->uc_mcontext.rsi;
|
|
uc.uc_mcontext.rdx = ctx->uc_mcontext.rdx;
|
|
uc.uc_mcontext.rcx = ctx->uc_mcontext.rcx;
|
|
uc.uc_mcontext.r8 = ctx->uc_mcontext.r8;
|
|
uc.uc_mcontext.r9 = ctx->uc_mcontext.r9;
|
|
uc.uc_mcontext.rax = ctx->uc_mcontext.rax;
|
|
uc.uc_mcontext.rbx = ctx->uc_mcontext.rbx;
|
|
uc.uc_mcontext.rbp = ctx->uc_mcontext.rbp;
|
|
uc.uc_mcontext.r10 = ctx->uc_mcontext.r10;
|
|
uc.uc_mcontext.r11 = ctx->uc_mcontext.r11;
|
|
uc.uc_mcontext.r12 = ctx->uc_mcontext.r12;
|
|
uc.uc_mcontext.r13 = ctx->uc_mcontext.r13;
|
|
uc.uc_mcontext.r14 = ctx->uc_mcontext.r14;
|
|
uc.uc_mcontext.r15 = ctx->uc_mcontext.r15;
|
|
uc.uc_mcontext.trapno = ctx->uc_mcontext.trapno;
|
|
uc.uc_mcontext.fs = ctx->uc_mcontext.fs;
|
|
uc.uc_mcontext.gs = ctx->uc_mcontext.gs;
|
|
uc.uc_mcontext.err = ctx->uc_mcontext.err;
|
|
uc.uc_mcontext.rip = ctx->uc_mcontext.rip;
|
|
uc.uc_mcontext.rsp = ctx->uc_mcontext.rsp;
|
|
*uc.uc_mcontext.fpregs = ctx->uc_mcontext.__fpregs;
|
|
((sigaction_f)(_base + rva))(sig, &si2, &uc);
|
|
ctx->uc_mcontext.rdi = uc.uc_mcontext.rdi;
|
|
ctx->uc_mcontext.rsi = uc.uc_mcontext.rsi;
|
|
ctx->uc_mcontext.rdx = uc.uc_mcontext.rdx;
|
|
ctx->uc_mcontext.rcx = uc.uc_mcontext.rcx;
|
|
ctx->uc_mcontext.r8 = uc.uc_mcontext.r8;
|
|
ctx->uc_mcontext.r9 = uc.uc_mcontext.r9;
|
|
ctx->uc_mcontext.rax = uc.uc_mcontext.rax;
|
|
ctx->uc_mcontext.rbx = uc.uc_mcontext.rbx;
|
|
ctx->uc_mcontext.rbp = uc.uc_mcontext.rbp;
|
|
ctx->uc_mcontext.r10 = uc.uc_mcontext.r10;
|
|
ctx->uc_mcontext.r11 = uc.uc_mcontext.r11;
|
|
ctx->uc_mcontext.r12 = uc.uc_mcontext.r12;
|
|
ctx->uc_mcontext.r13 = uc.uc_mcontext.r13;
|
|
ctx->uc_mcontext.r14 = uc.uc_mcontext.r14;
|
|
ctx->uc_mcontext.r15 = uc.uc_mcontext.r15;
|
|
ctx->uc_mcontext.trapno = uc.uc_mcontext.trapno;
|
|
ctx->uc_mcontext.fs = uc.uc_mcontext.fs;
|
|
ctx->uc_mcontext.gs = uc.uc_mcontext.gs;
|
|
ctx->uc_mcontext.err = uc.uc_mcontext.err;
|
|
ctx->uc_mcontext.rip = uc.uc_mcontext.rip;
|
|
ctx->uc_mcontext.rsp = uc.uc_mcontext.rsp;
|
|
ctx->uc_mcontext.__fpregs = *uc.uc_mcontext.fpregs;
|
|
}
|
|
}
|
|
/*
|
|
* When the NetBSD kernel invokes this signal handler it pushes a
|
|
* trampoline on the stack which does two things: 1) it calls this
|
|
* function, and 2) calls sys_sigreturn() once this returns.
|
|
*/
|
|
}
|