Get Cosmopolitan into releasable state

A new rollup tool now exists for flattening out the headers in a way
that works better for our purposes than cpp. A lot of the API clutter
has been removed. APIs that aren't a sure thing in terms of general
recommendation are now marked internal.

There's now a smoke test for the amalgamation archive and gigantic
header file. So we can now guarantee you can use this project on the
easiest difficulty setting without the gigantic repository.

A website is being created, which is currently a work in progress:
https://justine.storage.googleapis.com/cosmopolitan/index.html
This commit is contained in:
Justine Tunney 2020-11-25 08:19:00 -08:00
parent dba7552c1e
commit ea0b5d9d1c
775 changed files with 6864 additions and 3963 deletions

View file

@ -226,7 +226,6 @@ uint32_t getsid(int) nosideeffect;
uint32_t gettid(void) nosideeffect;
uint32_t getuid(void) nosideeffect;
uint32_t umask(int32_t);
void *getprocaddressmodule(const char *, const char *);
#define getcwd(BUF, SIZE) \
(isconstant(BUF) && (&(BUF)[0] == NULL) ? get_current_dir_name() \

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/timespec.h"

View file

@ -17,14 +17,13 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/progn.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/progn.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/conv/conv.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/nt/ntdll.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ok.h"

View file

@ -19,7 +19,7 @@
*/
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/errno.h"

View file

@ -19,6 +19,7 @@
*/
#include "libc/calls/internal.h"
#include "libc/nt/enum/filemapflags.h"
#include "libc/nt/enum/pageflags.h"
#include "libc/nt/memory.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/prot.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/conv/conv.h"
@ -32,8 +32,8 @@
#include "libc/sysv/consts/s.h"
textwindows int fstat$nt(int64_t handle, struct stat *st) {
int filetype;
uint64_t actualsize;
enum NtFileType filetype;
struct NtByHandleFileInformation wst;
struct NtFileCompressionInfo fci;
if (GetFileInformationByHandle(handle, &wst)) {

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/initializer.h"
#include "libc/bits/initializer.internal.h"
#include "libc/bits/pushpop.h"
#include "libc/calls/internal.h"
#include "libc/nt/runtime.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"

View file

@ -22,21 +22,20 @@
#include "libc/calls/internal.h"
#include "libc/dce.h"
#include "libc/nt/process.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
static int g_pid;
static void __updatepid(void) {
g_pid = __getpid();
static int __get_pid(void) {
if (!IsWindows()) {
return getpid$sysv();
} else {
return GetCurrentProcessId();
}
}
int __getpid(void) {
if (!IsWindows()) {
return GETPID();
} else {
return NtGetPid();
}
static void __update_pid(void) {
g_pid = __get_pid();
}
/**
@ -46,8 +45,8 @@ int __getpid(void) {
int getpid(void) {
static bool once;
if (!once) {
__updatepid();
atfork(__updatepid, NULL);
__update_pid();
atfork(__update_pid, NULL);
once = true;
}
return g_pid;

View file

@ -20,8 +20,9 @@
#include "libc/bits/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/kntprioritycombos.h"
#include "libc/calls/kntprioritycombos.internal.h"
#include "libc/conv/conv.h"
#include "libc/nexgen32e/ffs.h"
#include "libc/nt/enum/processcreationflags.h"
#include "libc/nt/enum/threadpriority.h"
#include "libc/nt/process.h"

View file

@ -17,12 +17,12 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/nt/dll.h"
#include "libc/calls/calls.h"
/**
* Returns address of function in a DLL that's already loaded.
*/
textwindows void *getprocaddressmodule(const char *module, const char *symbol) {
textwindows void *GetProcAddressModule(const char *module, const char *symbol) {
return GetProcAddress(GetModuleHandle(module), symbol);
}

View file

@ -24,6 +24,8 @@
#include "libc/nt/createfile.h"
#include "libc/nt/enum/accessmask.h"
#include "libc/nt/enum/creationdisposition.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/enum/filesharemode.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/sysv/consts/at.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/progn.h"
#include "libc/bits/progn.internal.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/dirent.h"
#include "libc/dce.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/str/str.h"

View file

@ -28,7 +28,6 @@
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/memtrack.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/prot.h"

View file

@ -17,10 +17,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/calls/calls.h"
#include "libc/sysv/errfuns.h"
/**

View file

@ -17,16 +17,17 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/ntspawn.h"
#include "libc/conv/conv.h"
#include "libc/macros.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/hascharacter.h"
#include "libc/nexgen32e/hascharacter.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/oldutf16.internal.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/str/tpdecode.internal.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/errfuns.h"

View file

@ -17,13 +17,14 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/calls/hefty/ntspawn.h"
#include "libc/conv/conv.h"
#include "libc/macros.h"
#include "libc/mem/mem.h"
#include "libc/str/oldutf16.internal.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/str/tpdecode.internal.h"
#include "libc/sysv/errfuns.h"
/**

View file

@ -1,6 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_HEFTY_MKVARARGV_H_
#define COSMOPOLITAN_LIBC_CALLS_HEFTY_MKVARARGV_H_
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

View file

@ -18,9 +18,9 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/alg/arraylist.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/ntspawn.h"
#include "libc/calls/internal.h"
@ -28,7 +28,6 @@
#include "libc/nt/enum/processcreationflags.h"
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/fileno.h"

View file

@ -17,11 +17,11 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/calls/calls.h"
/**
* Replaces tilde in path w/ user home folder.

View file

@ -18,10 +18,10 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/alg/arraylist.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/calls/hefty/ntspawn.h"
#include "libc/dce.h"
#include "libc/nexgen32e/tinystrcmp.h"
#include "libc/nexgen32e/tinystrcmp.internal.h"
#include "libc/str/str.h"
static int CompareStrings(const char *l, const char *r) {

View file

@ -21,7 +21,6 @@
#include "libc/calls/hefty/mkvarargv.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/mem/mem.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
/**

View file

@ -23,6 +23,7 @@
#include "libc/calls/hefty/ntspawn.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/internal.h"
#include "libc/nt/enum/processcreationflags.h"
#include "libc/nt/enum/startf.h"
#include "libc/nt/files.h"
#include "libc/nt/ipc.h"

View file

@ -24,6 +24,7 @@
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/nt/console.h"
#include "libc/nt/enum/consolemodeflags.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"

View file

@ -196,7 +196,6 @@ void *mremap$sysv(void *, u64, u64, i32, void *) hidden;
cosmopolitan § syscalls » system five » support
*/
int __getpid(void) hidden;
void __onfork(void) hidden;
bool32 __sigenter(i32, struct siginfo *, struct ucontext *) hidden;
i32 fixupnewfd$sysv(i32, i32) hidden;
@ -246,7 +245,6 @@ int symlink$nt(const char *, const char *) hidden;
int sysinfo$nt(struct sysinfo *) hidden;
int truncate$nt(const char *, u64) hidden;
int unlink$nt(const char *) hidden;
int wait4$nt(int, int *, int, struct rusage *) hidden;
i64 lseek$nt(int, i64, int) hidden;
ssize_t read$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
ssize_t write$nt(struct Fd *, const struct iovec *, size_t, ssize_t) hidden;
@ -260,6 +258,7 @@ int nanosleep$nt(const struct timespec *, struct timespec *) hidden;
*/
void WinMainForked(void) hidden;
void *GetProcAddressModule(const char *, const char *) hidden;
int getsetpriority$nt(int, unsigned, int, int (*)(int));
void ntcontext2linux(struct ucontext *, const struct NtContext *) hidden;
struct NtOverlapped *offset2overlap(int64_t, struct NtOverlapped *) hidden;

View file

@ -18,8 +18,8 @@
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/calls/struct/metatermios.h"
#include "libc/calls/termios-internal.h"
#include "libc/calls/struct/metatermios.internal.h"
#include "libc/calls/termios.internal.h"
#include "libc/sysv/consts/termios.h"
int ioctl$tcgets$nt(int, struct termios *);

View file

@ -18,9 +18,10 @@
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/calls/struct/metatermios.h"
#include "libc/calls/termios-internal.h"
#include "libc/calls/struct/metatermios.internal.h"
#include "libc/calls/termios.internal.h"
#include "libc/nt/console.h"
#include "libc/nt/enum/consolemodeflags.h"
#include "libc/nt/enum/version.h"
#include "libc/nt/struct/teb.h"
#include "libc/sysv/consts/o.h"

View file

@ -18,8 +18,8 @@
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/calls/struct/metatermios.h"
#include "libc/calls/termios-internal.h"
#include "libc/calls/struct/metatermios.internal.h"
#include "libc/calls/termios.internal.h"
#include "libc/dce.h"
#include "libc/sysv/consts/termios.h"

View file

@ -1,20 +1,20 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_IOCTL_H_
#define COSMOPOLITAN_LIBC_CALLS_IOCTL_H_
#include "libc/macros.h"
#include "libc/sysv/consts/termios.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » input output control
cosmopolitan § system calls » ioctl
*/
int ioctl(int, uint64_t, void *);
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » input output control » undiamonding
cosmopolitan § system calls » ioctl » undiamonding (size optimization)
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#include "libc/macros.h"
#include "libc/sysv/consts/termios.h"
#define ioctl(FD, REQUEST, MEMORY) ioctl$dispatch(FD, REQUEST, MEMORY)

View file

@ -18,13 +18,13 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/conv/conv.h"
#include "libc/dce.h"
#include "libc/log/log.h"
#include "libc/nexgen32e/vendor.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/nt/struct/teb.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"

View file

@ -40,10 +40,15 @@
* @asyncsignalsafe
*/
int kill(int pid, int sig) {
if (pid == getpid()) return raise(sig);
int me;
if (!IsWindows()) {
return kill$sysv(pid, sig, 1);
} else {
return enosys();
me = getpid();
if (!pid || pid == me || pid == -me) {
return raise(sig);
} else {
return enosys();
}
}
}

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/calls/kntprioritycombos.h"
#include "libc/calls/kntprioritycombos.internal.h"
#include "libc/limits.h"
#include "libc/macros.h"
#include "libc/nt/enum/processcreationflags.h"

View file

@ -19,6 +19,7 @@
*/
#include "libc/calls/internal.h"
#include "libc/macros.h"
#include "libc/nt/enum/offerpriority.h"
#include "libc/nt/memory.h"
#include "libc/nt/runtime.h"
#include "libc/nt/struct/memoryrangeentry.h"
@ -31,7 +32,7 @@ forceinline typeof(PrefetchVirtualMemory) *GetPrefetchVirtualMemory(void) {
if (!once) {
once = true;
PrefetchVirtualMemory_ = /* win8.1+ */
getprocaddressmodule("KernelBase.dll", "PrefetchVirtualMemory");
GetProcAddressModule("KernelBase.dll", "PrefetchVirtualMemory");
}
return PrefetchVirtualMemory_;
}
@ -42,7 +43,7 @@ forceinline typeof(OfferVirtualMemory) *GetOfferVirtualMemory(void) {
if (!once) {
once = true;
OfferVirtualMemory_ = /* win8.1+ */
getprocaddressmodule("KernelBase.dll", "OfferVirtualMemory");
GetProcAddressModule("KernelBase.dll", "OfferVirtualMemory");
}
return OfferVirtualMemory_;
}

View file

@ -17,10 +17,11 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/calls/ntmagicpaths.h"
#include "libc/nexgen32e/tinystrcmp.h"
#include "libc/calls/ntmagicpaths.internal.h"
#include "libc/nexgen32e/tinystrcmp.internal.h"
#include "libc/str/oldutf16.internal.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/str/tpdecode.internal.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/errfuns.h"

View file

@ -22,6 +22,7 @@
#include "libc/macros.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/sock/internal.h"
#include "libc/sock/select.internal.h"
int nanosleep$xnu(const struct timespec *req, struct timespec *rem) {
long millis;

View file

@ -17,12 +17,14 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/conv/conv.h"
#include "libc/sysv/consts/prio.h"
static int clamp(int p) { return max(-NZERO, min(NZERO - 1, p)); }
static int clamp(int p) {
return max(-NZERO, min(NZERO - 1, p));
}
/**
* Changes process priority.

View file

@ -18,8 +18,8 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/initializer.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/initializer.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/nexgen32e/rdtsc.h"

View file

@ -20,6 +20,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/nt/enum/accessmask.h"
#include "libc/nt/enum/securityimpersonationlevel.h"
#include "libc/nt/enum/securityinformation.h"
#include "libc/nt/errors.h"
#include "libc/nt/files.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/calls/ntmagicpaths.h"
#include "libc/calls/ntmagicpaths.internal.h"
const struct NtMagicPaths kNtMagicPaths = {
#define TAB(NAME, STRING) STRING,

View file

@ -19,9 +19,12 @@
*/
#include "libc/assert.h"
#include "libc/calls/internal.h"
#include "libc/calls/ntmagicpaths.h"
#include "libc/nexgen32e/tinystrcmp.h"
#include "libc/calls/ntmagicpaths.internal.h"
#include "libc/nexgen32e/tinystrcmp.internal.h"
#include "libc/nt/createfile.h"
#include "libc/nt/enum/accessmask.h"
#include "libc/nt/enum/creationdisposition.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/enum/filesharemode.h"
#include "libc/nt/enum/filetype.h"
#include "libc/nt/enum/fsctl.h"

View file

@ -21,12 +21,14 @@
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/conv/conv.h"
#include "libc/conv/isslash.h"
#include "libc/conv/isslash.internal.h"
#include "libc/conv/itoa.h"
#include "libc/dce.h"
#include "libc/nt/createfile.h"
#include "libc/nt/enum/accessmask.h"
#include "libc/nt/enum/creationdisposition.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/enum/filesharemode.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/o.h"

View file

@ -1,34 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#ifndef COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_
#define COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » openbsd
*/
typedef unsigned char u_char;
int pledge(const char *promises, const char *execpromises);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ */

View file

@ -0,0 +1,15 @@
#ifndef COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_
#define COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » openbsd
*/
typedef unsigned char u_char;
int pledge(const char *promises, const char *execpromises);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_COMPAT_OPENBSD_H_ */

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/iovec.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/iovec.h"

View file

@ -19,7 +19,23 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/runtime/missioncritical.h"
#include "libc/nt/console.h"
#include "libc/nt/enum/ctrlevent.h"
#include "libc/nt/runtime.h"
#include "libc/sysv/consts/sig.h"
static uint32_t GetCtrlEvent(int sig) {
switch (sig) {
case SIGINT:
return kNtCtrlCEvent;
case SIGHUP:
return kNtCtrlCloseEvent;
case SIGQUIT:
return kNtCtrlBreakEvent;
default:
ExitProcess(128 + sig);
}
}
/**
* Sends signal to this process.
@ -28,4 +44,23 @@
* @return 0 on success or -1 w/ errno
* @asyncsignalsafe
*/
int raise(int sig) { return RAISE(sig); }
int raise(int sig) {
if (sig == SIGTRAP) {
DebugBreak();
return 0;
}
if (sig == SIGFPE) {
volatile int x = 0;
x = 1 / x;
return 0;
}
if (!IsWindows()) {
return kill$sysv(getpid(), sig, 1);
} else {
if (GenerateConsoleCtrlEvent(GetCtrlEvent(sig), 0)) {
return 0;
} else {
return winerr();
}
}
}

View file

@ -18,6 +18,7 @@
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/nt/enum/movefileexflags.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/str/str.h"

View file

@ -17,11 +17,13 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/dce.h"
#include "libc/limits.h"
#include "libc/nt/enum/processaccess.h"
#include "libc/nt/enum/threadaccess.h"
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/nt/thread.h"
@ -64,7 +66,6 @@ static textwindows noinline int sched_setaffinity$nt(int pid,
*
* @param pid is the process or thread id (or 0 for caller)
* @param bitsetsize is byte length of bitset
* @param bitset can be manipulated using bt(), bts(), etc.
* @return 0 on success, or -1 w/ errno
*/
int sched_setaffinity(int pid, uint64_t bitsetsize, const void *bitset) {

View file

@ -17,9 +17,9 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/internal.h"
#include "libc/calls/kntprioritycombos.h"
#include "libc/calls/kntprioritycombos.internal.h"
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/nt/thread.h"

View file

@ -20,10 +20,10 @@
#include "libc/bits/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/sigaction-freebsd.h"
#include "libc/calls/struct/sigaction-linux.h"
#include "libc/calls/struct/sigaction-openbsd.h"
#include "libc/calls/struct/sigaction-xnu.h"
#include "libc/calls/struct/sigaction-freebsd.internal.h"
#include "libc/calls/struct/sigaction-linux.internal.h"
#include "libc/calls/struct/sigaction-openbsd.internal.h"
#include "libc/calls/struct/sigaction-xnu.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/typedef/sigaction_f.h"
#include "libc/calls/ucontext.h"
@ -63,7 +63,7 @@ union metasigaction {
static void sigaction$cosmo2native(union metasigaction *sa) {
if (!sa) return;
switch (hostos) {
switch (__hostos) {
case LINUX:
SWITCHEROO(sa->cosmo, sa->linux, sa_handler, sa_flags, sa_restorer,
sa_mask);
@ -87,7 +87,7 @@ static void sigaction$cosmo2native(union metasigaction *sa) {
static void sigaction$native2cosmo(union metasigaction *sa) {
if (!sa) return;
switch (hostos) {
switch (__hostos) {
case LINUX:
SWITCHEROO(sa->linux, sa->cosmo, sa_handler, sa_flags, sa_restorer,
sa_mask);

View file

@ -18,13 +18,20 @@
02110-1301 USA
*/
#include "libc/calls/sigbits.h"
#include "libc/calls/calls.h"
#include "libc/sysv/errfuns.h"
/**
* Adds sig to set.
* Adds signal to set.
*
* @return true, false, or -1 w/ errno
* @error EINVAL
* @asyncsignalsafe
*/
int(sigaddset)(sigset_t *set, int sig) { return sigaddset(set, sig); }
int sigaddset(sigset_t *set, int sig) {
unsigned i = sig - 1;
if (i < sizeof(set->__bits) * 8) {
set->__bits[i >> 6] |= 1ull << (i & 63);
return 0;
} else {
return einval();
}
}

View file

@ -1,52 +1,14 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_SIGBITS_H_
#define COSMOPOLITAN_LIBC_CALLS_SIGBITS_H_
#include "libc/bits/bits.h"
#include "libc/bits/progn.h"
#include "libc/str/str.h"
#include "libc/calls/struct/sigset.h"
#include "libc/sysv/errfuns.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sigset;
int sigaddset(struct sigset *, int) paramsnonnull();
int sigdelset(struct sigset *, int) paramsnonnull();
int sigemptyset(struct sigset *) paramsnonnull();
int sigfillset(struct sigset *) paramsnonnull();
int sigismember(const struct sigset *, int) paramsnonnull() nosideeffect;
#define sigemptyset(SET) \
({ \
memset((SET), 0, sizeof(struct sigset)); \
0; \
})
#define sigfillset(SET) \
({ \
memset((SET), -1, sizeof(struct sigset)); \
0; \
})
#define sigaddset(SET, SIG) \
({ \
int Sig = (SIG); \
__IsValidSignal(Sig) ? PROGN(bts((SET)->sig, Sig - 1), 0) : einval(); \
})
#define sigdelset(SET, SIG) \
({ \
int Sig = (SIG); \
__IsValidSignal(Sig) ? PROGN(btr((SET)->sig, Sig - 1), 0) : einval(); \
})
#define sigismember(SET, SIG) \
({ \
int Sig = (SIG); \
__IsValidSignal(Sig) ? bt((SET)->sig, Sig - 1) : einval(); \
})
#define __IsValidSignal(SIG) (1 <= (SIG) && (SIG) <= NSIG)
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) */

View file

@ -18,13 +18,20 @@
02110-1301 USA
*/
#include "libc/calls/sigbits.h"
#include "libc/calls/calls.h"
#include "libc/sysv/errfuns.h"
/**
* Removes sig from set.
* Removes signal from set.
*
* @return 0 on success, or -1 w/ errno
* @error EINVAL
* @asyncsignalsafe
*/
int(sigdelset)(sigset_t *set, int sig) { return sigdelset(set, sig); }
int sigdelset(sigset_t *set, int sig) {
unsigned i = sig - 1;
if (i < sizeof(set->__bits) * 8) {
set->__bits[i >> 6] &= ~(1ull << (i & 63));
return 0;
} else {
return einval();
}
}

View file

@ -18,13 +18,15 @@
02110-1301 USA
*/
#include "libc/calls/sigbits.h"
#include "libc/calls/calls.h"
#include "libc/str/str.h"
/**
* Removes all signals from set.
*
* @return 0 on success, or -1 w/ errno
* @error EINVAL
* @asyncsignalsafe
*/
int(sigemptyset)(sigset_t *set) { return sigemptyset(set); }
int sigemptyset(sigset_t *set) {
memset(set->__bits, 0, sizeof(set->__bits));
return 0;
}

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/calls/sigbits.h"
#include "libc/calls/calls.h"
#include "libc/str/str.h"
/**
* Adds all signals to set.
@ -26,4 +26,7 @@
* @return 0 on success, or -1 w/ errno
* @asyncsignalsafe
*/
int(sigfillset)(sigset_t *set) { return sigfillset(set); }
int sigfillset(sigset_t *set) {
memset(set->__bits, -1, sizeof(set->__bits));
return 0;
}

View file

@ -21,6 +21,9 @@
#include "libc/calls/struct/sigaction.h"
#include "libc/str/str.h"
/**
* Configures process to ignore signal.
*/
int sigignore(int sig) {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));

View file

@ -18,13 +18,19 @@
02110-1301 USA
*/
#include "libc/calls/sigbits.h"
#include "libc/calls/calls.h"
#include "libc/sysv/errfuns.h"
/**
* Returns true if sig set.
* Returns true if signal is member of set.
*
* @return true, false, or -1 w/ errno
* @error EINVAL
* @asyncsignalsafe
*/
int(sigismember)(const sigset_t *set, int sig) { return sigismember(set, sig); }
int sigismember(const sigset_t *set, int sig) {
unsigned i = sig - 1;
if (i < sizeof(set->__bits) * 8) {
return (set->__bits[i >> 6] >> (i & 63)) & 1;
} else {
return einval();
}
}

View file

@ -20,6 +20,9 @@
#include "libc/calls/internal.h"
#include "libc/nt/createfile.h"
#include "libc/nt/enum/accessmask.h"
#include "libc/nt/enum/creationdisposition.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/enum/filesharemode.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/runtime.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/calls/struct/metastat.h"
#include "libc/calls/struct/metastat.internal.h"
#include "libc/dce.h"
#define SWITCHEROO(S1, S2, A, B, C, D, E, F, G, H, I, J, K, L, M) \

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_XNU_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_XNU_H_
#include "libc/calls/internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct __darwin_ucontext;

View file

@ -2,11 +2,9 @@
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct sigset { /* cosmo abi (linux is uint64_t) */
uint32_t sig[4]; /* ignore sig[2] and sig[3] (for freebsd) */
} aligned(8);
typedef struct sigset sigset_t;
typedef struct sigset {
uint64_t __bits[2];
} sigset_t;
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ */

View file

@ -20,6 +20,9 @@
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/nt/createfile.h"
#include "libc/nt/enum/accessmask.h"
#include "libc/nt/enum/creationdisposition.h"
#include "libc/nt/enum/filesharemode.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/sysv/consts/ok.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/sysinfo.h"

View file

@ -1,8 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_INTERNAL_H_
#ifndef __STRICT_ANSI__
#include "libc/bits/safemacros.h"
#include "libc/calls/struct/metatermios.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/struct/metatermios.internal.h"
#include "libc/calls/struct/termios.h"
#include "libc/str/str.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)

View file

@ -18,9 +18,9 @@
02110-1301 USA
*/
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/metatermios.h"
#include "libc/calls/termios-internal.h"
#include "libc/calls/struct/metatermios.internal.h"
#include "libc/calls/termios.h"
#include "libc/calls/termios.internal.h"
#include "libc/dce.h"
void *termios2host(union metatermios *t, const struct termios *lt) {

View file

@ -18,9 +18,9 @@
02110-1301 USA
*/
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/metatermios.h"
#include "libc/calls/termios-internal.h"
#include "libc/calls/struct/metatermios.internal.h"
#include "libc/calls/termios.h"
#include "libc/calls/termios.internal.h"
#include "libc/dce.h"
void termios2linux(struct termios *lt, const union metatermios *t) {

View file

@ -20,7 +20,10 @@
#include "libc/calls/internal.h"
#include "libc/conv/conv.h"
#include "libc/nt/createfile.h"
#include "libc/nt/enum/accessmask.h"
#include "libc/nt/enum/creationdisposition.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/enum/filesharemode.h"
#include "libc/nt/files.h"
#include "libc/nt/runtime.h"
#include "libc/nt/synchronization.h"

View file

@ -28,7 +28,6 @@
#include "libc/nt/runtime.h"
#include "libc/nt/struct/filetime.h"
#include "libc/nt/synchronization.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/w.h"

View file

@ -19,6 +19,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/wait4.h"
#include "libc/dce.h"
/**

11
libc/calls/wait4.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_WAIT4_H_
#define COSMOPOLITAN_LIBC_CALLS_WAIT4_H_
#include "libc/calls/struct/rusage.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int wait4$nt(int, int *, int, struct rusage *) hidden;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_WAIT4_H_ */

View file

@ -19,6 +19,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/wait4.h"
#include "libc/dce.h"
/**

View file

@ -18,14 +18,11 @@
02110-1301 USA
*/
#include "libc/calls/internal.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/ucontext.h"
#include "libc/nt/enum/exceptionhandleractions.h"
#include "libc/nt/signals.h"
#include "libc/nt/enum/signal.h"
#include "libc/nt/struct/ntexceptionpointers.h"
#include "libc/nt/struct/ntexceptionrecord.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sig.h"
textwindows unsigned __wincrash(struct NtExceptionPointers *ep) {
int sig;

View file

@ -3,23 +3,18 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
ssize_t flistxattr(int filedes, char *list, size_t size);
ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size);
int fsetxattr(int filedes, const char *name, const void *value, size_t size,
int flags);
int fremovexattr(int filedes, const char *name);
ssize_t listxattr(const char *path, char *list, size_t size);
ssize_t getxattr(const char *path, const char *name, void *value, size_t size);
int setxattr(const char *path, const char *name, const void *value, size_t size,
int flags);
int removexattr(const char *path, const char *name);
ssize_t llistxattr(const char *path, char *list, size_t size);
ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size);
int lsetxattr(const char *path, const char *name, const void *value,
size_t size, int flags);
int lremovexattr(const char *path, const char *name);
ssize_t flistxattr(int, char *, size_t);
ssize_t fgetxattr(int, const char *, void *, size_t);
int fsetxattr(int, const char *, const void *, size_t, int);
int fremovexattr(int, const char *);
ssize_t listxattr(const char *, char *, size_t);
ssize_t getxattr(const char *, const char *, void *, size_t);
int setxattr(const char *, const char *, const void *, size_t, int);
int removexattr(const char *, const char *);
ssize_t llistxattr(const char *, char *, size_t);
ssize_t lgetxattr(const char *, const char *, void *, size_t);
int lsetxattr(const char *, const char *, const void *, size_t, int);
int lremovexattr(const char *, const char *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */