Improve ZIP filesystem and change its prefix

The ZIP filesystem has a breaking change. You now need to use /zip/ to
open() / opendir() / etc. assets within the ZIP structure of your APE
binary, instead of the previous convention of using zip: or zip! URIs.
This is needed because Python likes to use absolute paths, and having
ZIP paths encoded like URIs simply broke too many things.

Many more system calls have been updated to be able to operate on ZIP
files and file descriptors. In particular fcntl() and ioctl() since
Python would do things like ask if a ZIP file is a terminal and get
confused when the old implementation mistakenly said yes, because the
fastest way to guarantee native file descriptors is to dup(2). This
change also improves the async signal safety of zipos and ensures it
doesn't maintain any open file descriptors beyond that which the user
has opened.

This change makes a lot of progress towards adding magic numbers that
are specific to platforms other than Linux. The philosophy here is that,
if you use an operating system like FreeBSD, then you should be able to
take advantage of FreeBSD exclusive features, even if we don't polyfill
them on other platforms. For example, you can now open() a file with the
O_VERIFY flag. If your program runs on other platforms, then Cosmo will
automatically set O_VERIFY to zero. This lets you safely use it without
the need for #ifdef or ifstatements which detract from readability.

One of the blindspots of the ASAN memory hardening we use to offer Rust
like assurances has always been that memory passed to the kernel via
system calls (e.g. writev) can't be checked automatically since the
kernel wasn't built with MODE=asan. This change makes more progress
ensuring that each system call will verify the soundness of memory
before it's passed to the kernel. The code for doing these checks is
fast, particularly for buffers, where it can verify 64 bytes a cycle.

- Correct O_LOOP definition on NT
- Introduce program_executable_name
- Add ASAN guards to more system calls
- Improve termios compatibility with BSDs
- Fix bug in Windows auxiliary value encoding
- Add BSD and XNU specific errnos and open flags
- Add check to ensure build doesn't talk to internet
This commit is contained in:
Justine Tunney 2021-08-22 01:04:18 -07:00
parent 2730c66f4a
commit 00611e9b06
319 changed files with 4418 additions and 2599 deletions

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon at,AT_SYMLINK_NOFOLLOW,0x0100,0x20,0x0200,2,0x200,0
.syscon at,AT_SYMLINK_NOFOLLOW,0x0100,0x20,0x0200,2,0x200,0x0100

2
libc/sysv/consts/EAUTH.S Normal file
View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EAUTH,0,80,80,80,80,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EBADARCH,0,86,0,0,0,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EBADEXEC,0,85,0,0,0,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EBADMACHO,0,88,0,0,0,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EBADRPC,0,72,72,72,72,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EDEVERR,0,83,0,0,0,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EFTYPE,0,79,79,79,79,0

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,ELOOP,40,62,62,62,62,10062
.syscon errno,ELOOP,40,62,62,62,62,1921

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,ENEEDAUTH,0,81,81,81,81,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,ENOATTR,0,93,87,83,93,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,ENOPOLICY,0,103,0,0,0,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EPROCLIM,0,67,67,67,67,10067

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EPROCUNAVAIL,0,76,76,76,76,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EPROGMISMATCH,0,75,75,75,75,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EPROGUNAVAIL,0,74,74,74,74,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,EPWROFF,0,82,0,0,0,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,ERPCMISMATCH,0,73,73,73,73,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon errno,ESHLIBVERS,0,87,0,0,0,0

2
libc/sysv/consts/FREAD.S Normal file
View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon fcntl,FREAD,0,1,1,1,1,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon fcntl,FWRITE,0,2,2,2,2,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon open,O_NOFOLLOW_ANY,0,0x20000000,0,0,0,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon open,O_VERIFY,0,0,0x00200000,0,0,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon sig,SIGINFO,0,29,29,29,29,0

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon sig,SIGRTMAX,0,0,126,0,63,0
.syscon sig,SIGRTMAX,64,0,126,0,63,0

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon sig,SIGRTMIN,0,0,65,0,33,0
.syscon sig,SIGRTMIN,32,0,65,0,33,0

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TCFLSH,0x540b,0,0,0,0,0
.syscon termios,TCFLSH,0x540b,0x80047410,0x80047410,0x80047410,0x80047410,0

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TCIOFF,2,3,3,3,3,0
.syscon termios,TCIOFF,2,3,3,3,3,2

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TCIOFLUSH,2,3,3,3,3,0
.syscon termios,TCIOFLUSH,2,3,3,3,3,2

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TCION,3,4,4,4,4,0
.syscon termios,TCION,3,4,4,4,4,3

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TCOFLUSH,1,2,2,2,2,0
.syscon termios,TCOFLUSH,1,2,2,2,2,1

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TCOON,1,2,2,2,2,0
.syscon termios,TCOON,1,2,2,2,2,1

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TIOCFLUSH,0,0x80047410,0x80047410,0x80047410,0x80047410,0
.syscon termios,TIOCFLUSH,0x540b,0x80047410,0x80047410,0x80047410,0x80047410,0

