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

@@ -0,0 +1,41 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/macros.h"
/ Makes fork() kernel ABI consistent across UNIX systems.
/
/ @return 0 if parent, pid if child, or -1 on error
fork$sysv:
push %rbp
mov %rsp,%rbp
.profilable
call __fork$sysv
#if SupportsXnu()
testb IsXnu()
jz 1f
cmp $-1,%rax
je 1f
neg %edx # edx is 0 for parent and 1 for child
not %edx # eax always returned with childs pid
and %edx,%eax
#endif
1: pop %rbp
ret
.endfn fork$sysv,globl,hidden

View File

@@ -21,6 +21,6 @@
/ Directly calls ftruncate() impl on host o/s if available.
ftruncate$sysv:
mov %rsp,%rdx # openbsd:pad
mov %rsi,%rdx # openbsd:pad
jmp __ftruncate$sysv
.endfn ftruncate$sysv,globl
.endfn ftruncate$sysv,globl,hidden

View File

@@ -29,7 +29,7 @@ lseek$sysv:
cmovnz .Lzero(%rip),%rsi
#endif
jmp __lseek$sysv
.endfn lseek$sysv,globl
.endfn lseek$sysv,globl,hidden
.rodata.cst8
.Lzero: .quad 0

View File

@@ -27,4 +27,4 @@ mmap$sysv:
call __mmap$sysv
leave
ret
.endfn mmap$sysv,globl
.endfn mmap$sysv,globl,hidden

View File

@@ -23,4 +23,4 @@
__wincrash$nt:
ezlea __wincrash,ax
jmp __nt2sysv
.endfn __wincrash$nt,globl
.endfn __wincrash$nt,globl,hidden

View File

@@ -23,4 +23,4 @@
pread$sysv:
mov %rcx,%r8 # openbsd:pad
jmp __pread$sysv
.endfn pread$sysv,globl
.endfn pread$sysv,globl,hidden

View File

@@ -23,4 +23,4 @@
preadv$sysv:
mov %rcx,%r8 # openbsd:pad
jmp __preadv$sysv
.endfn preadv$sysv,globl
.endfn preadv$sysv,globl,hidden

View File

@@ -23,4 +23,4 @@
pwrite$sysv:
mov %rcx,%r8 # openbsd:pad
jmp __pwrite$sysv
.endfn pwrite$sysv,globl
.endfn pwrite$sysv,globl,hidden

View File

@@ -23,4 +23,4 @@
pwritev$sysv:
mov %rcx,%r8 # openbsd:pad
jmp __pwritev$sysv
.endfn pwritev$sysv,globl
.endfn pwritev$sysv,globl,hidden

View File

@@ -21,6 +21,6 @@
/ Directly calls truncate() impl on host o/s if available.
truncate$sysv:
mov %rsp,%rdx # openbsd:pad
mov %rsi,%rdx # openbsd:pad
jmp __truncate$sysv
.endfn truncate$sysv,globl
.endfn truncate$sysv,globl,hidden