mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-04 19:52:28 +00:00
Ensure ^C gets printed to Windows console
This commit is contained in:
parent
e228aa3e14
commit
fd15b2d7a3
5 changed files with 37 additions and 9 deletions
|
@ -216,12 +216,6 @@ o//libc/calls/writev.o: private \
|
||||||
-mgeneral-regs-only
|
-mgeneral-regs-only
|
||||||
|
|
||||||
# these assembly files are safe to build on aarch64
|
# these assembly files are safe to build on aarch64
|
||||||
o/$(MODE)/libc/calls/getcontext.o: libc/calls/getcontext.S
|
|
||||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
|
||||||
o/$(MODE)/libc/calls/swapcontext.o: libc/calls/swapcontext.S
|
|
||||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
|
||||||
o/$(MODE)/libc/calls/tailcontext.o: libc/calls/tailcontext.S
|
|
||||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
|
||||||
o/$(MODE)/libc/calls/stackjump.o: libc/calls/stackjump.S
|
o/$(MODE)/libc/calls/stackjump.o: libc/calls/stackjump.S
|
||||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ int CountConsoleInputBytes(void);
|
||||||
int FlushConsoleInputBytes(void);
|
int FlushConsoleInputBytes(void);
|
||||||
int64_t GetConsoleInputHandle(void);
|
int64_t GetConsoleInputHandle(void);
|
||||||
int64_t GetConsoleOutputHandle(void);
|
int64_t GetConsoleOutputHandle(void);
|
||||||
|
void EchoConsoleNt(const char *, size_t, bool);
|
||||||
int IsWindowsExecutable(int64_t, const char16_t *);
|
int IsWindowsExecutable(int64_t, const char16_t *);
|
||||||
void InterceptTerminalCommands(const char *, size_t);
|
void InterceptTerminalCommands(const char *, size_t);
|
||||||
|
|
||||||
|
|
|
@ -320,9 +320,12 @@ textwindows static int ProcessKeyEvent(const struct NtInputRecord *r, char *p) {
|
||||||
// note we define _POSIX_VDISABLE as zero
|
// note we define _POSIX_VDISABLE as zero
|
||||||
// tcsetattr() lets anyone reconfigure these keybindings
|
// tcsetattr() lets anyone reconfigure these keybindings
|
||||||
if (c && !(__ttyconf.magic & kTtyNoIsigs) && !__keystroke.bypass_mode) {
|
if (c && !(__ttyconf.magic & kTtyNoIsigs) && !__keystroke.bypass_mode) {
|
||||||
|
char b[] = {c};
|
||||||
if (c == __ttyconf.vintr) {
|
if (c == __ttyconf.vintr) {
|
||||||
|
EchoConsoleNt(b, 1, false);
|
||||||
return AddSignal(SIGINT);
|
return AddSignal(SIGINT);
|
||||||
} else if (c == __ttyconf.vquit) {
|
} else if (c == __ttyconf.vquit) {
|
||||||
|
EchoConsoleNt(b, 1, false);
|
||||||
return AddSignal(SIGQUIT);
|
return AddSignal(SIGQUIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -457,7 +460,8 @@ textwindows static void WriteCtl(const char *p, size_t n, bool escape_harder) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textwindows static void EchoTty(const char *p, size_t n, bool escape_harder) {
|
textwindows void EchoConsoleNt(const char *p, size_t n, bool escape_harder) {
|
||||||
|
InitConsole();
|
||||||
if (!(__ttyconf.magic & kTtySilence)) {
|
if (!(__ttyconf.magic & kTtySilence)) {
|
||||||
if (__ttyconf.magic & kTtyEchoRaw) {
|
if (__ttyconf.magic & kTtyEchoRaw) {
|
||||||
WriteTty(p, n);
|
WriteTty(p, n);
|
||||||
|
@ -517,7 +521,7 @@ textwindows static void IngestConsoleInputRecord(struct NtInputRecord *r) {
|
||||||
memcpy(k->buf, buf, sizeof(k->buf));
|
memcpy(k->buf, buf, sizeof(k->buf));
|
||||||
k->buflen = len;
|
k->buflen = len;
|
||||||
dll_make_last(&__keystroke.line, &k->elem);
|
dll_make_last(&__keystroke.line, &k->elem);
|
||||||
EchoTty(buf, len, true);
|
EchoConsoleNt(buf, len, true);
|
||||||
if (!__keystroke.freekeys) {
|
if (!__keystroke.freekeys) {
|
||||||
dll_make_last(&__keystroke.list, __keystroke.line);
|
dll_make_last(&__keystroke.list, __keystroke.line);
|
||||||
__keystroke.line = 0;
|
__keystroke.line = 0;
|
||||||
|
@ -616,7 +620,7 @@ textwindows static void IngestConsoleInputRecord(struct NtInputRecord *r) {
|
||||||
|
|
||||||
// echo input if it was successfully recorded
|
// echo input if it was successfully recorded
|
||||||
// assuming the win32 console isn't doing it already
|
// assuming the win32 console isn't doing it already
|
||||||
EchoTty(buf, len, false);
|
EchoConsoleNt(buf, len, false);
|
||||||
|
|
||||||
// save keystroke to appropriate list
|
// save keystroke to appropriate list
|
||||||
if (__ttyconf.magic & kTtyUncanon) {
|
if (__ttyconf.magic & kTtyUncanon) {
|
||||||
|
|
|
@ -119,6 +119,12 @@ o/$(MODE)/libc/intrin/windowstimetotimespec.o: private \
|
||||||
-O2
|
-O2
|
||||||
|
|
||||||
# these assembly files are safe to build on aarch64
|
# these assembly files are safe to build on aarch64
|
||||||
|
o/$(MODE)/libc/intrin/getcontext.o: libc/intrin/getcontext.S
|
||||||
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
|
o/$(MODE)/libc/intrin/swapcontext.o: libc/intrin/swapcontext.S
|
||||||
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
|
o/$(MODE)/libc/intrin/tailcontext.o: libc/intrin/tailcontext.S
|
||||||
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
o/$(MODE)/libc/intrin/aarch64/%.o: libc/intrin/aarch64/%.S
|
o/$(MODE)/libc/intrin/aarch64/%.o: libc/intrin/aarch64/%.S
|
||||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
o/$(MODE)/libc/intrin/fenv.o: libc/intrin/fenv.S
|
o/$(MODE)/libc/intrin/fenv.o: libc/intrin/fenv.S
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "libc/sysv/consts/sig.h"
|
#include "libc/sysv/consts/sig.h"
|
||||||
#include "ape/sections.internal.h"
|
#include "ape/sections.internal.h"
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/internal.h"
|
||||||
#include "libc/calls/sig.internal.h"
|
#include "libc/calls/sig.internal.h"
|
||||||
#include "libc/calls/state.internal.h"
|
#include "libc/calls/state.internal.h"
|
||||||
#include "libc/calls/struct/sigaction.h"
|
#include "libc/calls/struct/sigaction.h"
|
||||||
|
@ -34,6 +35,7 @@
|
||||||
#include "libc/intrin/describebacktrace.h"
|
#include "libc/intrin/describebacktrace.h"
|
||||||
#include "libc/intrin/dll.h"
|
#include "libc/intrin/dll.h"
|
||||||
#include "libc/intrin/maps.h"
|
#include "libc/intrin/maps.h"
|
||||||
|
#include "libc/intrin/nomultics.h"
|
||||||
#include "libc/intrin/strace.h"
|
#include "libc/intrin/strace.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/nt/console.h"
|
#include "libc/nt/console.h"
|
||||||
|
@ -54,6 +56,7 @@
|
||||||
#include "libc/sysv/consts/sa.h"
|
#include "libc/sysv/consts/sa.h"
|
||||||
#include "libc/sysv/consts/sicode.h"
|
#include "libc/sysv/consts/sicode.h"
|
||||||
#include "libc/sysv/consts/ss.h"
|
#include "libc/sysv/consts/ss.h"
|
||||||
|
#include "libc/sysv/consts/termios.h"
|
||||||
#include "libc/thread/posixthread.internal.h"
|
#include "libc/thread/posixthread.internal.h"
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
|
|
||||||
|
@ -622,12 +625,32 @@ static textwindows int __sig_console_sig(uint32_t dwCtrlType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static textwindows int __sig_console_char(uint32_t dwCtrlType) {
|
||||||
|
switch (dwCtrlType) {
|
||||||
|
case kNtCtrlCEvent:
|
||||||
|
return __ttyconf.vintr;
|
||||||
|
case kNtCtrlBreakEvent:
|
||||||
|
return __ttyconf.vquit;
|
||||||
|
default:
|
||||||
|
return _POSIX_VDISABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
__msabi textwindows dontinstrument bool32 __sig_console(uint32_t dwCtrlType) {
|
__msabi textwindows dontinstrument bool32 __sig_console(uint32_t dwCtrlType) {
|
||||||
// win32 launches a thread to deliver ctrl-c and ctrl-break when typed
|
// win32 launches a thread to deliver ctrl-c and ctrl-break when typed
|
||||||
// it only happens when kNtEnableProcessedInput is in play on console.
|
// it only happens when kNtEnableProcessedInput is in play on console.
|
||||||
// otherwise we need to wait until read-nt.c discovers that keystroke.
|
// otherwise we need to wait until read-nt.c discovers that keystroke.
|
||||||
struct CosmoTib tls;
|
struct CosmoTib tls;
|
||||||
__bootstrap_tls(&tls, __builtin_frame_address(0));
|
__bootstrap_tls(&tls, __builtin_frame_address(0));
|
||||||
|
|
||||||
|
// ensure that ^C or ^\ gets printed to console appropriately
|
||||||
|
if (_weaken(EchoConsoleNt)) {
|
||||||
|
char c;
|
||||||
|
if ((c = __sig_console_char(dwCtrlType)) != _POSIX_VDISABLE)
|
||||||
|
_weaken(EchoConsoleNt)(&c, sizeof(c), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// take control of random thread and inject call to signal handler
|
||||||
__sig_generate(__sig_console_sig(dwCtrlType), SI_KERNEL);
|
__sig_generate(__sig_console_sig(dwCtrlType), SI_KERNEL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue