2020-06-16 13:38:43 +00:00
|
|
|
|
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
2023-12-08 03:11:56 +00:00
|
|
|
|
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 :vi │
|
2020-06-15 14:18:57 +00:00
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
|
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
|
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
|
│ 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. │
|
2020-06-15 14:18:57 +00:00
|
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
|
│ 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. │
|
2020-06-15 14:18:57 +00:00
|
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2022-09-13 06:10:38 +00:00
|
|
|
|
#include "libc/intrin/strace.internal.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
|
#include "libc/dce.h"
|
2021-03-01 07:42:35 +00:00
|
|
|
|
#include "libc/macros.internal.h"
|
2023-11-28 22:24:28 +00:00
|
|
|
|
#include "libc/thread/pt.internal.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
2022-11-03 16:32:12 +00:00
|
|
|
|
#define SIG_IGN 1
|
|
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
|
/* ▄▄▄
|
|
|
|
|
▄▄▄ ▀▓▓▒▄
|
|
|
|
|
▄▓▒▒░ ▀▓▒▒▒▄
|
|
|
|
|
▄▓▓▓▒▀ ▄▄▄▄ ▒▓▒▒░▒▄
|
|
|
|
|
▄▓▓▓▒▓ ▄▄▓██▓▓▓▓▒▒▒▒▓▓▄▄▓▓▒▒▒░░▒
|
|
|
|
|
▓▓▓▓▒▒▒▄▄ ░▒█▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓▒░░▒░
|
|
|
|
|
██▓▓▓▒▒░░▒▒▒▒▓▓▓▓▓▓▒▓▒░▒▒░▀▒▒▒▒░▀░▒▒▒░▒
|
|
|
|
|
▓▓▓▓▓▓▓▒▒▒▒▒▒▓▓▒▓▓▒▒▒░▒▒░░ ░▒▒░ ░▒▒▒▒
|
|
|
|
|
▀▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░░▒░░ ░▒▒ ░ ▀▒▒
|
|
|
|
|
▀▓▓█▓▓▓▓▓▓▓▓▓▓▒▒░░▒▒░░ ░░░▓░ ▓░░░▒
|
|
|
|
|
▀▀█▓███▓▓▓▓▓▒▒░░░▒░░ ░█▓░█▓░█▓▓▄▒░
|
|
|
|
|
░▓██▓▓▓▓▓▒▒░░░▒░░ ░████▓▒▓█▓▀░▀▄
|
|
|
|
|
░▓██▓▓▓▓▓▒▒▒░░░▒░░ ▒██▓▒▒▒▒▒▒░░░▒
|
|
|
|
|
████▓▓▓▓▓▒▒▒▒▒▒▒▒▒░░▒▓▓▒░░░░▒░░░▒░ ░░░░░
|
|
|
|
|
░▓███▓▓▓▓▓▒▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒░░░ ░░░░░ ░
|
|
|
|
|
▓███▓▓▓▓▓▒▓▒▒▒▒░░░░░░░░░▒▓▒▒░▀ ░░░ ░░░░░
|
|
|
|
|
▀▒██▓▓▓▓▒▒▒▓▓▓▓▒▒▒▒▒▒▒▓▀▀░ ░░░░░░░░░ ░
|
|
|
|
|
▓▓▓▓▓▓▓▒▓▒▒▒▒▓▓▓▒▀░ ░░░░░▄░░░ ░░░ ░░░░░░
|
|
|
|
|
▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓ █▓▒░░▒░░░░ ░░░░░░░░
|
|
|
|
|
▄▓▓▓▒▒▒▒▒░░░░░░░▒▄▄▄░▒▓▓▒▒░▀░
|
|
|
|
|
░▓█▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒░░░▒ besiyata
|
|
|
|
|
▓▓█▓▓▒▓▓▓▒▒▒░░░░░░▒▓▓▓▓▒▒▒▒▒░ dishmaya
|
|
|
|
|
▓▓█▓▓▓▓▓▓▒▒▒░░░░░░░▒▓▓▒▀▀▀
|
|
|
|
|
▓▓██▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▀
|
|
|
|
|
█▓▓█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▀
|
|
|
|
|
▒▓▓▓▓▀░░▒▓▓▓▓▓▓▓▓▒▒░░▒
|
|
|
|
|
▄▓▓▀░░░▄▓▓▓▓▒▒▒▒▒░░░░▄░
|
|
|
|
|
▄███▄▄▓▓▓▓▓▓▓▒▒▒▒▒░░▒▒░
|
|
|
|
|
▄▓▓▓█▓█▓▓███▓▓▓▓▓▓▓▓▓▓▓░
|
|
|
|
|
▄░▓▓▓▓▓▓▀▒▓▓▓▒▒▓▒░░░▒▓▒░░░▓
|
|
|
|
|
▄▄▄░▒▓▓▓▓▓▓░▀▀ ▓▓▒░▓▒▒▒▒▒▒▒▒▒▒▄░░▀▀░░ ▄▄▄▄
|
|
|
|
|
▄▄▄▒▒▓▓█▓▓▓▓▓▀▀▀▀▀ ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▀░░▀░░▒▒▒░░░ ░░░░░
|
|
|
|
|
▄▓▓▓▒▀▀ ▓▒▓▓▓▓▓▒▒▒▒▒▒▒▒▓░░░ ▒▒▒░░░░░░░░▒
|
|
|
|
|
█▓▓▒ ▄▄▄ ▀▓▒▓▒▒▒▓▓▓▓▓▓▒▒▒░░░░░░░░░▒▒░░░░░░░
|
|
|
|
|
▀▓▓▓▓▒▄▄▒▒▒▒▒▒▄▄ ▀▀▀▀░░▒▒▒▒░░░░░░
|
|
|
|
|
▀▀▀▓▓▓▓▒▒▒▒▒▓▓▄▄
|
|
|
|
|
╔────────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
|
│ cosmopolitan § bell system five » system call support ─╬─│┼
|
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
|
2020-12-27 15:02:35 +00:00
|
|
|
|
.initbss 300,_init_systemfive
|
|
|
|
|
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// Performs System Five System Call.
|
|
|
|
|
//
|
|
|
|
|
// Cosmopolitan is designed to delegate all function calls into the
|
|
|
|
|
// Linux, FreeBSD, OpenBSD, and XNU kernels via this function, with
|
|
|
|
|
// few exceptions. This function should generally only be called by
|
|
|
|
|
// generated thunks in the libc/sysv/syscalls/ directory.
|
|
|
|
|
//
|
|
|
|
|
// It's safe to call this function on Windows, where it will always
|
|
|
|
|
// return -1 with errno == ENOSYS. Further note that -1 is the only
|
|
|
|
|
// return value that means error, a common anti-pattern is to check
|
|
|
|
|
// for values less than 0 (which is more problematic on 32-bit).
|
|
|
|
|
//
|
|
|
|
|
// It is important to consider that system calls are one order of a
|
|
|
|
|
// magnitude more expensive than normal function calls. For example
|
|
|
|
|
// getpid() on Linux usually takes 500ns, and cached i/o calls will
|
|
|
|
|
// take 1µs or more. So we don't need to inline them like Chromium.
|
|
|
|
|
//
|
|
|
|
|
// Another thing to consider is that BSDs only loosely follow the
|
|
|
|
|
// System Five ABI for the SYSCALL instruction. For example Linux
|
|
|
|
|
// always follows the six argument limit but the FreeBSD sendfile
|
|
|
|
|
// system call accepts a seventh argument that is passed on stack
|
|
|
|
|
// and OpenBSD modifies functions like mmap so that the sixth arg
|
|
|
|
|
// is passed on the stack. There's also the carry flag convention
|
|
|
|
|
// that XNU, FreeBSD, and OpenBSD inherited from 386BSD aka Jolix
|
|
|
|
|
//
|
|
|
|
|
// @param %rax function ordinal supplied by jump slot
|
|
|
|
|
// @param %rdi,%rsi,%rdx,%rcx,%r8,%r9 and rest on stack
|
|
|
|
|
// @return %rax:%rdx is result, or -1 w/ errno on error
|
|
|
|
|
// @clob %rcx,%r10,%r11
|
|
|
|
|
// @see syscalls.sh
|
2020-11-25 16:19:00 +00:00
|
|
|
|
__systemfive:
|
|
|
|
|
.quad 0
|
|
|
|
|
.endobj __systemfive,globl,hidden
|
2022-03-16 20:33:13 +00:00
|
|
|
|
__pid: .quad 0
|
|
|
|
|
.endobj __pid,globl,hidden
|
2020-06-15 14:18:57 +00:00
|
|
|
|
.previous
|
2021-02-03 04:21:06 +00:00
|
|
|
|
|
2022-11-05 02:55:41 +00:00
|
|
|
|
systemfive_cp:
|
|
|
|
|
push %rbp
|
2023-06-03 15:12:13 +00:00
|
|
|
|
mov %rsp,%rbp // so backtraces work
|
|
|
|
|
systemfive_cancellable: // our pthread_cancel() miracle code
|
|
|
|
|
cmpb $0,__tls_enabled(%rip) // inspired by the musl libc design!
|
|
|
|
|
je 1f // we handle linux and bsd together!
|
Release Cosmopolitan v3.3
This change upgrades to GCC 12.3 and GNU binutils 2.42. The GNU linker
appears to have changed things so that only a single de-duplicated str
table is present in the binary, and it gets placed wherever the linker
wants, regardless of what the linker script says. To cope with that we
need to stop using .ident to embed licenses. As such, this change does
significant work to revamp how third party licenses are defined in the
codebase, using `.section .notice,"aR",@progbits`.
This new GCC 12.3 toolchain has support for GNU indirect functions. It
lets us support __target_clones__ for the first time. This is used for
optimizing the performance of libc string functions such as strlen and
friends so far on x86, by ensuring AVX systems favor a second codepath
that uses VEX encoding. It shaves some latency off certain operations.
It's a useful feature to have for scientific computing for the reasons
explained by the test/libcxx/openmp_test.cc example which compiles for
fifteen different microarchitectures. Thanks to the upgrades, it's now
also possible to use newer instruction sets, such as AVX512FP16, VNNI.
Cosmo now uses the %gs register on x86 by default for TLS. Doing it is
helpful for any program that links `cosmo_dlopen()`. Such programs had
to recompile their binaries at startup to change the TLS instructions.
That's not great, since it means every page in the executable needs to
be faulted. The work of rewriting TLS-related x86 opcodes, is moved to
fixupobj.com instead. This is great news for MacOS x86 users, since we
previously needed to morph the binary every time for that platform but
now that's no longer necessary. The only platforms where we need fixup
of TLS x86 opcodes at runtime are now Windows, OpenBSD, and NetBSD. On
Windows we morph TLS to point deeper into the TIB, based on a TlsAlloc
assignment, and on OpenBSD/NetBSD we morph %gs back into %fs since the
kernels do not allow us to specify a value for the %gs register.
OpenBSD users are now required to use APE Loader to run Cosmo binaries
and assimilation is no longer possible. OpenBSD kernel needs to change
to allow programs to specify a value for the %gs register, or it needs
to stop marking executable pages loaded by the kernel as mimmutable().
This release fixes __constructor__, .ctor, .init_array, and lastly the
.preinit_array so they behave the exact same way as glibc.
We no longer use hex constants to define math.h symbols like M_PI.
2024-02-20 19:12:09 +00:00
|
|
|
|
mov %gs:0x30,%r10 // CosmoTib::tib_self
|
2023-06-03 15:12:13 +00:00
|
|
|
|
mov 0x28(%r10),%r10 // CosmoTib::tib_pthread
|
|
|
|
|
test %r10,%r10 // is it a posix thread?
|
|
|
|
|
jz 1f // it's spawn() probably
|
|
|
|
|
testb $PT_NOCANCEL,0x00(%r10) // PosixThread::flags
|
|
|
|
|
jnz 1f // canceler no cancelling
|
2022-11-06 02:49:41 +00:00
|
|
|
|
#if IsModeDbg()
|
|
|
|
|
testb $PT_INCANCEL,0x00(%r10)
|
|
|
|
|
jz 5f
|
|
|
|
|
#endif
|
2023-07-10 11:29:46 +00:00
|
|
|
|
cmpl $0,0x04(%r10) // PosixThread::cancelled
|
2023-06-03 15:12:13 +00:00
|
|
|
|
jne systemfive_cancel // we will tail call below
|
|
|
|
|
1: mov %rcx,%r10 // move the fourth argument
|
|
|
|
|
clc // no cancellable system calls exist
|
|
|
|
|
syscall // that have 7+ args on the bsd OSes
|
|
|
|
|
systemfive_cancellable_end: // i/o calls park here for long time
|
2022-11-05 02:55:41 +00:00
|
|
|
|
pop %rbp
|
2022-11-06 02:49:41 +00:00
|
|
|
|
jnc 2f
|
2023-06-03 15:12:13 +00:00
|
|
|
|
neg %rax // turns bsd errno to system v errno
|
|
|
|
|
2: cmp $-4095,%rax // but we still check again on eintr
|
|
|
|
|
jae 3f // branch because system call failed
|
|
|
|
|
ret // done if the system call succeeded
|
|
|
|
|
3: neg %eax // now examine the nature of failure
|
|
|
|
|
cmp EINTR(%rip),%eax // did the SIGTHR cancel our IO call
|
|
|
|
|
jne systemfive_errno // werent interrupted by OnSigCancel
|
|
|
|
|
cmpb $0,__tls_enabled(%rip) // make sure it's safe to grab %fs:0
|
|
|
|
|
je systemfive_errno // tls is disabled we can't continue
|
Release Cosmopolitan v3.3
This change upgrades to GCC 12.3 and GNU binutils 2.42. The GNU linker
appears to have changed things so that only a single de-duplicated str
table is present in the binary, and it gets placed wherever the linker
wants, regardless of what the linker script says. To cope with that we
need to stop using .ident to embed licenses. As such, this change does
significant work to revamp how third party licenses are defined in the
codebase, using `.section .notice,"aR",@progbits`.
This new GCC 12.3 toolchain has support for GNU indirect functions. It
lets us support __target_clones__ for the first time. This is used for
optimizing the performance of libc string functions such as strlen and
friends so far on x86, by ensuring AVX systems favor a second codepath
that uses VEX encoding. It shaves some latency off certain operations.
It's a useful feature to have for scientific computing for the reasons
explained by the test/libcxx/openmp_test.cc example which compiles for
fifteen different microarchitectures. Thanks to the upgrades, it's now
also possible to use newer instruction sets, such as AVX512FP16, VNNI.
Cosmo now uses the %gs register on x86 by default for TLS. Doing it is
helpful for any program that links `cosmo_dlopen()`. Such programs had
to recompile their binaries at startup to change the TLS instructions.
That's not great, since it means every page in the executable needs to
be faulted. The work of rewriting TLS-related x86 opcodes, is moved to
fixupobj.com instead. This is great news for MacOS x86 users, since we
previously needed to morph the binary every time for that platform but
now that's no longer necessary. The only platforms where we need fixup
of TLS x86 opcodes at runtime are now Windows, OpenBSD, and NetBSD. On
Windows we morph TLS to point deeper into the TIB, based on a TlsAlloc
assignment, and on OpenBSD/NetBSD we morph %gs back into %fs since the
kernels do not allow us to specify a value for the %gs register.
OpenBSD users are now required to use APE Loader to run Cosmo binaries
and assimilation is no longer possible. OpenBSD kernel needs to change
to allow programs to specify a value for the %gs register, or it needs
to stop marking executable pages loaded by the kernel as mimmutable().
This release fixes __constructor__, .ctor, .init_array, and lastly the
.preinit_array so they behave the exact same way as glibc.
We no longer use hex constants to define math.h symbols like M_PI.
2024-02-20 19:12:09 +00:00
|
|
|
|
mov %gs:0x30,%rcx // CosmoTib::tib_self
|
2023-06-03 15:12:13 +00:00
|
|
|
|
mov 0x28(%rcx),%rcx // CosmoTib::tib_pthread
|
|
|
|
|
test %rcx,%rcx // is it a posix thread?
|
|
|
|
|
jz systemfive_errno // it's spawn() probably
|
|
|
|
|
testb $PT_NOCANCEL,0x00(%rcx) // PosixThread::flags
|
|
|
|
|
jnz systemfive_errno // cancellation is disabled
|
2023-07-10 11:29:46 +00:00
|
|
|
|
cmpl $0,0x04(%rcx) // PosixThread::cancelled
|
2023-06-03 15:12:13 +00:00
|
|
|
|
je systemfive_errno // we aren't actually cancelled
|
|
|
|
|
jmp 4f // now we are in fact cancelled
|
|
|
|
|
systemfive_cancel: // SIGTHR will jump here too
|
2022-11-05 02:55:41 +00:00
|
|
|
|
pop %rbp
|
Make improvements
- Every unit test now passes on Apple Silicon. The final piece of this
puzzle was porting our POSIX threads cancelation support, since that
works differently on ARM64 XNU vs. AMD64. Our semaphore support on
Apple Silicon is also superior now compared to AMD64, thanks to the
grand central dispatch library which lets *NSYNC locks go faster.
- The Cosmopolitan runtime is now more stable, particularly on Windows.
To do this, thread local storage is mandatory at all runtime levels,
and the innermost packages of the C library is no longer being built
using ASAN. TLS is being bootstrapped with a 128-byte TIB during the
process startup phase, and then later on the runtime re-allocates it
either statically or dynamically to support code using _Thread_local.
fork() and execve() now do a better job cooperating with threads. We
can now check how much stack memory is left in the process or thread
when functions like kprintf() / execve() etc. call alloca(), so that
ENOMEM can be raised, reduce a buffer size, or just print a warning.
- POSIX signal emulation is now implemented the same way kernels do it
with pthread_kill() and raise(). Any thread can interrupt any other
thread, regardless of what it's doing. If it's blocked on read/write
then the killer thread will cancel its i/o operation so that EINTR can
be returned in the mark thread immediately. If it's doing a tight CPU
bound operation, then that's also interrupted by the signal delivery.
Signal delivery works now by suspending a thread and pushing context
data structures onto its stack, and redirecting its execution to a
trampoline function, which calls SetThreadContext(GetCurrentThread())
when it's done.
- We're now doing a better job managing locks and handles. On NetBSD we
now close semaphore file descriptors in forked children. Semaphores on
Windows can now be canceled immediately, which means mutexes/condition
variables will now go faster. Apple Silicon semaphores can be canceled
too. We're now using Apple's pthread_yield() funciton. Apple _nocancel
syscalls are now used on XNU when appropriate to ensure pthread_cancel
requests aren't lost. The MbedTLS library has been updated to support
POSIX thread cancelations. See tool/build/runitd.c for an example of
how it can be used for production multi-threaded tls servers. Handles
on Windows now leak less often across processes. All i/o operations on
Windows are now overlapped, which means file pointers can no longer be
inherited across dup() and fork() for the time being.
- We now spawn a thread on Windows to deliver SIGCHLD and wakeup wait4()
which means, for example, that posix_spawn() now goes 3x faster. POSIX
spawn is also now more correct. Like Musl, it's now able to report the
failure code of execve() via a pipe although our approach favors using
shared memory to do that on systems that have a true vfork() function.
- We now spawn a thread to deliver SIGALRM to threads when setitimer()
is used. This enables the most precise wakeups the OS makes possible.
- The Cosmopolitan runtime now uses less memory. On NetBSD for example,
it turned out the kernel would actually commit the PT_GNU_STACK size
which caused RSS to be 6mb for every process. Now it's down to ~4kb.
On Apple Silicon, we reduce the mandatory upstream thread size to the
smallest possible size to reduce the memory overhead of Cosmo threads.
The examples directory has a program called greenbean which can spawn
a web server on Linux with 10,000 worker threads and have the memory
usage of the process be ~77mb. The 1024 byte overhead of POSIX-style
thread-local storage is now optional; it won't be allocated until the
pthread_setspecific/getspecific functions are called. On Windows, the
threads that get spawned which are internal to the libc implementation
use reserve rather than commit memory, which shaves a few hundred kb.
- sigaltstack() is now supported on Windows, however it's currently not
able to be used to handle stack overflows, since crash signals are
still generated by WIN32. However the crash handler will still switch
to the alt stack, which is helpful in environments with tiny threads.
- Test binaries are now smaller. Many of the mandatory dependencies of
the test runner have been removed. This ensures many programs can do a
better job only linking the the thing they're testing. This caused the
test binaries for LIBC_FMT for example, to decrease from 200kb to 50kb
- long double is no longer used in the implementation details of libc,
except in the APIs that define it. The old code that used long double
for time (instead of struct timespec) has now been thoroughly removed.
- ShowCrashReports() is now much tinier in MODE=tiny. Instead of doing
backtraces itself, it'll just print a command you can run on the shell
using our new `cosmoaddr2line` program to view the backtrace.
- Crash report signal handling now works in a much better way. Instead
of terminating the process, it now relies on SA_RESETHAND so that the
default SIG_IGN behavior can terminate the process if necessary.
- Our pledge() functionality has now been fully ported to AARCH64 Linux.
2023-09-19 03:44:45 +00:00
|
|
|
|
4: jmp _pthread_cancel_ack // tail call
|
|
|
|
|
.weak _pthread_cancel_ack // must be linked if we're cancelled
|
2022-11-06 02:49:41 +00:00
|
|
|
|
#if IsModeDbg()
|
2023-06-03 15:12:13 +00:00
|
|
|
|
not_a_cancellation_point: // need BEGIN/END_CANCELLATION_POINT
|
2022-11-06 02:49:41 +00:00
|
|
|
|
nop
|
|
|
|
|
.weak report_cancellation_point
|
|
|
|
|
5: ezlea report_cancellation_point,cx
|
|
|
|
|
test %rcx,%rcx
|
|
|
|
|
jz 6f
|
|
|
|
|
call *%rcx
|
|
|
|
|
6: ud2
|
|
|
|
|
nop
|
|
|
|
|
#endif
|
2022-11-04 08:04:43 +00:00
|
|
|
|
.globl systemfive_cancellable_end
|
2022-11-05 02:55:41 +00:00
|
|
|
|
.globl systemfive_cancellable
|
|
|
|
|
.globl systemfive_cancel
|
|
|
|
|
.endfn systemfive_cp
|
2022-11-04 08:04:43 +00:00
|
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
|
.Lanchorpoint:
|
2021-02-24 04:23:19 +00:00
|
|
|
|
#if SupportsLinux() || SupportsMetal()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
systemfive_linux:
|
2023-06-03 15:12:13 +00:00
|
|
|
|
and $0xfff,%eax // remove nonlinux bits from ordinal
|
|
|
|
|
cmp $0xfff,%eax // checks if unsupported by platform
|
|
|
|
|
je systemfive_enosys // never taken branches cost nothing
|
|
|
|
|
btr $11,%eax // 0x800 means a call is cancellable
|
|
|
|
|
jc systemfive_cp // it is handled by the holiest code
|
|
|
|
|
mov %rcx,%r10 // syscall instruction clobbers %rcx
|
|
|
|
|
push %rbp // linux never reads args from stack
|
|
|
|
|
mov %rsp,%rbp // having frame will help backtraces
|
|
|
|
|
syscall // this is known as a context switch
|
|
|
|
|
pop %rbp // next we check to see if it failed
|
|
|
|
|
cmp $-4095,%rax // system five nexgen32e abi § a.2.1
|
|
|
|
|
jae systemfive_error // encodes errno as neg return value
|
2020-06-15 14:18:57 +00:00
|
|
|
|
ret
|
2021-02-08 17:19:00 +00:00
|
|
|
|
.endfn systemfive_linux,globl,hidden
|
|
|
|
|
systemfive_error:
|
2020-06-15 14:18:57 +00:00
|
|
|
|
neg %eax
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// 𝑠𝑙𝑖𝑑𝑒
|
|
|
|
|
.endfn systemfive_error,globl,hidden
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2021-02-08 17:19:00 +00:00
|
|
|
|
systemfive_errno:
|
2022-05-16 20:20:08 +00:00
|
|
|
|
xchg %eax,%ecx
|
|
|
|
|
.errno
|
2023-06-03 15:12:13 +00:00
|
|
|
|
mov %ecx,(%rax) // normalize to c library convention
|
|
|
|
|
push $-1 // negative one is only error result
|
|
|
|
|
pop %rax // the push pop is to save code size
|
2020-06-15 14:18:57 +00:00
|
|
|
|
ret
|
2021-02-08 17:19:00 +00:00
|
|
|
|
.endfn systemfive_errno,globl,hidden
|
|
|
|
|
systemfive_enosys:
|
2020-06-15 14:18:57 +00:00
|
|
|
|
mov ENOSYS(%rip),%eax
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp systemfive_errno
|
|
|
|
|
.endfn systemfive_enosys,globl,hidden
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#if SupportsNetbsd()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
systemfive_netbsd:
|
2021-02-05 14:16:20 +00:00
|
|
|
|
shr $4*13,%rax
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp systemfive_bsdscrub
|
2021-02-11 16:37:18 +00:00
|
|
|
|
.endfn systemfive_netbsd,globl,hidden
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
#if SupportsOpenbsd()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
systemfive_openbsd:
|
2021-02-05 14:16:20 +00:00
|
|
|
|
shr $4*10,%rax
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp systemfive_bsdscrub
|
|
|
|
|
.endfn systemfive_openbsd,globl,hidden
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
#if SupportsFreebsd()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
systemfive_freebsd:
|
2021-02-05 14:16:20 +00:00
|
|
|
|
shr $4*7,%rax
|
2020-06-15 14:18:57 +00:00
|
|
|
|
movzwl %ax,%eax
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// 𝑠𝑙𝑖𝑑𝑒
|
|
|
|
|
.endfn systemfive_freebsd,globl,hidden
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
#if SupportsBsd()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
systemfive_bsdscrub:
|
2021-02-05 14:16:20 +00:00
|
|
|
|
and $0xfff,%eax
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// 𝑠𝑙𝑖𝑑𝑒
|
|
|
|
|
.endfn systemfive_bsdscrub,globl,hidden
|
|
|
|
|
systemfive_bsd:
|
2020-06-15 14:18:57 +00:00
|
|
|
|
cmp $0xfff,%ax
|
2021-02-08 17:19:00 +00:00
|
|
|
|
je systemfive_enosys
|
2023-06-03 15:12:13 +00:00
|
|
|
|
btr $11,%eax // checks/reset the 800 cancellable bit
|
2022-11-05 02:55:41 +00:00
|
|
|
|
jc systemfive_cp
|
2022-06-23 20:01:01 +00:00
|
|
|
|
mov %rcx,%r10
|
2023-06-03 15:12:13 +00:00
|
|
|
|
syscall // bsd will need arg on stack sometimes
|
|
|
|
|
jc systemfive_errno // bsd sets carry flag if %rax is errno
|
2020-06-15 14:18:57 +00:00
|
|
|
|
ret
|
2021-02-08 17:19:00 +00:00
|
|
|
|
.endfn systemfive_bsd
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
#if SupportsXnu()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
systemfive_xnu:
|
2023-06-03 15:12:13 +00:00
|
|
|
|
// 0x?????????2153??? // how syscalls.sh encodes xnu ordinals
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// │└┴┴┐
|
|
|
|
|
// │ ├┬┐
|
2023-06-03 15:12:13 +00:00
|
|
|
|
// 0x0000000002000153 // how xnu wants ordinals to be encoded
|
2020-06-15 14:18:57 +00:00
|
|
|
|
mov %eax,%r11d
|
2021-02-05 14:16:20 +00:00
|
|
|
|
and $0x0f000000,%r11d
|
|
|
|
|
shl $8,%eax
|
|
|
|
|
shr $20,%eax
|
2020-06-15 14:18:57 +00:00
|
|
|
|
or %r11d,%eax
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp systemfive_bsd
|
|
|
|
|
.endfn systemfive_xnu,globl,hidden
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2020-06-15 14:18:57 +00:00
|
|
|
|
.previous
|
|
|
|
|
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// Initializes System Five system call support.
|
|
|
|
|
//
|
|
|
|
|
// (1) Extracts parameters passed by kernel
|
|
|
|
|
// (2) Detects OS without issuing system calls
|
|
|
|
|
// (3) Unpacks magnums from libc/sysv/consts.sh
|
|
|
|
|
// (4) Replaces stack with one we control
|
|
|
|
|
//
|
|
|
|
|
// @param %r15 is auxv
|
|
|
|
|
// @note OpenBSD devs: let us know if you start using auxv
|
2020-06-15 14:18:57 +00:00
|
|
|
|
.init.start 300,_init_systemfive
|
|
|
|
|
push %rbx
|
|
|
|
|
push %rsi
|
2022-04-16 17:40:23 +00:00
|
|
|
|
// Detect the operating system.
|
2023-05-19 02:05:08 +00:00
|
|
|
|
mov __hostos(%rip),%eax
|
2022-04-16 17:40:23 +00:00
|
|
|
|
#if SupportsWindows() || SupportsXnu() || SupportsFreebsd()
|
|
|
|
|
// set by libc/ape.S for XNU
|
|
|
|
|
// set by libc/crt/crt.S for XNU/FreeBSD
|
|
|
|
|
// set by libc/nt/winmain.greg.c for New Technology
|
|
|
|
|
test %eax,%eax
|
2023-06-03 15:12:13 +00:00
|
|
|
|
jnz _init_systemfive_detected // os is already known
|
2022-04-16 17:40:23 +00:00
|
|
|
|
#endif
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#if SupportsOpenbsd()
|
2023-06-03 15:12:13 +00:00
|
|
|
|
cmpq $0,(%r15) // OpenBSD has no auxv
|
2021-02-24 12:00:38 +00:00
|
|
|
|
jnz 0f
|
2022-10-11 03:31:25 +00:00
|
|
|
|
mov $_HOSTOPENBSD,%al
|
2022-04-16 17:40:23 +00:00
|
|
|
|
jmp _init_systemfive_detected
|
2021-02-24 12:00:38 +00:00
|
|
|
|
0:
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
|
|
|
|
#if SupportsNetbsd()
|
2021-02-24 12:00:38 +00:00
|
|
|
|
xor %ecx,%ecx
|
2023-06-03 15:12:13 +00:00
|
|
|
|
0: cmpq $2014,(%r15,%rcx,8) // NetBSD's AT_EXECFN
|
2021-02-24 12:00:38 +00:00
|
|
|
|
jne 1f
|
2022-10-11 03:31:25 +00:00
|
|
|
|
mov $_HOSTNETBSD,%al
|
2022-04-16 17:40:23 +00:00
|
|
|
|
jmp _init_systemfive_detected
|
2021-02-24 12:00:38 +00:00
|
|
|
|
1: cmpq $0,(%r15,%rcx,8)
|
|
|
|
|
lea 2(%ecx),%ecx
|
2021-02-05 14:16:20 +00:00
|
|
|
|
jnz 0b
|
2021-02-24 12:00:38 +00:00
|
|
|
|
2:
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2022-10-11 03:31:25 +00:00
|
|
|
|
mov $_HOSTLINUX,%al
|
2022-04-16 17:40:23 +00:00
|
|
|
|
_init_systemfive_detected:
|
2023-05-19 02:05:08 +00:00
|
|
|
|
mov %eax,__hostos(%rip)
|
2021-02-24 12:00:38 +00:00
|
|
|
|
bsr %eax,%eax
|
|
|
|
|
mov $_init_systemfive_jmptab,%ebx
|
|
|
|
|
movzbl (%rbx,%rax),%eax
|
|
|
|
|
lea (%rbx,%rax),%eax
|
|
|
|
|
jmp *%rax
|
|
|
|
|
_init_systemfive_jmptab:
|
|
|
|
|
.byte _init_systemfive_linux-_init_systemfive_jmptab
|
|
|
|
|
.byte _init_systemfive_metal-_init_systemfive_jmptab
|
|
|
|
|
.byte _init_systemfive_windows-_init_systemfive_jmptab
|
|
|
|
|
.byte _init_systemfive_xnu-_init_systemfive_jmptab
|
|
|
|
|
.byte _init_systemfive_openbsd-_init_systemfive_jmptab
|
|
|
|
|
.byte _init_systemfive_freebsd-_init_systemfive_jmptab
|
|
|
|
|
.byte _init_systemfive_netbsd-_init_systemfive_jmptab
|
|
|
|
|
.endobj _init_systemfive_jmptab
|
2021-02-08 17:19:00 +00:00
|
|
|
|
_init_systemfive_linux:
|
2021-02-24 12:00:38 +00:00
|
|
|
|
#if SupportsLinux()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
pushb systemfive_linux-.Lanchorpoint
|
2021-02-24 12:00:38 +00:00
|
|
|
|
mov $syscon_linux,%esi
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp _init_systemfive_os
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_linux
|
2021-02-08 17:19:00 +00:00
|
|
|
|
_init_systemfive_metal:
|
2021-02-24 12:00:38 +00:00
|
|
|
|
#if SupportsMetal()
|
2021-09-28 05:58:51 +00:00
|
|
|
|
pushb systemfive_enosys-.Lanchorpoint
|
2021-02-24 12:00:38 +00:00
|
|
|
|
mov $syscon_linux,%esi
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp _init_systemfive_os
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_metal
|
2021-02-08 17:19:00 +00:00
|
|
|
|
_init_systemfive_windows:
|
2021-02-24 12:00:38 +00:00
|
|
|
|
#if SupportsWindows()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
pushb systemfive_enosys-.Lanchorpoint
|
2021-02-24 12:00:38 +00:00
|
|
|
|
mov $syscon_windows,%esi
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp _init_systemfive_os
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_windows
|
|
|
|
|
_init_systemfive_xnu:
|
|
|
|
|
#if SupportsXnu()
|
|
|
|
|
pushb systemfive_xnu-.Lanchorpoint
|
|
|
|
|
mov $syscon_xnu,%esi
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp _init_systemfive_os
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_xnu
|
2021-02-08 17:19:00 +00:00
|
|
|
|
_init_systemfive_openbsd:
|
2021-02-24 12:00:38 +00:00
|
|
|
|
#if SupportsOpenbsd()
|
2021-02-08 17:19:00 +00:00
|
|
|
|
pushb systemfive_openbsd-.Lanchorpoint
|
2021-02-24 12:00:38 +00:00
|
|
|
|
mov $syscon_openbsd,%esi
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp _init_systemfive_os
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_openbsd
|
|
|
|
|
_init_systemfive_freebsd:
|
|
|
|
|
#if SupportsFreebsd()
|
|
|
|
|
pushb systemfive_freebsd-.Lanchorpoint
|
|
|
|
|
mov $syscon_freebsd,%esi
|
2021-02-08 17:19:00 +00:00
|
|
|
|
jmp _init_systemfive_os
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_freebsd
|
|
|
|
|
_init_systemfive_netbsd:
|
|
|
|
|
#if SupportsNetbsd()
|
|
|
|
|
pushb systemfive_netbsd-.Lanchorpoint
|
|
|
|
|
mov $syscon_netbsd,%esi
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// 𝑠𝑙𝑖𝑑𝑒
|
2021-02-08 12:04:42 +00:00
|
|
|
|
#endif
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_netbsd
|
2021-02-08 17:19:00 +00:00
|
|
|
|
_init_systemfive_os:
|
2020-06-15 14:18:57 +00:00
|
|
|
|
pop %rax
|
2021-02-24 12:00:38 +00:00
|
|
|
|
add $.Lanchorpoint,%eax
|
2020-11-25 16:19:00 +00:00
|
|
|
|
stosq #→ __systemfive
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// 𝑠𝑙𝑖𝑑𝑒
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_os
|
2021-02-08 17:19:00 +00:00
|
|
|
|
_init_systemfive_magnums:
|
2020-06-15 14:18:57 +00:00
|
|
|
|
push %rdi
|
2021-02-24 12:00:38 +00:00
|
|
|
|
mov $syscon_start,%edi
|
|
|
|
|
2: cmp $syscon_end,%edi
|
2020-06-15 14:18:57 +00:00
|
|
|
|
jnb 5f
|
2021-02-24 12:00:38 +00:00
|
|
|
|
xor %ebx,%ebx
|
2020-06-15 14:18:57 +00:00
|
|
|
|
xor %ecx,%ecx
|
|
|
|
|
xor %edx,%edx
|
2023-06-03 15:12:13 +00:00
|
|
|
|
3: lodsb // decodes uleb128
|
2021-02-24 12:00:38 +00:00
|
|
|
|
movzbl %al,%edx
|
|
|
|
|
and $127,%dl
|
|
|
|
|
shl %cl,%rdx
|
|
|
|
|
or %rdx,%rbx
|
|
|
|
|
add $7,%cl
|
|
|
|
|
test $128,%al
|
|
|
|
|
jnz 3b
|
|
|
|
|
xchg %rbx,%rax
|
2020-06-15 14:18:57 +00:00
|
|
|
|
stosq
|
2023-11-29 11:45:54 +00:00
|
|
|
|
#if SYSDEBUG
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
inc %r8d
|
|
|
|
|
#endif
|
2020-06-15 14:18:57 +00:00
|
|
|
|
jmp 2b
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
5: nop
|
2023-11-29 11:45:54 +00:00
|
|
|
|
#if SYSDEBUG
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
push %rdi
|
|
|
|
|
push %rsi
|
|
|
|
|
push %r8
|
|
|
|
|
call __describe_os
|
|
|
|
|
mov %rax,%rdx
|
|
|
|
|
pop %r8
|
|
|
|
|
.weak __stracef
|
|
|
|
|
ezlea __stracef,ax
|
|
|
|
|
test %rax,%rax
|
|
|
|
|
jz 5f
|
|
|
|
|
ezlea .Llog,di
|
|
|
|
|
mov %r8d,%esi
|
2023-11-10 12:14:27 +00:00
|
|
|
|
push %rax
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
call *%rax
|
2023-11-10 12:14:27 +00:00
|
|
|
|
pop %rax
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
5: pop %rsi
|
|
|
|
|
pop %rdi
|
|
|
|
|
#endif /* DEBUGSYS */
|
|
|
|
|
pop %rdi
|
2021-02-01 11:33:13 +00:00
|
|
|
|
pop %rsi
|
|
|
|
|
pop %rbx
|
2021-02-08 17:19:00 +00:00
|
|
|
|
// 𝑠𝑙𝑖𝑑𝑒
|
2021-02-24 12:00:38 +00:00
|
|
|
|
.endfn _init_systemfive_magnums
|
2022-03-16 20:33:13 +00:00
|
|
|
|
#if SupportsSystemv()
|
|
|
|
|
_init_systemfive_pid:
|
|
|
|
|
ezlea __hostos,cx
|
|
|
|
|
mov (%rcx),%al
|
|
|
|
|
mov (%rdi),%eax
|
2022-10-11 03:31:25 +00:00
|
|
|
|
testb $_HOSTWINDOWS|_HOSTMETAL,(%rcx)
|
2022-03-16 20:33:13 +00:00
|
|
|
|
jnz 1f
|
2023-06-10 01:02:06 +00:00
|
|
|
|
mov __NR_getpid(%rip),%eax
|
2022-03-16 20:33:13 +00:00
|
|
|
|
syscall
|
|
|
|
|
1: stosq
|
|
|
|
|
.endfn _init_systemfive_pid
|
|
|
|
|
#endif
|
2022-11-03 16:32:12 +00:00
|
|
|
|
#if SupportsBsd() && !defined(TINY)
|
|
|
|
|
_init_systemfive_sigsys:
|
2023-06-03 15:12:13 +00:00
|
|
|
|
testb IsBsd() // BSDs will trap SIGSYS!
|
|
|
|
|
jz 1f // We want ENOSYS instead
|
|
|
|
|
push %rdi // XNU removed some calls
|
|
|
|
|
push %rsi // in past, so this makes
|
|
|
|
|
xor %eax,%eax // troubleshooting easier
|
|
|
|
|
push %rax // but it's non-essential
|
2022-11-03 16:32:12 +00:00
|
|
|
|
push %rax
|
|
|
|
|
push %rax
|
|
|
|
|
push %rax
|
|
|
|
|
push %rax
|
2023-06-03 15:12:13 +00:00
|
|
|
|
push $SIG_IGN // sigaction_meta size 48
|
2023-06-10 01:02:06 +00:00
|
|
|
|
mov __NR_sigaction(%rip),%eax // mag
|
2023-11-28 22:24:28 +00:00
|
|
|
|
mov SIGSYS(%rip),%edi // sig
|
2023-06-03 15:12:13 +00:00
|
|
|
|
mov %rsp,%rsi // new
|
|
|
|
|
xor %edx,%edx // old
|
|
|
|
|
mov $8,%r10d // for linux
|
|
|
|
|
xor %r8d,%r8d // for netbsd
|
2022-11-03 16:32:12 +00:00
|
|
|
|
syscall
|
|
|
|
|
add $6*8,%rsp
|
|
|
|
|
pop %rsi
|
|
|
|
|
pop %rdi
|
|
|
|
|
1: .endfn _init_systemfive_sigsys
|
|
|
|
|
#endif
|
2021-02-08 17:19:00 +00:00
|
|
|
|
_init_systemfive_done:
|
2021-02-01 11:33:13 +00:00
|
|
|
|
nop
|
|
|
|
|
.init.end 300,_init_systemfive,globl,hidden
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
2023-11-29 11:45:54 +00:00
|
|
|
|
#if SYSDEBUG
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
.rodata.str1.1
|
|
|
|
|
.Llog: .ascii STRACE_PROLOGUE
|
|
|
|
|
.ascii "bell system five system call support"
|
2022-04-24 16:59:22 +00:00
|
|
|
|
.asciz " %'u magnums loaded on %s\n"
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
.previous
|
|
|
|
|
#endif /* DEBUGSYS */
|