View file

@ -1,2 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TIOCSTART,0,0x2000746e,0x2000746e,0x2000746e,0x2000746e,0
.syscon termios,TIOCSTART,0x540A,0x2000746e,0x2000746e,0x2000746e,0x2000746e,0

View file

@ -0,0 +1,2 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon termios,TIOCSTOP,0x540A,0x2000746f,0x2000746f,0x2000746f,0x2000746f,0

View file

@ -20,6 +20,7 @@ extern const long O_NDELAY;
extern const long O_NOATIME;
extern const long O_NOCTTY;
extern const long O_NOFOLLOW;
extern const long O_NOFOLLOW_ANY;
extern const long O_NONBLOCK;
extern const long O_PATH;
extern const long O_RANDOM;
@ -34,41 +35,44 @@ extern const long O_SYNC;
extern const long O_TMPFILE;
extern const long O_TRUNC;
extern const long O_TTY_INIT;
extern const long O_VERIFY;
extern const long O_WRONLY;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define O_ACCMODE SYMBOLIC(O_ACCMODE)
#define O_APPEND SYMBOLIC(O_APPEND)
#define O_ASYNC SYMBOLIC(O_ASYNC)
#define O_CLOEXEC SYMBOLIC(O_CLOEXEC)
#define O_CREAT SYMBOLIC(O_CREAT)
#define O_DIRECT SYMBOLIC(O_DIRECT)
#define O_DIRECTORY SYMBOLIC(O_DIRECTORY)
#define O_DSYNC SYMBOLIC(O_DSYNC)
#define O_EXCL SYMBOLIC(O_EXCL)
#define O_EXEC SYMBOLIC(O_EXEC)
#define O_EXLOCK SYMBOLIC(O_EXLOCK)
#define O_LARGEFILE SYMBOLIC(O_LARGEFILE)
#define O_NDELAY SYMBOLIC(O_NDELAY)
#define O_NOATIME SYMBOLIC(O_NOATIME)
#define O_NOCTTY SYMBOLIC(O_NOCTTY)
#define O_NOFOLLOW SYMBOLIC(O_NOFOLLOW)
#define O_NONBLOCK SYMBOLIC(O_NONBLOCK)
#define O_PATH SYMBOLIC(O_PATH)
#define O_RANDOM SYMBOLIC(O_RANDOM)
#define O_RDONLY SYMBOLIC(O_RDONLY)
#define O_RDWR SYMBOLIC(O_RDWR)
#define O_RSYNC SYMBOLIC(O_RSYNC)
#define O_SEARCH SYMBOLIC(O_SEARCH)
#define O_SEQUENTIAL SYMBOLIC(O_SEQUENTIAL)
#define O_SHLOCK SYMBOLIC(O_SHLOCK)
#define O_SPARSE SYMBOLIC(O_SPARSE)
#define O_SYNC SYMBOLIC(O_SYNC)
#define O_TMPFILE SYMBOLIC(O_TMPFILE)
#define O_TRUNC SYMBOLIC(O_TRUNC)
#define O_TTY_INIT SYMBOLIC(O_TTY_INIT)
#define O_WRONLY SYMBOLIC(O_WRONLY)
#define O_ACCMODE SYMBOLIC(O_ACCMODE)
#define O_APPEND SYMBOLIC(O_APPEND)
#define O_ASYNC SYMBOLIC(O_ASYNC)
#define O_CLOEXEC SYMBOLIC(O_CLOEXEC)
#define O_CREAT SYMBOLIC(O_CREAT)
#define O_DIRECT SYMBOLIC(O_DIRECT)
#define O_DIRECTORY SYMBOLIC(O_DIRECTORY)
#define O_DSYNC SYMBOLIC(O_DSYNC)
#define O_EXCL SYMBOLIC(O_EXCL)
#define O_EXEC SYMBOLIC(O_EXEC)
#define O_EXLOCK SYMBOLIC(O_EXLOCK)
#define O_LARGEFILE SYMBOLIC(O_LARGEFILE)
#define O_NDELAY SYMBOLIC(O_NDELAY)
#define O_NOATIME SYMBOLIC(O_NOATIME)
#define O_NOCTTY SYMBOLIC(O_NOCTTY)
#define O_NOFOLLOW SYMBOLIC(O_NOFOLLOW)
#define O_NOFOLLOW_ANY SYMBOLIC(O_NOFOLLOW_ANY)
#define O_NONBLOCK SYMBOLIC(O_NONBLOCK)
#define O_PATH SYMBOLIC(O_PATH)
#define O_RANDOM SYMBOLIC(O_RANDOM)
#define O_RDONLY SYMBOLIC(O_RDONLY)
#define O_RDWR SYMBOLIC(O_RDWR)
#define O_RSYNC SYMBOLIC(O_RSYNC)
#define O_SEARCH SYMBOLIC(O_SEARCH)
#define O_SEQUENTIAL SYMBOLIC(O_SEQUENTIAL)
#define O_SHLOCK SYMBOLIC(O_SHLOCK)
#define O_SPARSE SYMBOLIC(O_SPARSE)
#define O_SYNC SYMBOLIC(O_SYNC)
#define O_TMPFILE SYMBOLIC(O_TMPFILE)
#define O_TRUNC SYMBOLIC(O_TRUNC)
#define O_TTY_INIT SYMBOLIC(O_TTY_INIT)
#define O_VERIFY SYMBOLIC(O_VERIFY)
#define O_WRONLY SYMBOLIC(O_WRONLY)
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_ */

