Fix XNU / FreeBSD / OpenBSD / RHEL5 / NT bugs

For the first time ever, all tests in this codebase now pass, when
run automatically on macos, freebsd, openbsd, rhel5, rhel7, alpine
and windows via the network using the runit and runitd build tools

- Fix vfork exec path etc.
- Add XNU opendir() support
- Add OpenBSD opendir() support
- Add Linux history to syscalls.sh
- Use copy_file_range on FreeBSD 13+
- Fix system calls with 7+ arguments
- Fix Windows with greater than 16 FDs
- Fix RUNIT.COM and RUNITD.COM flakiness
- Fix OpenBSD munmap() when files are mapped
- Fix long double so it's actually long on Windows
- Fix OpenBSD truncate() and ftruncate() thunk typo
- Let Windows fcntl() be used on socket files descriptors
- Fix Windows fstat() which had an accidental printf statement
- Fix RHEL5 CLOCK_MONOTONIC by not aliasing to CLOCK_MONOTONIC_RAW

This is wonderful. I never could have dreamed it would be possible
to get it working so well on so many platforms with tiny binaries.

Fixes #31
Fixes #25
Fixes #14
This commit is contained in:
Justine Tunney 2021-01-25 13:08:05 -08:00
parent c20dad3534
commit 45b72485ad
1032 changed files with 6083 additions and 2348 deletions

10
libc/nt/enum/wt.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_WT_H_
#define COSMOPOLITAN_LIBC_NT_ENUM_WT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define kNtWtExecuteonlyonce 8
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_WT_H_ */

View file

@ -1,2 +1,12 @@
.include "o/libc/nt/codegen.inc"
.imp kernel32,__imp_RegisterWaitForSingleObject,RegisterWaitForSingleObject,1191
.text.windows
RegisterWaitForSingleObject:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_RegisterWaitForSingleObject(%rip),%rax
jmp __sysv2nt6
.endfn RegisterWaitForSingleObject,globl
.previous

View file

@ -4689,7 +4689,7 @@ imp 'RegisterTouchWindow' RegisterTouchWindow user32 2275
imp 'RegisterUserApiHook' RegisterUserApiHook user32 2276
imp 'RegisterWaitChainCOMCallback' RegisterWaitChainCOMCallback advapi32 1695
imp 'RegisterWaitForInputIdle' RegisterWaitForInputIdle kernel32 1190
imp 'RegisterWaitForSingleObject' RegisterWaitForSingleObject kernel32 1191
imp 'RegisterWaitForSingleObject' RegisterWaitForSingleObject kernel32 1191 6
imp 'RegisterWaitForSingleObjectEx' RegisterWaitForSingleObjectEx KernelBase 1389
imp 'RegisterWaitUntilOOBECompleted' RegisterWaitUntilOOBECompleted kernel32 1193
imp 'RegisterWindowMessageA' RegisterWindowMessageA user32 2277

View file

@ -5,9 +5,9 @@
struct NtM128A {
uint64_t Low;
int64_t High;
} forcealign(16);
};
struct NtXmmSaveArea32 {
struct NtXmmSaveArea32 { /* basically same as struct FpuState */
uint16_t ControlWord;
uint16_t StatusWord;
uint8_t TagWord;
@ -53,7 +53,7 @@ struct NtContext {
uint64_t LastBranchFromRip;
uint64_t LastExceptionToRip;
uint64_t LastExceptionFromRip;
} forcealign(16);
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_CONTEXT_H_ */

View file

@ -50,6 +50,8 @@ COSMOPOLITAN_C_START_
typedef void (*NtTimerapcroutine)(void *lpArgToCompletionRoutine,
uint32_t dwTimerLowValue,
uint32_t dwTimerHighValue);
typedef void (*NtWaitOrTimerCallback)(void *lpParameter,
bool32 TimerOrWaitFired);
void Sleep(uint32_t dwMilliseconds);
uint32_t SleepEx(uint32_t dwMilliseconds, bool32 bAlertable);
@ -68,6 +70,10 @@ uint32_t WaitForSingleObjectEx(int64_t hHandle, uint32_t dwMilliseconds,
uint32_t WaitForMultipleObjectsEx(unsigned int nCount, const int64_t *lpHandles,
bool32 bWaitAll, uint32_t dwMilliseconds,
bool32 bAlertable);
bool32 RegisterWaitForSingleObject(int64_t *phNewWaitObject, int64_t hObject,
NtWaitOrTimerCallback Callback,
void *Context, uint32_t dwMilliseconds,
uint32_t dwFlags);
int64_t CreateWaitableTimer(struct NtSecurityAttributes *lpTimerAttributes,
bool32 bManualReset, const char16_t *lpTimerName);