Reduce makefile dependencies by 10%

The includes in libc/calls/calls.h have now been refactored so that
functions with struct parameters are declared in libc/calls/struct/
This commit is contained in:
Justine Tunney 2022-06-08 20:01:28 -07:00
parent 4e7ce1538c
commit adac64a52b
202 changed files with 372 additions and 319 deletions

View file

@ -19,7 +19,6 @@
#include "dsp/tty/tty.h" #include "dsp/tty/tty.h"
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/siginfo.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"

View file

@ -8,7 +8,7 @@
*/ */
#endif #endif
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h" #include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"

View file

@ -8,7 +8,6 @@
*/ */
#endif #endif
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"

View file

@ -10,7 +10,7 @@
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/bits/atomic.h" #include "libc/bits/atomic.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h" #include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"

View file

@ -15,6 +15,7 @@
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/sysv/consts/dt.h" #include "libc/sysv/consts/dt.h"
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h" #include "libc/x/x.h"
struct stat st; struct stat st;

View file

@ -8,7 +8,6 @@
*/ */
#endif #endif
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/rusage.h" #include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/errno.h" #include "libc/errno.h"

View file

@ -114,7 +114,6 @@
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/bits/safemacros.internal.h" #include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/dirent.h" #include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/rlimit.h" #include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
@ -142,6 +141,7 @@
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/ok.h" #include "libc/sysv/consts/ok.h"
#include "libc/sysv/consts/rlim.h" #include "libc/sysv/consts/rlim.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/consts/sig.h" #include "libc/sysv/consts/sig.h"
#include "libc/sysv/consts/w.h" #include "libc/sysv/consts/w.h"
#include "third_party/gdtoa/gdtoa.h" #include "third_party/gdtoa/gdtoa.h"

View file

@ -15,6 +15,7 @@
#include "libc/stdio/stdio.h" #include "libc/stdio/stdio.h"
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/sysv/consts/exit.h" #include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#include "third_party/musl/ftw.h" #include "third_party/musl/ftw.h"

View file

@ -1,21 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_ #ifndef COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_ #define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_
#include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/sigval.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/sysinfo.h"
#include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/tms.h"
#include "libc/calls/struct/utsname.h"
#include "libc/dce.h"
#include "libc/fmt/pflink.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/consts/sig.h"
#define _POSIX_VERSION 200809L #define _POSIX_VERSION 200809L
#define _POSIX2_VERSION _POSIX_VERSION #define _POSIX2_VERSION _POSIX_VERSION
@ -46,14 +30,6 @@
#define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT)
#define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT)
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#define S_ISCHR(mode) (((mode)&S_IFMT) == S_IFCHR)
#define S_ISBLK(mode) (((mode)&S_IFMT) == S_IFBLK)
#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
#define S_ISFIFO(mode) (((mode)&S_IFMT) == S_IFIFO)
#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)
#define WCOREDUMP(s) (0x80 & (s)) #define WCOREDUMP(s) (0x80 & (s))
#define WEXITSTATUS(s) ((0xff00 & (s)) >> 8) #define WEXITSTATUS(s) ((0xff00 & (s)) >> 8)
#define WIFCONTINUED(s) ((s) == 0xffff) #define WIFCONTINUED(s) ((s) == 0xffff)
@ -72,8 +48,6 @@ COSMOPOLITAN_C_START_
typedef int sig_atomic_t; typedef int sig_atomic_t;
DIR *fdopendir(int) dontdiscard;
DIR *opendir(const char *) dontdiscard;
bool fileexists(const char *); bool fileexists(const char *);
bool isdirectory(const char *); bool isdirectory(const char *);
bool isexecutable(const char *); bool isexecutable(const char *);
@ -94,9 +68,7 @@ int chmod(const char *, uint32_t);
int chown(const char *, uint32_t, uint32_t); int chown(const char *, uint32_t, uint32_t);
int chroot(const char *); int chroot(const char *);
int close(int); int close(int);
int closedir(DIR *);
int creat(const char *, uint32_t); int creat(const char *, uint32_t);
int dirfd(DIR *);
int dup(int); int dup(int);
int dup2(int, int); int dup2(int, int);
int dup3(int, int, int); int dup3(int, int, int);
@ -119,8 +91,6 @@ int fdatasync(int);
int filecmp(const char *, const char *); int filecmp(const char *, const char *);
int flock(int, int); int flock(int, int);
int fork(void); int fork(void);
int fstat(int, struct stat *);
int fstatat(int, const char *, struct stat *, int);
int fsync(int); int fsync(int);
int ftruncate(int, int64_t); int ftruncate(int, int64_t);
int getdents(unsigned, void *, unsigned, long *); int getdents(unsigned, void *, unsigned, long *);
@ -137,8 +107,6 @@ int getppid(void);
int getpriority(int, unsigned); int getpriority(int, unsigned);
int getresgid(uint32_t *, uint32_t *, uint32_t *); int getresgid(uint32_t *, uint32_t *, uint32_t *);
int getresuid(uint32_t *, uint32_t *, uint32_t *); int getresuid(uint32_t *, uint32_t *, uint32_t *);
int getrlimit(int, struct rlimit *);
int getrusage(int, struct rusage *);
int getsid(int) nosideeffect libcesque; int getsid(int) nosideeffect libcesque;
int gettid(void) libcesque; int gettid(void) libcesque;
int getuid(void) nosideeffect libcesque; int getuid(void) nosideeffect libcesque;
@ -146,8 +114,6 @@ int kill(int, int);
int killpg(int, int); int killpg(int, int);
int link(const char *, const char *) dontthrow; int link(const char *, const char *) dontthrow;
int linkat(int, const char *, int, const char *, int); int linkat(int, const char *, int, const char *, int);
int lstat(const char *, struct stat *);
int lutimes(const char *, const struct timeval[2]);
int madvise(void *, uint64_t, int); int madvise(void *, uint64_t, int);
int mincore(void *, size_t, unsigned char *); int mincore(void *, size_t, unsigned char *);
int mkdir(const char *, uint32_t); int mkdir(const char *, uint32_t);
@ -193,79 +159,46 @@ int setregid(uint32_t, uint32_t);
int setresgid(uint32_t, uint32_t, uint32_t); int setresgid(uint32_t, uint32_t, uint32_t);
int setresuid(uint32_t, uint32_t, uint32_t); int setresuid(uint32_t, uint32_t, uint32_t);
int setreuid(uint32_t, uint32_t); int setreuid(uint32_t, uint32_t);
int setrlimit(int, const struct rlimit *);
int setsid(void); int setsid(void);
int setuid(int); int setuid(int);
int sigignore(int); int sigignore(int);
int siginterrupt(int, int); int siginterrupt(int, int);
int sigprocmask(int, const struct sigset *, struct sigset *);
int sigqueue(int, int, const union sigval);
int sigsuspend(const struct sigset *);
int stat(const char *, struct stat *);
int symlink(const char *, const char *); int symlink(const char *, const char *);
int symlinkat(const char *, int, const char *); int symlinkat(const char *, int, const char *);
int sync_file_range(int, int64_t, int64_t, unsigned); int sync_file_range(int, int64_t, int64_t, unsigned);
int sysctl(const int *, unsigned, void *, size_t *, void *, size_t); int sysctl(const int *, unsigned, void *, size_t *, void *, size_t);
int sysinfo(struct sysinfo *);
int tgkill(int, int, int); int tgkill(int, int, int);
int tkill(int, int); int tkill(int, int);
int touch(const char *, uint32_t); int touch(const char *, uint32_t);
int truncate(const char *, uint64_t); int truncate(const char *, uint64_t);
int ttyname_r(int, char *, size_t); int ttyname_r(int, char *, size_t);
int umask(int); int umask(int);
int uname(struct utsname *);
int unlink(const char *); int unlink(const char *);
int unlink_s(const char **); int unlink_s(const char **);
int unlinkat(int, const char *, int); int unlinkat(int, const char *, int);
int vfork(void) returnstwice; int vfork(void) returnstwice;
int wait(int *); int wait(int *);
int wait3(int *, int, struct rusage *);
int wait4(int, int *, int, struct rusage *);
int waitpid(int, int *, int); int waitpid(int, int *, int);
intptr_t syscall(int, ...); intptr_t syscall(int, ...);
long ptrace(int, ...); long ptrace(int, ...);
long telldir(DIR *);
long times(struct tms *);
size_t GetFileSize(const char *); size_t GetFileSize(const char *);
ssize_t copy_file_range(int, long *, int, long *, size_t, uint32_t); ssize_t copy_file_range(int, long *, int, long *, size_t, uint32_t);
ssize_t copyfd(int, int64_t *, int, int64_t *, size_t, uint32_t); ssize_t copyfd(int, int64_t *, int, int64_t *, size_t, uint32_t);
ssize_t getfiledescriptorsize(int); ssize_t getfiledescriptorsize(int);
ssize_t lseek(int, int64_t, unsigned); ssize_t lseek(int, int64_t, unsigned);
ssize_t pread(int, void *, size_t, int64_t); ssize_t pread(int, void *, size_t, int64_t);
ssize_t preadv(int, struct iovec *, int, int64_t);
ssize_t pwrite(int, const void *, size_t, int64_t); ssize_t pwrite(int, const void *, size_t, int64_t);
ssize_t pwritev(int, const struct iovec *, int, int64_t);
ssize_t read(int, void *, size_t); ssize_t read(int, void *, size_t);
ssize_t readansi(int, char *, size_t); ssize_t readansi(int, char *, size_t);
ssize_t readlink(const char *, char *, size_t); ssize_t readlink(const char *, char *, size_t);
ssize_t readlinkat(int, const char *, char *, size_t); ssize_t readlinkat(int, const char *, char *, size_t);
ssize_t splice(int, int64_t *, int, int64_t *, size_t, uint32_t); ssize_t splice(int, int64_t *, int, int64_t *, size_t, uint32_t);
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t);
ssize_t write(int, const void *, size_t); ssize_t write(int, const void *, size_t);
struct dirent *readdir(DIR *);
void rewinddir(DIR *);
void sync(void); void sync(void);
int clone(int (*)(void *), void *, size_t, int, void *, int *, void *, size_t, int clone(int (*)(void *), void *, size_t, int, void *, int *, void *, size_t,
int *); int *);
int futex(uint32_t *, int, int, const struct timespec *, uint32_t *);
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » formatting
*/
int dprintf(int, const char *, ...) printfesque(2) paramsnonnull((2));
int vdprintf(int, const char *, va_list) paramsnonnull();
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » link-time optimizations
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define dprintf(FD, FMT, ...) (dprintf)(FD, PFLINK(FMT), ##__VA_ARGS__)
#define vdprintf(FD, FMT, VA) (vdprintf)(FD, PFLINK(FMT), VA)
#endif /* GNU && !ANSI */
COSMOPOLITAN_C_END_ COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_ */

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/errno.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
#include "libc/nt/errors.h" #include "libc/nt/errors.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"

View file

@ -16,13 +16,12 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/bits/weaken.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/errno.h"
#include "libc/nt/enum/filetype.h" #include "libc/nt/enum/filetype.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h"
textwindows int sys_close_nt(struct Fd *fd) { textwindows int sys_close_nt(struct Fd *fd) {
int e; int e;

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/bits/weaken.h" #include "libc/bits/weaken.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
@ -48,7 +49,7 @@
*/ */
int close(int fd) { int close(int fd) {
int rc; int rc;
_spinlock(&__fds_lock); __fds_lock();
if (fd == -1) { if (fd == -1) {
rc = 0; rc = 0;
} else if (fd < 0) { } else if (fd < 0) {
@ -80,7 +81,7 @@ int close(int fd) {
__releasefd_unlocked(fd); __releasefd_unlocked(fd);
} }
} }
_spunlock(&__fds_lock); __fds_unlock();
STRACE("%s(%d) → %d% m", "close", fd, rc); STRACE("%s(%d) → %d% m", "close", fd, rc);
return rc; return rc;
} }

View file

@ -30,6 +30,7 @@
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/nt/struct/filetime.h" #include "libc/nt/struct/filetime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/madv.h" #include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/bits/popcnt.h" #include "libc/bits/popcnt.h"
#include "libc/calls/sigbits.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"

View file

@ -19,18 +19,15 @@
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/nt/enum/filemapflags.h" #include "libc/nt/enum/filemapflags.h"
#include "libc/nt/enum/pageflags.h" #include "libc/nt/enum/pageflags.h"
#include "libc/nt/memory.h" #include "libc/nt/memory.h"
#include "libc/nt/process.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/nt/struct/processmemorycounters.h" #include "libc/nt/struct/processmemorycounters.h"
#include "libc/nt/struct/securityattributes.h"
#include "libc/runtime/directmap.internal.h" #include "libc/runtime/directmap.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/map.h" #include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
textwindows struct DirectMap sys_mmap_nt(void *addr, size_t size, int prot, textwindows struct DirectMap sys_mmap_nt(void *addr, size_t size, int prot,
int flags, int fd, int64_t off) { int flags, int fd, int64_t off) {

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/dprintf.h"
/** /**
* Formats string directly to file descriptor. * Formats string directly to file descriptor.

18
libc/calls/dprintf.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_
#define COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_
#include "libc/fmt/pflink.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int dprintf(int, const char *, ...) printfesque(2) paramsnonnull((2));
int vdprintf(int, const char *, va_list) paramsnonnull();
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define dprintf(FD, FMT, ...) (dprintf)(FD, PFLINK(FMT), ##__VA_ARGS__)
#define vdprintf(FD, FMT, VA) (vdprintf)(FD, PFLINK(FMT), VA)
#endif /* GNU && !ANSI */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_ */

View file

@ -16,15 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/bits/bits.h"
#include "libc/bits/weaken.h" #include "libc/bits/weaken.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/spinlock.h" #include "libc/intrin/spinlock.h"
#include "libc/mem/mem.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/sock/internal.h" #include "libc/sock/internal.h"
@ -41,12 +37,12 @@ textwindows int sys_dup_nt(int oldfd, int newfd, int flags, int start) {
if (oldfd < 0) return ebadf(); if (oldfd < 0) return ebadf();
if (flags & ~O_CLOEXEC) return einval(); if (flags & ~O_CLOEXEC) return einval();
_spinlock(&__fds_lock); __fds_lock();
if (oldfd >= g_fds.n || if (oldfd >= g_fds.n ||
(g_fds.p[oldfd].kind != kFdFile && g_fds.p[oldfd].kind != kFdSocket && (g_fds.p[oldfd].kind != kFdFile && g_fds.p[oldfd].kind != kFdSocket &&
g_fds.p[oldfd].kind != kFdConsole)) { g_fds.p[oldfd].kind != kFdConsole)) {
_spunlock(&__fds_lock); __fds_unlock();
return ebadf(); return ebadf();
} }
@ -54,19 +50,19 @@ textwindows int sys_dup_nt(int oldfd, int newfd, int flags, int start) {
for (;;) { for (;;) {
if (newfd == -1) { if (newfd == -1) {
if ((newfd = __reservefd_unlocked(start)) == -1) { if ((newfd = __reservefd_unlocked(start)) == -1) {
_spunlock(&__fds_lock); __fds_unlock();
return -1; return -1;
} }
break; break;
} else { } else {
if (__ensurefds_unlocked(newfd) == -1) { if (__ensurefds_unlocked(newfd) == -1) {
_spunlock(&__fds_lock); __fds_unlock();
return -1; return -1;
} }
if (g_fds.p[newfd].kind) { if (g_fds.p[newfd].kind) {
_spunlock(&__fds_lock); __fds_unlock();
close(newfd); close(newfd);
_spinlock(&__fds_lock); __fds_lock();
} }
if (!g_fds.p[newfd].kind) { if (!g_fds.p[newfd].kind) {
g_fds.p[newfd].kind = kFdReserved; g_fds.p[newfd].kind = kFdReserved;
@ -96,6 +92,6 @@ textwindows int sys_dup_nt(int oldfd, int newfd, int flags, int start) {
rc = __winerr(); rc = __winerr();
} }
_spunlock(&__fds_lock); __fds_unlock();
return rc; return rc;
} }

View file

@ -20,6 +20,7 @@
#include "libc/bits/safemacros.internal.h" #include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/mem/alloca.h" #include "libc/mem/alloca.h"
#include "libc/paths.h" #include "libc/paths.h"

View file

@ -17,18 +17,12 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/syscall_support-nt.internal.h" #include "libc/calls/syscall_support-nt.internal.h"
#include "libc/intrin/spinlock.h"
#include "libc/nt/createfile.h" #include "libc/nt/createfile.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/enum/filesharemode.h"
#include "libc/nt/enum/status.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/nt/nt/file.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/nt/struct/fileaccessinformation.h"
#include "libc/nt/struct/filebasicinformation.h"
#include "libc/nt/struct/iostatusblock.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/madv.h" #include "libc/sysv/consts/madv.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
@ -36,7 +30,7 @@
textwindows int sys_fadvise_nt(int fd, uint64_t offset, uint64_t len, textwindows int sys_fadvise_nt(int fd, uint64_t offset, uint64_t len,
int advice) { int advice) {
int64_t h1, h2; int64_t h1, h2;
int flags, mode; int rc, flags, mode;
uint32_t perm, share, attr; uint32_t perm, share, attr;
if (!__isfdkind(fd, kFdFile)) return ebadf(); if (!__isfdkind(fd, kFdFile)) return ebadf();
h1 = g_fds.p[fd].handle; h1 = g_fds.p[fd].handle;
@ -49,6 +43,7 @@ textwindows int sys_fadvise_nt(int fd, uint64_t offset, uint64_t len,
case MADV_RANDOM: case MADV_RANDOM:
flags |= O_RANDOM; flags |= O_RANDOM;
break; break;
case MADV_WILLNEED:
case MADV_SEQUENTIAL: case MADV_SEQUENTIAL:
flags |= O_SEQUENTIAL; flags |= O_SEQUENTIAL;
break; break;
@ -56,14 +51,19 @@ textwindows int sys_fadvise_nt(int fd, uint64_t offset, uint64_t len,
return einval(); return einval();
} }
if (GetNtOpenFlags(flags, mode, &perm, &share, 0, &attr) == -1) return -1; if (GetNtOpenFlags(flags, mode, &perm, &share, 0, &attr) == -1) return -1;
__fds_lock();
if ((h2 = ReOpenFile(h1, perm, share, attr)) != -1) { if ((h2 = ReOpenFile(h1, perm, share, attr)) != -1) {
if (h2 != h1) { if (h2 != h1) {
CloseHandle(h1); CloseHandle(h1);
g_fds.p[fd].handle = h2; g_fds.p[fd].handle = h2;
} }
g_fds.p[fd].flags = flags; g_fds.p[fd].flags = flags;
return 0; rc = 0;
} else { } else {
return __winerr(); rc = __winerr();
} }
__fds_unlock();
return rc;
} }

View file

@ -23,6 +23,7 @@
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/ok.h" #include "libc/sysv/consts/ok.h"

View file

@ -11,6 +11,7 @@
#include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/siginfo.h"
#include "libc/calls/struct/sigval.h" #include "libc/calls/struct/sigval.h"
#include "libc/calls/struct/stat.h" #include "libc/calls/struct/stat.h"
#include "libc/calls/struct/sysinfo.h"
#include "libc/calls/struct/timespec.h" #include "libc/calls/struct/timespec.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"
#include "libc/calls/struct/winsize.h" #include "libc/calls/struct/winsize.h"

View file

@ -20,6 +20,7 @@
#include "libc/bits/weaken.h" #include "libc/bits/weaken.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/intrin/cmpxchg.h" #include "libc/intrin/cmpxchg.h"
#include "libc/mem/mem.h"
#include "libc/nt/errors.h" #include "libc/nt/errors.h"
#include "libc/nt/iphlpapi.h" #include "libc/nt/iphlpapi.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"

View file

@ -42,7 +42,7 @@ textwindows int ioctl_tiocgwinsz_nt(struct Fd *fd, struct winsize *ws) {
rc = -1; rc = -1;
e = errno; e = errno;
if (ws) { if (ws) {
_spinlock(&__fds_lock); __fds_lock();
fds[0] = fd, fds[1] = g_fds.p + 1, fds[2] = g_fds.p + 0; fds[0] = fd, fds[1] = g_fds.p + 1, fds[2] = g_fds.p + 0;
GetStartupInfo(&startinfo); GetStartupInfo(&startinfo);
for (i = 0; i < ARRAYLEN(fds); ++i) { for (i = 0; i < ARRAYLEN(fds); ++i) {
@ -76,7 +76,7 @@ textwindows int ioctl_tiocgwinsz_nt(struct Fd *fd, struct winsize *ws) {
ebadf(); ebadf();
} }
} }
_spunlock(&__fds_lock); __fds_unlock();
} else { } else {
efault(); efault();
} }

View file

@ -24,6 +24,7 @@
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/nt/enum/filetype.h" #include "libc/nt/enum/filetype.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/sysv/consts/s.h"
/** /**
* Returns true if file descriptor is backed by character i/o. * Returns true if file descriptor is backed by character i/o.

View file

@ -28,6 +28,7 @@
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h" #include "libc/zipos/zipos.internal.h"

View file

@ -26,6 +26,7 @@
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h" #include "libc/zipos/zipos.internal.h"

View file

@ -28,6 +28,7 @@
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
#include "libc/zipos/zipos.internal.h" #include "libc/zipos/zipos.internal.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/struct/stat.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
/** /**

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/assert.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/ntmagicpaths.internal.h" #include "libc/calls/ntmagicpaths.internal.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
@ -25,6 +26,7 @@
#include "libc/nt/createfile.h" #include "libc/nt/createfile.h"
#include "libc/nt/enum/filetype.h" #include "libc/nt/enum/filetype.h"
#include "libc/nt/files.h" #include "libc/nt/files.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/fileno.h" #include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
@ -79,7 +81,7 @@ textwindows int sys_open_nt(int dirfd, const char *file, uint32_t flags,
int32_t mode) { int32_t mode) {
int fd; int fd;
ssize_t rc; ssize_t rc;
_spinlock(&__fds_lock); __fds_lock();
if ((rc = fd = __reservefd_unlocked(-1)) != -1) { if ((rc = fd = __reservefd_unlocked(-1)) != -1) {
if ((flags & O_ACCMODE) == O_RDWR && !strcmp(file, kNtMagicPaths.devtty)) { if ((flags & O_ACCMODE) == O_RDWR && !strcmp(file, kNtMagicPaths.devtty)) {
rc = sys_open_nt_console(dirfd, &kNtMagicPaths, flags, mode, fd); rc = sys_open_nt_console(dirfd, &kNtMagicPaths, flags, mode, fd);
@ -89,7 +91,7 @@ textwindows int sys_open_nt(int dirfd, const char *file, uint32_t flags,
if (rc == -1) { if (rc == -1) {
__releasefd_unlocked(fd); __releasefd_unlocked(fd);
} }
_spunlock(&__fds_lock); __fds_unlock();
} }
return rc; return rc;
} }

View file

@ -36,14 +36,14 @@ textwindows int sys_pipe_nt(int pipefd[2], unsigned flags) {
int reader, writer; int reader, writer;
char16_t pipename[64]; char16_t pipename[64];
CreatePipeName(pipename); CreatePipeName(pipename);
_spinlock(&__fds_lock); __fds_lock();
if ((reader = __reservefd_unlocked(-1)) == -1) { if ((reader = __reservefd_unlocked(-1)) == -1) {
_spunlock(&__fds_lock); __fds_unlock();
return -1; return -1;
} }
if ((writer = __reservefd_unlocked(-1)) == -1) { if ((writer = __reservefd_unlocked(-1)) == -1) {
__releasefd_unlocked(reader); __releasefd_unlocked(reader);
_spunlock(&__fds_lock); __fds_unlock();
return -1; return -1;
} }
if (~flags & O_DIRECT) { if (~flags & O_DIRECT) {
@ -51,10 +51,10 @@ textwindows int sys_pipe_nt(int pipefd[2], unsigned flags) {
} else { } else {
mode = kNtPipeTypeMessage | kNtPipeReadmodeMessage; mode = kNtPipeTypeMessage | kNtPipeReadmodeMessage;
} }
_spunlock(&__fds_lock); __fds_unlock();
hin = CreateNamedPipe(pipename, kNtPipeAccessInbound | kNtFileFlagOverlapped, hin = CreateNamedPipe(pipename, kNtPipeAccessInbound | kNtFileFlagOverlapped,
mode, 1, PIPE_BUF, PIPE_BUF, 0, &kNtIsInheritable); mode, 1, PIPE_BUF, PIPE_BUF, 0, &kNtIsInheritable);
_spinlock(&__fds_lock); __fds_lock();
if (hin != -1) { if (hin != -1) {
if ((hout = CreateFile(pipename, kNtGenericWrite, 0, &kNtIsInheritable, if ((hout = CreateFile(pipename, kNtGenericWrite, 0, &kNtIsInheritable,
kNtOpenExisting, kNtFileFlagOverlapped, 0)) != -1) { kNtOpenExisting, kNtFileFlagOverlapped, 0)) != -1) {
@ -68,7 +68,7 @@ textwindows int sys_pipe_nt(int pipefd[2], unsigned flags) {
g_fds.p[writer].handle = hout; g_fds.p[writer].handle = hout;
pipefd[0] = reader; pipefd[0] = reader;
pipefd[1] = writer; pipefd[1] = writer;
_spunlock(&__fds_lock); __fds_unlock();
return 0; return 0;
} else { } else {
CloseHandle(hin); CloseHandle(hin);
@ -76,6 +76,6 @@ textwindows int sys_pipe_nt(int pipefd[2], unsigned flags) {
} }
__releasefd_unlocked(writer); __releasefd_unlocked(writer);
__releasefd_unlocked(reader); __releasefd_unlocked(reader);
_spunlock(&__fds_lock); __fds_unlock();
return -1; return -1;
} }

View file

@ -21,7 +21,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/sig.internal.h" #include "libc/calls/sig.internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
@ -69,7 +68,7 @@ textwindows int sys_poll_nt(struct pollfd *fds, uint64_t nfds, uint64_t *ms) {
// we need to read static variables // we need to read static variables
// we might need to spawn threads and open pipes // we might need to spawn threads and open pipes
_spinlock(&poll_lock); _spinlock(&poll_lock);
_spinlock(&__fds_lock); __fds_lock();
for (gotinvals = failed = sn = pn = i = 0; i < nfds; ++i) { for (gotinvals = failed = sn = pn = i = 0; i < nfds; ++i) {
if (fds[i].fd < 0) continue; if (fds[i].fd < 0) continue;
if (__isfdopen(fds[i].fd)) { if (__isfdopen(fds[i].fd)) {
@ -115,7 +114,7 @@ textwindows int sys_poll_nt(struct pollfd *fds, uint64_t nfds, uint64_t *ms) {
++gotinvals; ++gotinvals;
} }
} }
_spunlock(&__fds_lock); __fds_unlock();
_spunlock(&poll_lock); _spunlock(&poll_lock);
if (failed) { if (failed) {
// failed to create a polling solution // failed to create a polling solution

View file

@ -46,7 +46,7 @@ static const char *__fdkind2str(int x) {
void __printfds(void) { void __printfds(void) {
int i; int i;
_spinlock(&__fds_lock); __fds_lock();
for (i = 0; i < g_fds.n; ++i) { for (i = 0; i < g_fds.n; ++i) {
if (!g_fds.p[i].kind) continue; if (!g_fds.p[i].kind) continue;
kprintf("%3d %s", i, __fdkind2str(g_fds.p[i].kind)); kprintf("%3d %s", i, __fdkind2str(g_fds.p[i].kind));
@ -57,5 +57,5 @@ void __printfds(void) {
if (g_fds.p[i].extra) kprintf(" extra=%ld", g_fds.p[i].extra); if (g_fds.p[i].extra) kprintf(" extra=%ld", g_fds.p[i].extra);
kprintf("\n"); kprintf("\n");
} }
_spunlock(&__fds_lock); __fds_unlock();
} }

View file

@ -20,6 +20,7 @@
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/fmt/itoa.h" #include "libc/fmt/itoa.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/termios.h" #include "libc/sysv/consts/termios.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"

View file

@ -69,9 +69,9 @@ int __ensurefds_unlocked(int fd) {
* Grows file descriptor array memory if needed. * Grows file descriptor array memory if needed.
*/ */
int __ensurefds(int fd) { int __ensurefds(int fd) {
_spinlock(&__fds_lock); __fds_lock();
fd = __ensurefds_unlocked(fd); fd = __ensurefds_unlocked(fd);
_spunlock(&__fds_lock); __fds_unlock();
return fd; return fd;
} }
@ -96,9 +96,9 @@ int __reservefd_unlocked(int start) {
*/ */
int __reservefd(int start) { int __reservefd(int start) {
int fd; int fd;
_spinlock(&__fds_lock); __fds_lock();
fd = __reservefd_unlocked(start); fd = __reservefd_unlocked(start);
_spunlock(&__fds_lock); __fds_unlock();
return fd; return fd;
} }
@ -108,12 +108,12 @@ int __reservefd(int start) {
static void FreeFds(void) { static void FreeFds(void) {
int i, keep = 3; int i, keep = 3;
STRACE("FreeFds()"); STRACE("FreeFds()");
_spinlock(&__fds_lock); __fds_lock();
for (i = keep; i < g_fds.n; ++i) { for (i = keep; i < g_fds.n; ++i) {
if (g_fds.p[i].kind) { if (g_fds.p[i].kind) {
_spunlock(&__fds_lock); __fds_unlock();
close(i); close(i);
_spinlock(&__fds_lock); __fds_lock();
} }
} }
if (g_fds.p != g_fds.__init_p) { if (g_fds.p != g_fds.__init_p) {
@ -125,7 +125,7 @@ static void FreeFds(void) {
g_fds.p = g_fds.__init_p; g_fds.p = g_fds.__init_p;
g_fds.n = ARRAYLEN(g_fds.__init_p); g_fds.n = ARRAYLEN(g_fds.__init_p);
} }
_spunlock(&__fds_lock); __fds_unlock();
} }
static textstartup void FreeFdsInit(void) { static textstartup void FreeFdsInit(void) {

View file

@ -19,6 +19,7 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/syscall-nt.internal.h" #include "libc/calls/syscall-nt.internal.h"
#include "libc/calls/syscall-sysv.internal.h" #include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
/** /**
* Sets nice value of thing. * Sets nice value of thing.

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/sig.internal.h" #include "libc/calls/sig.internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/intrin/cmpxchg.h" #include "libc/intrin/cmpxchg.h"
@ -28,6 +27,7 @@
#include "libc/runtime/internal.h" #include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/sysv/consts/sa.h" #include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
/** /**

View file

@ -22,7 +22,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/sig.internal.h" #include "libc/calls/sig.internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigaction-freebsd.internal.h" #include "libc/calls/struct/sigaction-freebsd.internal.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/sigbits.h" #include "libc/calls/struct/sigset.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
/** /**

View file

@ -1,15 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_SIGBITS_H_
#define COSMOPOLITAN_LIBC_CALLS_SIGBITS_H_
#include "libc/calls/struct/sigset.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int sigaddset(sigset_t *, int) paramsnonnull();
int sigdelset(sigset_t *, int) paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull();
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_SIGBITS_H_ */

View file

@ -41,9 +41,9 @@ void _check_sigchld(void) {
int pids[64]; int pids[64];
uint32_t i, n; uint32_t i, n;
int64_t handles[64]; int64_t handles[64];
_spinlock(&__fds_lock); __fds_lock();
n = __sample_pids(pids, handles, true); n = __sample_pids(pids, handles, true);
_spunlock(&__fds_lock); __fds_unlock();
if (!n) return; if (!n) return;
i = WaitForMultipleObjects(n, handles, false, 0); i = WaitForMultipleObjects(n, handles, false, 0);
if (i == kNtWaitTimeout) return; if (i == kNtWaitTimeout) return;
@ -61,8 +61,8 @@ void _check_sigchld(void) {
CloseHandle(handles[i]); CloseHandle(handles[i]);
__releasefd(pids[i]); __releasefd(pids[i]);
} }
_spinlock(&__fds_lock); __fds_lock();
g_fds.p[pids[i]].zombie = true; g_fds.p[pids[i]].zombie = true;
_spunlock(&__fds_lock); __fds_unlock();
__sig_add(SIGCHLD, CLD_EXITED); __sig_add(SIGCHLD, CLD_EXITED);
} }

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/sigbits.h" #include "libc/calls/struct/sigset.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
/** /**

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/sigbits.h" #include "libc/calls/struct/sigset.h"
#include "libc/str/str.h" #include "libc/str/str.h"
/** /**

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/sigbits.h" #include "libc/calls/struct/sigset.h"
#include "libc/str/str.h" #include "libc/str/str.h"
/** /**

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/sigbits.h" #include "libc/calls/struct/sigset.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
/** /**

View file

@ -18,6 +18,7 @@
*/ */
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/str/str.h"
int sys_sigprocmask(int how, const sigset_t *opt_set, int sys_sigprocmask(int how, const sigset_t *opt_set,
sigset_t *opt_out_oldset) { sigset_t *opt_out_oldset) {

View file

@ -20,7 +20,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/sig.internal.h" #include "libc/calls/sig.internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/dce.h" #include "libc/dce.h"

View file

@ -20,7 +20,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/sig.internal.h" #include "libc/calls/sig.internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/dce.h" #include "libc/dce.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/struct/stat.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
/** /**

View file

@ -4,13 +4,16 @@
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_
hidden extern int __vforked; hidden extern int __vforked;
hidden extern int __fds_lock; hidden extern int __fds_lock_obj;
hidden extern int __sig_lock_obj; hidden extern int __sig_lock_obj;
hidden extern bool __time_critical; hidden extern bool __time_critical;
hidden extern unsigned __sighandrvas[NSIG]; hidden extern unsigned __sighandrvas[NSIG];
hidden extern unsigned __sighandflags[NSIG]; hidden extern unsigned __sighandflags[NSIG];
hidden extern const struct NtSecurityAttributes kNtIsInheritable; hidden extern const struct NtSecurityAttributes kNtIsInheritable;
void __fds_lock(void);
void __fds_unlock(void);
COSMOPOLITAN_C_END_ COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STATE_INTERNAL_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STATE_INTERNAL_H_ */

View file

@ -13,5 +13,13 @@ struct dirent { /* linux getdents64 abi */
struct dirstream; struct dirstream;
typedef struct dirstream DIR; typedef struct dirstream DIR;
DIR *fdopendir(int) dontdiscard;
DIR *opendir(const char *) dontdiscard;
int closedir(DIR *);
int dirfd(DIR *);
long telldir(DIR *);
struct dirent *readdir(DIR *);
void rewinddir(DIR *);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_ */

View file

@ -7,5 +7,9 @@ struct iovec {
size_t iov_len; size_t iov_len;
}; };
ssize_t preadv(int, struct iovec *, int, int64_t);
ssize_t pwritev(int, const struct iovec *, int, int64_t);
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_ */

View file

@ -7,5 +7,8 @@ struct rlimit {
uint64_t rlim_max; /* maximum limit in bytes */ uint64_t rlim_max; /* maximum limit in bytes */
}; };
int getrlimit(int, struct rlimit *);
int setrlimit(int, const struct rlimit *);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_ */

View file

@ -4,28 +4,27 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
struct rusage { struct rusage {
union { struct timeval ru_utime; /* user CPU time used */
struct { struct timeval ru_stime; /* system CPU time used */
struct timeval ru_utime; /* user CPU time used */ int64_t ru_maxrss; /* maximum resident set size in (kb) */
struct timeval ru_stime; /* system CPU time used */ int64_t ru_ixrss; /* shared memory size (integral kb CLK_TCK) */
int64_t ru_maxrss; /* maximum resident set size in (kb) */ int64_t ru_idrss; /* unshared data size (integral kb CLK_TCK) */
int64_t ru_ixrss; /* shared memory size (integral kb CLK_TCK) */ int64_t ru_isrss; /* unshared stack size (integral kb CLK_TCK) */
int64_t ru_idrss; /* unshared data size (integral kb CLK_TCK) */ int64_t ru_minflt; /* page reclaims */
int64_t ru_isrss; /* unshared stack size (integral kb CLK_TCK) */ int64_t ru_majflt; /* page faults */
int64_t ru_minflt; /* page reclaims */ int64_t ru_nswap; /* swaps */
int64_t ru_majflt; /* page faults */ int64_t ru_inblock; /* block input operations */
int64_t ru_nswap; /* swaps */ int64_t ru_oublock; /* block output operations */
int64_t ru_inblock; /* block input operations */ int64_t ru_msgsnd; /* IPC messages sent */
int64_t ru_oublock; /* block output operations */ int64_t ru_msgrcv; /* IPC messages received */
int64_t ru_msgsnd; /* IPC messages sent */ int64_t ru_nsignals; /* signals received */
int64_t ru_msgrcv; /* IPC messages received */ int64_t ru_nvcsw; /* voluntary context switches */
int64_t ru_nsignals; /* signals received */ int64_t ru_nivcsw; /* involuntary context switches */
int64_t ru_nvcsw; /* voluntary context switches */
int64_t ru_nivcsw; /* involuntary context switches */
};
uint8_t __conservatism[1024];
};
}; };
int getrusage(int, struct rusage *);
int wait3(int *, int, struct rusage *);
int wait4(int, int *, int, struct rusage *);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_ */

View file

@ -4,6 +4,7 @@
#include "libc/calls/typedef/sigaction_f.h" #include "libc/calls/typedef/sigaction_f.h"
#include "libc/calls/typedef/sighandler_t.h" #include "libc/calls/typedef/sighandler_t.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/sysv/consts/sig.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
struct sigaction { /* cosmo abi */ struct sigaction { /* cosmo abi */

View file

@ -6,5 +6,14 @@ typedef struct sigset {
uint64_t __bits[2]; uint64_t __bits[2];
} sigset_t; } sigset_t;
int sigprocmask(int, const sigset_t *, sigset_t *);
int sigsuspend(const sigset_t *);
int sigaddset(sigset_t *, int) paramsnonnull();
int sigdelset(sigset_t *, int) paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull();
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ */

View file

@ -7,5 +7,7 @@ union sigval {
void *sival_ptr; void *sival_ptr;
}; };
int sigqueue(int, int, const union sigval);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_ */

View file

@ -22,5 +22,10 @@ struct stat { /* cosmo abi */
uint64_t st_gen; /* xnu/bsd only */ uint64_t st_gen; /* xnu/bsd only */
}; };
int stat(const char *, struct stat *);
int lstat(const char *, struct stat *);
int fstat(int, struct stat *);
int fstatat(int, const char *, struct stat *, int);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_H_ */

View file

@ -18,5 +18,7 @@ struct sysinfo {
uint32_t mem_unit; /* ram stuff above is multiples of this */ uint32_t mem_unit; /* ram stuff above is multiples of this */
}; };
int sysinfo(struct sysinfo *);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_ */

View file

@ -7,5 +7,7 @@ struct timespec {
int64_t tv_nsec; /* nanoseconds */ int64_t tv_nsec; /* nanoseconds */
}; };
int futex(uint32_t *, int, int, const struct timespec *, uint32_t *);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_ */

View file

@ -7,5 +7,7 @@ struct timeval {
int64_t tv_usec; /* microseconds */ int64_t tv_usec; /* microseconds */
}; };
int lutimes(const char *, const struct timeval[2]);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_ */

View file

@ -9,5 +9,7 @@ struct tms {
int64_t tms_cstime; /* children kernelspace time */ int64_t tms_cstime; /* children kernelspace time */
}; };
long times(struct tms *);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_ */

View file

@ -14,5 +14,7 @@ struct utsname {
char domainname[SYS_NMLN]; char domainname[SYS_NMLN];
}; };
int uname(struct utsname *);
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_UTSNAME_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_UTSNAME_H_ */

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/struct/rusage.h"
/** /**
* Waits for status to change on any child process. * Waits for status to change on any child process.

View file

@ -16,8 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/struct/rusage.h"
#include "libc/dce.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"
/** /**

View file

@ -20,7 +20,6 @@
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/sig.internal.h" #include "libc/calls/sig.internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/rusage.h" #include "libc/calls/struct/rusage.h"
@ -60,7 +59,7 @@ static textwindows int sys_wait4_nt_impl(int pid, int *opt_out_wstatus,
struct NtProcessMemoryCountersEx memcount; struct NtProcessMemoryCountersEx memcount;
struct NtFileTime createfiletime, exitfiletime, kernelfiletime, userfiletime; struct NtFileTime createfiletime, exitfiletime, kernelfiletime, userfiletime;
if (_check_interrupts(true, g_fds.p)) return eintr(); if (_check_interrupts(true, g_fds.p)) return eintr();
_spinlock(&__fds_lock); __fds_lock();
if (pid != -1 && pid != 0) { if (pid != -1 && pid != 0) {
if (pid < 0) { if (pid < 0) {
/* XXX: this is sloppy */ /* XXX: this is sloppy */
@ -76,12 +75,12 @@ static textwindows int sys_wait4_nt_impl(int pid, int *opt_out_wstatus,
g_fds.p[pid].handle = handle; g_fds.p[pid].handle = handle;
g_fds.p[pid].flags = O_CLOEXEC; g_fds.p[pid].flags = O_CLOEXEC;
} else { } else {
_spunlock(&__fds_lock); __fds_unlock();
CloseHandle(handle); CloseHandle(handle);
return echild(); return echild();
} }
} else { } else {
_spunlock(&__fds_lock); __fds_unlock();
return echild(); return echild();
} }
} }
@ -91,11 +90,11 @@ static textwindows int sys_wait4_nt_impl(int pid, int *opt_out_wstatus,
} else { } else {
count = __sample_pids(pids, handles, false); count = __sample_pids(pids, handles, false);
if (!count) { if (!count) {
_spunlock(&__fds_lock); __fds_unlock();
return echild(); return echild();
} }
} }
_spunlock(&__fds_lock); __fds_unlock();
for (;;) { for (;;) {
if (_check_interrupts(true, 0)) return eintr(); if (_check_interrupts(true, 0)) return eintr();
dwExitCode = kNtStillActive; dwExitCode = kNtStillActive;

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/struct/rusage.h"
/** /**
* Waits for status to change on process. * Waits for status to change on process.

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/sig.internal.h" #include "libc/calls/sig.internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/typedef/sigaction_f.h" #include "libc/calls/typedef/sigaction_f.h"

View file

@ -0,0 +1,24 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
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.
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.
*/
#include "libc/macros.internal.h"
.privileged
_spinlock_gettid:
jmp gettid
.endfn _spinlock_gettid,globl

View file

@ -0,0 +1,24 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
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.
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.
*/
#include "libc/macros.internal.h"
.privileged
_spinlock_yield:
jmp sched_yield
.endfn _spinlock_yield,globl

View file

@ -27,7 +27,7 @@
privileged int _trylock_debug_4(int *lock, const char *lockname, privileged int _trylock_debug_4(int *lock, const char *lockname,
const char *file, int line, const char *func) { const char *file, int line, const char *func) {
int owner = 0; int owner = 0;
int me = gettid(); int me = _spinlock_gettid();
if (_lockcmpxchgp(lock, &owner, me)) { if (_lockcmpxchgp(lock, &owner, me)) {
return 0; return 0;
} else if (owner != me) { } else if (owner != me) {

View file

@ -19,13 +19,22 @@
#include "libc/bits/pushpop.h" #include "libc/bits/pushpop.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/intrin/spinlock.h"
#include "libc/nt/runtime.h" #include "libc/nt/runtime.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
STATIC_YOINK("_init_g_fds"); STATIC_YOINK("_init_g_fds");
struct Fds g_fds; struct Fds g_fds;
_Alignas(64) int __fds_lock; _Alignas(64) int __fds_lock_obj;
void __fds_lock(void) {
_spinlock(&__fds_lock_obj);
}
void __fds_unlock(void) {
_spunlock(&__fds_lock_obj);
}
textstartup void InitializeFileDescriptors(void) { textstartup void InitializeFileDescriptors(void) {
struct Fds *fds; struct Fds *fds;

View file

@ -22,7 +22,7 @@
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
void __releasefd(int fd) { void __releasefd(int fd) {
_spinlock(&__fds_lock); __fds_lock();
__releasefd_unlocked(fd); __releasefd_unlocked(fd);
_spunlock(&__fds_lock); __fds_unlock();
} }

View file

@ -1,15 +1,11 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_ #ifndef COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_
#define COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_ #define COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/intrin/lockcmpxchg.h"
#include "libc/intrin/lockcmpxchgp.h"
/*───────────────────────────────────────────────────────────────────────────│─╗ /*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § spinlocks cosmopolitan § spinlocks
privileged unsophisticated locking subroutines */ privileged unsophisticated locking subroutines */
#if IsModeDbg() && !defined(_SPINLOCK_DEBUG) #if defined(MODE_DBG) && !defined(_SPINLOCK_DEBUG)
#define _SPINLOCK_DEBUG #define _SPINLOCK_DEBUG
#endif #endif
@ -17,7 +13,7 @@
#define _spinlock(lock) _spinlock_ndebug(lock) #define _spinlock(lock) _spinlock_ndebug(lock)
#define _spinlock_ndebug(lock) _spinlock_cooperative(lock) #define _spinlock_ndebug(lock) _spinlock_cooperative(lock)
#define _trylock(lock) _trylock_debug(lock) #define _trylock(lock) _trylock_debug(lock)
#define _seizelock(lock) _seizelock_impl(lock, gettid()) #define _seizelock(lock) _seizelock_impl(lock, _spinlock_gettid())
#elif defined(TINY) #elif defined(TINY)
#define _spinlock(lock) _spinlock_tiny(lock) #define _spinlock(lock) _spinlock_tiny(lock)
#define _spinlock_ndebug(lock) _spinlock_tiny(lock) #define _spinlock_ndebug(lock) _spinlock_tiny(lock)
@ -72,12 +68,14 @@
} else if (++__tries & 7) { \ } else if (++__tries & 7) { \
__builtin_ia32_pause(); \ __builtin_ia32_pause(); \
} else { \ } else { \
sched_yield(); \ _spinlock_yield(); \
} \ } \
} \ } \
} while (0) } while (0)
int _spinlock_gettid(void);
int _trylock_debug_4(int *, const char *, const char *, int, const char *); int _trylock_debug_4(int *, const char *, const char *, int, const char *);
void _spinlock_debug_4(int *, const char *, const char *, int, const char *); void _spinlock_debug_4(int *, const char *, const char *, int, const char *);
void _spinlock_yield(void);
#endif /* COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_ */ #endif /* COSMOPOLITAN_LIBC_INTRIN_SPINLOCK_H_ */

View file

@ -1,7 +1,6 @@
#ifndef LIBC_ISYSTEM_SIGNAL_H_ #ifndef LIBC_ISYSTEM_SIGNAL_H_
#define LIBC_ISYSTEM_SIGNAL_H_ #define LIBC_ISYSTEM_SIGNAL_H_
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/siginfo.h"
#include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/sicode.h"

View file

@ -1,5 +1,4 @@
#ifndef LIBC_ISYSTEM_SYS_UTSNAME_H_ #ifndef LIBC_ISYSTEM_SYS_UTSNAME_H_
#define LIBC_ISYSTEM_SYS_UTSNAME_H_ #define LIBC_ISYSTEM_SYS_UTSNAME_H_
#include "libc/calls/calls.h"
#include "libc/calls/struct/utsname.h" #include "libc/calls/struct/utsname.h"
#endif #endif

View file

@ -21,7 +21,6 @@
#include "libc/bits/safemacros.internal.h" #include "libc/bits/safemacros.internal.h"
#include "libc/bits/weaken.h" #include "libc/bits/weaken.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/syscall_support-sysv.internal.h" #include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h" #include "libc/dce.h"

View file

@ -21,6 +21,7 @@
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/intrin/lockcmpxchg.h" #include "libc/intrin/lockcmpxchg.h"
#include "libc/mem/mem.h"
#include "libc/runtime/internal.h" #include "libc/runtime/internal.h"
#include "libc/runtime/memtrack.internal.h" #include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/dprintf.h"
#include "libc/fmt/fmt.h" #include "libc/fmt/fmt.h"
#include "libc/log/log.h" #include "libc/log/log.h"
#include "libc/mem/mem.h" #include "libc/mem/mem.h"

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/dprintf.h"
#include "libc/log/log.h" #include "libc/log/log.h"
#include "libc/mem/mem.h" #include "libc/mem/mem.h"

View file

@ -18,10 +18,10 @@
*/ */
#include "libc/bits/weaken.h" #include "libc/bits/weaken.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/state.internal.h" #include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/utsname.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/asan.internal.h" #include "libc/intrin/asan.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/bits/bits.h" #include "libc/bits/bits.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h" #include "libc/calls/struct/siginfo.h"
#include "libc/calls/ucontext.h" #include "libc/calls/ucontext.h"

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigaction.h" #include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigaltstack.h" #include "libc/calls/struct/sigaltstack.h"
#include "libc/log/internal.h" #include "libc/log/internal.h"

View file

@ -19,6 +19,7 @@
#include "libc/bits/bits.h" #include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h" #include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/dprintf.h"
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/stat.h" #include "libc/calls/struct/stat.h"
#include "libc/calls/struct/timeval.h" #include "libc/calls/struct/timeval.h"

View file

@ -1,6 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_ #ifndef COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_ #define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_
#include "libc/bits/asmflag.h" #include "libc/bits/asmflag.h"
#include "libc/dce.h"
#include "libc/nexgen32e/x86feature.h" #include "libc/nexgen32e/x86feature.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0) #if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_ COSMOPOLITAN_C_START_

View file

@ -16,16 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/weaken.h"
#include "libc/calls/calls.h"
#include "libc/intrin/spinlock.h" #include "libc/intrin/spinlock.h"
#include "libc/nexgen32e/rdtsc.h" #include "libc/nexgen32e/rdtsc.h"
#include "libc/nt/thread.h"
#include "libc/rand/rand.h"
#include "libc/runtime/internal.h" #include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/auxv.h"
static int thepid; static int thepid;

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sig.internal.h" #include "libc/calls/sig.internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/runtime/internal.h" #include "libc/runtime/internal.h"

View file

@ -20,6 +20,7 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/fmt/conv.h" #include "libc/fmt/conv.h"
#include "libc/runtime/clktck.h" #include "libc/runtime/clktck.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/auxv.h" #include "libc/sysv/consts/auxv.h"
struct clockinfo_netbsd { struct clockinfo_netbsd {

View file

@ -31,6 +31,7 @@
#include "libc/nt/thread.h" #include "libc/nt/thread.h"
#include "libc/nt/thunk/msabi.h" #include "libc/nt/thunk/msabi.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/clone.h" #include "libc/sysv/consts/clone.h"
#include "libc/sysv/consts/futex.h" #include "libc/sysv/consts/futex.h"
#include "libc/sysv/consts/nr.h" #include "libc/sysv/consts/nr.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h" #include "libc/runtime/symbols.internal.h"
/** /**

View file

@ -47,6 +47,7 @@
#include "libc/runtime/internal.h" #include "libc/runtime/internal.h"
#include "libc/runtime/memtrack.internal.h" #include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h" #include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h" #include "libc/sysv/consts/prot.h"

View file

@ -21,6 +21,7 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
#include "libc/runtime/runtime.h" #include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h" #include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h" #include "libc/sysv/errfuns.h"

View file

@ -16,10 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h" #include "libc/calls/struct/rlimit.h"
#include "libc/limits.h" #include "libc/limits.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/rlim.h" #include "libc/sysv/consts/rlim.h"
long GetResourceLimit(int resource) { long GetResourceLimit(int resource) {

View file

@ -18,7 +18,6 @@
*/ */
#include "libc/bits/bits.h" #include "libc/bits/bits.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"

View file

@ -19,7 +19,6 @@
#define ShouldUseMsabiAttribute() 1 #define ShouldUseMsabiAttribute() 1
#include "libc/bits/asmflag.h" #include "libc/bits/asmflag.h"
#include "libc/calls/internal.h" #include "libc/calls/internal.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/errno.h" #include "libc/errno.h"

View file

@ -20,6 +20,7 @@
#include "libc/calls/strace.internal.h" #include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigset.h" #include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/termios.h" #include "libc/calls/struct/termios.h"
#include "libc/calls/struct/utsname.h"
#include "libc/calls/termios.h" #include "libc/calls/termios.h"
#include "libc/calls/ttydefaults.h" #include "libc/calls/ttydefaults.h"
#include "libc/dce.h" #include "libc/dce.h"

View file

@ -16,14 +16,10 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/runtime/clktck.h" #include "libc/runtime/clktck.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h" #include "libc/runtime/sysconf.h"
#include "libc/sysv/consts/limits.h" #include "libc/sysv/consts/limits.h"
#include "libc/sysv/consts/rlim.h"
#include "libc/sysv/consts/rlimit.h" #include "libc/sysv/consts/rlimit.h"
/** /**

View file

@ -52,7 +52,7 @@ textwindows int sys_accept_nt(struct Fd *fd, void *addr, uint32_t *addrsize,
if ((!(flags & SOCK_NONBLOCK) || if ((!(flags & SOCK_NONBLOCK) ||
__sys_ioctlsocket_nt(h, FIONBIO, (uint32_t[]){1}) != -1) && __sys_ioctlsocket_nt(h, FIONBIO, (uint32_t[]){1}) != -1) &&
(sockfd2 = calloc(1, sizeof(struct SockFd)))) { (sockfd2 = calloc(1, sizeof(struct SockFd)))) {
_spinlock(&__fds_lock); __fds_lock();
if ((client = __reservefd_unlocked(-1)) != -1) { if ((client = __reservefd_unlocked(-1)) != -1) {
sockfd2->family = sockfd->family; sockfd2->family = sockfd->family;
sockfd2->type = sockfd->type; sockfd2->type = sockfd->type;
@ -62,10 +62,10 @@ textwindows int sys_accept_nt(struct Fd *fd, void *addr, uint32_t *addrsize,
g_fds.p[client].mode = 0140666; g_fds.p[client].mode = 0140666;
g_fds.p[client].handle = h; g_fds.p[client].handle = h;
g_fds.p[client].extra = (uintptr_t)sockfd2; g_fds.p[client].extra = (uintptr_t)sockfd2;
_spunlock(&__fds_lock); __fds_unlock();
return client; return client;
} }
_spunlock(&__fds_lock); __fds_unlock();
free(sockfd2); free(sockfd2);
} }
__sys_closesocket_nt(h); __sys_closesocket_nt(h);

View file

@ -1342,12 +1342,12 @@ static textwindows dontinline int sys_epoll_create1_nt(uint32_t flags) {
__releasefd(fd); __releasefd(fd);
return -1; return -1;
} }
_spinlock(&__fds_lock); __fds_lock();
g_fds.p[fd].kind = kFdEpoll; g_fds.p[fd].kind = kFdEpoll;
g_fds.p[fd].handle = ephnd; g_fds.p[fd].handle = ephnd;
g_fds.p[fd].flags = flags; g_fds.p[fd].flags = flags;
g_fds.p[fd].mode = 0140666; g_fds.p[fd].mode = 0140666;
_spunlock(&__fds_lock); __fds_unlock();
return fd; return fd;
} }

View file

@ -64,13 +64,13 @@ textwindows int sys_socket_nt(int family, int type, int protocol) {
sockfd->family = family; sockfd->family = family;
sockfd->type = truetype; sockfd->type = truetype;
sockfd->protocol = protocol; sockfd->protocol = protocol;
_spinlock(&__fds_lock); __fds_lock();
g_fds.p[fd].kind = kFdSocket; g_fds.p[fd].kind = kFdSocket;
g_fds.p[fd].flags = oflags; g_fds.p[fd].flags = oflags;
g_fds.p[fd].mode = 0140666; g_fds.p[fd].mode = 0140666;
g_fds.p[fd].handle = h; g_fds.p[fd].handle = h;
g_fds.p[fd].extra = (uintptr_t)sockfd; g_fds.p[fd].extra = (uintptr_t)sockfd;
_spunlock(&__fds_lock); __fds_unlock();
return fd; return fd;
} else { } else {
__releasefd(fd); __releasefd(fd);

Some files were not shown because too many files have changed in this diff Show more