mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 20:40:28 +00:00
Get all tests passing on NetBSD
This commit is contained in:
parent
23ae9dfceb
commit
b2cd58a322
41 changed files with 202 additions and 655 deletions
|
@ -32,9 +32,11 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
|
|||
for (i = 0; argv[i];) ++i;
|
||||
shargs = alloca((i + 2) * sizeof(char *));
|
||||
memcpy(shargs + 2, argv + 1, i * sizeof(char *));
|
||||
shargs[0] = !IsFreebsd() ? _PATH_BSHELL
|
||||
: firstnonnull(commandv("bash", alloca(PATH_MAX)),
|
||||
_PATH_BSHELL);
|
||||
if (IsFreebsd() || IsNetbsd()) {
|
||||
shargs[0] = firstnonnull(commandv("bash", alloca(PATH_MAX)), _PATH_BSHELL);
|
||||
} else {
|
||||
shargs[0] = _PATH_BSHELL;
|
||||
}
|
||||
shargs[1] = prog;
|
||||
return __sys_execve(shargs[0], shargs, envp);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
#define XNU_F_GETPATH 50
|
||||
#define XNU_MAXPATHLEN 1024
|
||||
#define NETBSD_F_GETPATH 15
|
||||
#define XNU_F_GETPATH 50
|
||||
#define XNU_MAXPATHLEN 1024
|
||||
|
||||
char *sys_getcwd_xnu(char *res, size_t size) {
|
||||
int fd;
|
||||
|
|
|
@ -28,7 +28,7 @@ static int __pid;
|
|||
|
||||
static int __getpid(void) {
|
||||
if (!IsWindows()) {
|
||||
return sys_getpid();
|
||||
return sys_getpid().ax;
|
||||
} else {
|
||||
return GetCurrentProcessId();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ static void __updatepid(void) {
|
|||
int getpid(void) {
|
||||
static bool once;
|
||||
if (__vforked) {
|
||||
return sys_getpid();
|
||||
return sys_getpid().ax;
|
||||
}
|
||||
if (!once) {
|
||||
__updatepid();
|
||||
|
|
|
@ -24,7 +24,11 @@
|
|||
*/
|
||||
int32_t getppid(void) {
|
||||
if (!IsWindows()) {
|
||||
return sys_getppid();
|
||||
if (!IsNetbsd()) {
|
||||
return sys_getppid();
|
||||
} else {
|
||||
return sys_getpid().dx;
|
||||
}
|
||||
} else {
|
||||
return sys_getppid_nt();
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ struct Fd {
|
|||
struct Fds {
|
||||
size_t f; // lowest free slot
|
||||
size_t n; // monotonic capacity
|
||||
struct Fd * p;
|
||||
struct Fd *p;
|
||||
struct Fd __init_p[OPEN_MAX];
|
||||
};
|
||||
|
||||
|
@ -172,7 +172,7 @@ i32 sys_setresgid(uint32_t, uint32_t, uint32_t) hidden;
|
|||
i32 sys_setresuid(uint32_t, uint32_t, uint32_t) hidden;
|
||||
i32 sys_setrlimit(i32, const struct rlimit *) hidden;
|
||||
i32 sys_setsid(void) hidden;
|
||||
i32 sys_sigaction(i32, const void *, void *, i64) hidden;
|
||||
i32 sys_sigaction(i32, const void *, void *, i64, i64) hidden;
|
||||
i32 sys_sigprocmask(i32, const sigset *, sigset *, u64) hidden;
|
||||
i32 sys_sigsuspend(const sigset *, u64) hidden;
|
||||
i32 sys_symlinkat(const char *, i32, const char *) hidden;
|
||||
|
@ -199,7 +199,7 @@ i64 sys_splice(i32, i64 *, i32, i64 *, u64, u32) hidden;
|
|||
i64 sys_vmsplice(i32, const struct iovec *, i64, u32) hidden;
|
||||
i64 sys_write(i32, const void *, u64) hidden;
|
||||
u32 sys_getgid(void) hidden;
|
||||
u32 sys_getpid(void) hidden;
|
||||
axdx_t sys_getpid(void) hidden;
|
||||
u32 sys_getsid(int) hidden;
|
||||
u32 sys_gettid(void) hidden;
|
||||
u32 sys_getuid(void) hidden;
|
||||
|
@ -219,6 +219,7 @@ void __sigenter_xnu(void *, i32, i32, void *, void *) hidden wontreturn;
|
|||
int sys_utimensat_xnu(int, const char *, const struct timespec *, int) hidden;
|
||||
int sys_nanosleep_xnu(const struct timespec *, struct timespec *) hidden;
|
||||
void __stat2linux(void *) hidden;
|
||||
void __restore_rt_netbsd(void) hidden;
|
||||
void __xnutrampoline(void *, i32, i32, const struct __darwin_siginfo *,
|
||||
const struct __darwin_ucontext *) hidden wontreturn;
|
||||
|
||||
|
|
29
libc/calls/netbsdtramp.S
Normal file
29
libc/calls/netbsdtramp.S
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*-*- 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/macros.h"
|
||||
.text.syscall
|
||||
|
||||
__restore_rt_netbsd:
|
||||
mov %r15,%rdi
|
||||
mov $308,%rax # setcontext
|
||||
syscall
|
||||
mov $-1,%edi
|
||||
mov $1,%rax # exit
|
||||
syscall
|
||||
.endfn __restore_rt_netbsd,globl,hidden
|
|
@ -34,8 +34,8 @@ sys_pipe:
|
|||
xor %esi,%esi
|
||||
#endif
|
||||
call __sys_pipe
|
||||
#if SupportsXnu()
|
||||
testb IsXnu()
|
||||
#if SupportsXnu() || SupportsNetbsd()
|
||||
testb $XNU|NETBSD,__hostos(%rip)
|
||||
jz 1f
|
||||
cmp $-1,%rax
|
||||
je 1f
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/calls/struct/sigaction-freebsd.internal.h"
|
||||
#include "libc/calls/struct/sigaction-linux.internal.h"
|
||||
#include "libc/calls/struct/sigaction-netbsd.h"
|
||||
#include "libc/calls/struct/sigaction-openbsd.internal.h"
|
||||
#include "libc/calls/struct/sigaction-xnu.internal.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
|
@ -42,6 +43,7 @@ union metasigaction {
|
|||
struct sigaction_linux linux;
|
||||
struct sigaction_freebsd freebsd;
|
||||
struct sigaction_openbsd openbsd;
|
||||
struct sigaction_netbsd netbsd;
|
||||
struct sigaction_xnu_in xnu_in;
|
||||
struct sigaction_xnu_out xnu_out;
|
||||
};
|
||||
|
@ -63,7 +65,7 @@ union metasigaction {
|
|||
} while (0);
|
||||
#endif
|
||||
|
||||
static void sigaction$cosmo2native(union metasigaction *sa) {
|
||||
static void sigaction_cosmo2native(union metasigaction *sa) {
|
||||
if (!sa) return;
|
||||
switch (__hostos) {
|
||||
case LINUX:
|
||||
|
@ -82,12 +84,16 @@ static void sigaction$cosmo2native(union metasigaction *sa) {
|
|||
SWITCHEROO(sa->cosmo, sa->openbsd, sa_handler, sa_flags, sa_flags,
|
||||
sa_mask);
|
||||
break;
|
||||
case NETBSD:
|
||||
SWITCHEROO(sa->cosmo, sa->netbsd, sa_handler, sa_flags, sa_flags,
|
||||
sa_mask);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void sigaction$native2cosmo(union metasigaction *sa) {
|
||||
static void sigaction_native2cosmo(union metasigaction *sa) {
|
||||
if (!sa) return;
|
||||
switch (__hostos) {
|
||||
case LINUX:
|
||||
|
@ -106,6 +112,10 @@ static void sigaction$native2cosmo(union metasigaction *sa) {
|
|||
SWITCHEROO(sa->openbsd, sa->cosmo, sa_handler, sa_flags, sa_flags,
|
||||
sa_mask);
|
||||
break;
|
||||
case NETBSD:
|
||||
SWITCHEROO(sa->netbsd, sa->cosmo, sa_handler, sa_flags, sa_flags,
|
||||
sa_mask);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -128,9 +138,12 @@ int(sigaction)(int sig, const struct sigaction *act, struct sigaction *oldact) {
|
|||
sizeof(struct sigaction) > sizeof(struct sigaction_xnu_in) &&
|
||||
sizeof(struct sigaction) > sizeof(struct sigaction_xnu_out) &&
|
||||
sizeof(struct sigaction) > sizeof(struct sigaction_freebsd) &&
|
||||
sizeof(struct sigaction) > sizeof(struct sigaction_openbsd));
|
||||
sizeof(struct sigaction) > sizeof(struct sigaction_openbsd) &&
|
||||
sizeof(struct sigaction) > sizeof(struct sigaction_netbsd));
|
||||
int64_t arg4, arg5;
|
||||
int rc, rva, oldrva;
|
||||
struct sigaction *ap, copy;
|
||||
if (IsMetal()) return enosys(); /* TODO: Signals on Metal */
|
||||
if (!(0 < sig && sig < NSIG)) return einval();
|
||||
if (sig == SIGKILL || sig == SIGSTOP) return einval();
|
||||
if (!act) {
|
||||
|
@ -147,32 +160,43 @@ int(sigaction)(int sig, const struct sigaction *act, struct sigaction *oldact) {
|
|||
return einval();
|
||||
}
|
||||
if (!IsWindows()) {
|
||||
if (!IsMetal()) {
|
||||
if (act) {
|
||||
memcpy(©, act, sizeof(copy));
|
||||
ap = ©
|
||||
if (IsXnu()) {
|
||||
ap->sa_restorer = (void *)&__xnutrampoline;
|
||||
ap->sa_handler = (void *)&__xnutrampoline;
|
||||
} else if (IsLinux()) {
|
||||
if (!(ap->sa_flags & SA_RESTORER)) {
|
||||
ap->sa_flags |= SA_RESTORER;
|
||||
ap->sa_restorer = &__restore_rt;
|
||||
}
|
||||
} else if (rva >= kSigactionMinRva) {
|
||||
ap->sa_sigaction = (sigaction_f)__sigenter;
|
||||
if (act) {
|
||||
memcpy(©, act, sizeof(copy));
|
||||
ap = ©
|
||||
if (IsXnu()) {
|
||||
ap->sa_restorer = (void *)&__xnutrampoline;
|
||||
ap->sa_handler = (void *)&__xnutrampoline;
|
||||
} else if (IsLinux()) {
|
||||
if (!(ap->sa_flags & SA_RESTORER)) {
|
||||
ap->sa_flags |= SA_RESTORER;
|
||||
ap->sa_restorer = &__restore_rt;
|
||||
}
|
||||
sigaction$cosmo2native((union metasigaction *)ap);
|
||||
} else {
|
||||
ap = NULL;
|
||||
} else if (IsNetbsd()) {
|
||||
ap->sa_sigaction = act->sa_sigaction;
|
||||
} else if (rva >= kSigactionMinRva) {
|
||||
ap->sa_sigaction = (sigaction_f)__sigenter;
|
||||
}
|
||||
rc = sys_sigaction(
|
||||
sig, ap, oldact,
|
||||
(!IsXnu() ? 8 /* or linux whines */
|
||||
: (int64_t)(intptr_t)oldact /* from go code */));
|
||||
if (rc != -1) sigaction$native2cosmo((union metasigaction *)oldact);
|
||||
sigaction_cosmo2native((union metasigaction *)ap);
|
||||
} else {
|
||||
return enosys(); /* TODO: Signals on Metal */
|
||||
ap = NULL;
|
||||
}
|
||||
if (IsXnu()) {
|
||||
arg4 = (int64_t)(intptr_t)oldact; /* from go code */
|
||||
arg5 = 0;
|
||||
} else if (IsNetbsd()) {
|
||||
if (ap) {
|
||||
arg4 = (int64_t)(intptr_t)&__restore_rt_netbsd;
|
||||
arg5 = 2; /* netbsd/lib/libc/arch/x86_64/sys/__sigtramp2.S */
|
||||
} else {
|
||||
arg4 = 0;
|
||||
arg5 = 0; /* netbsd/lib/libc/arch/x86_64/sys/__sigtramp2.S */
|
||||
}
|
||||
} else {
|
||||
arg4 = 8; /* or linux whines */
|
||||
arg5 = 0;
|
||||
}
|
||||
if ((rc = sys_sigaction(sig, ap, oldact, arg4, arg5)) != -1) {
|
||||
sigaction_native2cosmo((union metasigaction *)oldact);
|
||||
}
|
||||
} else {
|
||||
if (oldact) {
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
|
||||
/ Directly calls ftruncate() impl on host o/s if available.
|
||||
sys_ftruncate:
|
||||
mov %rsi,%rdx # openbsd:pad
|
||||
mov %rsi,%rdx # netbsd+openbsd:pad
|
||||
jmp __sys_ftruncate
|
||||
.endfn sys_ftruncate,globl,hidden
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
|
||||
/ Directly calls lseek() impl on host o/s if available.
|
||||
sys_lseek:
|
||||
#if SupportsOpenbsd()
|
||||
testb IsOpenbsd() # openbsd:evilpad
|
||||
cmovnz %rdx,%rcx
|
||||
#if SupportsOpenbsd() || SupportsNetbsd()
|
||||
testb $OPENBSD|NETBSD,__hostos(%rip)
|
||||
cmovnz %rdx,%rcx # openbsd:evilpad
|
||||
cmovnz %rsi,%rdx
|
||||
cmovnz .Lzero(%rip),%rsi
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
sys_mmap:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %r9 # openbsd:pad
|
||||
push %r9 # netbsd+openbsd:pad
|
||||
call __sys_mmap
|
||||
leave
|
||||
ret
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
|
||||
/ Directly calls pread() impl on host o/s if available.
|
||||
sys_pread:
|
||||
mov %rcx,%r8 # openbsd:pad
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pread
|
||||
.endfn sys_pread,globl,hidden
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
|
||||
/ Directly calls preadv() impl on host o/s if available.
|
||||
sys_preadv:
|
||||
mov %rcx,%r8 # openbsd:pad
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_preadv
|
||||
.endfn sys_preadv,globl,hidden
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
|
||||
/ Directly calls pwrite() impl on host o/s if available.
|
||||
sys_pwrite:
|
||||
mov %rcx,%r8 # openbsd:pad
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pwrite
|
||||
.endfn sys_pwrite,globl,hidden
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
|
||||
/ Directly calls pwritev() impl on host o/s if available.
|
||||
sys_pwritev:
|
||||
mov %rcx,%r8 # openbsd:pad
|
||||
mov %rcx,%r8 # netbsd+openbsd:pad
|
||||
jmp __sys_pwritev
|
||||
.endfn sys_pwritev,globl,hidden
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
|
||||
/ Directly calls truncate() impl on host o/s if available.
|
||||
sys_truncate:
|
||||
mov %rsi,%rdx # openbsd:pad
|
||||
mov %rsi,%rdx # netbsd+openbsd:pad
|
||||
jmp __sys_truncate
|
||||
.endfn sys_truncate,globl,hidden
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows int sys_wait4_nt(int pid, int *opt_out_wstatus, int options,
|
||||
struct rusage *opt_out_rusage) {
|
||||
struct rusage *opt_out_rusage) {
|
||||
int pids[64];
|
||||
int64_t handles[64];
|
||||
uint32_t dwExitCode;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue