Replace COSMO define with _COSMO_SOURCE

This change might cause ABI breakages for /opt/cosmos. It's needed to
help us better conform to header declaration practices.
This commit is contained in:
Justine Tunney 2023-08-13 20:31:27 -07:00
parent a033b65a33
commit c776a32f75
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
238 changed files with 858 additions and 1069 deletions

View file

@ -398,7 +398,9 @@ o/cosmopolitan.h: \
$(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS)) \
$(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_INCS))
$(file >$(TMPDIR)/$(subst /,_,$@),libc/integral/normalize.inc $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS)))
@$(ECHO) '#define COSMO' >$@
@$(ECHO) '#ifndef __STRICT_ANSI__' >$@
@$(ECHO) '#define _COSMO_SOURCE' >>$@
@$(ECHO) '#endif' >>$@
@$(COMPILE) -AROLLUP -T$@ o/$(MODE)/tool/build/rollup.com @$(TMPDIR)/$(subst /,_,$@) >>$@
o/cosmopolitan.html: private .UNSANDBOXED = 1

View file

@ -218,7 +218,7 @@ MATHEMATICAL = \
-fwrapv
DEFAULT_CPPFLAGS += \
-DCOSMO \
-D_COSMO_SOURCE \
-DMODE='"$(MODE)"' \
-DIMAGE_BASE_VIRTUAL=$(IMAGE_BASE_VIRTUAL) \
-nostdinc \

View file