View file

@ -9,9 +9,11 @@ extern const long SIGALRM;
extern const long SIGBUS;
extern const long SIGCHLD;
extern const long SIGCONT;
extern const long SIGEMT;
extern const long SIGFPE;
extern const long SIGHUP;
extern const long SIGILL;
extern const long SIGINFO;
extern const long SIGINT;
extern const long SIGIO;
extern const long SIGIOT;
@ -41,7 +43,6 @@ extern const long SIGVTALRM;
extern const long SIGWINCH;
extern const long SIGXCPU;
extern const long SIGXFSZ;
extern const long SIGEMT;
extern const long SIG_ATOMIC_MIN;
extern const long SIG_BLOCK;
@ -56,9 +57,11 @@ COSMOPOLITAN_C_END_
#define SIGBUS SYMBOLIC(SIGBUS)
#define SIGCHLD SYMBOLIC(SIGCHLD)
#define SIGCONT SYMBOLIC(SIGCONT)
#define SIGEMT SYMBOLIC(SIGEMT)
#define SIGFPE LITERALLY(8)
#define SIGHUP LITERALLY(1)
#define SIGILL LITERALLY(4)
#define SIGINFO SYMBOLIC(SIGINFO)
#define SIGINT LITERALLY(2)
#define SIGIO SYMBOLIC(SIGIO)
#define SIGIOT LITERALLY(6)
@ -88,7 +91,6 @@ COSMOPOLITAN_C_END_
#define SIGWINCH LITERALLY(28)
#define SIGXCPU LITERALLY(24)
#define SIGXFSZ LITERALLY(25)
#define SIGEMT SYMBOLIC(SIGEMT)
#define SIG_ATOMIC_MIN SYMBOLIC(SIG_ATOMIC_MIN)
#define SIG_BLOCK SYMBOLIC(SIG_BLOCK)

View file

@ -144,6 +144,7 @@ extern const long TIOCSPGRP;
extern const long TIOCSTART;
extern const long TIOCSTAT;
extern const long TIOCSTI;
extern const long TIOCSTOP;
extern const long TIOCSTSTAMP;
extern const long TIOCSWINSZ;
extern const long TIOCTIMESTAMP;
@ -177,18 +178,20 @@ extern const long XTABS;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define IGNBRK LITERALLY(0x01)
#define BRKINT LITERALLY(0x02)
#define IGNPAR LITERALLY(0x04)
#define PARMRK LITERALLY(0x08)
#define INPCK LITERALLY(0x10)
#define ISTRIP LITERALLY(0x20)
#define INLCR LITERALLY(0x40)
#define IGNCR LITERALLY(0x80)
#define ICRNL LITERALLY(0x0100)
#define IXANY LITERALLY(0x0800)
#define IMAXBEL LITERALLY(0x2000)
#define OPOST LITERALLY(0x01)
#define BRKINT LITERALLY(0x02)
#define ICRNL LITERALLY(0x0100)
#define IGNBRK LITERALLY(0x01)
#define IGNCR LITERALLY(0x80)
#define IGNPAR LITERALLY(0x04)
#define IMAXBEL LITERALLY(0x2000)
#define INLCR LITERALLY(0x40)
#define INPCK LITERALLY(0x10)
#define ISTRIP LITERALLY(0x20)
#define IXANY LITERALLY(0x0800)
#define OPOST LITERALLY(0x01)
#define PARMRK LITERALLY(0x08)
#define TIOCSTART SYMBOLIC(TIOCSTART)
#define TIOCSTOP SYMBOLIC(TIOCSTOP)
#define NLDLY SYMBOLIC(NLDLY)
#define NL0 LITERALLY(0)