mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Rewrite Windows console input handling
This change removes our use of ENABLE_VIRTUAL_TERMINAL_INPUT (which isn't very good) in favor of having read() translate Windows Console input events to ANSI/XTERM sequences by hand. This makes it possible to capture important keystrokes (e.g. ctrl-space) that weren't possible before. Most importantly this change also removes the stdin/sigwinch worker threads, which never really worked that well. Interactive TTY sessions will now work reliably when a Cosmo process spawns or forks another Cosmo process, e.g. unbourne.com launching emacs.com.
This commit is contained in:
parent
ececec4c94
commit
d6c2830850
27 changed files with 635 additions and 464 deletions
|
@ -111,23 +111,27 @@ static void _pthread_cancel_listen(void) {
|
|||
|
||||
static void pthread_cancel_nt(struct PosixThread *pt, intptr_t hThread) {
|
||||
uint32_t old_suspend_count;
|
||||
if ((pt->pt_flags & PT_ASYNC) && !(pt->pt_flags & PT_NOCANCEL)) {
|
||||
if ((old_suspend_count = SuspendThread(hThread)) != -1u) {
|
||||
if (!(pt->pt_flags & PT_NOCANCEL) &&
|
||||
(pt->pt_flags & (PT_ASYNC | PT_MASKED))) {
|
||||
pt->pt_flags |= PT_NOCANCEL;
|
||||
pt->abort_errno = ECANCELED;
|
||||
if ((pt->pt_flags & PT_ASYNC) &&
|
||||
(old_suspend_count = SuspendThread(hThread)) != -1u) {
|
||||
if (!old_suspend_count) {
|
||||
struct NtContext cpu;
|
||||
cpu.ContextFlags = kNtContextControl | kNtContextInteger;
|
||||
if (GetThreadContext(hThread, &cpu)) {
|
||||
pt->pt_flags |= PT_NOCANCEL;
|
||||
cpu.Rip = (uintptr_t)pthread_exit;
|
||||
cpu.Rdi = (uintptr_t)PTHREAD_CANCELED;
|
||||
cpu.Rsp &= -16;
|
||||
*(uintptr_t *)(cpu.Rsp -= sizeof(uintptr_t)) = cpu.Rip;
|
||||
pt->abort_errno = ECANCELED;
|
||||
unassert(SetThreadContext(hThread, &cpu));
|
||||
__sig_cancel(pt, 0);
|
||||
}
|
||||
}
|
||||
ResumeThread(hThread);
|
||||
}
|
||||
__sig_cancel(pt);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue