Make improvements

- You can now run `make -j8 toolchain` on Windows
- You can now run `make -j` on MacOS ARM64 and BSD OSes
- You can now use our Emacs dev environment on MacOS/Windows
- Fix bug where the x16 register was being corrupted by --ftrace
- The programs under build/bootstrap/ are updated as fat binaries
- The Makefile now explains how to download cosmocc-0.0.12 toolchain
- The build scripts under bin/ now support "cosmo" branded toolchains
- stat() now goes faster on Windows (shaves 100ms off `make` latency)
- Code cleanup and added review on the Windows signal checking code
- posix_spawnattr_setrlimit() now works around MacOS ARM64 bugs
- Landlock Make now favors posix_spawn() on non-Linux/OpenBSD
- posix_spawn() now has better --strace logging on Windows
- fstatat() can now avoid EACCES in more cases on Windows
- fchmod() can now change the readonly bit on Windows
This commit is contained in:
Justine Tunney 2023-10-14 20:57:15 -07:00
parent 06c6baaf50
commit c9fecf3a55
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
109 changed files with 1188 additions and 454 deletions

View file

@ -48,10 +48,25 @@ CreateFile(const char16_t *lpFileName, //
int64_t opt_hTemplateFile) {
int64_t hHandle;
uint32_t micros = 1;
char buf_accessflags[512];
(void)buf_accessflags;
char buf_shareflags[64];
(void)buf_shareflags;
char buf_secattr[32];
(void)buf_secattr;
char buf_flagattr[256];
(void)buf_flagattr;
TryAgain:
hHandle = __imp_CreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
opt_lpSecurity, dwCreationDisposition,
dwFlagsAndAttributes, opt_hTemplateFile);
NTTRACE("CreateFile(%#hs, %s, %s, %s, %s, %s, %ld) → {%ld, %d}", lpFileName,
(DescribeNtFileAccessFlags)(buf_accessflags, dwDesiredAccess),
(DescribeNtFileShareFlags)(buf_shareflags, dwShareMode),
(DescribeNtSecurityAttributes)(buf_secattr, opt_lpSecurity),
DescribeNtCreationDisposition(dwCreationDisposition),
(DescribeNtFileFlagAttr)(buf_flagattr, dwFlagsAndAttributes),
opt_hTemplateFile, hHandle, __imp_GetLastError());
if (hHandle == -1) {
switch (__imp_GetLastError()) {
case kNtErrorPipeBusy:
@ -77,12 +92,5 @@ TryAgain:
}
__winerr();
}
NTTRACE("CreateFile(%#hs, %s, %s, %s, %s, %s, %ld) → %ld% m", lpFileName,
DescribeNtFileAccessFlags(dwDesiredAccess),
DescribeNtFileShareFlags(dwShareMode),
DescribeNtSecurityAttributes(opt_lpSecurity),
DescribeNtCreationDisposition(dwCreationDisposition),
DescribeNtFileFlagAttr(dwFlagsAndAttributes), opt_hTemplateFile,
hHandle);
return hHandle;
}

View file

