2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
|
|
|
|
|
2022-04-28 16:42:36 +00:00
|
|
|
#define _POSIX_VERSION 200809L
|
|
|
|
#define _POSIX2_VERSION _POSIX_VERSION
|
|
|
|
#define _XOPEN_VERSION 700
|
|
|
|
|
2023-02-23 16:09:34 +00:00
|
|
|
#define _POSIX_MAPPED_FILES _POSIX_VERSION
|
|
|
|
#define _POSIX_FSYNC _POSIX_VERSION
|
|
|
|
#define _POSIX_IPV6 _POSIX_VERSION
|
|
|
|
#define _POSIX_THREADS _POSIX_VERSION
|
|
|
|
#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
|
|
|
|
#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
|
|
|
|
#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION
|
|
|
|
#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
|
|
|
|
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
|
|
|
|
#define _POSIX_THREAD_CPUTIME _POSIX_VERSION
|
|
|
|
#define _POSIX_TIMEOUTS _POSIX_VERSION
|
|
|
|
#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION
|
|
|
|
#define _POSIX_CPUTIME _POSIX_VERSION
|
|
|
|
#define _POSIX_BARRIERS _POSIX_VERSION
|
|
|
|
#define _POSIX_SPIN_LOCKS _POSIX_VERSION
|
|
|
|
#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION
|
|
|
|
#define _POSIX_SEMAPHORES _POSIX_VERSION
|
|
|
|
#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION
|
2023-04-27 17:42:52 +00:00
|
|
|
#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION
|
2023-08-17 07:25:01 +00:00
|
|
|
#define _POSIX_SPAWN _POSIX_VERSION
|
2023-02-23 16:09:34 +00:00
|
|
|
|
Make improvements
- We now serialize the file descriptor table when spawning / executing
processes on Windows. This means you can now inherit more stuff than
just standard i/o. It's needed by bash, which duplicates the console
to file descriptor #255. We also now do a better job serializing the
environment variables, so you're less likely to encounter E2BIG when
using your bash shell. We also no longer coerce environ to uppercase
- execve() on Windows now remotely controls its parent process to make
them spawn a replacement for itself. Then it'll be able to terminate
immediately once the spawn succeeds, without having to linger around
for the lifetime as a shell process for proxying the exit code. When
process worker thread running in the parent sees the child die, it's
given a handle to the new child, to replace it in the process table.
- execve() and posix_spawn() on Windows will now provide CreateProcess
an explicit handle list. This allows us to remove handle locks which
enables better fork/spawn concurrency, with seriously correct thread
safety. Other codebases like Go use the same technique. On the other
hand fork() still favors the conventional WIN32 inheritence approach
which can be a little bit messy, but is *controlled* by guaranteeing
perfectly clean slates at both the spawning and execution boundaries
- sigset_t is now 64 bits. Having it be 128 bits was a mistake because
there's no reason to use that and it's only supported by FreeBSD. By
using the system word size, signal mask manipulation on Windows goes
very fast. Furthermore @asyncsignalsafe funcs have been rewritten on
Windows to take advantage of signal masking, now that it's much more
pleasant to use.
- All the overlapped i/o code on Windows has been rewritten for pretty
good signal and cancelation safety. We're now able to ensure overlap
data structures are cleaned up so long as you don't longjmp() out of
out of a signal handler that interrupted an i/o operation. Latencies
are also improved thanks to the removal of lots of "busy wait" code.
Waits should be optimal for everything except poll(), which shall be
the last and final demon we slay in the win32 i/o horror show.
- getrusage() on Windows is now able to report RUSAGE_CHILDREN as well
as RUSAGE_SELF, thanks to aggregation in the process manager thread.
2023-10-08 12:36:18 +00:00
|
|
|
#define NSIG 64
|
|
|
|
|
2022-05-14 11:33:58 +00:00
|
|
|
#define SEEK_SET 0 /* relative to beginning */
|
|
|
|
#define SEEK_CUR 1 /* relative to current position */
|
|
|
|
#define SEEK_END 2 /* relative to end */
|
|
|
|
#define __WALL 0x40000000 /* Wait on all children, regardless of type */
|
|
|
|
#define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
#define SIG_ERR ((void (*)(int))(-1))
|
2022-09-05 15:43:52 +00:00
|
|
|
#define SIG_DFL ((void (*)(int))0)
|
|
|
|
#define SIG_IGN ((void (*)(int))1)
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2023-06-18 07:55:09 +00:00
|
|
|
#define CLOCKS_PER_SEC 1000000L
|
|
|
|
|
2021-04-21 02:14:21 +00:00
|
|
|
#define MAP_FAILED ((void *)-1)
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2023-07-30 21:26:21 +00:00
|
|
|
#define WTERMSIG(x) (127 & (x))
|
|
|
|
#define WCOREDUMP(x) (128 & (x))
|
|
|
|
#define WIFEXITED(x) (!WTERMSIG(x))
|
|
|
|
#define WEXITSTATUS(x) ((x) >> 8)
|
|
|
|
#define WSTOPSIG(x) ((0xff00 & (x)) >> 8)
|
|
|
|
#define WIFSTOPPED(x) __wifstopped(x)
|
|
|
|
#define WIFSIGNALED(x) __wifsignaled(x)
|
|
|
|
#define WIFCONTINUED(x) __wifcontinued(x)
|
|
|
|
#define W_STOPCODE(x) ((x) << 8 | 0177)
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2023-08-14 03:31:27 +00:00
|
|
|
#ifdef _COSMO_SOURCE
|
|
|
|
#define clone __clone
|
|
|
|
#define commandv __commandv
|
|
|
|
#define fileexists __fileexists
|
|
|
|
#define ischardev __ischardev
|
|
|
|
#define isdirectory __isdirectory
|
|
|
|
#define isexecutable __isexecutable
|
|
|
|
#define isregularfile __isregularfile
|
|
|
|
#define issymlink __issymlink
|
|
|
|
#define makedirs __makedirs
|
|
|
|
#define tmpfd __tmpfd
|
|
|
|
#endif
|
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
|
|
│ cosmopolitan § system calls ─╬─│┼
|
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
|
|
|
typedef int sig_atomic_t;
|
|
|
|
|
2023-07-03 09:47:05 +00:00
|
|
|
bool32 isatty(int);
|
2020-08-25 11:23:25 +00:00
|
|
|
char *getcwd(char *, size_t);
|
2023-09-07 05:39:36 +00:00
|
|
|
char *realpath(const char *, char *) __wur;
|
2020-06-15 14:18:57 +00:00
|
|
|
char *ttyname(int);
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
int access(const char *, int) dontthrow;
|
2020-08-25 11:23:25 +00:00
|
|
|
int chdir(const char *);
|
2022-10-17 18:02:04 +00:00
|
|
|
int chmod(const char *, unsigned);
|
|
|
|
int chown(const char *, unsigned, unsigned);
|
2021-08-12 07:42:14 +00:00
|
|
|
int chroot(const char *);
|
2020-06-15 14:18:57 +00:00
|
|
|
int close(int);
|
2022-07-20 22:13:39 +00:00
|
|
|
int close_range(unsigned, unsigned, unsigned);
|
|
|
|
int closefrom(int);
|
2022-10-17 18:02:04 +00:00
|
|
|
int creat(const char *, unsigned);
|
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
2021-08-22 08:04:18 +00:00
|
|
|
int dup(int);
|
2020-06-15 14:18:57 +00:00
|
|
|
int dup2(int, int);
|
|
|
|
int dup3(int, int, int);
|
|
|
|
int execl(const char *, const char *, ...) nullterminated();
|
|
|
|
int execle(const char *, const char *, ...) nullterminated((1));
|
|
|
|
int execlp(const char *, const char *, ...) nullterminated();
|
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
2021-08-22 08:04:18 +00:00
|
|
|
int execv(const char *, char *const[]);
|
|
|
|
int execve(const char *, char *const[], char *const[]);
|
|
|
|
int execvp(const char *, char *const[]);
|
2022-10-11 00:52:41 +00:00
|
|
|
int faccessat(int, const char *, int, int);
|
2021-08-12 07:42:14 +00:00
|
|
|
int fchdir(int);
|
2022-10-17 18:02:04 +00:00
|
|
|
int fchmod(int, unsigned) dontthrow;
|
|
|
|
int fchmodat(int, const char *, unsigned, int);
|
|
|
|
int fchown(int, unsigned, unsigned);
|
|
|
|
int fchownat(int, const char *, unsigned, unsigned, int);
|
2020-10-27 10:39:46 +00:00
|
|
|
int fcntl(int, int, ...);
|
2020-06-15 14:18:57 +00:00
|
|
|
int fdatasync(int);
|
2022-10-17 18:02:04 +00:00
|
|
|
int fexecve(int, char *const[], char *const[]);
|
2020-06-15 14:18:57 +00:00
|
|
|
int flock(int, int);
|
|
|
|
int fork(void);
|
|
|
|
int fsync(int);
|
|
|
|
int ftruncate(int, int64_t);
|
2020-11-09 23:41:11 +00:00
|
|
|
int getdomainname(char *, size_t);
|
2022-10-17 18:02:04 +00:00
|
|
|
int getgroups(int, unsigned[]);
|
2020-11-09 23:41:11 +00:00
|
|
|
int gethostname(char *, size_t);
|
2022-04-24 16:59:22 +00:00
|
|
|
int getloadavg(double *, int);
|
2022-07-24 12:54:26 +00:00
|
|
|
int getpgid(int) libcesque;
|
2022-04-24 16:59:22 +00:00
|
|
|
int getpgrp(void) nosideeffect;
|
2022-05-23 17:15:53 +00:00
|
|
|
int getpid(void) nosideeffect libcesque;
|
2020-06-15 14:18:57 +00:00
|
|
|
int getppid(void);
|
|
|
|
int getpriority(int, unsigned);
|
2022-05-23 17:15:53 +00:00
|
|
|
int getsid(int) nosideeffect libcesque;
|
2023-07-11 11:29:33 +00:00
|
|
|
int ioctl(int, unsigned long, ...);
|
2022-07-25 02:40:32 +00:00
|
|
|
int issetugid(void);
|
2020-06-15 14:18:57 +00:00
|
|
|
int kill(int, int);
|
|
|
|
int killpg(int, int);
|
2022-10-17 18:02:04 +00:00
|
|
|
int lchmod(const char *, unsigned);
|
|
|
|
int lchown(const char *, unsigned, unsigned);
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
int link(const char *, const char *) dontthrow;
|
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
2021-08-22 08:04:18 +00:00
|
|
|
int linkat(int, const char *, int, const char *, int);
|
2022-05-14 11:33:58 +00:00
|
|
|
int mincore(void *, size_t, unsigned char *);
|
2022-10-12 17:44:54 +00:00
|
|
|
int mkdir(const char *, unsigned);
|
|
|
|
int mkdirat(int, const char *, unsigned);
|
2022-10-17 18:02:04 +00:00
|
|
|
int mknod(const char *, unsigned, uint64_t);
|
2020-06-15 14:18:57 +00:00
|
|
|
int nice(int);
|
2021-05-14 12:36:58 +00:00
|
|
|
int open(const char *, int, ...);
|
2020-08-25 11:23:25 +00:00
|
|
|
int openat(int, const char *, int, ...);
|
2020-06-15 14:18:57 +00:00
|
|
|
int pause(void);
|
2021-01-25 21:08:05 +00:00
|
|
|
int pipe(int[hasatleast 2]);
|
|
|
|
int pipe2(int[hasatleast 2], int);
|
2022-10-11 00:52:41 +00:00
|
|
|
int posix_fadvise(int, int64_t, int64_t, int);
|
2020-06-15 14:18:57 +00:00
|
|
|
int posix_madvise(void *, uint64_t, int);
|
|
|
|
int raise(int);
|
2021-08-16 22:26:31 +00:00
|
|
|
int reboot(int);
|
2020-06-15 14:18:57 +00:00
|
|
|
int remove(const char *);
|
|
|
|
int rename(const char *, const char *);
|
|
|
|
int renameat(int, const char *, int, const char *);
|
|
|
|
int rmdir(const char *);
|
|
|
|
int sched_yield(void);
|
2022-10-17 18:02:04 +00:00
|
|
|
int setegid(unsigned);
|
|
|
|
int seteuid(unsigned);
|
2022-10-11 00:52:41 +00:00
|
|
|
int setfsgid(unsigned);
|
|
|
|
int setfsuid(unsigned);
|
|
|
|
int setgid(unsigned);
|
2022-10-17 18:02:04 +00:00
|
|
|
int setgroups(size_t, const unsigned[]);
|
2020-06-15 14:18:57 +00:00
|
|
|
int setpgid(int, int);
|
2022-04-24 16:59:22 +00:00
|
|
|
int setpgrp(void);
|
2020-06-15 14:18:57 +00:00
|
|
|
int setpriority(int, unsigned, int);
|
2022-10-17 18:02:04 +00:00
|
|
|
int setregid(unsigned, unsigned);
|
|
|
|
int setreuid(unsigned, unsigned);
|
2020-06-15 14:18:57 +00:00
|
|
|
int setsid(void);
|
2022-10-11 00:52:41 +00:00
|
|
|
int setuid(unsigned);
|
2023-11-01 06:57:52 +00:00
|
|
|
int shm_open(const char *, int, unsigned);
|
|
|
|
int shm_unlink(const char *);
|
2020-06-15 14:18:57 +00:00
|
|
|
int sigignore(int);
|
2021-08-18 21:21:30 +00:00
|
|
|
int siginterrupt(int, int);
|
2020-06-15 14:18:57 +00:00
|
|
|
int symlink(const char *, const char *);
|
|
|
|
int symlinkat(const char *, int, const char *);
|
2022-10-11 00:52:41 +00:00
|
|
|
int truncate(const char *, int64_t);
|
2020-06-15 14:18:57 +00:00
|
|
|
int ttyname_r(int, char *, size_t);
|
|
|
|
int unlink(const char *);
|
|
|
|
int unlinkat(int, const char *, int);
|
2023-11-05 20:59:18 +00:00
|
|
|
int usleep(uint64_t);
|
2020-10-27 10:39:46 +00:00
|
|
|
int vfork(void) returnstwice;
|
2020-06-15 14:18:57 +00:00
|
|
|
int wait(int *);
|
|
|
|
int waitpid(int, int *, int);
|
2023-06-18 07:55:09 +00:00
|
|
|
int64_t clock(void);
|
|
|
|
int64_t time(int64_t *);
|
2022-10-17 18:02:04 +00:00
|
|
|
ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned);
|
2022-10-11 00:52:41 +00:00
|
|
|
ssize_t lseek(int, int64_t, int);
|
2021-08-12 07:42:14 +00:00
|
|
|
ssize_t pread(int, void *, size_t, int64_t);
|
|
|
|
ssize_t pwrite(int, const void *, size_t, int64_t);
|
2020-06-15 14:18:57 +00:00
|
|
|
ssize_t read(int, void *, size_t);
|
2021-08-18 21:21:30 +00:00
|
|
|
ssize_t readlink(const char *, char *, size_t);
|
2020-06-15 14:18:57 +00:00
|
|
|
ssize_t readlinkat(int, const char *, char *, size_t);
|
|
|
|
ssize_t write(int, const void *, size_t);
|
2023-06-18 07:55:09 +00:00
|
|
|
unsigned alarm(unsigned);
|
2022-10-17 18:02:04 +00:00
|
|
|
unsigned getegid(void) nosideeffect;
|
|
|
|
unsigned geteuid(void) nosideeffect;
|
|
|
|
unsigned getgid(void) nosideeffect;
|
|
|
|
unsigned getuid(void) libcesque;
|
2023-06-18 07:55:09 +00:00
|
|
|
unsigned sleep(unsigned);
|
2023-08-21 09:28:24 +00:00
|
|
|
unsigned ualarm(unsigned, unsigned);
|
2022-10-17 18:02:04 +00:00
|
|
|
unsigned umask(unsigned);
|
2021-08-12 07:42:14 +00:00
|
|
|
void sync(void);
|
2022-04-24 16:59:22 +00:00
|
|
|
|
2023-08-14 03:31:27 +00:00
|
|
|
#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
|
|
|
|
int syncfs(int);
|
|
|
|
int prctl(int, ...);
|
|
|
|
int gettid(void) libcesque;
|
|
|
|
int setresgid(unsigned, unsigned, unsigned);
|
|
|
|
int setresuid(unsigned, unsigned, unsigned);
|
|
|
|
int getresgid(unsigned *, unsigned *, unsigned *);
|
|
|
|
int getresuid(unsigned *, unsigned *, unsigned *);
|
2023-09-06 10:54:42 +00:00
|
|
|
char *get_current_dir_name(void) __wur;
|
2023-08-14 03:31:27 +00:00
|
|
|
int sync_file_range(int, int64_t, int64_t, unsigned);
|
|
|
|
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned);
|
|
|
|
int memfd_create(const char *, unsigned int);
|
|
|
|
int execvpe(const char *, char *const[], char *const[]);
|
|
|
|
int euidaccess(const char *, int);
|
|
|
|
int eaccess(const char *, int);
|
|
|
|
int madvise(void *, uint64_t, int);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _COSMO_SOURCE
|
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
|
|
|
bool32 fdexists(int);
|
2023-08-14 03:31:27 +00:00
|
|
|
bool32 fileexists(const char *);
|
2023-11-01 06:57:52 +00:00
|
|
|
bool32 ischardev(int);
|
2023-08-14 03:31:27 +00:00
|
|
|
bool32 isdirectory(const char *);
|
|
|
|
bool32 isexecutable(const char *);
|
|
|
|
bool32 isregularfile(const char *);
|
|
|
|
bool32 issymlink(const char *);
|
2023-06-15 20:50:42 +00:00
|
|
|
char *commandv(const char *, char *, size_t);
|
2023-11-02 20:06:23 +00:00
|
|
|
int __getcwd(char *, size_t);
|
2023-07-06 13:57:28 +00:00
|
|
|
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
|
2023-11-01 06:57:52 +00:00
|
|
|
int fadvise(int, uint64_t, uint64_t, int);
|
2023-06-15 20:50:42 +00:00
|
|
|
int makedirs(const char *, unsigned);
|
|
|
|
int pivot_root(const char *, const char *);
|
|
|
|
int pledge(const char *, const char *);
|
|
|
|
int seccomp(unsigned, unsigned, void *);
|
|
|
|
int sys_iopl(int);
|
2023-11-01 06:57:52 +00:00
|
|
|
int sys_ioprio_get(int, int);
|
|
|
|
int sys_ioprio_set(int, int, int);
|
2023-06-15 20:50:42 +00:00
|
|
|
int sys_mlock(const void *, size_t);
|
|
|
|
int sys_mlock2(const void *, size_t, int);
|
|
|
|
int sys_mlockall(int);
|
|
|
|
int sys_munlock(const void *, size_t);
|
|
|
|
int sys_munlockall(void);
|
2023-11-01 06:57:52 +00:00
|
|
|
int sys_personality(uint64_t);
|
2023-06-15 20:50:42 +00:00
|
|
|
int sys_ptrace(int, ...);
|
|
|
|
int sys_sysctl(const int *, unsigned, void *, size_t *, void *, size_t);
|
|
|
|
int tmpfd(void);
|
|
|
|
int touch(const char *, unsigned);
|
|
|
|
int unveil(const char *, const char *);
|
|
|
|
long ptrace(int, ...);
|
|
|
|
ssize_t copyfd(int, int, size_t);
|
|
|
|
ssize_t readansi(int, char *, size_t);
|
2023-07-01 12:09:32 +00:00
|
|
|
ssize_t tinyprint(int, const char *, ...) nullterminated();
|
2023-11-01 06:57:52 +00:00
|
|
|
void shm_path_np(const char *, char[hasatleast 78]);
|
2023-08-14 03:31:27 +00:00
|
|
|
#endif /* _COSMO_SOURCE */
|
2023-06-08 13:12:26 +00:00
|
|
|
|
2023-07-30 21:26:21 +00:00
|
|
|
int __wifstopped(int) pureconst;
|
|
|
|
int __wifcontinued(int) pureconst;
|
|
|
|
int __wifsignaled(int) pureconst;
|
|
|
|
|
2023-08-14 03:31:27 +00:00
|
|
|
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
|
|
|
|
#define lseek64 lseek
|
|
|
|
#define pread64 pread
|
|
|
|
#define pwrite64 pwrite
|
|
|
|
#define truncate64 truncate
|
|
|
|
#define ftruncate64 ftruncate
|
|
|
|
#define lockf64 lockf
|
|
|
|
#endif
|
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_ */
|