mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Add siglongjmp() for aarch64
This commit is contained in:
parent
c88f95a892
commit
22cf6e11eb
13 changed files with 34 additions and 49 deletions
|
@ -82,7 +82,7 @@ int EnableRawMode(void) {
|
|||
|
||||
t.c_iflag &= ~(INPCK | ISTRIP | PARMRK | INLCR | IGNCR | ICRNL | IXON |
|
||||
IGNBRK | BRKINT);
|
||||
t.c_lflag &= ~(IEXTEN | ICANON | ECHO | ECHONL /* | ISIG */);
|
||||
t.c_lflag &= ~(IEXTEN | ICANON | ECHO | ECHONL);
|
||||
t.c_cflag &= ~(CSIZE | PARENB);
|
||||
t.c_oflag |= OPOST | ONLCR;
|
||||
t.c_cflag |= CS8;
|
||||
|
|
|
@ -214,10 +214,12 @@ static textwindows int ProcessKeyEvent(const struct NtInputRecord *r, char *p) {
|
|||
}
|
||||
|
||||
// handle ctrl-d the end of file keystroke
|
||||
if (c == __veof && __veof != _POSIX_VDISABLE) {
|
||||
STRACE("encountered CTRL(%#c) c_cc[VEOF] closing console input", CTRL(c));
|
||||
__keystroke.end_of_file = true;
|
||||
return 0;
|
||||
if (!(__ttymagic & kFdTtyUncanon)) {
|
||||
if (c == __veof && __veof != _POSIX_VDISABLE) {
|
||||
STRACE("encountered CTRL(%#c) c_cc[VEOF] closing console input", CTRL(c));
|
||||
__keystroke.end_of_file = true;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// insert esc prefix when alt is held
|
||||
|
|
|
@ -53,8 +53,8 @@ int setpgid(int pid, int pgid) {
|
|||
rc = __winerr();
|
||||
}
|
||||
} else {
|
||||
// irregular use cases not supported on windows
|
||||
rc = einval();
|
||||
// avoid bash printing scary warnings for now
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
STRACE("setpgid(%d, %d) → %d% m", pid, pgid, rc);
|
||||
|
|
|
@ -21,7 +21,7 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
#define kFdTtyEchoing 1 /* read()→write() (ECHO && !ICANON) */
|
||||
#define kFdTtyEchoRaw 2 /* don't ^X visualize control codes */
|
||||
#define kFdTtyMunging 4 /* enable input / output remappings */
|
||||
#define kFdTtyUncanon 4 /* enables non-canonical (raw) mode */
|
||||
#define kFdTtyNoCr2Nl 8 /* don't map \r → \n (a.k.a !ICRNL) */
|
||||
#define kFdTtyNoIsigs 16
|
||||
#define kFdTtyNoBlock 32
|
||||
|
|
|
@ -95,7 +95,7 @@ textwindows int tcgetattr_nt(int fd, struct termios *tio) {
|
|||
if (!(__ttymagic & kFdTtyNoIsigs)) {
|
||||
tio->c_lflag |= ISIG;
|
||||
}
|
||||
if ((inmode & kNtEnableProcessedInput) || (__ttymagic & kFdTtyMunging)) {
|
||||
if (inmode & kNtEnableProcessedInput) {
|
||||
tio->c_lflag |= IEXTEN;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) {
|
|||
}
|
||||
|
||||
if (opt == TCSAFLUSH) {
|
||||
tcflush(fd, TCIFLUSH);
|
||||
FlushConsoleInputBytes(hInput);
|
||||
}
|
||||
inmode &= ~(kNtEnableLineInput | kNtEnableEchoInput |
|
||||
kNtEnableProcessedInput | kNtEnableVirtualTerminalInput);
|
||||
|
@ -78,7 +78,7 @@ textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) {
|
|||
kNtEnableLineInput | kNtEnableProcessedInput | kNtEnableQuickEditMode;
|
||||
} else {
|
||||
inmode &= ~kNtEnableQuickEditMode;
|
||||
__ttymagic |= kFdTtyMunging;
|
||||
__ttymagic |= kFdTtyUncanon;
|
||||
if (!tio->c_cc[VMIN]) {
|
||||
__ttymagic |= kFdTtyNoBlock;
|
||||
}
|
||||
|
|
|
@ -62,3 +62,4 @@ longjmp:
|
|||
#endif
|
||||
.endfn longjmp,globl
|
||||
.alias longjmp,_longjmp
|
||||
.alias longjmp,siglongjmp
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 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/macros.internal.h"
|
||||
|
||||
// Loads previously saved processor state.
|
||||
//
|
||||
// @param rdi points to the jmp_buf
|
||||
// @param esi is returned by setjmp() invocation (coerced nonzero)
|
||||
// @noreturn
|
||||
// @asyncsignalsafe
|
||||
siglongjmp:
|
||||
jmp longjmp
|
||||
.endfn siglongjmp,globl
|
|
@ -20,7 +20,6 @@
|
|||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
// kudos rich felker for the brilliant design
|
||||
int __sigsetjmp_tail(sigjmp_buf jb, int rc) {
|
||||
|
@ -28,8 +27,6 @@ int __sigsetjmp_tail(sigjmp_buf jb, int rc) {
|
|||
sizeof(sigjmp_buf) == sizeof(jmp_buf) + 8 + 8 + sizeof(sigset_t),
|
||||
"please recompute sigjmp_buf w.r.t. sigset_t");
|
||||
void *p = (char *)jb + sizeof(jmp_buf) + 8 + 8;
|
||||
npassert(!sigprocmask(SIG_SETMASK, rc ? p : 0, rc ? 0 : p));
|
||||
sigprocmask(SIG_SETMASK, rc ? p : 0, rc ? 0 : p);
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -8,8 +8,10 @@ COSMOPOLITAN_C_START_
|
|||
|
||||
#ifdef __x86_64__
|
||||
typedef long jmp_buf[8];
|
||||
typedef long sigjmp_buf[12];
|
||||
#elif defined(__aarch64__)
|
||||
typedef long jmp_buf[22];
|
||||
typedef long sigjmp_buf[26];
|
||||
#elif defined(__powerpc64__)
|
||||
typedef unsigned __int128 jmp_buf[32];
|
||||
#elif defined(__s390x__)
|
||||
|
@ -18,8 +20,6 @@ typedef unsigned long jmp_buf[18];
|
|||
typedef unsigned long jmp_buf[26];
|
||||
#endif
|
||||
|
||||
typedef long sigjmp_buf[12];
|
||||
|
||||
void mcount(void);
|
||||
int daemon(int, int);
|
||||
unsigned long getauxval(unsigned long);
|
||||
|
|
|
@ -112,6 +112,8 @@ o/$(MODE)/libc/runtime/zipos.o: libc/runtime/zipos.S
|
|||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/runtime/switchstacks.o: libc/runtime/switchstacks.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
o/$(MODE)/libc/runtime/sigsetjmp.o: libc/runtime/sigsetjmp.S
|
||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||
|
||||
LIBC_RUNTIME_LIBS = $(foreach x,$(LIBC_RUNTIME_ARTIFACTS),$($(x)))
|
||||
LIBC_RUNTIME_SRCS = $(foreach x,$(LIBC_RUNTIME_ARTIFACTS),$($(x)_SRCS))
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
// @return eax 0 when set and !0 when longjmp'd
|
||||
// @returnstwice
|
||||
sigsetjmp:
|
||||
#ifdef __x86_64__
|
||||
test %esi,%esi
|
||||
jz setjmp
|
||||
popq 64(%rdi)
|
||||
|
@ -45,5 +46,19 @@ sigsetjmp:
|
|||
mov %eax,%esi
|
||||
mov 72(%rdi),%rbx
|
||||
jmp __sigsetjmp_tail
|
||||
#elif defined(__aarch64__)
|
||||
cbz x1,setjmp
|
||||
str x30,[x0,#176]
|
||||
str x19,[x0,#176+8+8]
|
||||
mov x19,x0
|
||||
bl setjmp
|
||||
mov w1,w0
|
||||
mov x0,x19
|
||||
ldr x30,[x0,#176]
|
||||
ldr x19,[x0,#176+8+8]
|
||||
b __sigsetjmp_tail
|
||||
#else
|
||||
#error "unsupported architecture"
|
||||
#endif
|
||||
.hidden __sigsetjmp_tail
|
||||
.endfn sigsetjmp,globl
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
sigjmp_buf jb;
|
||||
volatile int sigs;
|
||||
|
@ -54,5 +53,3 @@ TEST(sigsetjmp, test) {
|
|||
ASSERT_EQ(1000, jumps);
|
||||
ASSERT_EQ(1000, sigs);
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
Loading…
Reference in a new issue