@ -49,7 +49,7 @@ void List(const char *path) {
const char *vpath;
if (strcmp(path, ".") == 0) {
vpath = "";
} else if (!_endswith(path, "/")) {
} else if (!endswith(path, "/")) {
vpath = _gc(xasprintf("%s/", path));
} else {
vpath = path;

View file

@ -28,6 +28,7 @@
#include "libc/mem/arraylist2.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/stdio/stdio.h"
@ -43,7 +44,6 @@
#include "libc/x/xasprintf.h"
#include "libc/x/xsigaction.h"
#include "libc/zip.internal.h"
#include "libc/runtime/zipos.internal.h"
#include "third_party/getopt/getopt.internal.h"
#include "third_party/libcxx/vector"
#include "tool/viz/lib/knobs.h"
@ -1676,7 +1676,7 @@ char* GetLine(void) {
static char* line;
static size_t linesize;
if (getline(&line, &linesize, stdin) > 0) {
return _chomp(line);
return chomp(line);
} else {
return NULL;
}

View file

@ -147,12 +147,12 @@ int main(int argc, char *argv[]) {
if (iscntrl(code[0]) && !code[1]) {
printf("is CTRL-%c a.k.a. ^%c\r\n", CTRL(code[0]), CTRL(code[0]));
if (code[0] == CTRL('C') || code[0] == CTRL('D')) break;
} else if (_startswith(code, "\e[") && _endswith(code, "R")) {
} else if (startswith(code, "\e[") && endswith(code, "R")) {
yn = 1, xn = 1;
sscanf(code, "\e[%d;%dR", &yn, &xn);
printf("inband signalling says terminal size is %d×%d\r\n", xn, yn);
} else if (_startswith(code, "\e[<") &&
(_endswith(code, "m") || _endswith(code, "M"))) {
} else if (startswith(code, "\e[<") &&
(endswith(code, "m") || endswith(code, "M"))) {
e = 0, y = 1, x = 1;
sscanf(code, "\e[<%d;%d;%d%c", &e, &y, &x, &c);
printf("mouse %s at %d×%d\r\n", describemouseevent(e | (c == 'm') << 2),

View file

@ -80,7 +80,7 @@ char *GetTime(void) {
struct timespec ts;
clock_gettime(0, &ts);
localtime_r(&ts.tv_sec, &tm);
return _chomp(asctime(&tm));
return chomp(asctime(&tm));
}
int main(int argc, char *argv[]) {

View file

@ -1,89 +0,0 @@
#if 0
/*─────────────────────────────────────────────────────────────────╗
To the extent possible under law, Justine Tunney has waived
all copyright and related or neighboring rights to this file,
as it is written in the following disclaimers:
http://unlicense.org/ │
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"
#include "third_party/xed/x86.h"
/**
* @fileoverview x86 instruction length decoder by way of hex pipe.
*
* Here's an example of how you can use it to decode a NOP stream:
*
* $ make -j8 o//examples/x86split.com
* $ echo 909090 | o//examples/x86split.com
* 90
* 90
* 90
*
* If there was a XOR instruction in there, it'd do this:
*
* $ make -j8 o//examples/x86split.com
* $ echo 904531FF90 | o//examples/x86split.com
* 90 # NOP
* 4531FF # XOR R15D,R15D
* 90 # NOP
*
* Now that you're able to split x86 instructions the rest is easy.
*/
int fgethex(FILE *f) {
int o, t = -1;
while (!((o = fgetc(f)) & ~0xFF)) {
switch (t) {
case -1:
t = isxdigit(o) ? hextoint(o) : -1;
break;
default:
if (isxdigit(o)) {
return t * 16 + hextoint(o);
}
break;
}
}
if (t >= 0) return einval();
return -1;
}
int main(int argc, char *argv[argc]) {
int err;
unsigned c, i, j, l;
struct XedDecodedInst xedd;
unsigned char buf[XED_MAX_INSTRUCTION_BYTES];
memset(buf, 0, sizeof(buf));
for (i = 0;;) {
if (i < XED_MAX_INSTRUCTION_BYTES) {
c = fgethex(stdin);
if (c != -1) {
buf[i++] = c;
continue;
} else if (i == 0) {
break;
}
}
if ((err = xed_instruction_length_decode(
xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64),
buf, i))) {
errno = err;
break;
}
l = xedd.length;
if (l <= 0 || l > i) abort();
for (j = 0; j < l; ++j) {
fputc("0123456789ABCDEF"[(buf[j] & 0xf0) >> 4], stdout);
fputc("0123456789ABCDEF"[(buf[j] & 0x0f) >> 0], stdout);
}
putchar('\n');
memcpy(&buf[0], &buf[l], i -= l);
}
return errno;
}

View file

@ -1,13 +1,13 @@
#ifdef _ASSERT_H
#undef _ASSERT_H
#undef assert
#ifdef COSMO
#ifdef _COSMO_SOURCE
#undef unassert
#undef npassert
#ifndef NDEBUG
#undef __assert_macro
#endif /* NDEBUG */
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
#endif /* _ASSERT_H */
#ifndef _ASSERT_H
@ -27,7 +27,7 @@ void __assert_fail(const char *, const char *, int) relegated;
#define static_assert _Static_assert
#endif
#ifdef COSMO
#ifdef _COSMO_SOURCE
extern bool __assert_disable;
#ifndef NDEBUG
#define unassert(x) __assert_macro(x, #x)
@ -56,7 +56,7 @@ extern bool __assert_disable;
(void)0; \
})
#endif /* NDEBUG */
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
COSMOPOLITAN_C_END_
#endif /* _ASSERT_H */

View file

@ -19,6 +19,7 @@
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/itimerval.h"
#include "libc/calls/struct/timeval.h"
#include "libc/sysv/consts/itimer.h"
/**

View file

@ -54,6 +54,19 @@
#define WIFCONTINUED(x) __wifcontinued(x)
#define W_STOPCODE(x) ((x) << 8 | 0177)
#ifdef _COSMO_SOURCE
#define clone __clone
#define commandv __commandv
#define fileexists __fileexists
#define ischardev __ischardev
#define isdirectory __isdirectory
#define isexecutable __isexecutable
#define isregularfile __isregularfile
#define issymlink __issymlink
#define makedirs __makedirs
#define tmpfd __tmpfd
#endif
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
@ -63,7 +76,6 @@ COSMOPOLITAN_C_START_
typedef int sig_atomic_t;
bool32 isatty(int);
char *get_current_dir_name(void) dontdiscard;
char *getcwd(char *, size_t);
char *realpath(const char *, char *);
char *ttyname(int);
@ -79,15 +91,12 @@ int creat(const char *, unsigned);
int dup(int);
int dup2(int, int);
int dup3(int, int, int);
int eaccess(const char *, int);
int euidaccess(const char *, int);
int execl(const char *, const char *, ...) nullterminated();
int execle(const char *, const char *, ...) nullterminated((1));
int execlp(const char *, const char *, ...) nullterminated();
int execv(const char *, char *const[]);
int execve(const char *, char *const[], char *const[]);
int execvp(const char *, char *const[]);
int execvpe(const char *, char *const[], char *const[]);
int faccessat(int, const char *, int, int);
int fadvise(int, uint64_t, uint64_t, int);
int fchdir(int);
@ -111,12 +120,8 @@ int getpgrp(void) nosideeffect;
int getpid(void) nosideeffect libcesque;
int getppid(void);
int getpriority(int, unsigned);
int getresgid(unsigned *, unsigned *, unsigned *);
int getresuid(unsigned *, unsigned *, unsigned *);
int getsid(int) nosideeffect libcesque;
int ioctl(int, unsigned long, ...);
int ioprio_get(int, int);
int ioprio_set(int, int, int);
int issetugid(void);
int kill(int, int);
int killpg(int, int);
@ -124,7 +129,6 @@ int lchmod(const char *, unsigned);
int lchown(const char *, unsigned, unsigned);
int link(const char *, const char *) dontthrow;
int linkat(int, const char *, int, const char *, int);
int madvise(void *, uint64_t, int);
int mincore(void *, size_t, unsigned char *);
int mkdir(const char *, unsigned);
int mkdirat(int, const char *, unsigned);
@ -140,7 +144,6 @@ int pipe(int[hasatleast 2]);
int pipe2(int[hasatleast 2], int);
int posix_fadvise(int, int64_t, int64_t, int);
int posix_madvise(void *, uint64_t, int);
int prctl(int, ...);
int raise(int);
int reboot(int);
int remove(const char *);
@ -158,8 +161,6 @@ int setpgid(int, int);
int setpgrp(void);
int setpriority(int, unsigned, int);
int setregid(unsigned, unsigned);
int setresgid(unsigned, unsigned, unsigned);
int setresuid(unsigned, unsigned, unsigned);
int setreuid(unsigned, unsigned);
int setsid(void);
int setuid(unsigned);
@ -167,9 +168,6 @@ int sigignore(int);
int siginterrupt(int, int);
int symlink(const char *, const char *);
int symlinkat(const char *, int, const char *);
int sync_file_range(int, int64_t, int64_t, unsigned);
int tcgetpgrp(int);
int tcsetpgrp(int, int);
int truncate(const char *, int64_t);
int ttyname_r(int, char *, size_t);
int unlink(const char *);
@ -187,7 +185,6 @@ ssize_t pwrite(int, const void *, size_t, int64_t);
ssize_t read(int, void *, size_t);
ssize_t readlink(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, unsigned);
ssize_t write(int, const void *, size_t);
unsigned alarm(unsigned);
unsigned getegid(void) nosideeffect;
@ -198,20 +195,34 @@ unsigned sleep(unsigned);
unsigned umask(unsigned);
void sync(void);
#ifdef COSMO
bool fileexists(const char *);
bool isdirectory(const char *);
bool isexecutable(const char *);
bool isregularfile(const char *);
bool issymlink(const char *);
#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
int syncfs(int);
int prctl(int, ...);
int gettid(void) libcesque;
int setresgid(unsigned, unsigned, unsigned);
int setresuid(unsigned, unsigned, unsigned);
int getresgid(unsigned *, unsigned *, unsigned *);
int getresuid(unsigned *, unsigned *, unsigned *);
char *get_current_dir_name(void) dontdiscard;
int sync_file_range(int, int64_t, int64_t, unsigned);
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned);
int memfd_create(const char *, unsigned int);
int execvpe(const char *, char *const[], char *const[]);
int euidaccess(const char *, int);
int eaccess(const char *, int);
int madvise(void *, uint64_t, int);
#endif
#ifdef _COSMO_SOURCE
bool32 fileexists(const char *);
bool32 isdirectory(const char *);
bool32 isexecutable(const char *);
bool32 isregularfile(const char *);
bool32 issymlink(const char *);
bool32 ischardev(int);
char *commandv(const char *, char *, size_t);
char *replaceuser(const char *) dontdiscard;
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
int gettid(void) libcesque;
int makedirs(const char *, unsigned);
int memfd_create(const char *, unsigned int);
int personality(uint64_t);
int pivot_root(const char *, const char *);
int pledge(const char *, const char *);
int seccomp(unsigned, unsigned, void *);
@ -219,10 +230,13 @@ int sys_iopl(int);
int sys_mlock(const void *, size_t);
int sys_mlock2(const void *, size_t, int);
int sys_mlockall(int);
int sys_personality(uint64_t);
int sys_munlock(const void *, size_t);
int sys_munlockall(void);
int sys_ptrace(int, ...);
int sys_sysctl(const int *, unsigned, void *, size_t *, void *, size_t);
int sys_ioprio_get(int, int);
int sys_ioprio_set(int, int, int);
int tgkill(int, int, int);
int tkill(int, int);
int tmpfd(void);
@ -232,12 +246,21 @@ long ptrace(int, ...);
ssize_t copyfd(int, int, size_t);
ssize_t readansi(int, char *, size_t);
ssize_t tinyprint(int, const char *, ...) nullterminated();
#endif
#endif /* _COSMO_SOURCE */
int __wifstopped(int) pureconst;
int __wifcontinued(int) pureconst;
int __wifsignaled(int) pureconst;
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define lseek64 lseek
#define pread64 pread
#define pwrite64 pwrite
#define truncate64 truncate
#define ftruncate64 ftruncate
#define lockf64 lockf
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_ */

View file

@ -111,7 +111,7 @@ static int sys_copyfile(const char *src, const char *dst, int flags) {
* @return 0 on success, or -1 w/ errno
*/
int _copyfile(const char *src, const char *dst, int flags) {
if (!IsWindows() || _startswith(src, "/zip/") || _startswith(dst, "/zip/")) {
if (!IsWindows() || startswith(src, "/zip/") || startswith(dst, "/zip/")) {
return sys_copyfile(src, dst, flags);
} else {
return sys_copyfile_nt(src, dst, flags);

View file

@ -27,10 +27,10 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/nt/files.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/errfuns.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns true if file exists at path.
@ -44,7 +44,7 @@
* or sockets, could be considered files for the purposes of this
* function. The stat() function may be used to differentiate them.
*/
bool fileexists(const char *path) {
bool32 fileexists(const char *path) {
int e;
bool res;
union metastat st;

View file

@ -60,7 +60,7 @@ static textwindows uint32_t GetSizeOfReparsePoint(int64_t fh) {
x = 0xfffd;
}
}
z += x < 0200 ? 1 : _bsrl(_tpenc(x)) >> 3;
z += x < 0200 ? 1 : _bsrl(tpenc(x)) >> 3;
}
} else {
STRACE("%s failed %m", "GetSizeOfReparsePoint");

View file

@ -59,7 +59,7 @@ textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) {
return eio();
}
for (h = j = i = 0; FileSystemNameBuffer[i]; i++) {
w = _tpenc(FileSystemNameBuffer[i]);
w = tpenc(FileSystemNameBuffer[i]);
do {
if (j + 1 < sizeof(f->f_fstypename)) {
h = ((unsigned)(w & 255) + h) * 0x9e3779b1u;

View file

@ -61,7 +61,7 @@ textwindows char *sys_getcwd_nt(char *buf, size_t size) {
}
w = x;
} else {
w = _tpenc(x);
w = tpenc(x);
}
do {
if (j < size) {

View file

@ -27,10 +27,10 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/nt/files.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns true if file exists and is a directory.
@ -45,7 +45,7 @@
*
* @see isregularfile(), issymlink(), ischardev()
*/
bool isdirectory(const char *path) {
bool32 isdirectory(const char *path) {
int e;
bool res;
union metastat st;

View file

@ -28,7 +28,7 @@
* @asyncsignalsafe
* @vforksafe
*/
bool isexecutable(const char *path) {
bool32 isexecutable(const char *path) {
struct stat st; /* execve() depends on this */
if (fstatat(AT_FDCWD, path, &st, 0)) return 0;
return !S_ISDIR(st.st_mode) && !!(st.st_mode & 0111);

View file

@ -25,10 +25,10 @@
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns true if file exists and is a regular file.
@ -42,7 +42,7 @@
*
* @see isdirectory(), ischardev(), issymlink()
*/
bool isregularfile(const char *path) {
bool32 isregularfile(const char *path) {
int e;
bool res;
union metastat st;

View file

@ -27,10 +27,10 @@
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/nt/files.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/s.h"
#include "libc/sysv/errfuns.h"
#include "libc/runtime/zipos.internal.h"
/**
* Returns true if file exists and is a symbolic link.
@ -45,7 +45,7 @@
*
* @see isregularfile(), isdirectory(), fileexists(), ischardev()
*/
bool issymlink(const char *path) {
bool32 issymlink(const char *path) {
int e;
bool res;
union metastat st;

View file

@ -78,7 +78,7 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf,
}
w = x;
} else {
w = _tpenc(x);
w = tpenc(x);
}
do {
if (j < bufsiz) {

View file

@ -195,7 +195,7 @@ static int __sigaction(int sig, const struct sigaction *act,
ap->sa_flags |= SA_RESTORER;
ap->sa_restorer = &__restore_rt;
}
if (IsWsl1()) {
if (__iswsl1()) {
sigenter = __sigenter_wsl;
} else {
sigenter = ap->sa_sigaction;

View file

@ -18,7 +18,7 @@ int utimensat(int, const char *, const struct timespec[2], int);
int timespec_getres(struct timespec *, int);
int timespec_get(struct timespec *, int);
#ifdef COSMO
#ifdef _COSMO_SOURCE
/* cosmopolitan libc's non-posix timespec library
removed by default due to emacs codebase clash */
#define timespec_zero ((struct timespec){0})
@ -47,7 +47,7 @@ static inline bool timespec_iszero(struct timespec __ts) {
static inline bool timespec_isvalid(struct timespec __ts) {
return __ts.tv_sec >= 0 && __ts.tv_nsec < 1000000000ull;
}
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -17,7 +17,7 @@ int settimeofday(const struct timeval *, const struct timezone *);
int lutimes(const char *, const struct timeval[2]);
int utimes(const char *, const struct timeval[2]);
#ifdef COSMO
#ifdef _COSMO_SOURCE
/* cosmopolitan libc's non-posix timevals library
removed by default due to emacs codebase clash */
#define timeval_zero ((struct timeval){0})
@ -43,7 +43,7 @@ static inline bool timeval_iszero(struct timeval __tv) {
static inline bool timeval_isvalid(struct timeval __tv) {
return __tv.tv_sec >= 0 && __tv.tv_usec < 1000000ull;
}
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -1,7 +1,7 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Copyright 2023 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
@ -16,20 +16,22 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
/**
* Converts ASCII hexadecimal character to integer case-insensitively.
* @return integer or 0 if c [0-9A-Fa-f]
* Syncs filesystem associated with file descriptor.
*
* Since Linux 5.8, syncfs() will report an error if an inode failed to
* be written during the time since syncfs() was last called.
*
* @return 0 on success, or -1 w/ errno
* @raise EIO if some kind of data/metadata write error happened
* @raise ENOSPC if disk space was exhausted during sync
* @raise EDQUOT (or ENOSPC) on some kinds of NFS errors
* @raise EBADF if `fd` isn't a valid file descriptor
* @raise ENOSYS on non-Linux
*/
int hextoint(int c) {
if ('0' <= c && c <= '9') {
return c - '0';
} else if ('a' <= c && c <= 'f') {
return c - 'a' + 10;
} else if ('A' <= c && c <= 'F') {
return c - 'A' + 10;
} else {
return 0;
}
int syncfs(int fd) {
return sys_syncfs(fd);
}

View file

@ -109,6 +109,7 @@ i32 sys_sigaltstack(const void *, void *);
i32 sys_symlinkat(const char *, i32, const char *);
i32 sys_sync(void);
i32 sys_sync_file_range(i32, i64, i64, u32);
i32 sys_syncfs(i32);
i32 sys_syslog(i32, char *, i32);
i32 sys_tgkill(i32, i32, i32);
i32 sys_tkill(i32, i32, void *);

View file

@ -25,8 +25,10 @@ int posix_openpt(int) dontdiscard;
int tcdrain(int);
int tcgetsid(int);
int tcgetpgrp(int);
int tcflow(int, int);
int tcflush(int, int);
int tcsetpgrp(int, int);
int tcsendbreak(int, int);
void cfmakeraw(struct termios *);
int cfsetspeed(struct termios *, uint32_t);

View file

@ -32,7 +32,8 @@
int verynice(void) {
int e = errno;
setpriority(PRIO_PROCESS, 0, 10);
ioprio_set(IOPRIO_WHO_PROCESS, 0, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0));
sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0));
struct sched_param param = {sched_get_priority_min(SCHED_IDLE)};
sched_setscheduler(0, SCHED_IDLE, &param);
errno = e;

View file

@ -49,5 +49,13 @@ typedef uint32_t nlink_t; /* uint16_t on xnu */
#define TIME_T_MAX __INT64_MAX__
#define TIME_T_MIN (-TIME_T_MAX - 1)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define blkcnt64_t blkcnt_t
#define fsblkcnt64_t fsblkcnt_t
#define fsfilcnt64_t fsfilcnt_t
#define ino64_t ino_t
#define off64_t off_t
#endif
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_WEIRDTYPES_H_ */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_DCE_H_
#define COSMOPOLITAN_LIBC_DCE_H_
#ifdef _COSMO_SOURCE
/*─────────────────────────────────────────────────────────────────────────────╗
cosmopolitan § autotune » dead code elimination
*/
@ -119,11 +120,12 @@ COSMOPOLITAN_C_START_
extern const int __hostos;
#ifdef __x86_64__
bool IsWsl1(void);
bool __iswsl1(void);
#else
#define IsWsl1() false
#define __iswsl1() false
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */
#endif /* COSMOPOLITAN_LIBC_DCE_H_ */

View file

@ -5,8 +5,8 @@
#include "libc/elf/struct/shdr.h"
#include "libc/elf/struct/sym.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#ifdef COSMO
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § executable linkable format
*/
@ -25,7 +25,7 @@ void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
const char *GetElfSectionName(const Elf64_Ehdr *, size_t, Elf64_Shdr *);
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);
#endif /* COSMO */
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_ELF_H_ */

View file

@ -660,8 +660,11 @@ extern const errno_t EXFULL;
extern errno_t __errno;
errno_t *__errno_location(void) dontthrow pureconst;
#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
extern char *program_invocation_short_name;
extern char *program_invocation_name;
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -86,7 +86,7 @@ libcesque nosideeffect;
cosmopolitan § conversion » manipulation
*/
#ifdef COSMO
#ifdef _COSMO_SOURCE
char *stripext(char *);
char *stripexts(char *);
#endif

View file

@ -26,7 +26,7 @@ char *fcvt(double, int, int *, int *);
char *ecvt(double, int, int *, int *);
char *gcvt(double, int, char *);
#ifdef COSMO
#ifdef _COSMO_SOURCE
int __vcscanf(int (*)(void *), int (*)(int, void *), void *, const char *,
va_list);
int __fmt(void *, void *, const char *, va_list);

View file

@ -1,8 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_FMT_ITOA_H_
#define COSMOPOLITAN_LIBC_FMT_ITOA_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#ifdef COSMO
#define LengthInt64 __LengthInt64
#define LengthUint64 __LengthUint64
@ -47,7 +47,7 @@ size_t int128toarray_radix10(int128_t, char *);
size_t uint128toarray_radix10(uint128_t, char *);
#endif
#endif /* COSMO */
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_ITOA_H_ */

View file

@ -1,8 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_FMT_LEB128_H_
#define COSMOPOLITAN_LIBC_FMT_LEB128_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#ifdef COSMO
#define sleb64 __sleb64
#define zleb64 __zleb64
@ -27,7 +27,7 @@ char *uleb128(char *, uint128_t);
int unsleb128(const void *, size_t, int128_t *);
#endif /* __STRICT_ANSI__ */
#endif /* COSMO */
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_FMT_LEB128_H_ */

View file

@ -118,11 +118,11 @@ typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __WINT_TYPE__ wint_t; /* uint32_t on linux but int32_t on xnu */
typedef __INT32_TYPE__ bool32;
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ bool32;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
@ -136,7 +136,6 @@ typedef __UINTMAX_TYPE__ uintmax_t;
typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t;
#endif
typedef struct {
intptr_t ax, dx;
} axdx_t;
@ -743,7 +742,8 @@ void abort(void) wontreturn;
#pragma GCC diagnostic error "-Wtrampolines"
#if __GNUC__ >= 6
#pragma GCC diagnostic error "-Wnonnull-compare"
#if defined(COSMO) && !defined(MODE_DBG) && !defined(STACK_FRAME_UNLIMITED)
#if defined(_COSMO_SOURCE) && !defined(MODE_DBG) && \
!defined(STACK_FRAME_UNLIMITED)
#pragma GCC diagnostic error "-Wframe-larger-than=131072"
#if __GNUC__ >= 9
// #pragma GCC diagnostic error "-Walloca-larger-than=1024"

View file

@ -74,7 +74,7 @@
#define __BIGGEST_ALIGNMENT__ 16
#endif
#ifdef COSMO
#ifdef _COSMO_SOURCE
/* Programs should call GetStackSize() */
#define APE_STACKSIZE 262144 /* default 256kb stack */
#define FRAMESIZE 0x10000

View file

@ -1,53 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 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/intrin/strace.internal.h"
#include "libc/runtime/memtrack.internal.h"
dontasan bool AreMemoryIntervalsOk(const struct MemoryIntervals *mm) {
/* asan runtime depends on this function */
int i;
size_t wantsize;
for (i = 0; i < mm->i; ++i) {
if (mm->p[i].y < mm->p[i].x) {
STRACE("AreMemoryIntervalsOk() y should be >= x!");
return false;
}
wantsize = (size_t)(mm->p[i].y - mm->p[i].x) * FRAMESIZE;
if (!(wantsize < mm->p[i].size && mm->p[i].size <= wantsize + FRAMESIZE)) {
STRACE("AreMemoryIntervalsOk(%p) size is wrong!"
" %'zu not within %'zu .. %'zu",
(uintptr_t)mm->p[i].x << 16, mm->p[i].size, wantsize,
wantsize + FRAMESIZE);
return false;
}
if (i) {
if (mm->p[i].h != -1 || mm->p[i - 1].h != -1) {
if (mm->p[i].x <= mm->p[i - 1].y) {
return false;
}
} else {
if (!(mm->p[i - 1].y + 1 <= mm->p[i].x)) {
STRACE("AreMemoryIntervalsOk() out of order or overlap!");
return false;
}
}
}
}
return true;
}

View file

@ -197,7 +197,7 @@ static uint64_t __asan_roundup2pow(uint64_t x) {
static char *__asan_utf8cpy(char *p, unsigned c) {
uint64_t z;
z = _tpenc(c);
z = tpenc(c);
do *p++ = z;
while ((z >>= 8));
return p;
@ -403,7 +403,7 @@ static bool __asan_is_mapped(int x) {
struct MemoryIntervals *m;
__mmi_lock();
m = _weaken(_mmi);
i = FindMemoryInterval(m, x);
i = __find_memory(m, x);
res = i < m->i && x >= m->p[i].x;
__mmi_unlock();
return res;
@ -1411,10 +1411,10 @@ void __asan_map_shadow(uintptr_t p, size_t n) {
flag = MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS;
sm = _weaken(sys_mmap)(addr, size, prot, flag, -1, 0);
if (sm.addr == MAP_FAILED ||
_weaken(TrackMemoryInterval)(m, a, a + i - 1, sm.maphandle,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
false, false, 0, size) == -1) {
_weaken(__track_memory)(m, a, a + i - 1, sm.maphandle,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, false,
false, 0, size) == -1) {
kprintf("error: could not map asan shadow memory\n");
__asan_die()();
__asan_unreachable();
@ -1487,7 +1487,7 @@ void __asan_init(int argc, char **argv, char **envp, intptr_t *auxv) {
}
REQUIRE(_mmi);
REQUIRE(sys_mmap);
REQUIRE(TrackMemoryInterval);
REQUIRE(__track_memory);
if (_weaken(hook_malloc) || _weaken(hook_calloc) || _weaken(hook_realloc) ||
_weaken(hook_realloc_in_place) || _weaken(hook_free) ||
_weaken(hook_malloc_usable_size)) {

View file

@ -1,8 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_BITS_H_
#define COSMOPOLITAN_LIBC_BITS_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#ifdef COSMO
int _bitreverse8(int) pureconst;
int _bitreverse16(int) pureconst;
@ -99,7 +99,7 @@ uint64_t _bitreverse64(uint64_t) pureconst;
__p + 64 / 8; \
}))
#endif /* COSMO */
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_H_ */

View file

@ -1,6 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#ifdef COSMO
#ifdef _COSMO_SOURCE
#define dll_make_first __dll_make_first
#define dll_make_last __dll_make_last
#define dll_remove __dll_remove
@ -53,5 +53,5 @@ void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */

View file

@ -37,8 +37,8 @@ static void *_mapframe(void *p, int f) {
flags = f | MAP_ANONYMOUS | MAP_FIXED;
if ((dm = sys_mmap(p, G, prot, flags, -1, 0)).addr == p) {
__mmi_lock();
rc = TrackMemoryInterval(&_mmi, (uintptr_t)p >> 16, (uintptr_t)p >> 16,
dm.maphandle, prot, flags, false, false, 0, G);
rc = __track_memory(&_mmi, (uintptr_t)p >> 16, (uintptr_t)p >> 16,
dm.maphandle, prot, flags, false, false, 0, G);
__mmi_unlock();
if (!rc) {
return p;

View file

@ -19,7 +19,7 @@
#include "libc/assert.h"
#include "libc/runtime/memtrack.internal.h"
dontasan unsigned FindMemoryInterval(const struct MemoryIntervals *mm, int x) {
dontasan unsigned __find_memory(const struct MemoryIntervals *mm, int x) {
unsigned l, m, r;
l = 0;
r = mm->i;

View file

@ -1,15 +1,15 @@
#ifndef COSMOPOLITAN_LIBC_BITS_HILBERT_H_
#define COSMOPOLITAN_LIBC_BITS_HILBERT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#ifdef COSMO
#define hilbert __hilbert
#define unhilbert __unhilbert
long hilbert(long, long, long) pureconst;
axdx_t unhilbert(long, long) pureconst;
#endif /* COSMO */
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_HILBERT_H_ */

View file

@ -33,7 +33,7 @@
/**
* Returns true if host platform is WSL 1.0.
*/
bool IsWsl1(void) {
bool __iswsl1(void) {
static char res;
if (res) return res & 1;
if (!IsLinux()) return res = 2, false;

View file

@ -1,6 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
#define COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
#ifdef COSMO
#ifdef _COSMO_SOURCE
#define kprintf __kprintf
#define ksnprintf __ksnprintf
@ -26,5 +26,5 @@ void _klog(const char *, size_t);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
#endif /* COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_ */

View file

@ -1,7 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_BITS_LIKELY_H_
#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef COSMO
#ifdef _COSMO_SOURCE
#define LIKELY(x) __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
@ -18,6 +18,6 @@
#define VERY_UNLIKELY(x) UNLIKELY(x)
#endif
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_LIKELY_H_ */

View file

@ -24,7 +24,6 @@
#include "libc/intrin/bits.h"
#include "libc/intrin/directmap.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/likely.h"
#include "libc/intrin/strace.internal.h"
#include "libc/log/libfatal.internal.h"
#include "libc/log/log.h"
@ -37,18 +36,8 @@
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/errfuns.h"
#if IsModeDbg()
#define ASSERT_MEMTRACK() \
if (!AreMemoryIntervalsOk(mm)) { \
PrintMemoryIntervals(2, mm); \
notpossible; \
}
#else
#define ASSERT_MEMTRACK()
#endif
static void *MoveMemoryIntervals(struct MemoryInterval *d,
const struct MemoryInterval *s, int n) {
static void *__shove_memory(struct MemoryInterval *d,
const struct MemoryInterval *s, int n) {
int i;
unassert(n >= 0);
if (d > s) {
@ -63,14 +52,14 @@ static void *MoveMemoryIntervals(struct MemoryInterval *d,
return d;
}
static void RemoveMemoryIntervals(struct MemoryIntervals *mm, int i, int n) {
static void __remove_memory(struct MemoryIntervals *mm, int i, int n) {
unassert(i >= 0);
unassert(i + n <= mm->i);
MoveMemoryIntervals(mm->p + i, mm->p + i + n, mm->i - (i + n));
__shove_memory(mm->p + i, mm->p + i + n, mm->i - (i + n));
mm->i -= n;
}
static bool ExtendMemoryIntervals(struct MemoryIntervals *mm) {
static bool __extend_memory(struct MemoryIntervals *mm) {
int prot, flags;
char *base, *shad;
size_t gran, size;
@ -89,7 +78,7 @@ static bool ExtendMemoryIntervals(struct MemoryIntervals *mm) {
}
dm = sys_mmap(base, gran, prot, flags, -1, 0);
if (!dm.addr) return false;
MoveMemoryIntervals(dm.addr, mm->p, mm->i);
__shove_memory(dm.addr, mm->p, mm->i);
mm->p = dm.addr;
mm->n = gran / sizeof(*mm->p);
} else {
@ -104,21 +93,20 @@ static bool ExtendMemoryIntervals(struct MemoryIntervals *mm) {
if (!dm.addr) return false;
mm->n = (size + gran) / sizeof(*mm->p);
}
ASSERT_MEMTRACK();
return true;
}
int CreateMemoryInterval(struct MemoryIntervals *mm, int i) {
static int __mint_memory(struct MemoryIntervals *mm, int i) {
unassert(i >= 0);
unassert(i <= mm->i);
unassert(mm->n >= 0);
if (UNLIKELY(mm->i == mm->n) && !ExtendMemoryIntervals(mm)) return enomem();
MoveMemoryIntervals(mm->p + i + 1, mm->p + i, mm->i++ - i);
if (mm->i == mm->n && !__extend_memory(mm)) return enomem();
__shove_memory(mm->p + i + 1, mm->p + i, mm->i++ - i);
return 0;
}
static int PunchHole(struct MemoryIntervals *mm, int x, int y, int i) {
if (CreateMemoryInterval(mm, i) == -1) return -1;
static int __punch_memory(struct MemoryIntervals *mm, int x, int y, int i) {
if (__mint_memory(mm, i) == -1) return -1;
mm->p[i + 0].size -= (size_t)(mm->p[i + 0].y - (x - 1)) * FRAMESIZE;
mm->p[i + 0].y = x - 1;
mm->p[i + 1].size -= (size_t)((y + 1) - mm->p[i + 1].x) * FRAMESIZE;
@ -126,19 +114,18 @@ static int PunchHole(struct MemoryIntervals *mm, int x, int y, int i) {
return 0;
}
int ReleaseMemoryIntervals(struct MemoryIntervals *mm, int x, int y,
void wf(struct MemoryIntervals *, int, int)) {
int __untrack_memory(struct MemoryIntervals *mm, int x, int y,
void wf(struct MemoryIntervals *, int, int)) {
unsigned l, r;
ASSERT_MEMTRACK();
unassert(y >= x);
if (!mm->i) return 0;
// binary search for the lefthand side
l = FindMemoryInterval(mm, x);
l = __find_memory(mm, x);
if (l == mm->i) return 0;
if (y < mm->p[l].x) return 0;
// binary search for the righthand side
r = FindMemoryInterval(mm, y);
r = __find_memory(mm, y);
if (r == mm->i || (r > l && y < mm->p[r].x)) --r;
unassert(r >= l);
unassert(x <= mm->p[r].y);
@ -152,7 +139,7 @@ int ReleaseMemoryIntervals(struct MemoryIntervals *mm, int x, int y,
// this isn't possible on windows because we track each
// 64kb segment on that platform using a separate entry
if (l == r && x > mm->p[l].x && y < mm->p[l].y) {
return PunchHole(mm, x, y, l);
return __punch_memory(mm, x, y, l);
}
// trim the right side of the lefthand map
@ -189,18 +176,17 @@ int ReleaseMemoryIntervals(struct MemoryIntervals *mm, int x, int y,
if (IsWindows() && wf) {
wf(mm, l, r);
}
RemoveMemoryIntervals(mm, l, r - l + 1);
__remove_memory(mm, l, r - l + 1);
}
return 0;
}
int TrackMemoryInterval(struct MemoryIntervals *mm, int x, int y, long h,
int prot, int flags, bool readonlyfile, bool iscow,
long offset, long size) {
int __track_memory(struct MemoryIntervals *mm, int x, int y, long h, int prot,
int flags, bool readonlyfile, bool iscow, long offset,
long size) {
unsigned i;
ASSERT_MEMTRACK();
unassert(y >= x);
i = FindMemoryInterval(mm, x);
i = __find_memory(mm, x);
// try to extend the righthand side of the lefthand entry
// we can't do that if we're tracking independent handles
@ -216,7 +202,7 @@ int TrackMemoryInterval(struct MemoryIntervals *mm, int x, int y, long h,
prot == mm->p[i].prot && flags == mm->p[i].flags) {
mm->p[i - 1].y = mm->p[i].y;
mm->p[i - 1].size += mm->p[i].size;
RemoveMemoryIntervals(mm, i, 1);
__remove_memory(mm, i, 1);
}
}
@ -231,7 +217,7 @@ int TrackMemoryInterval(struct MemoryIntervals *mm, int x, int y, long h,
// otherwise, create a new entry and memmove the items
else {
if (CreateMemoryInterval(mm, i) == -1) return -1;
if (__mint_memory(mm, i) == -1) return -1;
mm->p[i].x = x;
mm->p[i].y = y;
mm->p[i].h = h;

View file

@ -1,8 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_BITS_PUSHPOP_H_
#define COSMOPOLITAN_LIBC_BITS_PUSHPOP_H_
#ifdef _COSMO_SOURCE
#include "libc/macros.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef COSMO
#if !defined(__GNUC__) || defined(__STRICT_ANSI__) || !defined(__x86_64__) || \
!defined(__MNO_RED_ZONE__)
@ -54,6 +54,6 @@
})
#endif
#endif /* COSMO */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */
#endif /* COSMOPOLITAN_LIBC_BITS_PUSHPOP_H_ */

View file

@ -1,7 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
#define COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef COSMO
#ifdef _COSMO_SOURCE
forceinline void repmovsb(void **dest, const void **src, size_t cx) {
char *di = (char *)*dest;
@ -23,6 +23,6 @@ forceinline void repmovsb(void **dest, const void **src, size_t cx) {
})
#endif
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_ */

View file

@ -1,7 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
#define COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef COSMO
#ifdef _COSMO_SOURCE
forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
unsigned char *di = (unsigned char *)dest;
@ -22,6 +22,6 @@ forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
})
#endif
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_ */

View file

@ -2,7 +2,7 @@
#define COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#ifdef COSMO
#ifdef _COSMO_SOURCE
/**
* Reads scalar from memory, offset by segment.
@ -20,7 +20,7 @@
Pk; \
})
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
#endif /* __GNUC__ && !__STRICT_ANSI__ */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_SEGMENTATION_H_ */

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bsr.h"
#include "libc/str/str.h"
static const uint16_t kTpEnc[32 - 7] = {
1 | 0300 << 8, 1 | 0300 << 8, 1 | 0300 << 8, 1 | 0300 << 8, 2 | 0340 << 8,
@ -29,7 +30,7 @@ static const uint16_t kTpEnc[32 - 7] = {
/**
* Encodes Thompson-Pike variable-length integer.
*/
uint64_t _tpenc(uint32_t c) {
uint64_t tpenc(uint32_t c) {
int e, n;
uint64_t w;
if (0 <= c && c <= 127) return c;

View file

@ -1,10 +1,10 @@
#ifndef _COSMO_H
#define _COSMO_H
#ifdef COSMO
#ifdef _COSMO_SOURCE
#define COSMO_ALREADY_DEFINED
#else
#define COSMO
#define _COSMO_SOURCE
#endif
/**
@ -62,7 +62,7 @@
#ifdef COSMO_ALREADY_DEFINED
#undef COSMO_ALREADY_DEFINED
#else
#undef COSMO
#undef _COSMO_SOURCE
#endif
#endif /* _COSMO_H */

View file

@ -1,5 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
#define COSMOPOLITAN_LIBC_LOG_LOG_H_
#ifdef _COSMO_SOURCE
#include "libc/stdio/stdio.h"
#define kLogFatal 0
@ -229,4 +230,5 @@ void vffatalf(ARGS, va_list) asm("vflogf") ATTRV relegated wontreturn libcesque;
#endif /* __STRICT_ANSI__ */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */
#endif /* COSMOPOLITAN_LIBC_LOG_LOG_H_ */

View file

@ -34,6 +34,7 @@
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/dprintf.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -55,10 +55,9 @@ size_t malloc_footprint(void);
size_t malloc_max_footprint(void);
size_t malloc_footprint_limit(void);
size_t malloc_set_footprint_limit(size_t);
void malloc_inspect_all(void (*handler)(void *, void *, size_t, void *),
void *);
void malloc_inspect_all(void (*)(void *, void *, size_t, void *), void *);
#ifdef COSMO
#ifdef _COSMO_SOURCE
bool __grow(void *, size_t *, size_t, size_t) paramsnonnull((1, 2)) libcesque;
#endif

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/tab.internal.h"
#include "libc/macros.internal.h"
.rodata
.balign 2

View file

@ -1,5 +1,14 @@
#ifndef COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
#define COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
#ifdef _COSMO_SOURCE
#define rldecode __rldecode
#define rldecode2 __rldecode2
#define lz4check __lz4check
#define lz4cpy __lz4cpy
#define lz4len __lz4len
#define lz4decode __lz4decode
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#if 0
@ -22,4 +31,5 @@ void *lz4decode(void *dest, const void *src);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */
#endif /* COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_ */

View file

@ -48,7 +48,7 @@ textwindows dontasan void DecodeDosArgv(int ignore, struct DosArgv *st) {
static textwindows dontasan void AppendDosArgv(wint_t wc, struct DosArgv *st) {
uint64_t w;
w = _tpenc(wc);
w = tpenc(wc);
do {
if (st->p >= st->pe) break;
*st->p++ = w & 0xff;

View file

@ -55,7 +55,7 @@ Recode16to8(char *dst, size_t dstsize, const char16_t *src) {
x = ToUpper(x);
}
}
w = _tpenc(x);
w = tpenc(x);
do {
if (r.ax + 1 < dstsize) {
dst[r.ax++] = w;

View file

@ -18,7 +18,7 @@
*/
#include "libc/runtime/memtrack.internal.h"
dontasan size_t GetMemtrackSize(struct MemoryIntervals *mm) {
dontasan size_t __get_memtrack_size(struct MemoryIntervals *mm) {
size_t i, n;
for (n = i = 0; i < mm->i; ++i) {
n += ((size_t)(mm->p[i].y - mm->p[i].x) + 1) << 16;

View file

@ -48,8 +48,8 @@ int GetDosEnviron(const char16_t *, char *, size_t, char **, size_t);
bool __intercept_flag(int *, char *[], const char *);
int sys_mprotect_nt(void *, size_t, int);
int __inflate(void *, size_t, const void *, size_t);
void *_Mmap(void *, size_t, int, int, int, int64_t) dontasan;
int _Munmap(char *, size_t) dontasan;
void *__mmap_unlocked(void *, size_t, int, int, int, int64_t) dontasan;
int __munmap_unlocked(char *, size_t) dontasan;
void __on_arithmetic_overflow(void);
void __init_fds(int, char **, char **);

View file

@ -20,7 +20,7 @@
static inline bool IsMemtrackedImpl(int x, int y) {
unsigned i;
i = FindMemoryInterval(&_mmi, x);
i = __find_memory(&_mmi, x);
if (i == _mmi.i) return false;
if (x < _mmi.p[i].x) return false;
for (;;) {

View file

@ -52,16 +52,16 @@ void __mmi_unlock(void);
void __mmi_funlock(void);
bool IsMemtracked(int, int);
void PrintSystemMappings(int);
unsigned FindMemoryInterval(const struct MemoryIntervals *, int) nosideeffect;
bool AreMemoryIntervalsOk(const struct MemoryIntervals *) nosideeffect;
unsigned __find_memory(const struct MemoryIntervals *, int) nosideeffect;
bool __check_memtrack(const struct MemoryIntervals *) nosideeffect;
void PrintMemoryIntervals(int, const struct MemoryIntervals *);
int TrackMemoryInterval(struct MemoryIntervals *, int, int, long, int, int,
bool, bool, long, long);
int ReleaseMemoryIntervals(struct MemoryIntervals *, int, int,
void (*)(struct MemoryIntervals *, int, int));
void ReleaseMemoryNt(struct MemoryIntervals *, int, int);
int UntrackMemoryIntervals(void *, size_t);
size_t GetMemtrackSize(struct MemoryIntervals *);
int __track_memory(struct MemoryIntervals *, int, int, long, int, int, bool,
bool, long, long);
int __untrack_memory(struct MemoryIntervals *, int, int,
void (*)(struct MemoryIntervals *, int, int));
void __release_memory_nt(struct MemoryIntervals *, int, int);
int __untrack_memories(void *, size_t);
size_t __get_memtrack_size(struct MemoryIntervals *);
#ifdef _NOPL0
#define __mmi_lock() _NOPL0("__threadcalls", __mmi_lock)

View file

@ -30,7 +30,7 @@ static inline dontasan void *GetFrameAddr(int f) {
return (void *)a;
}
dontasan void ReleaseMemoryNt(struct MemoryIntervals *mm, int l, int r) {
dontasan void __release_memory_nt(struct MemoryIntervals *mm, int l, int r) {
int i;
for (i = l; i <= r; ++i) {
UnmapViewOfFile(GetFrameAddr(mm->p[i].x));

View file

@ -68,22 +68,22 @@
#define SHADE(x) (((intptr_t)(x) >> 3) + 0x7fff8000)
#define FRAME(x) ((int)((intptr_t)(x) >> 16))
static pureconst unsigned long RoundDownTwoPow(unsigned long x) {
static inline pureconst unsigned long __rounddown2pow(unsigned long x) {
return x ? 1ul << _bsrl(x) : 0;
}
static wontreturn void OnUnrecoverableMmapError(const char *s) {
static wontreturn void __mmap_die(const char *s) {
if (_weaken(__die)) _weaken(__die)();
STRACE("%s %m", s);
_Exitr(199);
}
static dontasan inline bool OverlapsExistingMapping(char *p, size_t n) {
static dontasan inline bool __overlaps_existing_mapping(char *p, size_t n) {
int a, b, i;
unassert(n > 0);
a = FRAME(p);
b = FRAME(p + (n - 1));
i = FindMemoryInterval(&_mmi, a);
i = __find_memory(&_mmi, a);
if (i < _mmi.i) {
if (a <= _mmi.p[i].x && _mmi.p[i].x <= b) return true;
if (a <= _mmi.p[i].y && _mmi.p[i].y <= b) return true;
@ -92,14 +92,14 @@ static dontasan inline bool OverlapsExistingMapping(char *p, size_t n) {
return false;
}
static dontasan bool ChooseMemoryInterval(int x, int n, int align, int *res) {
static dontasan bool __choose_memory(int x, int n, int align, int *res) {
// TODO: improve performance
int i, start, end;
unassert(align > 0);
if (_mmi.i) {
// find the start of the automap memory region
i = FindMemoryInterval(&_mmi, x);
i = __find_memory(&_mmi, x);
if (i < _mmi.i) {
// check to see if there's space available before the first entry
@ -153,23 +153,23 @@ static dontasan bool ChooseMemoryInterval(int x, int n, int align, int *res) {
return false;
}
dontasan static bool Automap(int count, int align, int *res) {
return ChooseMemoryInterval(FRAME(kAutomapStart), count, align, res) &&
dontasan static bool __auto_map(int count, int align, int *res) {
return __choose_memory(FRAME(kAutomapStart), count, align, res) &&
*res + count <= FRAME(kAutomapStart + (kAutomapSize - 1));
}
static dontasan void *FinishMemory(void *addr, size_t size, int prot, int flags,
int fd, int64_t off, int f, int x, int n,
struct DirectMap dm) {
static dontasan void *__finish_memory(void *addr, size_t size, int prot,
int flags, int fd, int64_t off, int f,
int x, int n, struct DirectMap dm) {
if (!IsWindows() && (flags & MAP_FIXED)) {
if (UntrackMemoryIntervals(addr, size)) {
OnUnrecoverableMmapError("FIXED UNTRACK FAILED");
if (__untrack_memories(addr, size)) {
__mmap_die("FIXED UNTRACK FAILED");
}
}
if (TrackMemoryInterval(&_mmi, x, x + (n - 1), dm.maphandle, prot, flags,
false, false, off, size)) {
if (__track_memory(&_mmi, x, x + (n - 1), dm.maphandle, prot, flags, false,
false, off, size)) {
if (sys_munmap(addr, n) == -1) {
OnUnrecoverableMmapError("TRACK MUNMAP FAILED");
__mmap_die("TRACK MUNMAP FAILED");
}
return MAP_FAILED;
}
@ -179,21 +179,20 @@ static dontasan void *FinishMemory(void *addr, size_t size, int prot, int flags,
return addr;
}
static dontasan void *MapMemory(void *addr, size_t size, int prot, int flags,
int fd, int64_t off, int f, int x, int n) {
static dontasan void *__map_memory(void *addr, size_t size, int prot, int flags,
int fd, int64_t off, int f, int x, int n) {
struct DirectMap dm;
dm = sys_mmap(addr, size, prot, f, fd, off);
if (VERY_UNLIKELY(dm.addr == MAP_FAILED)) {
if (IsWindows() && (flags & MAP_FIXED)) {
OnUnrecoverableMmapError(
"can't recover from MAP_FIXED errors on Windows");
__mmap_die("can't recover from MAP_FIXED errors on Windows");
}
return MAP_FAILED;
}
if (VERY_UNLIKELY(dm.addr != addr)) {
OnUnrecoverableMmapError("KERNEL DIDN'T RESPECT MAP_FIXED");
__mmap_die("KERNEL DIDN'T RESPECT MAP_FIXED");
}
return FinishMemory(addr, size, prot, flags, fd, off, f, x, n, dm);
return __finish_memory(addr, size, prot, flags, fd, off, f, x, n, dm);
}
/**
@ -202,11 +201,9 @@ static dontasan void *MapMemory(void *addr, size_t size, int prot, int flags,
* This is useful on Windows since it allows us to partially unmap or
* punch holes into existing mappings.
*/
static textwindows dontinline dontasan void *MapMemories(char *addr,
size_t size, int prot,
int flags, int fd,
int64_t off, int f,
int x, int n) {
static textwindows dontinline dontasan void *__map_memories(
char *addr, size_t size, int prot, int flags, int fd, int64_t off, int f,
int x, int n) {
size_t i, m;
int64_t oi, sz;
struct DirectMap dm;
@ -221,19 +218,19 @@ static textwindows dontinline dontasan void *MapMemories(char *addr,
iscow = (flags & MAP_TYPE) != MAP_SHARED && fd != -1;
readonlyfile = (flags & MAP_TYPE) == MAP_SHARED && fd != -1 &&
(g_fds.p[fd].flags & O_ACCMODE) == O_RDONLY;
if (TrackMemoryInterval(&_mmi, x + (n - 1), x + (n - 1), dm.maphandle, prot,
flags, readonlyfile, iscow, oi, sz) == -1) {
OnUnrecoverableMmapError("MapMemories unrecoverable #1");
if (__track_memory(&_mmi, x + (n - 1), x + (n - 1), dm.maphandle, prot, flags,
readonlyfile, iscow, oi, sz) == -1) {
__mmap_die("__map_memories unrecoverable #1");
}
for (i = 0; i < m; i += FRAMESIZE) {
oi = fd == -1 ? 0 : off + i;
sz = FRAMESIZE;
dm = sys_mmap(addr + i, sz, prot, f, fd, oi);
if (dm.addr == MAP_FAILED ||
TrackMemoryInterval(&_mmi, x + i / FRAMESIZE, x + i / FRAMESIZE,
dm.maphandle, prot, flags, readonlyfile, iscow, oi,
sz) == -1) {
OnUnrecoverableMmapError("MapMemories unrecoverable #2");
__track_memory(&_mmi, x + i / FRAMESIZE, x + i / FRAMESIZE,
dm.maphandle, prot, flags, readonlyfile, iscow, oi,
sz) == -1) {
__mmap_die("__map_memories unrecoverable #2");
}
}
if (_weaken(__asan_map_shadow) && !OverlapsShadowSpace(addr, size)) {
@ -242,8 +239,8 @@ static textwindows dontinline dontasan void *MapMemories(char *addr,
return addr;
}
dontasan inline void *_Mmap(void *addr, size_t size, int prot, int flags,
int fd, int64_t off) {
dontasan inline void *__mmap_unlocked(void *addr, size_t size, int prot,
int flags, int fd, int64_t off) {
char *p = addr;
struct DirectMap dm;
size_t requested_size;
@ -301,14 +298,15 @@ dontasan inline void *_Mmap(void *addr, size_t size, int prot, int flags,
}
if (__virtualmax < LONG_MAX &&
(ckd_add(&virtualneed, (virtualused = GetMemtrackSize(&_mmi)), size) ||
(ckd_add(&virtualneed, (virtualused = __get_memtrack_size(&_mmi)),
size) ||
virtualneed > __virtualmax)) {
STRACE("mmap %'zu size + %'zu inuse exceeds virtual memory limit %'zu",
size, virtualused, __virtualmax);
return VIP(enomem());
}
clashes = OverlapsImageSpace(p, size) || OverlapsExistingMapping(p, size);
clashes = OverlapsImageSpace(p, size) || __overlaps_existing_mapping(p, size);
if ((flags & MAP_FIXED_NOREPLACE) == MAP_FIXED_NOREPLACE && clashes) {
STRACE("mmap noreplace overlaps existing");
@ -320,18 +318,18 @@ dontasan inline void *_Mmap(void *addr, size_t size, int prot, int flags,
return VIP(einval());
}
a = MAX(1, RoundDownTwoPow(size) >> 16);
a = MAX(1, __rounddown2pow(size) >> 16);
f = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED;
if (flags & MAP_FIXED) {
x = FRAME(p);
if (IsWindows()) {
if (UntrackMemoryIntervals(p, size)) {
OnUnrecoverableMmapError("FIXED UNTRACK FAILED");
if (__untrack_memories(p, size)) {
__mmap_die("FIXED UNTRACK FAILED");
}
}
} else if (p && !clashes && !OverlapsShadowSpace(p, size)) {
x = FRAME(p);
} else if (!Automap(n, a, &x)) {
} else if (!__auto_map(n, a, &x)) {
STRACE("automap has no room for %d frames with %d alignment", n, a);
return VIP(enomem());
}
@ -379,7 +377,7 @@ dontasan inline void *_Mmap(void *addr, size_t size, int prot, int flags,
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
.addr == p);
dm.addr = p;
p = FinishMemory(p, size, prot, flags, fd, off, f, x, n, dm);
p = __finish_memory(p, size, prot, flags, fd, off, f, x, n, dm);
if (IsAsan() && p != MAP_FAILED) {
__asan_poison(p, page_size, kAsanStackOverflow);
}
@ -398,9 +396,9 @@ dontasan inline void *_Mmap(void *addr, size_t size, int prot, int flags,
}
if (!IsWindows()) {
p = MapMemory(p, size, prot, flags, fd, off, f, x, n);
p = __map_memory(p, size, prot, flags, fd, off, f, x, n);
} else {
p = MapMemories(p, size, prot, flags, fd, off, f, x, n);
p = __map_memories(p, size, prot, flags, fd, off, f, x, n);
}
if (p != MAP_FAILED) {
@ -477,14 +475,14 @@ void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) {
#endif
__mmi_lock();
if (!__isfdkind(fd, kFdZip)) {
res = _Mmap(addr, size, prot, flags, fd, off);
res = __mmap_unlocked(addr, size, prot, flags, fd, off);
} else {
res = _weaken(__zipos_Mmap)(
res = _weaken(__zipos_mmap)(
addr, size, prot, flags,
(struct ZiposHandle *)(intptr_t)g_fds.p[fd].handle, off);
}
#if SYSDEBUG
toto = __strace > 0 ? GetMemtrackSize(&_mmi) : 0;
toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0;
#endif
__mmi_unlock();
STRACE("mmap(%p, %'zu, %s, %s, %d, %'ld) → %p% m (%'zu bytes total)", addr,

View file

@ -29,7 +29,7 @@ textwindows int sys_mprotect_nt(void *addr, size_t size, int prot) {
__mmi_lock();
size = (size + 4095) & -4096;
p = addr;
i = FindMemoryInterval(&_mmi, (intptr_t)p >> 16);
i = __find_memory(&_mmi, (intptr_t)p >> 16);
if (i == _mmi.i || (!i && p + size <= (char *)ADDR_32_TO_48(_mmi.p[0].x))) {
// memory isn't in memtrack
// let's just trust the user then

View file

@ -29,7 +29,7 @@ dontasan textwindows int sys_msync_nt(char *addr, size_t size, int flags) {
int i, rc = 0;
char *a, *b, *x, *y;
__mmi_lock();
for (i = FindMemoryInterval(&_mmi, (intptr_t)addr >> 16); i < _mmi.i; ++i) {
for (i = __find_memory(&_mmi, (intptr_t)addr >> 16); i < _mmi.i; ++i) {
x = (char *)ADDR_32_TO_48(_mmi.p[i].x);
y = x + _mmi.p[i].size;
if ((x <= addr && addr < y) || (x < addr + size && addr + size <= y) ||

View file

@ -39,9 +39,9 @@
#define ALIGNED(p) (!(IP(p) & (FRAMESIZE - 1)))
#define FRAME(x) ((int)((intptr_t)(x) >> 16))
static dontasan void MunmapShadow(char *p, size_t n) {
static dontasan void __munmap_shadow(char *p, size_t n) {
intptr_t a, b, x, y;
KERNTRACE("MunmapShadow(%p, %'zu)", p, n);
KERNTRACE("__munmap_shadow(%p, %'zu)", p, n);
a = ((intptr_t)p >> 3) + 0x7fff8000;
b = a + (n >> 3);
if (IsMemtracked(FRAME(a), FRAME(b - 1))) {
@ -52,7 +52,7 @@ static dontasan void MunmapShadow(char *p, size_t n) {
// to be >1mb since we can only unmap it if it's aligned, and
// as such we poison the edges if there are any.
__repstosb((void *)a, kAsanUnmapped, x - a);
_Munmap((void *)x, y - x);
__munmap_unlocked((void *)x, y - x);
__repstosb((void *)y, kAsanUnmapped, b - y);
} else {
// otherwise just poison and assume reuse
@ -66,15 +66,15 @@ static dontasan void MunmapShadow(char *p, size_t n) {
// our api supports doing things like munmap(0, 0x7fffffffffff) but some
// platforms (e.g. openbsd) require that we know the specific intervals
// or else it returns EINVAL. so we munmap a piecewise.
static dontasan void MunmapImpl(char *p, size_t n) {
static dontasan void __munmap_impl(char *p, size_t n) {
char *q;
size_t m;
intptr_t a, b, c;
int i, l, r, rc, beg, end;
KERNTRACE("MunmapImpl(%p, %'zu)", p, n);
KERNTRACE("__munmap_impl(%p, %'zu)", p, n);
l = FRAME(p);
r = FRAME(p + n - 1);
i = FindMemoryInterval(&_mmi, l);
i = __find_memory(&_mmi, l);
for (; i < _mmi.i && r >= _mmi.p[i].x; ++i) {
if (l >= _mmi.p[i].x && r <= _mmi.p[i].y) {
@ -104,15 +104,15 @@ static dontasan void MunmapImpl(char *p, size_t n) {
if (!IsWindows()) {
npassert(!sys_munmap(q, m));
} else {
// Handled by UntrackMemoryIntervals() on Windows
// Handled by __untrack_memories() on Windows
}
if (IsAsan() && !OverlapsShadowSpace(p, n)) {
MunmapShadow(q, m);
__munmap_shadow(q, m);
}
}
}
dontasan int _Munmap(char *p, size_t n) {
dontasan int __munmap_unlocked(char *p, size_t n) {
unsigned i;
char poison;
intptr_t a, b, x, y;
@ -137,8 +137,8 @@ dontasan int _Munmap(char *p, size_t n) {
STRACE("munmap(%p) isn't 64kb aligned", p);
return einval();
}
MunmapImpl(p, n);
return UntrackMemoryIntervals(p, n);
__munmap_impl(p, n);
return __untrack_memories(p, n);
}
/**
@ -156,9 +156,9 @@ int munmap(void *p, size_t n) {
int rc;
size_t toto;
__mmi_lock();
rc = _Munmap(p, n);
rc = __munmap_unlocked(p, n);
#if SYSDEBUG
toto = __strace > 0 ? GetMemtrackSize(&_mmi) : 0;
toto = __strace > 0 ? __get_memtrack_size(&_mmi) : 0;
#endif
__mmi_unlock();
STRACE("munmap(%.12p, %'zu) → %d% m (%'zu bytes total)", p, n, rc, toto);

View file

@ -19,10 +19,10 @@
#include "libc/calls/calls.h"
#include "libc/runtime/runtime.h"
int _OpenExecutable(void) {
int __open_executable(void) {
tinyprint(2,
"error: redbean StoreAsset() support is currently unavailable "
"because _OpenExecutable() in a regressed state, due to the "
"because __open_executable() in a regressed state, due to the "
"work we're doing on Arm64 support; we're hoping to address "
"this soon; please try using redbean v2.2 or rewinding to "
"commit 38112aeb206cc95ef615c268ca809cad693ecb9e\n",

View file

@ -20,8 +20,6 @@ typedef unsigned long jmp_buf[26];
typedef long sigjmp_buf[12];
extern char **environ;
void mcount(void);
int daemon(int, int);
unsigned long getauxval(unsigned long);
@ -65,7 +63,11 @@ int getdtablesize(void);
int sethostname(const char *, size_t);
int acct(const char *);
#ifdef COSMO
#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
extern char **environ;
#endif
#ifdef _COSMO_SOURCE
extern int __argc;
extern char **__argv;
extern char **__envp;
@ -100,7 +102,7 @@ int _cocmd(int, char **, char **);
/* executable program */
char *GetProgramExecutableName(void);
char *GetInterpreterExecutableName(char *, size_t);
int _OpenExecutable(void);
int __open_executable(void);
/* execution control */
int verynice(void);
axdx_t setlongerjmp(jmp_buf)
@ -130,7 +132,7 @@ void GetCpuidBrand(char[13], uint32_t);
long _GetResourceLimit(int);
const char *__describe_os(void);
int __arg_max(void);
#endif
#endif /* _COSMO_SOURCE */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -77,7 +77,6 @@ o/$(MODE)/libc/runtime/ftracer.o: private \
o/$(MODE)/libc/runtime/cosmo2.o \
o/$(MODE)/libc/runtime/fork-nt.o \
o/$(MODE)/libc/runtime/printmemoryintervals.o \
o/$(MODE)/libc/runtime/arememoryintervalsok.o \
o/$(MODE)/libc/runtime/findmemoryinterval.o \
o/$(MODE)/libc/runtime/sys_mprotect.greg.o \
o/$(MODE)/libc/runtime/getdosargv.o \

View file

@ -1,7 +1,7 @@
#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef COSMO
#ifdef _COSMO_SOURCE
/**
* Tunes APE stack maximum size.
@ -136,8 +136,8 @@ forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
void *NewCosmoStack(void) vallocesque;
int FreeCosmoStack(void *) libcesque;
#endif /* COSMO */
COSMOPOLITAN_C_END_
#endif /* GNU ELF */
#endif /* _COSMO_SOURCE */
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_STACK_H_ */

View file

@ -21,11 +21,11 @@
#include "libc/macros.internal.h"
#include "libc/runtime/memtrack.internal.h"
int UntrackMemoryIntervals(void *addr, size_t size) {
int __untrack_memories(void *addr, size_t size) {
int a, b;
unassert(size > 0);
a = ROUNDDOWN((intptr_t)addr, FRAMESIZE) >> 16;
b = ROUNDDOWN((intptr_t)addr + size - 1, FRAMESIZE) >> 16;
return ReleaseMemoryIntervals(&_mmi, a, b,
SupportsWindows() ? ReleaseMemoryNt : 0);
return __untrack_memory(&_mmi, a, b,
SupportsWindows() ? __release_memory_nt : 0);
}

View file

@ -37,6 +37,6 @@ void __warn_if_powersave(void) {
if ((fd = open(FILE, O_RDONLY)) == -1) return;
read(fd, buf, 15);
close(fd);
if (!_startswith(buf, "powersave")) return;
if (!startswith(buf, "powersave")) return;
write(2, WARN, sizeof(WARN) - 1);
}

View file

@ -48,7 +48,7 @@
* it does not need to be 64kb aligned.
* @return virtual base address of new mapping, or MAP_FAILED w/ errno
*/
dontasan void *__zipos_Mmap(void *addr, size_t size, int prot, int flags,
dontasan void *__zipos_mmap(void *addr, size_t size, int prot, int flags,
struct ZiposHandle *h, int64_t off) {
if (!(flags & MAP_PRIVATE) ||
(flags & ~(MAP_PRIVATE | MAP_FILE | MAP_FIXED | MAP_FIXED_NOREPLACE)) ||
@ -64,8 +64,8 @@ dontasan void *__zipos_Mmap(void *addr, size_t size, int prot, int flags,
}
const int tempProt = !IsXnu() ? prot | PROT_WRITE : PROT_WRITE;
void *outAddr =
_Mmap(addr, size, tempProt, (flags & (~MAP_FILE)) | MAP_ANONYMOUS, -1, 0);
void *outAddr = __mmap_unlocked(addr, size, tempProt,
(flags & (~MAP_FILE)) | MAP_ANONYMOUS, -1, 0);
if (outAddr == MAP_FAILED) {
return MAP_FAILED;
}
@ -83,7 +83,7 @@ dontasan void *__zipos_Mmap(void *addr, size_t size, int prot, int flags,
return outAddr;
} while (0);
const int e = errno;
_Munmap(outAddr, size);
__munmap_unlocked(outAddr, size);
errno = e;
strace_enabled(+1);
return MAP_FAILED;

View file

@ -32,7 +32,7 @@
.yoink __zipos_read
.yoink __zipos_stat
.yoink __zipos_notat
.yoink __zipos_Mmap
.yoink __zipos_mmap
// TODO(jart): why does corruption happen when zip has no assets?
.yoink .cosmo

View file

@ -50,7 +50,7 @@ ssize_t __zipos_write(struct ZiposHandle *, const struct iovec *, size_t,
int64_t __zipos_lseek(struct ZiposHandle *, int64_t, unsigned);
int __zipos_fcntl(int, int, uintptr_t);
int __zipos_notat(int, const char *);
void *__zipos_Mmap(void *, uint64_t, int32_t, int32_t, struct ZiposHandle *,
void *__zipos_mmap(void *, uint64_t, int32_t, int32_t, struct ZiposHandle *,
int64_t) dontasan;
#ifdef _NOPL0

View file

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

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio_ext.h"
void __fseterr(FILE *f) {

View file

@ -43,7 +43,7 @@ FILE *__stdio_alloc(void) {
f = kmalloc(sizeof(FILE));
}
if (f) {
((pthread_mutex_t *)f->lock)->_type = PTHREAD_MUTEX_RECURSIVE;
f->lock._type = PTHREAD_MUTEX_RECURSIVE;
}
return f;
}

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/struct/dirent.h"
#include "libc/stdio/internal.h"
#include "libc/str/str.h"
int alphasort(const struct dirent **a, const struct dirent **b) {

View file

@ -1,6 +1,6 @@
#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_
#ifdef COSMO
#ifdef _COSMO_SOURCE
#define APPEND_COOKIE 21578
@ -34,5 +34,5 @@ ssize_t kvappendf(char **, const char *, va_list);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMO */
#endif /* _COSMO_SOURCE */
#endif /* COSMOPOLITAN_LIBC_STDIO_APPEND_H_ */

View file

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

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio_ext.h"
/**

View file

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

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -43,7 +43,7 @@ static void __stdio_fork_prepare(void) {
__fflush_lock();
for (int i = 0; i < __fflush.handles.i; ++i) {
if ((f = __fflush.handles.p[i])) {
pthread_mutex_lock((pthread_mutex_t *)f->lock);
pthread_mutex_lock(&f->lock);
}
}
}
@ -52,7 +52,7 @@ static void __stdio_fork_parent(void) {
FILE *f;
for (int i = __fflush.handles.i; i--;) {
if ((f = __fflush.handles.p[i])) {
pthread_mutex_unlock((pthread_mutex_t *)f->lock);
pthread_mutex_unlock(&f->lock);
}
}
__fflush_unlock();
@ -60,12 +60,10 @@ static void __stdio_fork_parent(void) {
static void __stdio_fork_child(void) {
FILE *f;
pthread_mutex_t *m;
for (int i = __fflush.handles.i; i--;) {
if ((f = __fflush.handles.p[i])) {
m = (pthread_mutex_t *)f->lock;
bzero(m, sizeof(*m));
m->_type = PTHREAD_MUTEX_RECURSIVE;
bzero(&f->lock, sizeof(f->lock));
f->lock._type = PTHREAD_MUTEX_RECURSIVE;
}
}
pthread_mutex_init(&__fflush_lock_obj, 0);

View file

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

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
@ -23,7 +24,7 @@
* Retrieves line from stream, e.g.
*
* char *line;
* while ((line = _chomp(fgetln(stdin, 0)))) {
* while ((line = chomp(fgetln(stdin, 0)))) {
* printf("%s\n", line);
* }
*

View file

@ -24,7 +24,7 @@
*
* This function is similar to getline() except it'll truncate lines
* exceeding size. The line ending marker is included and may be removed
* using _chomp().
* using chomp().
*
* When reading from the console on Windows in `ICANON` mode, the
* returned line will end with `\r\n` rather than `\n`.

View file

@ -19,6 +19,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -27,7 +28,7 @@
*
* This function is similar to getline() except it'll truncate lines
* exceeding size. The line ending marker is included and may be removed
* using _chomp().
* using chomp().
*
* @param s is output buffer
* @param size is capacity of s

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/thompike.h"
#include "libc/str/tpdecodecb.internal.h"

View file

@ -24,7 +24,7 @@
*
* This function is similar to getline() except it'll truncate lines
* exceeding size. The line ending marker is included and may be removed
* using _chomp().
* using chomp().
*
* @param s is is nul-terminated string that's non-null
* @param size is byte length of `s`

View file

@ -25,7 +25,7 @@
*
* This function is similar to getline() except it'll truncate lines
* exceeding size. The line ending marker is included and may be removed
* using _chomp().
* using chomp().
*
* @param s is is nul-terminated string that's non-null
* @param size is byte length of `s`

View file

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

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio_ext.h"
/**

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/thread.h"
@ -24,5 +25,5 @@
* Acquires reentrant lock on stdio object, blocking if needed.
*/
void(flockfile)(FILE *f) {
pthread_mutex_lock((pthread_mutex_t *)f->lock);
pthread_mutex_lock(&f->lock);
}

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/stdio/fflush.internal.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/stdio_ext.h"

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