Fix ctrl-c in redbean on Windows

This commit is contained in:
Justine Tunney 2023-10-13 07:43:47 -07:00
parent d458642790
commit 4bcb107cb0
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 326 additions and 32 deletions

View file

@ -247,6 +247,7 @@ static textwindows int __sig_killer(struct PosixThread *pt, int sig, int sic) {
STRACE("kill contention of %u on tid %d", old_suspend_count,
_pthread_tid(pt));
pt->tib->tib_sigpending |= 1ull << (sig - 1);
ResumeThread(th);
return 0;
}
struct NtContext nc;

View file

@ -1059,15 +1059,12 @@ privileged size_t kvsnprintf(char *b, size_t n, const char *fmt, va_list v) {
privileged void kvprintf(const char *fmt, va_list v) {
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Walloca-larger-than="
long size = 3000;
/* long size = __get_safe_size(8000, 3000); */
/* if (size < 80) { */
/* asm("int3"); */
/* klog(STACK_ERROR, sizeof(STACK_ERROR) - 1); */
/* return; */
/* } */
long size = __get_safe_size(8000, 3000);
if (size < 80) {
asm("int3");
klog(STACK_ERROR, sizeof(STACK_ERROR) - 1);
return;
}
char *buf = alloca(size);
CheckLargeStackAllocation(buf, size);
#pragma GCC pop_options

View file

@ -107,7 +107,7 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
}
addr = frame->addr;
#ifdef __x86_64__
if (addr == (uintptr_t)_weaken(__gc)) {
if (gi && addr == (uintptr_t)_weaken(__gc)) {
do {
--gi;
} while ((addr = garbage->p[gi].ret) == (uintptr_t)_weaken(__gc));
@ -116,7 +116,7 @@ static int PrintBacktraceUsingAddr2line(int fd, const struct StackFrame *bp) {
argv[i++] = buf + j;
buf[j++] = '0';
buf[j++] = 'x';
j += uint64toarray_radix16(addr - 1, buf + j) + 1;
j += uint64toarray_radix16(addr, buf + j) + 1;
}
argv[i++] = NULL;
if (sys_pipe2(pipefds, O_CLOEXEC) == -1) {

View file

@ -73,20 +73,7 @@ dontinstrument dontasan int PrintBacktraceUsingSymbols(
}
#endif
if (addr) {
if (
#ifdef __x86_64__
/*
* we subtract one to handle the case of noreturn functions
* with a call instruction at the end, since %rip in such
* cases will point to the start of the next function.
* generally %rip always points to the byte after the
* instruction. one exception is in case like __restore_rt
* where the kernel creates a stack frame that points to the
* beginning of the function.
*/
(symbol = __get_symbol(st, addr - 1)) != -1 ||
#endif
(symbol = __get_symbol(st, addr)) != -1) {
if ((symbol = __get_symbol(st, addr)) != -1) {
addend = addr - st->addr_base;
addend -= st->symbols[symbol].x;
} else {

View file

@ -135,7 +135,7 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f,
(dprintf)(STDERR_FILENO,
"exiting due to aforementioned error (host %s pid %d tid %d)\n",
buf32, getpid(), gettid());
__die();
_Exit(22);
}
ALLOW_SIGNALS;

View file

@ -291,7 +291,7 @@ struct NtInterfaceInfo {
*/
int32_t WSAStartup(uint16_t wVersionRequested, struct NtWsaData *lpWSAData)
paramsnonnull() __wur;
paramsnonnull();
int WSACleanup(void);
int WSAGetLastError(void) nosideeffect;

View file

@ -17,8 +17,10 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigset.internal.h"
#include "libc/calls/syscall-nt.internal.h"
#include "libc/errno.h"
#include "libc/intrin/dll.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/console.h"
#include "libc/nt/enum/ctrlevent.h"
@ -53,6 +55,16 @@ textwindows int sys_kill_nt(int pid, int sig) {
// just call raise() if we're targeting self
if (pid <= 0 || pid == getpid()) {
if (sig) {
if (pid <= 0) {
struct Dll *e;
BLOCK_SIGNALS;
__proc_lock();
for (e = dll_first(__proc.list); e; e = dll_next(__proc.list, e)) {
TerminateProcess(PROC_CONTAINER(e)->handle, sig);
}
__proc_unlock();
ALLOW_SIGNALS;
}
return raise(sig);
} else {
return 0; // ability check passes

View file

@ -22,6 +22,7 @@
#include "libc/calls/struct/fd.internal.h"
#include "libc/calls/struct/sigset.internal.h"
#include "libc/cosmo.h"
#include "libc/errno.h"
#include "libc/nt/enum/wsaid.h"
#include "libc/nt/thunk/msabi.h"
#include "libc/nt/winsock.h"
@ -140,6 +141,9 @@ textwindows int sys_accept_nt(struct Fd *f, struct sockaddr_storage *addr,
WeFailed:
pthread_cleanup_pop(false);
__sig_unblock(m);
if (client == -1 && errno == ECONNRESET) {
errno = ECONNABORTED;
}
return client;
}