@ -19,10 +19,12 @@
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/runtime.h"
#include "libc/nt/struct/securityattributes.h"
#include "libc/nt/thread.h"
__msabi extern typeof(CreateThread) *const __imp_CreateThread;
__msabi extern typeof(GetLastError) *const __imp_GetLastError;
/**
* Opens file on the New Technology.
@ -41,9 +43,10 @@ CreateThread(const struct NtSecurityAttributes *lpThreadAttributes,
int64_t hHandle;
hHandle = __imp_CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress,
lpParameter, dwCreationFlags, opt_lpThreadId);
NTTRACE("CreateThread(%s, %'zu, %t, %p, %s, %p) → %ld% m",
NTTRACE("CreateThread(%s, %'zu, %t, %p, %s, %p) → {%ld, %d}",
DescribeNtSecurityAttributes(lpThreadAttributes), dwStackSize,
lpStartAddress, lpParameter,
DescribeThreadCreateFlags(dwCreationFlags), opt_lpThreadId, hHandle);
DescribeThreadCreateFlags(dwCreationFlags), opt_lpThreadId, hHandle,
__imp_GetLastError());
return hHandle;
}

View file

@ -19,8 +19,10 @@
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
__msabi extern typeof(FlushFileBuffers) *const __imp_FlushFileBuffers;
__msabi extern typeof(GetLastError) *const __imp_GetLastError;
/**
* Flushes buffers of specified file to disk.
@ -36,6 +38,7 @@ __msabi extern typeof(FlushFileBuffers) *const __imp_FlushFileBuffers;
textwindows bool32 FlushFileBuffers(int64_t hFile) {
bool32 ok;
ok = __imp_FlushFileBuffers(hFile);
NTTRACE("FlushFileBuffers(%ld) → %hhhd% m", hFile, ok);
NTTRACE("FlushFileBuffers(%ld) → {%hhhd, %d}", hFile, ok,
__imp_GetLastError());
return ok;
}

View file

@ -33,7 +33,11 @@
#define kPid "TracerPid:\t"
static textwindows bool IsBeingDebugged(void) {
#ifdef __x86_64__
return !!NtGetPeb()->BeingDebugged;
#else
return false;
#endif
}
/**

View file

@ -9,7 +9,8 @@
#if defined(__x86_64__) && !defined(__STRICT_ANSI__)
typedef char __intrin_xmm_t _Vector_size(16) forcealign(16) mayalias;
typedef char __intrin_xmm_t
__attribute__((__vector_size__(16), __aligned__(16), __may_alias__));
#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C) \
do { \

View file

@ -20,9 +20,11 @@
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/nt/thunk/msabi.h"
__msabi extern typeof(ReOpenFile) *const __imp_ReOpenFile;
__msabi extern typeof(GetLastError) *const __imp_GetLastError;
/**
* Reopens file on the New Technology.
@ -34,9 +36,10 @@ int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess,
int64_t hHandle;
hHandle = __imp_ReOpenFile(hOriginalFile, dwDesiredAccess, dwShareMode,
dwFlagsAndAttributes);
NTTRACE("ReOpenFile(%ld, %s, %s, %s) → %ld% m", hOriginalFile,
NTTRACE("ReOpenFile(%ld, %s, %s, %s) → {%ld, %d}", hOriginalFile,
DescribeNtFileAccessFlags(dwDesiredAccess),
DescribeNtFileShareFlags(dwShareMode),
DescribeNtFileFlagAttr(dwFlagsAndAttributes), hHandle);
DescribeNtFileFlagAttr(dwFlagsAndAttributes), hHandle,
__imp_GetLastError());
return hHandle;
}

View file

@ -23,6 +23,7 @@
#include "libc/nt/thunk/msabi.h"
__msabi extern typeof(TerminateProcess) *const __imp_TerminateProcess;
__msabi extern typeof(GetLastError) *const __imp_GetLastError;
/**
* Terminates the specified process and all of its threads.
@ -30,6 +31,7 @@ __msabi extern typeof(TerminateProcess) *const __imp_TerminateProcess;
textwindows bool32 TerminateProcess(int64_t hProcess, uint32_t uWaitStatus) {
bool32 ok;
ok = __imp_TerminateProcess(hProcess, uWaitStatus);
NTTRACE("TerminateProcess(%ld, %u) → %hhhd% m", hProcess, uWaitStatus, ok);
NTTRACE("TerminateProcess(%ld, %u) → {%hhhd, %d}", hProcess, uWaitStatus, ok,
__imp_GetLastError());
return ok;
}

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/runtime.h"
#include "libc/nt/synchronization.h"
#include "libc/nt/thunk/msabi.h"
@ -26,14 +27,15 @@ __msabi extern typeof(WaitForMultipleObjects)
/**
* Waits for handles to change status.
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
*
* @return -1u on error w/ GetLastError()
* @raise kNtErrorInvalidParameter if `bWaitAll` and `lpHandles` has dupes
*/
uint32_t WaitForMultipleObjects(uint32_t nCount, const int64_t *lpHandles,
bool32 bWaitAll, uint32_t dwMilliseconds) {
uint32_t x;
x = __imp_WaitForMultipleObjects(nCount, lpHandles, bWaitAll, dwMilliseconds);
if (x == -1u) __winerr();
POLLTRACE("WaitForMultipleObjects(%ld, %p, %hhhd, %'d) → %d% m", nCount,
lpHandles, bWaitAll, dwMilliseconds, x);
POLLTRACE("WaitForMultipleObjects(%ld, %p, %hhhd, %'d) → %d %d", nCount,
lpHandles, bWaitAll, dwMilliseconds, x, GetLastError());
return x;
}

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/nt/runtime.h"
#include "libc/nt/synchronization.h"
#include "libc/nt/thunk/msabi.h"
@ -30,7 +31,7 @@ __msabi extern typeof(WaitForSingleObject) *const __imp_WaitForSingleObject;
uint32_t WaitForSingleObject(int64_t hHandle, uint32_t dwMilliseconds) {
uint32_t rc;
rc = __imp_WaitForSingleObject(hHandle, dwMilliseconds);
POLLTRACE("WaitForSingleObject(%ld, %'d) → %d% m", hHandle, dwMilliseconds,
rc);
POLLTRACE("WaitForSingleObject(%ld, %'d) → %d %d", hHandle, dwMilliseconds,
rc, GetLastError());
return rc;
}