Fix copy/paste issue in Windows console

This commit is contained in:
Justine Tunney 2023-10-14 15:27:04 -07:00
parent bd48e6c666
commit 06c6baaf50
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
7 changed files with 30 additions and 37 deletions

View file

@ -31,7 +31,6 @@
#include "libc/intrin/atomic.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/dll.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/nomultics.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
@ -129,14 +128,14 @@ struct Keystroke {
struct Keystrokes {
atomic_uint once;
bool end_of_file;
bool ohno_decckm;
uint16_t utf16hs;
atomic_int_fast16_t used;
int64_t cin, cot;
struct Dll *list;
struct Dll *line;
struct Dll *free;
bool end_of_file;
bool ohno_decckm;
unsigned char pc;
uint16_t utf16hs;
pthread_mutex_t lock;
const struct VirtualKey *vkt;
struct Keystroke pool[512];
@ -156,6 +155,12 @@ static textwindows void OpenConsole(void) {
kNtFileShareWrite, 0, kNtOpenExisting, 0, 0);
}
static textwindows int AddSignal(int sig) {
atomic_fetch_or_explicit(&__get_tls()->tib_sigpending, 1ull << (sig - 1),
memory_order_relaxed);
return 0;
}
static textwindows void InitConsole(void) {
cosmo_once(&__keystroke.once, OpenConsole);
}
@ -295,9 +300,9 @@ static textwindows int ProcessKeyEvent(const struct NtInputRecord *r, char *p) {
// tcsetattr() lets anyone reconfigure these keybindings
if (c && !(__ttyconf.magic & kTtyNoIsigs)) {
if (c == __ttyconf.vintr) {
return __sig_enqueue(SIGINT);
return AddSignal(SIGINT);
} else if (c == __ttyconf.vquit) {
return __sig_enqueue(SIGQUIT);
return AddSignal(SIGQUIT);
}
}
@ -399,7 +404,7 @@ static textwindows int ConvertConsoleInputToAnsi(const struct NtInputRecord *r,
case kNtMouseEvent:
return ProcessMouseEvent(r, p);
case kNtWindowBufferSizeEvent:
return __sig_enqueue(SIGWINCH);
return AddSignal(SIGWINCH);
default:
return 0;
}
@ -409,8 +414,8 @@ static textwindows struct Keystroke *NewKeystroke(void) {
struct Dll *e;
struct Keystroke *k = 0;
int i, n = ARRAYLEN(__keystroke.pool);
if (atomic_load_explicit(&__keystroke.pc, memory_order_acquire) < n &&
(i = atomic_fetch_add(&__keystroke.pc, 1)) < n) {
if (atomic_load_explicit(&__keystroke.used, memory_order_acquire) < n &&
(i = atomic_fetch_add(&__keystroke.used, 1)) < n) {
k = __keystroke.pool + i;
} else {
if ((e = dll_first(__keystroke.free))) {

View file

@ -91,7 +91,8 @@ textwindows void __sig_delete(int sig) {
BLOCK_SIGNALS;
_pthread_lock();
for (e = dll_last(_pthread_list); e; e = dll_prev(_pthread_list, e)) {
POSIXTHREAD_CONTAINER(e)->tib->tib_sigpending &= ~(1ull << (sig - 1));
atomic_fetch_and_explicit(&POSIXTHREAD_CONTAINER(e)->tib->tib_sigpending,
~(1ull << (sig - 1)), memory_order_relaxed);
}
_pthread_unlock();
ALLOW_SIGNALS;
@ -157,7 +158,8 @@ static textwindows bool __sig_start(struct PosixThread *pt, int sig,
}
if (pt->tib->tib_sigmask & (1ull << (sig - 1))) {
STRACE("enqueing %G on %d", sig, _pthread_tid(pt));
pt->tib->tib_sigpending |= 1ull << (sig - 1);
atomic_fetch_or_explicit(&pt->tib->tib_sigpending, 1ull << (sig - 1),
memory_order_relaxed);
return false;
}
if (*rva == (intptr_t)SIG_DFL) {
@ -339,7 +341,8 @@ static int __sig_killer(struct PosixThread *pt, int sig, int sic) {
!((uintptr_t)__executable_start <= nc.Rip &&
nc.Rip < (uintptr_t)__privileged_start)) {
STRACE("enqueing %G on %d rip %p", sig, _pthread_tid(pt), nc.Rip);
pt->tib->tib_sigpending |= 1ull << (sig - 1);
atomic_fetch_or_explicit(&pt->tib->tib_sigpending, 1ull << (sig - 1),
memory_order_relaxed);
ResumeThread(th);
__sig_cancel(pt, sig, flags);
return 0;

View file

@ -55,7 +55,8 @@ int sigpending(sigset_t *pending) {
rc = 0;
} else if (IsWindows()) {
*pending = atomic_load_explicit(&__sig.pending, memory_order_acquire) |
__get_tls()->tib_sigpending;
atomic_load_explicit(&__get_tls()->tib_sigpending,
memory_order_acquire);
rc = 0;
} else {
rc = enosys();

View file

@ -15,7 +15,6 @@ COSMOPOLITAN_C_START_
} \
while (0)
int __sig_enqueue(int);
sigset_t __sig_block(void);
void __sig_unblock(sigset_t);
void __sig_finishwait(sigset_t);