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

View file

@ -22,7 +22,8 @@
/ Environment variable pointer list.
.bss
.align 8
environ:.quad 0
environ:
.quad 0
.endobj environ,globl
.previous

View file

@ -55,6 +55,7 @@ memcpy: mov %rdi,%rax
/ @mode long
.align 16
MemCpy: .leafprologue
.profilable
mov $.Lmemcpytab.ro.size,%ecx
cmp %rcx,%rdx
cmovb %rdx,%rcx

View file

@ -46,17 +46,15 @@ memset: mov %rdi,%rax
/ @mode long
MemSet: .leafprologue
.profilable
push %rbx
movd %esi,%xmm3
mov $.Lmemsettab.ro.size,%ecx
cmp %rcx,%rdx
cmovb %rdx,%rcx
ezlea memsettab,bx
jmp *(%rbx,%rcx,8)
jmp *memsettab(,%rcx,8)
.Lanchorpoint:
.L32r: cmp $1024,%rdx
jae .Lerms
.L32: vpbroadcastb %xmm3,%ymm3
.L32: vmovd %esi,%xmm3
vpbroadcastb %xmm3,%ymm3
mov $32,%ecx
1: lea 32(%rcx),%rcx
vmovdqu %ymm3,-64(%rdi,%rcx)
@ -67,7 +65,8 @@ MemSet: .leafprologue
jmp .L0
.L16r: cmp $1024,%rdx
jae .Lerms
.L16: pbroadcastb %xmm3
.L16: movd %esi,%xmm3
pbroadcastb %xmm3
mov $16,%ecx
1: lea 16(%rcx),%rcx
movdqu %xmm3,-32(%rdi,%rcx)
@ -75,19 +74,16 @@ MemSet: .leafprologue
ja 1b
movdqu %xmm3,-16(%rdi,%rdx)
pxor %xmm3,%xmm3
.L0: pop %rbx
.leafepilogue
.L8: movzbq %sil,%rbx
mov $0x0101010101010101,%rcx
imul %rcx,%rbx
mov %rbx,(%rdi)
mov %rbx,-8(%rdi,%rdx)
.L0: .leafepilogue
.L8: movzbl %sil,%ecx
imul .Lb8(%rip),%rcx
mov %rcx,(%rdi)
mov %rcx,-8(%rdi,%rdx)
jmp .L0
.L4: movzbl %sil,%ebx
mov $0x01010101,%ecx
imul %ecx,%ebx
mov %ebx,(%rdi)
mov %ebx,-4(%rdi,%rdx)
.L4: movzbl %sil,%ecx
imul $0x01010101,%ecx,%ecx
mov %ecx,(%rdi)
mov %ecx,-4(%rdi,%rdx)
jmp .L0
.L3: mov %sil,2(%rdi)
.L2: mov %sil,1(%rdi)
@ -103,6 +99,10 @@ MemSet: .leafprologue
jmp .L0
.endfn MemSet,globl,hidden
.rodata.cst8
.Lb8: .quad 0x0101010101010101
.previous
.initro 300,_init_memset
memsettab.ro:
.byte .L0 - .Lanchorpoint

View file

@ -19,15 +19,16 @@
#include "libc/macros.h"
/ Returns prefix length, consisting of chars not in reject.
/ a.k.a. Return index of first byte that's in charset.
/
/ @param rdi is string
/ @param rsi is reject nul-terminated character set
/ @return rax is index of first byte in charset
/ @see strspn(), strtok_r()
/ @asyncsignalsafe
strcspn:
push %rbp
mov %rsp,%rbp
.profilable
sub $16,%rsp
push %rdi
mov %rsi,%rdi