From 4f66d7f2dd298b5b8557f4177411d9ec90648e9b Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sun, 10 Dec 2023 01:29:25 -0800 Subject: [PATCH] Add WIN32 pseudo console APIs See #999 --- libc/nt/console.h | 5 +++++ libc/nt/enum/pseudoconsole.h | 6 ++++++ libc/nt/kernel32/ClosePseudoConsole.S | 20 ++++++++++++++++++++ libc/nt/kernel32/CreatePseudoConsole.S | 18 ++++++++++++++++++ libc/nt/kernel32/ResizePseudoConsole.S | 18 ++++++++++++++++++ libc/nt/master.sh | 3 +++ third_party/make/config.h | 4 ++-- 7 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 libc/nt/enum/pseudoconsole.h create mode 100644 libc/nt/kernel32/ClosePseudoConsole.S create mode 100644 libc/nt/kernel32/CreatePseudoConsole.S create mode 100644 libc/nt/kernel32/ResizePseudoConsole.S diff --git a/libc/nt/console.h b/libc/nt/console.h index 36982c7ef..2dd895180 100644 --- a/libc/nt/console.h +++ b/libc/nt/console.h @@ -106,6 +106,11 @@ bool32 SetConsoleCursorInfo( int64_t hConsoleOutput, const struct NtConsoleCursorInfo *lpConsoleCursorInfo); +long CreatePseudoConsole(struct NtCoord size, int64_t hInput, int64_t hOutput, + uint32_t dwFlags, int64_t *out_phPC); +long ResizePseudoConsole(int64_t hPC, struct NtCoord size); +void ClosePseudoConsole(int64_t hPC); + #if ShouldUseMsabiAttribute() #include "libc/nt/thunk/console.inc" #endif /* ShouldUseMsabiAttribute() */ diff --git a/libc/nt/enum/pseudoconsole.h b/libc/nt/enum/pseudoconsole.h new file mode 100644 index 000000000..1e897848a --- /dev/null +++ b/libc/nt/enum/pseudoconsole.h @@ -0,0 +1,6 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_PSEUDOCONSOLE_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_PSEUDOCONSOLE_H_ + +#define kNtPseudoconsoleInheritCursor 1 + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_PSEUDOCONSOLE_H_ */ diff --git a/libc/nt/kernel32/ClosePseudoConsole.S b/libc/nt/kernel32/ClosePseudoConsole.S new file mode 100644 index 000000000..66ae2d527 --- /dev/null +++ b/libc/nt/kernel32/ClosePseudoConsole.S @@ -0,0 +1,20 @@ +#include "libc/nt/codegen.h" +.imp kernel32,__imp_ClosePseudoConsole,ClosePseudoConsole + + .text.windows + .ftrace1 +ClosePseudoConsole: + .ftrace2 +#ifdef __x86_64__ + push %rbp + mov %rsp,%rbp + mov %rdi,%rcx + sub $32,%rsp + call *__imp_ClosePseudoConsole(%rip) + leave +#elif defined(__aarch64__) + mov x0,#0 +#endif + ret + .endfn ClosePseudoConsole,globl + .previous diff --git a/libc/nt/kernel32/CreatePseudoConsole.S b/libc/nt/kernel32/CreatePseudoConsole.S new file mode 100644 index 000000000..1de6313ae --- /dev/null +++ b/libc/nt/kernel32/CreatePseudoConsole.S @@ -0,0 +1,18 @@ +#include "libc/nt/codegen.h" +.imp kernel32,__imp_CreatePseudoConsole,CreatePseudoConsole + + .text.windows + .ftrace1 +CreatePseudoConsole: + .ftrace2 +#ifdef __x86_64__ + push %rbp + mov %rsp,%rbp + mov __imp_CreatePseudoConsole(%rip),%rax + jmp __sysv2nt6 +#elif defined(__aarch64__) + mov x0,#0 + ret +#endif + .endfn CreatePseudoConsole,globl + .previous diff --git a/libc/nt/kernel32/ResizePseudoConsole.S b/libc/nt/kernel32/ResizePseudoConsole.S new file mode 100644 index 000000000..b10b73d47 --- /dev/null +++ b/libc/nt/kernel32/ResizePseudoConsole.S @@ -0,0 +1,18 @@ +#include "libc/nt/codegen.h" +.imp kernel32,__imp_ResizePseudoConsole,ResizePseudoConsole + + .text.windows + .ftrace1 +ResizePseudoConsole: + .ftrace2 +#ifdef __x86_64__ + push %rbp + mov %rsp,%rbp + mov __imp_ResizePseudoConsole(%rip),%rax + jmp __sysv2nt +#elif defined(__aarch64__) + mov x0,#0 + ret +#endif + .endfn ResizePseudoConsole,globl + .previous diff --git a/libc/nt/master.sh b/libc/nt/master.sh index 69d4dd09d..4552e9d8a 100755 --- a/libc/nt/master.sh +++ b/libc/nt/master.sh @@ -58,6 +58,7 @@ imp 'CancelSynchronousIo' CancelSynchronousIo kernel32 1 imp 'CheckRemoteDebuggerPresent' CheckRemoteDebuggerPresent kernel32 2 imp 'ClearCommBreak' ClearCommBreak kernel32 1 imp 'CloseHandle' CloseHandle kernel32 1 +imp 'ClosePseudoConsole' ClosePseudoConsole kernel32 1 # Windows 10+ imp 'ConnectNamedPipe' ConnectNamedPipe kernel32 2 imp 'ContinueDebugEvent' ContinueDebugEvent kernel32 3 imp 'CopyFile' CopyFileW kernel32 3 @@ -65,6 +66,7 @@ imp 'CreateEvent' CreateEventW kernel32 4 imp 'CreateEventEx' CreateEventExW kernel32 4 imp 'CreateHardLink' CreateHardLinkW kernel32 3 imp 'CreateIoCompletionPort' CreateIoCompletionPort kernel32 4 +imp 'CreatePseudoConsole' CreatePseudoConsole kernel32 5 # Windows 10+ imp 'CreateSemaphore' CreateSemaphoreW kernel32 4 imp 'CreateToolhelp32Snapshot' CreateToolhelp32Snapshot kernel32 2 imp 'CreateWaitableTimer' CreateWaitableTimerW kernel32 3 @@ -227,6 +229,7 @@ imp 'ReleaseSemaphore' ReleaseSemaphore kernel32 3 imp 'RemoveVectoredContinueHandler' RemoveVectoredContinueHandler kernel32 1 imp 'RemoveVectoredExceptionHandler' RemoveVectoredExceptionHandler kernel32 1 imp 'ResetEvent' ResetEvent kernel32 1 +imp 'ResizePseudoConsole' ResizePseudoConsole kernel32 2 # Windows 10+ imp 'ResumeThread' ResumeThread kernel32 1 imp 'SetConsoleActiveScreenBuffer' SetConsoleActiveScreenBuffer kernel32 1 # TODO(jart): 6.2 and higher imp 'SetConsoleCP' SetConsoleCP kernel32 1 # TODO(jart): 6.2 and higher diff --git a/third_party/make/config.h b/third_party/make/config.h index c39b40a7f..2612fd297 100644 --- a/third_party/make/config.h +++ b/third_party/make/config.h @@ -507,10 +507,10 @@ #define HAVE_WORKING_VFORK 1 /* Default C++ compiler. */ -#define MAKE_CXX "/opt/cosmocc/bin/aarch64-unknown-cosmo-c++" +#define MAKE_CXX "c++" /* Build host information. */ -#define MAKE_HOST "x86_64-pc-linux-musl" +#define MAKE_HOST "x86_64-linux-cosmo" /* Define to 1 to enable job server support in GNU Make. */ #define MAKE_JOBSERVER 1