mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Make fixes and improvements
- Invent iso8601us() for faster timestamps - Improve --strace descriptions of sigset_t - Rebuild the Landlock Make bootstrap binary - Introduce MODE=sysv for non-Windows builds - Permit OFD fcntl() locks under pledge(flock) - redbean can now protect your kernel from ddos - Have vfork() fallback to sys_fork() not fork() - Change kmalloc() to not die when out of memory - Improve documentation for some termios functions - Rewrite putenv() and friends to conform to POSIX - Fix linenoise + strace verbosity issue on Windows - Fix regressions in our ability to show backtraces - Change redbean SetHeader() to no-op if value is nil - Improve fcntl() so SQLite locks work in non-WAL mode - Remove some unnecessary work during fork() on Windows - Create redbean-based SSL reverse proxy for IPv4 TurfWar - Fix ape/apeinstall.sh warning when using non-bash shells - Add ProgramTrustedIp(), and IsTrustedIp() APIs to redbean - Support $PWD, $UID, $GID, and $EUID in command interpreter - Introduce experimental JTqFpD APE prefix for non-Windows builds - Invent blackhole daemon for firewalling IP addresses via UNIX named socket - Add ProgramTokenBucket(), AcquireToken(), and CountTokens() APIs to redbean
This commit is contained in:
parent
648bf6555c
commit
f7ff77d865
209 changed files with 3818 additions and 998 deletions
|
@ -20,7 +20,6 @@
|
|||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "libc/macros.internal.h"
|
||||
.privileged
|
||||
|
||||
// Forks process without copying page tables.
|
||||
//
|
||||
|
@ -32,37 +31,55 @@
|
|||
// do anything in a vfork()'d child process. TLS memory must not
|
||||
// be disabled (it's enabled by default) since vfork() needs it.
|
||||
//
|
||||
// What makes vfork() dangerous is that any changes to memory in
|
||||
// the child process can happen in the parent too. The exception
|
||||
// to this rule is `errno` which is saved/restored in a register
|
||||
// by this implementation. However, despite its dangers, vfork's
|
||||
// performance is irresistible and wonderous to behold. If safer
|
||||
// code is desired, consider posix_spawn() which uses vfork().
|
||||
//
|
||||
// Do not make the assumption that the parent is suspended until
|
||||
// the child terminates since this impl calls fork() on Windows,
|
||||
// OpenBSD, and MacOS.
|
||||
// the child terminates since this uses the raw fork system call
|
||||
// on Windows, OpenBSD, and MacOS. In that case the process will
|
||||
// proceed without blocking the parent; however, the `__vforked`
|
||||
// variable is still set to true in the child, so lock functions
|
||||
// won't do anything, and other functions shall change behavior.
|
||||
// This ensures that, even if the operating system does not give
|
||||
// us the performance of vfork(), we'll still be able to cut out
|
||||
// the libc overhead, e.g. pthread_atfork().
|
||||
//
|
||||
// @return pid of child process or 0 if forked process
|
||||
// @returnstwice
|
||||
// @threadsafe
|
||||
// @vforksafe
|
||||
vfork: call __require_tls
|
||||
xor %edi,%edi # dwCreationFlags
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
jmp fork # TODO: asan and vfork don't mix?
|
||||
.endfn vfork,globl
|
||||
#else
|
||||
#if SupportsWindows()
|
||||
testb IsWindows()
|
||||
jnz sys_fork_nt # and we're lucky to have that
|
||||
#endif
|
||||
#if SupportsXnu()
|
||||
testb IsXnu()
|
||||
jnz fork
|
||||
#endif
|
||||
#if SupportsOpenbsd()
|
||||
testb IsOpenbsd()
|
||||
jnz fork # fake vfork plus msyscall issues
|
||||
#endif
|
||||
vfork:
|
||||
#if !IsTiny()
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
call __require_tls
|
||||
#ifdef SYSDEBUG
|
||||
ezlea .Llog,di
|
||||
call __stracef
|
||||
#endif /* SYSDEBUG */
|
||||
#endif
|
||||
pop %rbp
|
||||
#endif
|
||||
mov %fs:0,%r9 # get thread information block
|
||||
#if SupportsWindows()
|
||||
testb IsWindows()
|
||||
jnz 6f # and we're lucky to have that
|
||||
#endif
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
jmp 5f # TODO: asan and vfork don't mix?
|
||||
#endif
|
||||
#if SupportsXnu()
|
||||
testb IsXnu()
|
||||
jnz 5f
|
||||
#endif
|
||||
#if SupportsOpenbsd()
|
||||
testb IsOpenbsd()
|
||||
jnz 5f # fake vfork plus msyscall issues
|
||||
#endif
|
||||
mov 0x3c(%r9),%r8d # avoid question of @vforksafe errno
|
||||
pop %rsi # saves return address in a register
|
||||
mov __NR_vfork(%rip),%eax
|
||||
|
@ -79,12 +96,35 @@ vfork: call __require_tls
|
|||
cmp $-4095,%eax
|
||||
jae systemfive_error
|
||||
mov %r8d,0x3c(%r9) # restore errno
|
||||
test %eax,%eax
|
||||
jnz .Lprnt
|
||||
.Lchld: orb $TIB_FLAG_VFORKED,0x40(%r9)
|
||||
1: test %eax,%eax
|
||||
jnz .Lpar
|
||||
.Lchi: orb $TIB_FLAG_VFORKED,0x40(%r9)
|
||||
ret
|
||||
.Lprnt: andb $~TIB_FLAG_VFORKED,0x40(%r9)
|
||||
.Lpar: andb $~TIB_FLAG_VFORKED,0x40(%r9)
|
||||
ret
|
||||
#if SupportsXnu() || SupportsOpenbsd() || defined(__SANITIZE_ADDRESS__)
|
||||
5: push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %r9
|
||||
push %r9
|
||||
call sys_fork
|
||||
pop %r9
|
||||
pop %r9
|
||||
pop %rbp
|
||||
jmp 1b
|
||||
#endif
|
||||
#if SupportsWindows()
|
||||
6: push %rbp
|
||||
mov %rsp,%rbp
|
||||
push %r9
|
||||
push %r9
|
||||
xor %edi,%edi # dwCreationFlags
|
||||
call sys_fork_nt
|
||||
pop %r9
|
||||
pop %r9
|
||||
pop %rbp
|
||||
jmp 1b
|
||||
#endif
|
||||
.endfn vfork,globl
|
||||
|
||||
#ifdef SYSDEBUG
|
||||
|
@ -93,5 +133,3 @@ vfork: call __require_tls
|
|||
.asciz "vfork()\n"
|
||||
.previous
|
||||
#endif /* DEBUGSYS */
|
||||
|
||||
#endif /* __SANITIZE_ADDRESS__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue