Improve system call wrappers

This change improves copy_file_range(), sendfile(), splice(), openpty(),
closefrom(), close_range(), fadvise() and posix_fadvise() in addition to
writing tests that confirm things like errno and seeking behavior across
platforms. We now less aggressively polyfill behavior with some of these
functions when the platform support isn't available. Please see:

https://justine.lol/cosmopolitan/functions.html
This commit is contained in:
Justine Tunney 2022-09-19 15:01:48 -07:00
parent 224c12f54d
commit c7a8cd21e9
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
89 changed files with 1151 additions and 414 deletions

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/macros.internal.inc"
.scall sys_fadvise,0xffffff213ffff0dd,globl,hidden
.scall sys_fadvise,0x1a0fff213ffff0dd,globl,hidden

View file

@ -1410,8 +1410,9 @@ syscon termios TIOCSTSTAMP 0 0 0 0x8008745a 0x8008745a 0 # boop
syscon termios ENDRUNDISC 0 0 0 0x9 0x9 0 # boop
syscon termios TIOCPTMASTER 0 0 0x2000741c 0 0 0 # boop
syscon termios TIOCPTYGRANT 0 0x20007454 0 0 0 0 # xnu grantpt()
syscon termios TIOCPTYUNLK 0 0x20007452 0 0 0 0 # xnu grantpt()
syscon termios TIOCPTYGNAME 0 0x40807453 0 0 0 0 # xnu grantpt()
syscon termios TIOCPTYUNLK 0 0x20007452 0 0 0 0 # xnu unlockpt()
syscon termios TIOCPTYGNAME 0 0x40807453 0 0 0 0 # xnu ptyname()
syscon termios TIOCPTSNAME 0 0 0 0 0x48087448 0 # netbsd ptyname()
syscon termios FIODGNAME 0 0 0x80106678 0 0 0 # freebsd ptsname_r()
syscon termios NETGRAPHDISC 0 0 0x6 0 0 0 # boop
syscon termios H4DISC 0 0 0x7 0 0 0 # boop

View file

@ -0,0 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon termios,TIOCPTSNAME,0,0,0,0,0x48087448,0

View file

@ -4,11 +4,11 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern const uint64_t FIOASYNC;
extern const uint64_t FIOCLEX;
extern const uint64_t FIONBIO;
extern const uint64_t FIONCLEX;
extern const uint64_t FIONREAD;
extern const uint32_t FIOASYNC;
extern const uint32_t FIOCLEX;
extern const uint32_t FIONBIO;
extern const uint32_t FIONCLEX;
extern const uint32_t FIONREAD;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -6,29 +6,25 @@ COSMOPOLITAN_C_START_
extern const int POSIX_FADV_DONTNEED;
extern const int POSIX_FADV_NOREUSE;
extern const int POSIX_FADV_NORMAL;
extern const int POSIX_FADV_RANDOM;
extern const int POSIX_FADV_SEQUENTIAL;
extern const int POSIX_FADV_WILLNEED;
extern const int POSIX_MADV_DONTNEED;
extern const int POSIX_MADV_NORMAL;
extern const int POSIX_MADV_RANDOM;
extern const int POSIX_MADV_SEQUENTIAL;
extern const int POSIX_MADV_WILLNEED;
extern const int POSIX_MADV_DONTNEED;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define POSIX_FADV_DONTNEED SYMBOLIC(POSIX_FADV_DONTNEED)
#define POSIX_FADV_NOREUSE SYMBOLIC(POSIX_FADV_NOREUSE)
#define POSIX_FADV_NORMAL SYMBOLIC(POSIX_FADV_NORMAL)
#define POSIX_FADV_RANDOM SYMBOLIC(POSIX_FADV_RANDOM)
#define POSIX_FADV_SEQUENTIAL SYMBOLIC(POSIX_FADV_SEQUENTIAL)
#define POSIX_FADV_WILLNEED SYMBOLIC(POSIX_FADV_WILLNEED)
#define POSIX_MADV_DONTNEED SYMBOLIC(POSIX_MADV_DONTNEED)
#define POSIX_MADV_NORMAL SYMBOLIC(POSIX_MADV_NORMAL)
#define POSIX_MADV_RANDOM SYMBOLIC(POSIX_MADV_RANDOM)
#define POSIX_MADV_SEQUENTIAL SYMBOLIC(POSIX_MADV_SEQUENTIAL)
#define POSIX_MADV_WILLNEED SYMBOLIC(POSIX_MADV_WILLNEED)
#define POSIX_FADV_NORMAL LITERALLY(0)
#define POSIX_FADV_RANDOM LITERALLY(1)
#define POSIX_FADV_SEQUENTIAL LITERALLY(2)
#define POSIX_FADV_WILLNEED LITERALLY(3)
#define POSIX_FADV_DONTNEED SYMBOLIC(POSIX_FADV_DONTNEED)
#define POSIX_FADV_NOREUSE SYMBOLIC(POSIX_FADV_NOREUSE)
#define POSIX_MADV_NORMAL LITERALLY(0)
#define POSIX_MADV_RANDOM LITERALLY(1)
#define POSIX_MADV_SEQUENTIAL LITERALLY(2)
#define POSIX_MADV_WILLNEED LITERALLY(3)
#define POSIX_MADV_DONTNEED SYMBOLIC(POSIX_MADV_DONTNEED)
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_ */

View file

@ -178,10 +178,6 @@ extern const uint8_t VTIME;
extern const uint8_t VWERASE;
extern const uint32_t XCASE;
extern const uint32_t XTABS;
extern const uint32_t FIODGNAME;
extern const uint32_t TIOCPTYGRANT;
extern const uint32_t TIOCPTYUNLK;
extern const uint32_t TIOCPTYGNAME;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
@ -254,7 +250,6 @@ COSMOPOLITAN_C_END_
#define EXTA SYMBOLIC(EXTA)
#define EXTB SYMBOLIC(EXTB)
#define EXTPROC SYMBOLIC(EXTPROC)
#define FIODGNAME SYMBOLIC(FIODGNAME)
#define FLUSHO SYMBOLIC(FLUSHO)
#define H4DISC SYMBOLIC(H4DISC)
#define HUPCL SYMBOLIC(HUPCL)
@ -324,9 +319,6 @@ COSMOPOLITAN_C_END_
#define TIOCNXCL SYMBOLIC(TIOCNXCL)
#define TIOCOUTQ SYMBOLIC(TIOCOUTQ)
#define TIOCPTMASTER SYMBOLIC(TIOCPTMASTER)
#define TIOCPTYGNAME SYMBOLIC(TIOCPTYGNAME)
#define TIOCPTYGRANT SYMBOLIC(TIOCPTYGRANT)
#define TIOCPTYUNLK SYMBOLIC(TIOCPTYUNLK)
#define TIOCREMOTE SYMBOLIC(TIOCREMOTE)
#define TIOCSBRK SYMBOLIC(TIOCSBRK)
#define TIOCSCTTY SYMBOLIC(TIOCSCTTY)

View file

@ -249,7 +249,7 @@ scall sys_getdents 0x18606311020c40d9 globl hidden # use opendir/readdir; four
scall sys_set_tid_address 0xfffffffffffff0da globl # no wrapper
scall sys_restart_syscall 0xfffffffffffff0db globl # no wrapper
scall sys_semtimedop 0xfffffffffffff0dc globl # no wrapper
scall sys_fadvise 0xffffff213ffff0dd globl hidden
scall sys_fadvise 0x1a0fff213ffff0dd globl hidden
scall sys_timer_create 0x0ebffffffffff0de globl # no wrapper
scall sys_timer_settime 0x1beffffffffff0df globl # no wrapper
scall sys_timer_gettime 0x1bfffffffffff0e0 globl # no wrapper
@ -383,7 +383,7 @@ scall sys_fsmount 0xfffffffffffff1b0 globl # no wrapper
scall sys_fspick 0xfffffffffffff1b1 globl # no wrapper
scall sys_pidfd_open 0xfffffffffffff1b2 globl # no wrapper
scall sys_clone3 0xfffffffffffff1b3 globl # no wrapper
scall sys_close_range 0xffffff23fffff1b4 globl hidden # linux 5.9
scall sys_close_range 0xffffff23fffff1b4 globl hidden # Linux 5.9
scall sys_openat2 0xfffffffffffff1b5 globl hidden # Linux 5.6
scall sys_pidfd_getfd 0xfffffffffffff1b6 globl # no wrapper
scall sys_faccessat2 0xfffffffffffff1b7 globl hidden