Fix warnings

This change fixes Cosmopolitan so it has fewer opinions about compiler
warnings. The whole repository had to be cleaned up to be buildable in
-Werror -Wall mode. This lets us benefit from things like strict const
checking. Some actual bugs might have been caught too.
This commit is contained in:
Justine Tunney 2023-09-01 20:49:13 -07:00
parent e2b3c3618e
commit 0d748ad58e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
571 changed files with 1306 additions and 1888 deletions

View file

@ -183,7 +183,7 @@ textwindows bool __sig_handle(int sigops, int sig, int si_code,
if (__sig_is_fatal(sig)) {
intptr_t hStderr;
const char *signame;
char *end, sigbuf[15], output[16];
char *end, sigbuf[21], output[22];
signame = strsignal_r(sig, sigbuf);
STRACE("terminating due to uncaught %s", signame);
hStderr = GetStdHandle(kNtStdErrorHandle);
@ -274,7 +274,6 @@ textwindows int __sig_add(int tid, int sig, int si_code) {
* @threadsafe
*/
textwindows bool __sig_check(int sigops) {
unsigned rva;
bool delivered;
struct Signal *sig;
delivered = false;

View file

@ -37,7 +37,6 @@ static void sys_clock_gettime_mono_init(void) {
int sys_clock_gettime_mono(struct timespec *time) {
uint64_t nanos;
uint64_t cycles;
struct timespec res;
if (X86_HAVE(INVTSC)) {
cosmo_once(&g_mono.once, sys_clock_gettime_mono_init);
cycles = rdtsc() - g_mono.base_tick;

View file

@ -43,6 +43,7 @@
*/
int closefrom(int first) {
int rc, err;
(void)err;
if (first < 0) {
// consistent with openbsd
// freebsd allows this but it's dangerous

View file

@ -39,8 +39,8 @@ static struct CopyFileRange {
} g_copy_file_range;
static bool HasCopyFileRange(void) {
int e;
bool ok;
int e, rc;
e = errno;
BLOCK_CANCELLATIONS;
if (IsLinux()) {

View file

@ -43,9 +43,9 @@ int execl(const char *exe, const char *arg, ... /*, NULL*/) {
va_end(va);
argv = alloca((i + 2) * sizeof(char *));
va_start(vb, arg);
argv[0] = arg;
argv[0] = (char *)arg;
for (i = 1;; ++i) {
if (!(argv[i] = va_arg(vb, const char *))) break;
if (!(argv[i] = va_arg(vb, char *))) break;
}
va_end(vb);
return execv(exe, argv);

View file

@ -45,9 +45,9 @@ int execle(const char *exe, const char *arg,
va_end(va);
argv = alloca((i + 2) * sizeof(char *));
va_start(vb, arg);
argv[0] = arg;
argv[0] = (char *)arg;
for (i = 1;; ++i) {
if (!(argv[i] = va_arg(vb, const char *))) break;
if (!(argv[i] = va_arg(vb, char *))) break;
}
va_end(vb);
return execve(exe, argv, envp);

View file

@ -49,9 +49,9 @@ int execlp(const char *prog, const char *arg, ... /*, NULL*/) {
va_end(va);
argv = alloca((i + 2) * sizeof(char *));
va_start(vb, arg);
argv[0] = arg;
argv[0] = (char *)arg;
for (i = 1;; ++i) {
if (!(argv[i] = va_arg(vb, const char *))) break;
if (!(argv[i] = va_arg(vb, char *))) break;
}
va_end(vb);

View file

@ -89,15 +89,15 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
".ape-" APE_VERSION_STR, buf))) ||
CanExecute((ape = Join(firstnonnull(getenv("HOME"), "."),
".ape-" APE_VERSION_STR, buf))))) {
shargs[0] = ape;
shargs[1] = "-";
shargs[2] = prog;
shargs[0] = (char *)ape;
shargs[1] = (char *)"-";
shargs[2] = (char *)prog;
memcpy(shargs + 3, argv, (i + 1) * sizeof(char *));
errno = e;
rc = __sys_execve(shargs[0], shargs, envp);
} else if (CanExecute(prog)) {
shargs[0] = _PATH_BSHELL;
shargs[1] = prog;
shargs[1] = (char *)prog;
memcpy(shargs + 2, argv + 1, i * sizeof(char *));
errno = e;
rc = __sys_execve(shargs[0], shargs, envp);

View file

@ -56,9 +56,8 @@
* @vforksafe
*/
int execve(const char *prog, char *const argv[], char *const envp[]) {
struct ZiposUri uri;
int rc;
size_t i;
struct ZiposUri uri;
if (!prog || !argv || !envp ||
(IsAsan() && (!__asan_is_valid_str(prog) || //
!__asan_is_valid_strlist(argv) || //

View file

@ -43,7 +43,7 @@ int sys_fadvise_netbsd(int, int, int64_t, int64_t, int) asm("sys_fadvise");
* @raise ENOSYS on XNU and OpenBSD
*/
int fadvise(int fd, uint64_t offset, uint64_t len, int advice) {
int rc, e = errno;
int rc;
if (IsLinux()) {
rc = sys_fadvise(fd, offset, len, advice);
} else if (IsFreebsd() || IsNetbsd()) {

View file

@ -124,11 +124,10 @@ textwindows void sys_fcntl_nt_lock_cleanup(int fd) {
static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
uintptr_t arg) {
int e;
uint32_t flags;
struct flock *l;
uint32_t flags, err;
int64_t pos, off, len, end;
struct FileLock *fl, *ft, **flp;
int64_t pos, off, len, end, size;
l = (struct flock *)arg;
len = l->l_len;
@ -171,7 +170,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
for (flp = &g_locks.list, fl = *flp; fl;) {
if (fl->fd == fd) {
if (EqualsFileLock(fl, off, len)) {
if (fl->exc == l->l_type == F_WRLCK) {
if (fl->exc == (l->l_type == F_WRLCK)) {
// we already have this lock
return 0;
} else {
@ -205,7 +204,7 @@ static textwindows int sys_fcntl_nt_lock(struct Fd *f, int fd, int cmd,
l->l_whence = SEEK_SET;
l->l_start = fl->off;
l->l_len = fl->len;
l->l_type == fl->exc ? F_WRLCK : F_RDLCK;
l->l_type = fl->exc ? F_WRLCK : F_RDLCK;
l->l_pid = getpid();
return 0;
}
@ -360,7 +359,6 @@ static textwindows int sys_fcntl_nt_setfl(int fd, unsigned *flags,
textwindows int sys_fcntl_nt(int fd, int cmd, uintptr_t arg) {
int rc;
uint32_t flags;
if (__isfdkind(fd, kFdFile) || //
__isfdkind(fd, kFdSocket) || //
__isfdkind(fd, kFdConsole)) {

View file

@ -45,7 +45,6 @@
static bool IsAPEFd(const int fd) {
char buf[8];
bool res;
return (sys_pread(fd, buf, 8, 0, 0) == 8) && IsAPEMagic(buf);
}
@ -115,7 +114,7 @@ static bool ape_to_elf(void *ape, const size_t apesize) {
* This does an inplace conversion of APE to ELF when detected!!!!
*/
static int fd_to_mem_fd(const int infd, char *path) {
if (!IsLinux() && !IsFreebsd() || !_weaken(mmap) || !_weaken(munmap)) {
if ((!IsLinux() && !IsFreebsd()) || !_weaken(mmap) || !_weaken(munmap)) {
return enosys();
}
@ -143,9 +142,9 @@ static int fd_to_mem_fd(const int infd, char *path) {
bool success = readRc != -1;
if (success && (st.st_size > 8) && IsAPEMagic(space)) {
int flags = fcntl(fd, F_GETFD);
if (success = (flags != -1) &&
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
ape_to_elf(space, st.st_size)) {
if ((success = (flags != -1) &&
(fcntl(fd, F_SETFD, flags & (~FD_CLOEXEC)) != -1) &&
ape_to_elf(space, st.st_size))) {
const int newfd = fcntl(fd, F_DUPFD, 9001);
if (newfd != -1) {
close(fd);
@ -232,7 +231,7 @@ int fexecve(int fd, char *const argv[], char *const envp[]) {
}
size_t numenvs;
for (numenvs = 0; envp[numenvs];) ++numenvs;
const size_t desenvs = min(500, max(numenvs + 1, 2));
// const size_t desenvs = min(500, max(numenvs + 1, 2));
static _Thread_local char *envs[500];
memcpy(envs, envp, numenvs * sizeof(char *));
envs[numenvs] = path;

View file

@ -28,7 +28,6 @@
*/
int32_t sys_fstatat(int32_t dirfd, const char *path, struct stat *st,
int32_t flags) {
int rc;
void *p;
union metastat ms;
if (IsAsan() && !__asan_is_valid_str(path)) return efault();

View file

@ -37,7 +37,6 @@
textwindows int sys_fstatfs_nt(int64_t handle, struct statfs *f) {
uint64_t w;
NtStatus st;
uint32_t type;
uint32_t h, i, j;
struct NtIoStatusBlock io;
struct NtFileFsFullSizeInformation fs;

View file

@ -57,7 +57,6 @@ textwindows int sys_getloadavg_nt(double *a, int n) {
}
static textstartup void sys_getloadavg_nt_init(void) {
double a[3];
if (IsWindows()) {
load = 1;
cpus = __get_cpu_count() / 2;

View file

@ -55,7 +55,6 @@ static gettimeofday_f *__gettimeofday = __gettimeofday_init;
*/
int gettimeofday(struct timeval *tv, struct timezone *tz) {
int rc;
axdx_t ad;
if (IsAsan() && ((tv && !__asan_is_valid(tv, sizeof(*tv))) ||
(tz && !__asan_is_valid(tz, sizeof(*tz))))) {
rc = efault();

View file

@ -4,7 +4,7 @@
COSMOPOLITAN_C_START_
int sys_getgroups(int size, uint32_t list[]);
int sys_setgroups(size_t size, uint32_t list[]);
int sys_setgroups(size_t size, const uint32_t list[]);
const char *DescribeGidList(char[128], int, int, const uint32_t list[]);
#define DescribeGidList(rc, length, gidlist) \

View file

@ -72,7 +72,6 @@ static struct HostAdapterInfoNode {
static int ioctl_default(int fd, unsigned long request, void *arg) {
int rc;
va_list va;
int64_t handle;
if (!IsWindows()) {
return sys_ioctl(fd, request, arg);
@ -94,7 +93,6 @@ static int ioctl_default(int fd, unsigned long request, void *arg) {
static int ioctl_fionread(int fd, uint32_t *arg) {
int rc;
va_list va;
int64_t handle;
uint32_t avail;
if (!IsWindows()) {
@ -323,7 +321,6 @@ static textwindows int createHostInfo(
struct NtIpAdapterPrefix *ap;
struct HostAdapterInfoNode *node = NULL;
char baseName[IFNAMSIZ];
char name[IFNAMSIZ];
int count, i;
/* __hostInfo must be empty */
unassert(__hostInfo == NULL);
@ -416,7 +413,6 @@ err:
static textwindows int ioctl_siocgifconf_nt(int fd, struct ifconf *ifc) {
struct ifreq *ptr;
struct NtIpAdapterAddresses *aa;
struct HostAdapterInfoNode *node;
if (__hostInfo) {
freeHostInfo();
@ -480,12 +476,12 @@ static int ioctl_siocgifconf_sysv(int fd, struct ifconf *ifc) {
* BSD ABIs mainly differ by having sockaddr::sa_len
* XNU uses a 32-bit length in a struct that's packed!
*/
int i, rc, fam;
int rc, fam;
size_t bufMax;
char *b, *p, *e;
char ifcBsd[16];
struct ifreq *req;
uint32_t bufLen, ip;
size_t numReq, bufMax;
if (IsLinux()) {
return sys_ioctl(fd, SIOCGIFCONF, ifc);
}

View file

@ -37,7 +37,6 @@
* @raise EPERM if pledge() was used without tty
*/
bool32 isatty(int fd) {
int e;
bool32 res;
struct winsize ws;
if (__isfdkind(fd, kFdZip)) {

View file

@ -38,7 +38,7 @@
*/
int mkfifo(const char *pathname, unsigned mode) {
// TODO(jart): Windows?
int e, rc;
int rc;
if (IsAsan() && !__asan_is_valid_str(pathname)) {
rc = efault();
} else if (IsLinux()) {

View file

@ -71,7 +71,6 @@ textwindows int mkntcmdline(char16_t cmdline[ARG_MAX / 2], char *const argv[]) {
wint_t x, y;
int slashes, n;
bool needsquote;
char16_t cbuf[2];
char *ansiargv[2];
size_t i, j, k, s;
if (!argv[0]) {

View file

@ -36,9 +36,9 @@ static inline int IsAlpha(int c) {
return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z');
}
static inline char *StrChr(char *s, int c) {
static inline char *StrChr(const char *s, int c) {
for (;; ++s) {
if ((*s & 255) == (c & 255)) return s;
if ((*s & 255) == (c & 255)) return (char *)s;
if (!*s) return 0;
}
}
@ -52,7 +52,6 @@ static textwindows inline int CompareStrings(const char *l, const char *r) {
static textwindows void FixPath(char *path) {
char *p;
size_t i;
// skip over variable name
while (*path++) {
@ -71,7 +70,7 @@ static textwindows void FixPath(char *path) {
// turn \c\... into c:\...
p = path;
if ((p[0] == '/' | p[0] == '\\') && IsAlpha(p[1]) &&
if ((p[0] == '/' || p[0] == '\\') && IsAlpha(p[1]) &&
(p[2] == '/' || p[2] == '\\')) {
p[0] = p[1];
p[1] = ':';
@ -92,7 +91,7 @@ static textwindows void FixPath(char *path) {
}
}
static textwindows void InsertString(char **a, size_t i, char *s,
static textwindows void InsertString(char **a, size_t i, const char *s,
char buf[ARG_MAX], size_t *bufi,
bool *have_systemroot) {
char *v;
@ -119,7 +118,7 @@ static textwindows void InsertString(char **a, size_t i, char *s,
for (j = i; j > 0 && CompareStrings(s, a[j - 1]) < 0; --j) {
a[j] = a[j - 1];
}
a[j] = s;
a[j] = (char *)s;
}
/**
@ -136,8 +135,6 @@ static textwindows void InsertString(char **a, size_t i, char *s,
textwindows int mkntenvblock(char16_t envvars[ARG_MAX / 2], char *const envp[],
const char *extravar, char buf[ARG_MAX]) {
bool v;
char *t;
axdx_t rc;
uint64_t w;
char **vars;
wint_t x, y;

View file

@ -25,7 +25,7 @@ int32_t sys_mount_linux(const char *source, const char *target,
const char *filesystemtype, uint64_t mountflags,
const void *data) asm("sys_mount");
int32_t sys_mount_bsd(const char *type, const char *dir, int32_t flags,
void *data) asm("sys_mount");
const void *data) asm("sys_mount");
/**
* Mounts file system.

View file

@ -37,7 +37,7 @@
void *sys_mremap(void *p, size_t n, size_t m, int f, void *q) {
#ifdef __x86_64__
bool cf;
uintptr_t res, rdi, rsi, rdx;
uintptr_t res, rdx;
register uintptr_t r8 asm("r8");
register uintptr_t r10 asm("r10");
if (IsLinux()) {

View file

@ -102,7 +102,6 @@ static long double nowl_vdso(void) {
long double nowl_setup(void) {
bool isfast;
uint64_t ticks;
__gettime = __clock_gettime_get(&isfast);
if (isfast) {
nowl = nowl_vdso;

View file

@ -26,13 +26,12 @@
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/sig.h"
#include "libc/thread/tls.h"
#include "libc/thread/tls2.h"
#include "libc/thread/tls2.internal.h"
#ifdef __x86_64__
textwindows bool32 __onntconsoleevent(uint32_t dwCtrlType) {
struct CosmoTib tib;
struct StackFrame *fr;
// win32 spawns a thread on its own just to deliver sigint
// TODO(jart): make signal code lockless so we can delete!

View file

@ -48,7 +48,7 @@ struct IoctlPtmGet {
static int openpty_impl(int *mfd, int *sfd, char *name,
const struct termios *tio, //
const struct winsize *wsz) {
int m, s, p;
int m, s;
struct IoctlPtmGet t;
RETURN_ON_ERROR((m = posix_openpt(O_RDWR | O_NOCTTY)));
if (!IsOpenbsd()) {
@ -66,7 +66,7 @@ static int openpty_impl(int *mfd, int *sfd, char *name,
*sfd = s;
if (name) strcpy(name, t.sname);
if (tio) npassert(!tcsetattr(s, TCSAFLUSH, tio));
if (wsz) npassert(!tcgetwinsize(s, wsz));
if (wsz) npassert(!tcsetwinsize(s, wsz));
return 0;
OnError:
if (m != -1) sys_close(m);

View file

@ -1079,11 +1079,11 @@ static privileged int GetTid(void) {
}
static privileged void Log(const char *s, ...) {
int res;
va_list va;
va_start(va, s);
do {
#ifdef __x86_64__
int res;
asm volatile("syscall"
: "=a"(res)
: "0"(__NR_linux_write), "D"(2), "S"(s), "d"(StrLen(s))
@ -1156,10 +1156,10 @@ static privileged int SigProcMask(int how, int64_t set, int64_t *old) {
}
static privileged void KillThisProcess(void) {
int res;
SigAction(Sigabrt, &(struct sigaction){0}, 0);
SigProcMask(Sig_Setmask, -1, 0);
#ifdef __x86_64__
int res;
asm volatile("syscall"
: "=a"(res)
: "0"(__NR_linux_kill), "D"(GetPid()), "S"(Sigabrt)
@ -1196,10 +1196,10 @@ static privileged void KillThisProcess(void) {
}
static privileged void KillThisThread(void) {
int res;
SigAction(Sigabrt, &(struct sigaction){0}, 0);
SigProcMask(Sig_Setmask, -1, 0);
#ifdef __x86_64__
int res;
asm volatile("syscall"
: "=a"(res)
: "0"(__NR_linux_tkill), "D"(GetTid()), "S"(Sigabrt)
@ -1233,7 +1233,7 @@ static privileged const char *GetSyscallName(uint16_t n) {
return "unknown";
}
static privileged int HasSyscall(struct Pledges *p, uint16_t n) {
static privileged int HasSyscall(const struct Pledges *p, uint16_t n) {
int i;
for (i = 0; i < p->len; ++i) {
if (p->syscalls[i] == n) {
@ -1249,11 +1249,11 @@ static privileged int HasSyscall(struct Pledges *p, uint16_t n) {
static privileged void OnSigSys(int sig, siginfo_t *si, void *vctx) {
bool found;
char ord[17];
int i, ok, mode = si->si_errno;
int i, mode = si->si_errno;
ucontext_t *ctx = vctx;
ctx->uc_mcontext.MCONTEXT_SYSCALL_RESULT_REGISTER = -Eperm;
FixCpy(ord, si->si_syscall, 12);
for (found = i = 0; i < ARRAYLEN(kPledge); ++i) {
for (found = false, i = 0; i < ARRAYLEN(kPledge); ++i) {
if (HasSyscall(kPledge + i, si->si_syscall)) {
Log("error: protected syscall ", GetSyscallName(si->si_syscall),
" (ord=", ord, "); pledge promise '", kPledge[i].name, "' to allow\n",
@ -1289,8 +1289,8 @@ static privileged void MonitorSigSys(void) {
}
}
static privileged void AppendFilter(struct Filter *f, struct sock_filter *p,
size_t n) {
static privileged void AppendFilter(struct Filter *f,
const struct sock_filter *p, size_t n) {
if (UNLIKELY(f->n + n > ARRAYLEN(f->p))) notpossible;
MemCpy(f->p + f->n, p, n * sizeof(*f->p));
f->n += n;
@ -2290,8 +2290,8 @@ static privileged void AppendPledge(struct Filter *f, //
* @vforksafe
*/
privileged int sys_pledge_linux(unsigned long ipromises, int mode) {
int i, rc = -1;
struct Filter f;
int i, e, rc = -1;
struct sock_filter sf[1] = {BPF_STMT(BPF_RET | BPF_K, 0)};
CheckLargeStackAllocation(&f, sizeof(f));
f.n = 0;

View file

@ -67,7 +67,7 @@ ssize_t pwrite(int fd, const void *buf, size_t size, int64_t offset) {
} else if (__isfdkind(fd, kFdSocket)) {
rc = espipe();
} else if (__isfdkind(fd, kFdFile)) {
rc = sys_write_nt(fd, (struct iovec[]){{buf, size}}, 1, offset);
rc = sys_write_nt(fd, (struct iovec[]){{(void *)buf, size}}, 1, offset);
} else {
return ebadf();
}

View file

@ -53,7 +53,7 @@ static dontubsan void RaiseSigFpe(void) {
* @asyncsignalsafe
*/
int raise(int sig) {
int rc, tid, event;
int rc;
STRACE("raise(%G) → ...", sig);
if (sig == SIGTRAP) {
DebugBreak();

View file

@ -66,7 +66,6 @@ static textwindows ssize_t sys_read_nt_impl(struct Fd *fd, void *data,
int filetype;
int64_t handle;
uint32_t remain;
uint32_t conmode;
char *targetdata;
uint32_t targetsize;
bool is_console_input;
@ -205,7 +204,6 @@ StartOver:
textwindows ssize_t sys_read_nt(struct Fd *fd, const struct iovec *iov,
size_t iovlen, int64_t opt_offset) {
ssize_t rc;
uint32_t size;
size_t i, total;
if (opt_offset < -1) return einval();
if (_check_interrupts(kSigOpRestartable)) return -1;

View file

@ -45,7 +45,7 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf,
if (__mkntpathat(dirfd, path, 0, path16) == -1) return -1;
mem = 16384;
memory = alloca(mem);
CheckLargeStackAllocation(memory, mem);
CheckLargeStackAllocation((char *)memory, mem);
rdb = (struct NtReparseDataBuffer *)memory;
if ((h = CreateFile(path16, 0, 0, 0, kNtOpenExisting,
kNtFileFlagOpenReparsePoint | kNtFileFlagBackupSemantics,

View file

@ -26,7 +26,7 @@ static bool IsDataAvailable(struct Fd *fd) {
return inb(fd->handle + UART_LSR) & UART_TTYDA;
}
static int GetFirstIov(struct iovec *iov, int iovlen) {
static int GetFirstIov(const struct iovec *iov, int iovlen) {
int i;
for (i = 0; i < iovlen; ++i) {
if (iov[i].iov_len) {

View file

@ -39,7 +39,6 @@ static volatile size_t mapsize;
* @asyncsignalsafe
*/
int __ensurefds_unlocked(int fd) {
bool relocate;
if (fd < g_fds.n) return fd;
g_fds.n = fd + 1;
g_fds.e = _extend(g_fds.p, g_fds.n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE,

View file

@ -488,7 +488,6 @@ static privileged void linuxssefpustate2xnu(
privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
struct siginfo_xnu *xnuinfo,
struct __darwin_ucontext *xnuctx) {
intptr_t ax;
int rva, flags;
struct Goodies {
ucontext_t uc;
@ -571,6 +570,7 @@ privileged void __sigenter_xnu(void *fn, int infostyle, int sig,
}
#ifdef __x86_64__
intptr_t ax;
asm volatile("syscall"
: "=a"(ax)
: "0"(0x20000b8 /* sigreturn */), "D"(xnuctx), "S"(infostyle)

View file

@ -50,9 +50,8 @@
* @vforksafe
*/
int sigprocmask(int how, const sigset_t *opt_set, sigset_t *opt_out_oldset) {
int res, rc, arg1;
int rc;
sigset_t old = {0};
const sigset_t *arg2;
if (IsAsan() &&
((opt_set && !__asan_is_valid(opt_set, sizeof(*opt_set))) ||
(opt_out_oldset &&

View file

@ -47,7 +47,8 @@
*/
int sigsuspend(const sigset_t *ignore) {
int rc;
sigset_t save, *arg, mask = {0};
const sigset_t *arg;
sigset_t save, mask = {0};
STRACE("sigsuspend(%s) → ...", DescribeSigset(0, ignore));
BEGIN_CANCELLATION_POINT;

View file

@ -47,10 +47,11 @@
int sigtimedwait(const sigset_t *set, siginfo_t *info,
const struct timespec *timeout) {
int rc;
char strsig[15];
char strsig[21];
struct timespec ts;
union siginfo_meta si = {0};
BEGIN_CANCELLATION_POINT;
(void)strsig;
if (IsAsan() && (!__asan_is_valid(set, sizeof(*set)) ||
(info && !__asan_is_valid(info, sizeof(*info))) ||

View file

@ -36,8 +36,8 @@ static struct Splice {
} g_splice;
static bool HasSplice(void) {
int e;
bool ok;
int e, rc;
e = errno;
if (IsLinux()) {
// Our testing indicates splice() doesn't work as documneted on

View file

@ -15,7 +15,7 @@ struct sock_filter {
struct sock_fprog {
unsigned short len;
struct sock_filter *filter;
const struct sock_filter *filter;
};
#define BPF_RVAL(code) ((code)&0x18)

View file

@ -21,7 +21,7 @@ ssize_t sys_writev_metal(struct Fd *, const struct iovec *, int);
ssize_t sys_writev_nt(int, const struct iovec *, int);
ssize_t sys_writev_serial(struct Fd *, const struct iovec *, int);
ssize_t sys_send_nt(int, const struct iovec *, size_t, uint32_t);
ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, void *,
ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, const void *,
uint32_t);
const char *DescribeIovec(char[300], ssize_t, const struct iovec *, int);

View file

@ -5,7 +5,7 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
const char *DescribeTermios(char[1024], ssize_t, struct termios *);
const char *DescribeTermios(char[1024], ssize_t, const struct termios *);
#define DescribeTermios(rc, tio) DescribeTermios(alloca(1024), rc, tio)

View file

@ -45,7 +45,7 @@ static inline bool timespec_iszero(struct timespec __ts) {
return !(__ts.tv_sec | __ts.tv_nsec);
}
static inline bool timespec_isvalid(struct timespec __ts) {
return __ts.tv_sec >= 0 && __ts.tv_nsec < 1000000000ull;
return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
}
#endif /* _COSMO_SOURCE */

View file

@ -42,7 +42,7 @@ static inline bool timeval_iszero(struct timeval __tv) {
return !(__tv.tv_sec | __tv.tv_usec);
}
static inline bool timeval_isvalid(struct timeval __tv) {
return __tv.tv_sec >= 0 && __tv.tv_usec < 1000000ull;
return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull;
}
#endif /* _COSMO_SOURCE */

View file

@ -7,7 +7,7 @@
COSMOPOLITAN_C_START_
int tcgetwinsize_nt(int, struct winsize *);
const char *DescribeWinsize(char[64], int, struct winsize *);
const char *DescribeWinsize(char[64], int, const struct winsize *);
#define DescribeWinsize(rc, ws) DescribeWinsize(alloca(64), rc, ws)
COSMOPOLITAN_C_END_

View file

@ -164,7 +164,6 @@ textwindows void __echo_terminal_input(struct Fd *fd, char *p, size_t n) {
textwindows int tcsetattr_nt(int fd, int opt, const struct termios *tio) {
bool32 ok;
int infd;
int64_t hInput, hOutput;
uint32_t inmode, outmode;
if (__isfdkind(fd, kFdConsole)) {

View file

@ -37,7 +37,6 @@
static textwindows errno_t sys_ttyname_nt(int fd, char *buf, size_t size) {
uint32_t mode;
const char *s;
if (GetConsoleMode(g_fds.p[fd].handle, &mode)) {
if (strlcpy(buf,
(mode & kNtEnableVirtualTerminalInput) ? "CONIN$" : "CONOUT$",

View file

@ -66,7 +66,6 @@ static void GetBsdStr(int c0, int c1, char *s) {
// Gets NT name ignoring errors with guaranteed NUL-terminator.
static textwindows void GetNtName(char *name, int kind) {
uint32_t n = SYS_NMLN;
char16_t name16[256];
uint32_t size = ARRAYLEN(name16);
if (GetComputerNameEx(kind, name16, &size)) {

View file

@ -211,8 +211,8 @@ static int unveil_init(void) {
static char *JoinPaths(char *buf, size_t size, const char *path,
const char *other) {
size_t pathlen, otherlen;
if (!other) return path;
if (!path) return other;
if (!other) return (char *)path;
if (!path) return (char *)other;
pathlen = strlen(path);
if (!pathlen || *other == '/') {
return (/*unconst*/ char *)other;

View file

@ -28,7 +28,6 @@
int sys_utimensat_xnu(int dirfd, const char *path, const struct timespec ts[2],
int flags) {
int i;
struct stat st;
struct timeval now, tv[2];
if (flags) return einval();

View file

@ -81,11 +81,11 @@ static textwindows void AddProcessStats(int64_t h, struct rusage *ru) {
static textwindows int sys_wait4_nt_impl(int *pid, int *opt_out_wstatus,
int options,
struct rusage *opt_out_rusage) {
int pids[64];
int64_t handle;
int rc, pids[64];
uint32_t i, count;
int64_t handles[64];
uint32_t dwExitCode;
uint32_t i, j, count;
if (*pid != -1 && *pid != 0) {
if (*pid < 0) {
// XXX: this is sloppy

View file

@ -32,7 +32,7 @@
#include "libc/sysv/consts/sicode.h"
#include "libc/sysv/consts/sig.h"
#include "libc/thread/tls.h"
#include "libc/thread/tls2.h"
#include "libc/thread/tls2.internal.h"
#ifdef __x86_64__

View file

@ -101,7 +101,6 @@ Finish:
// this makes it possible for our read() implementation to periodically
// poll for signals while performing a blocking overlapped io operation
dontasan dontubsan dontinstrument textwindows void WinMainStdin(void) {
uint32_t mode;
char16_t pipename[64];
int64_t hStdin, hWriter, hReader, hThread, hSemaphore;
if (!SupportsWindows()) return;

View file

@ -79,9 +79,9 @@ ssize_t write(int fd, const void *buf, size_t size) {
} else if (fd >= g_fds.n) {
rc = ebadf();
} else if (IsMetal()) {
rc = sys_writev_metal(g_fds.p + fd, &(struct iovec){buf, size}, 1);
rc = sys_writev_metal(g_fds.p + fd, &(struct iovec){(void *)buf, size}, 1);
} else if (IsWindows()) {
rc = sys_writev_nt(fd, &(struct iovec){buf, size}, 1);
rc = sys_writev_nt(fd, &(struct iovec){(void *)buf, size}, 1);
} else {
rc = enosys();
}

View file

@ -47,7 +47,6 @@ int getaddrinfo(const char *name, const char *service,
const struct addrinfo *hints, struct addrinfo **res) {
int rc, port;
const char *canon;
size_t protolen;
struct addrinfo *ai;
char proto[32];
port = 0;

View file

@ -58,7 +58,7 @@ int getnameinfo(const struct sockaddr *addr, uint32_t addrlen, char *name,
int flags) {
char *p, rdomain[1 + sizeof "255.255.255.255.in-addr.arpa"];
char info[NI_MAXHOST + 1];
int rc, port;
int port;
uint8_t *ip;
unsigned int valid_flags;

View file

@ -10,6 +10,7 @@ COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § executable linkable format
*/
/* clang-format off */
bool IsElfSymbolContent(const Elf64_Sym *);
bool IsElf64Binary(const Elf64_Ehdr *, size_t);
@ -18,11 +19,11 @@ Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *, size_t, char *, const char *);
const char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
const char *GetElfSectionName(const Elf64_Ehdr *, size_t, Elf64_Shdr *);
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);
COSMOPOLITAN_C_END_

View file

@ -28,7 +28,7 @@
* @param mapsize is the number of bytes past `elf` we can access
* @return pointer to section header within image, or null
*/
Elf64_Shdr *FindElfSectionByName(Elf64_Ehdr *elf, size_t mapsize,
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *elf, size_t mapsize,
char *shdrstrtab, const char *name) {
long i;
Elf64_Shdr *shdr;

View file

@ -39,7 +39,7 @@ void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated
const Elf64_Shdr *shdr) { // foreign
Elf64_Off last;
if (!shdr) return 0;
if (!shdr->sh_size) return elf;
if (!shdr->sh_size) return (void *)elf;
if (shdr->sh_type == SHT_NOBITS) return 0;
if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0;
if (last > mapsize) return 0;

View file

@ -18,8 +18,8 @@
*/
#include "libc/elf/elf.h"
const char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize,
Elf64_Shdr *shdr) {
char *GetElfSectionName(const Elf64_Ehdr *elf, size_t mapsize,
const Elf64_Shdr *shdr) {
if (!shdr) return 0;
return GetElfString(elf, mapsize, GetElfSectionNameStringTable(elf, mapsize),
shdr->sh_name);

View file

@ -39,10 +39,10 @@
* 3. a nul byte wasn't present within `[strtab+i,elf+mapsize)`, or
* 4. an arithmetic overflow occurred
*/
const char *GetElfString(const Elf64_Ehdr *elf, // validated
size_t mapsize, // validated
const char *strtab, // validated
Elf64_Word i) { // foreign
char *GetElfString(const Elf64_Ehdr *elf, // validated
size_t mapsize, // validated
const char *strtab, // validated
Elf64_Word i) { // foreign
const char *e;
if (!i) return "";
e = (const char *)elf;
@ -50,5 +50,5 @@ const char *GetElfString(const Elf64_Ehdr *elf, // validated
if (i >= mapsize) return 0;
if (strtab + i >= e + mapsize) return 0;
if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0;
return (const char *)strtab + i;
return (char *)strtab + i;
}

View file

@ -41,7 +41,7 @@ char *GetElfStringTable(const Elf64_Ehdr *elf, //
const char *section_name) {
int i;
char *name;
Elf64_Shdr *shdr;
const Elf64_Shdr *shdr;
for (i = 0; i < elf->e_shnum; ++i) {
if ((shdr = GetElfSectionHeaderAddress(elf, mapsize, i)) &&
shdr->sh_type == SHT_STRTAB &&

View file

@ -22,7 +22,7 @@ COSMOPOLITAN_C_START_
((Elf64_Shdr *)((intptr_t)(e) + (e)->e_shoff + \
(unsigned)(e)->e_shentsize * (i)))
static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) {
static inline char *GetStrtab(const Elf64_Ehdr *e, size_t *n) {
int i;
char *name;
Elf64_Shdr *shdr;
@ -39,7 +39,7 @@ static inline char *GetStrtab(Elf64_Ehdr *e, size_t *n) {
return 0;
}
static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) {
static inline Elf64_Sym *GetSymtab(const Elf64_Ehdr *e, Elf64_Xword *n) {
int i;
Elf64_Shdr *shdr;
for (i = e->e_shnum; i-- > 0;) {
@ -52,9 +52,10 @@ static inline Elf64_Sym *GetSymtab(Elf64_Ehdr *e, Elf64_Xword *n) {
return 0;
}
static inline void GetImageRange(Elf64_Ehdr *elf, intptr_t *x, intptr_t *y) {
static inline void GetImageRange(const Elf64_Ehdr *elf, intptr_t *x,
intptr_t *y) {
unsigned i;
Elf64_Phdr *phdr;
const Elf64_Phdr *phdr;
intptr_t start, end, pstart, pend;
start = INTPTR_MAX;
end = 0;

View file

@ -17,7 +17,7 @@ int snprintf(char *, size_t, const char *, ...)
printfesque(3) dontthrow nocallback;
int vsnprintf(char *, size_t, const char *, va_list)
dontthrow nocallback;
int sprintf(char *, const char *, ...) printfesque(2) dontthrow nocallback;
int sprintf(char *, const char *, ...) dontthrow nocallback;
int vsprintf(char *, const char *, va_list)
dontthrow nocallback;
int sscanf(const char *, const char *, ...) scanfesque(2);

View file

@ -14,7 +14,7 @@ char *sleb64(char *, int64_t);
char *zleb64(char[hasatleast 10], int64_t);
char *uleb64(char[hasatleast 10], uint64_t);
int unzleb64(const char *, size_t, int64_t *);
int unuleb64(char *, size_t, uint64_t *);
int unuleb64(const char *, size_t, uint64_t *);
COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */

View file

@ -28,9 +28,9 @@ extern const struct MagnumStr kSockOptnames[];
extern const struct MagnumStr kTcpOptnames[];
extern const struct MagnumStr kPollNames[];
char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int);
const char *DescribeMagnum(char *, const struct MagnumStr *, const char *, int);
__funline char *GetMagnumStr(const struct MagnumStr *ms, int x) {
__funline const char *GetMagnumStr(const struct MagnumStr *ms, int x) {
int i;
for (i = 0; ms[i].x != MAGNUM_TERMINATOR; ++i) {
if (x == MAGNUM_NUMBER(ms, i)) {
@ -44,7 +44,7 @@ __funline char *GetMagnumStr(const struct MagnumStr *ms, int x) {
* Converts errno value to descriptive sentence.
* @return non-null rodata string or null if not found
*/
__funline char *_strerdoc(int x) {
__funline const char *_strerdoc(int x) {
if (x) {
return GetMagnumStr(kErrnoDocs, x);
} else {
@ -56,7 +56,7 @@ __funline char *_strerdoc(int x) {
* Converts errno value to symbolic name.
* @return non-null rodata string or null if not found
*/
__funline char *_strerrno(int x) {
__funline const char *_strerrno(int x) {
if (x) {
return GetMagnumStr(kErrnoNames, x);
} else {

View file

@ -53,7 +53,7 @@ long strtol(const char *s, char **endptr, int base) {
char t = 0;
long x = 0;
int d, c = *s;
CONSUME_SPACES(s, c);
CONSUME_SPACES(char, s, c);
GET_SIGN(s, c, d);
GET_RADIX(s, c, base);
if ((c = kBase36[c & 255]) && --c < base) {
@ -67,7 +67,9 @@ long strtol(const char *s, char **endptr, int base) {
} while ((c = kBase36[*++s & 255]) && --c < base);
}
}
if (t && endptr) *endptr = s;
if (t && endptr) {
*endptr = (char *)s;
}
return x;
}

View file

@ -2,8 +2,8 @@
#define COSMOPOLITAN_LIBC_FMT_STRTOL_H_
#include "libc/errno.h"
#define CONSUME_SPACES(s, c) \
if (endptr) *endptr = s; \
#define CONSUME_SPACES(t, s, c) \
if (endptr) *endptr = (t *)(s); \
while (c == ' ' || c == '\t') c = *++s
#define GET_SIGN(s, c, d) \

View file

@ -42,20 +42,24 @@ unsigned long strtoul(const char *s, char **endptr, int base) {
char t = 0;
int d, c = *s;
unsigned long x = 0;
CONSUME_SPACES(s, c);
CONSUME_SPACES(char, s, c);
GET_SIGN(s, c, d);
GET_RADIX(s, c, base);
if ((c = kBase36[c & 255]) && --c < base) {
t |= 1;
do {
if (ckd_mul(&x, x, base) || ckd_add(&x, x, c)) {
if (endptr) *endptr = s + 1;
if (endptr) {
*endptr = (char *)(s + 1);
}
errno = ERANGE;
return ULONG_MAX;
}
} while ((c = kBase36[*++s & 255]) && --c < base);
}
if (t && endptr) *endptr = s;
if (t && endptr) {
*endptr = (char *)s;
}
return d > 0 ? x : -x;
}

View file

@ -26,7 +26,7 @@
* @param x receives number number
* @return bytes decoded or -1 on error
*/
int unuleb64(char *p, size_t n, uint64_t *x) {
int unuleb64(const char *p, size_t n, uint64_t *x) {
int k;
size_t i;
uint64_t t;

View file

@ -41,7 +41,7 @@ long wcstol(const wchar_t *s, wchar_t **endptr, int base) {
char t = 0;
long x = 0;
int d, c = *s;
CONSUME_SPACES(s, c);
CONSUME_SPACES(wchar_t, s, c);
GET_SIGN(s, c, d);
GET_RADIX(s, c, base);
if ((c = kBase36[c & 255]) && --c < base) {
@ -55,7 +55,9 @@ long wcstol(const wchar_t *s, wchar_t **endptr, int base) {
} while ((c = kBase36[*++s & 255]) && --c < base);
}
}
if (t && endptr) *endptr = s;
if (t && endptr) {
*endptr = (wchar_t *)s;
}
return x;
}

View file

@ -41,20 +41,24 @@ unsigned long wcstoul(const wchar_t *s, wchar_t **endptr, int base) {
char t = 0;
int d, c = *s;
unsigned long x = 0;
CONSUME_SPACES(s, c);
CONSUME_SPACES(wchar_t, s, c);
GET_SIGN(s, c, d);
GET_RADIX(s, c, base);
if ((c = kBase36[c & 255]) && --c < base) {
t |= 1;
do {
if (ckd_mul(&x, x, base) || ckd_add(&x, x, c)) {
if (endptr) *endptr = s + 1;
if (endptr) {
*endptr = (wchar_t *)(s + 1);
}
errno = ERANGE;
return ULONG_MAX;
}
} while ((c = kBase36[*++s & 255]) && --c < base);
}
if (t && endptr) *endptr = s;
if (t && endptr) {
*endptr = (wchar_t *)s;
}
return d > 0 ? x : -x;
}

View file

@ -651,101 +651,13 @@ void abort(void) wontreturn;
#define initarray _Section(".init_array")
#endif
#ifndef __STRICT_ANSI__
#if defined(__GNUC__) || defined(__llvm__)
#pragma GCC diagnostic ignored \
"-Wundef" /* complaints about __ASSEMBLER__/__LINKER__ */
#pragma GCC diagnostic ignored "-Wsign-compare" /* lint needs to change */
#pragma GCC diagnostic ignored "-Wtype-limits" /* makes macros unsafe */
#pragma GCC diagnostic ignored "-Woverflow" /* also breaks macros */
#pragma GCC diagnostic ignored "-Wformat" /* forces only gnu pf */
#pragma GCC diagnostic ignored "-Wunused-parameter" /* extreme prejudice */
#pragma GCC diagnostic ignored "-Wunused-function" /* contradicts dce! */
#pragma GCC diagnostic ignored "-Wunused-const-variable" /* let me dce */
#pragma GCC diagnostic ignored "-Wunused-variable" /* belongs in tidy */
#pragma GCC diagnostic ignored "-Wformat-extra-args" /* is also broken */
#pragma GCC diagnostic ignored "-Wparentheses" /* annoying tidy */
#pragma GCC diagnostic ignored "-Wdangling-else" /* come on tidy */
#pragma GCC diagnostic ignored "-Wformat-security" /* come on tidy */
#pragma GCC diagnostic ignored "-Wunused-value" /* breaks macros */
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" /* libcxx */
#pragma GCC diagnostic ignored "-Wformat" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wformat-extra-args" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wunused-function" /* contradicts dce */
#pragma GCC diagnostic ignored "-Wunused-const-variable" /* sooo ridiculous */
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wimplicit-int"
#pragma GCC diagnostic ignored "-Wc++-compat"
#endif /* C++ */
#endif /* GCC || LLVM */
#if defined(__GNUC__) && !defined(__llvm__)
/* why we need authorization to name a variable `yn' */
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
#pragma GCC diagnostic ignored "-Wfree-nonheap-object" /* broken #54202 */
#ifndef __cplusplus
#if __GNUC__ >= 6
#pragma GCC diagnostic ignored /* wut */ "-Wdiscarded-qualifiers"
#pragma GCC diagnostic ignored /* tidy */ "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored /* tidy */ "-Wunused-but-set-parameter"
#endif /* GCC6+ */
#if __GNUC__ >= 8
#pragma GCC diagnostic ignored "-Wstringop-truncation"
#pragma GCC diagnostic ignored "-Wstringop-overflow" /* breaks strndup */
#endif /* GCC8+ */
#if __GNUC__ + 0 >= 9
#pragma GCC diagnostic ignored /* "always true" breaks dce */ "-Waddress"
#if __GNUC__ >= 11
#pragma GCC diagnostic ignored /* annoying */ "-Wattributes"
#pragma GCC diagnostic ignored /* orwellian */ "-Wold-style-definition"
#pragma GCC diagnostic ignored /* what? */ "-Wformat-overflow"
#endif /* GCC11+ */
#endif /* GCC9+ */
#endif /* !C++ */
#endif /* GCC && !LLVM */
#ifdef __llvm__
#pragma clang diagnostic ignored \
"-Wincompatible-pointer-types-discards-qualifiers"
#pragma clang diagnostic ignored "-Wbuiltin-requires-header"
#pragma clang diagnostic ignored "-Wparentheses-equality" /*-save-temps*/
#pragma clang diagnostic ignored "-Wunused-value" /*({-save-temps})*/
#pragma clang diagnostic ignored "-Wstring-plus-int" /* special ed */
#pragma clang diagnostic ignored "-Wunused-value" /* extreme prejudice */
#pragma clang diagnostic ignored "-Wbuiltin-requires-header"
#pragma clang diagnostic ignored \
"-Wincompatible-pointer-types-discards-qualifiers"
#endif /* !GCC && LLVM */
#endif /* ANSI */
#ifndef __W__
#ifndef __STRICT_ANSI__
#if defined(__GNUC__) || defined(__llvm__)
#pragma GCC diagnostic error "-Wpointer-arith"
#pragma GCC diagnostic error "-Wnonnull"
#pragma GCC diagnostic error "-Wunused-result"
#pragma GCC diagnostic error "-Wstrict-aliasing"
#ifndef __cplusplus
#pragma GCC diagnostic error "-Wimplicit-function-declaration"
#if __GNUC__ >= 6
#pragma GCC diagnostic error "-Wincompatible-pointer-types"
#if __GNUC__ >= 8
#pragma GCC diagnostic error "-Wmultistatement-macros"
#pragma GCC diagnostic error "-Wpacked-not-aligned"
#pragma GCC diagnostic error "-Wcast-align=strict"
#pragma GCC diagnostic error "-Wif-not-aligned"
#endif /* GCC 8+ */
#endif /* GCC 6+ */
#endif /* __cplusplus */
#endif /* GCC || LLVM */
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC diagnostic error "-Wwrite-strings"
#pragma GCC diagnostic error "-Wtrampolines"
#if __GNUC__ >= 6
#pragma GCC diagnostic error "-Wnonnull-compare"
#elif __GNUC__ >= 9
#pragma GCC diagnostic error /* e.g. fabs not abs */ "-Wabsolute-value"
#endif /* GCC 6+ */
#endif /* GCC && !LLVM */
#ifdef __llvm__
#pragma clang diagnostic error "-Wassume"
#endif /* !GCC && LLVM */
#endif /* ANSI */
#endif /* -w */
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bulls */
#endif
#ifndef __STRICT_ANSI__
#ifdef __x86_64__
@ -829,9 +741,13 @@ void abort(void) wontreturn;
#define __strong_reference(sym, alias) __weak_reference(sym, alias)
#endif
#if defined(__GNUC__) || defined(__llvm__)
#define __funline \
extern __inline \
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
#else
#define __funline static inline
#endif
#define MACHINE_CODE_ANALYSIS_BEGIN_
#define MACHINE_CODE_ANALYSIS_END_

View file

@ -129,13 +129,13 @@ struct AsanExtra {
};
struct AsanSourceLocation {
const char *filename;
char *filename;
int line;
int column;
};
struct AsanAccessInfo {
const char *addr;
char *addr;
const uintptr_t first_bad_addr;
size_t size;
bool iswrite;
@ -143,7 +143,7 @@ struct AsanAccessInfo {
};
struct AsanGlobal {
const char *addr;
char *addr;
size_t size;
size_t size_with_redzone;
const void *name;
@ -517,7 +517,6 @@ struct AsanFault __asan_check(const void *p, long n) {
*/
struct AsanFault __asan_check_str(const char *p) {
uint64_t w;
struct AsanFault f;
signed char c, k, *s;
s = SHADOW(p);
if (OverlapsShadowSpace(p, 1)) {
@ -1059,7 +1058,8 @@ static struct AsanExtra *__asan_get_extra(const void *p, size_t *c) {
long x, n;
struct AsanExtra *e;
f = (intptr_t)p >> 16;
if (!kisdangerous(p) && (n = _weaken(dlmalloc_usable_size)(p)) > sizeof(*e) &&
if (!kisdangerous(p) &&
(n = _weaken(dlmalloc_usable_size)((void *)p)) > sizeof(*e) &&
!ckd_add(&x, (intptr_t)p, n) && x <= 0x800000000000 &&
(LIKELY(f == (int)((x - 1) >> 16)) || !kisdangerous((void *)(x - 1))) &&
(LIKELY(f == (int)((x = x - sizeof(*e)) >> 16)) ||
@ -1227,7 +1227,6 @@ void *__asan_memalign(size_t align, size_t size) {
}
void *__asan_calloc(size_t n, size_t m) {
char *p;
struct AsanTrace bt;
__asan_trace(&bt, RBP);
if (ckd_mul(&n, n, m)) n = -1;
@ -1498,7 +1497,7 @@ void __asan_init(int argc, char **argv, char **envp, intptr_t *auxv) {
__asan_shadow_existing_mappings();
__asan_map_shadow((uintptr_t)__executable_start, _end - __executable_start);
__asan_map_shadow(0, 4096);
__asan_poison(0, getauxval(AT_PAGESZ), kAsanNullPage);
__asan_poison((void *)__veil("r", 0L), getauxval(AT_PAGESZ), kAsanNullPage);
if (!IsWindows()) {
sys_mprotect((void *)0x7fff8000, 0x10000, PROT_READ);
}

View file

@ -29,18 +29,17 @@
* @note 30gbps on Nehalem (Intel 2008+) otherwise 3gbps
*/
size_t _countbits(const void *a, size_t n) {
int i;
size_t t;
unsigned b;
uint64_t x;
long Ai, Bi, Ci, Di;
long Ao, Bo, Co, Do;
const char *p, *e;
t = 0;
p = a;
e = p + n;
if (!IsTiny()) {
#ifdef __x86_64__
long Ai, Bi, Ci, Di;
long Ao, Bo, Co, Do;
if (X86_HAVE(POPCNT)) {
while (p + sizeof(long) * 4 <= e) {
__builtin_memcpy(&Ai, p + 000, sizeof(long));

View file

@ -28,7 +28,7 @@ int begin_cancellation_point(void) {
int state = 0;
struct CosmoTib *tib;
struct PosixThread *pt;
if (__enable_tls) {
if (__tls_enabled) {
tib = __get_tls();
if ((pt = (struct PosixThread *)tib->tib_pthread)) {
state = pt->flags & PT_INCANCEL;
@ -41,7 +41,7 @@ int begin_cancellation_point(void) {
void end_cancellation_point(int state) {
struct CosmoTib *tib;
struct PosixThread *pt;
if (__enable_tls) {
if (__tls_enabled) {
tib = __get_tls();
if ((pt = (struct PosixThread *)tib->tib_pthread)) {
pt->flags &= ~PT_INCANCEL;

View file

@ -38,13 +38,14 @@ __msabi extern typeof(Sleep) *const __imp_Sleep;
* @return handle, or -1 on failure w/ `errno` set appropriately
* @note this wrapper takes care of ABI, STRACE(), and __winerr()
*/
textwindows int64_t CreateFile(const char16_t *lpFileName, //
uint32_t dwDesiredAccess, //
uint32_t dwShareMode, //
struct NtSecurityAttributes *opt_lpSecurity, //
int dwCreationDisposition, //
uint32_t dwFlagsAndAttributes, //
int64_t opt_hTemplateFile) {
textwindows int64_t
CreateFile(const char16_t *lpFileName, //
uint32_t dwDesiredAccess, //
uint32_t dwShareMode, //
const struct NtSecurityAttributes *opt_lpSecurity, //
int dwCreationDisposition, //
uint32_t dwFlagsAndAttributes, //
int64_t opt_hTemplateFile) {
int64_t hHandle;
uint32_t micros = 1;
TryAgain:

View file

@ -19,12 +19,12 @@
#include "libc/intrin/describeflags.internal.h"
// TODO(jart): Fork this function into ASAN and non-ASAN versions.
const char *DescribeFlags(char *p, size_t n, struct DescribeFlags *d, size_t m,
const char *prefix, unsigned x) {
const char *DescribeFlags(char *p, size_t n, const struct DescribeFlags *d,
size_t m, const char *prefix, unsigned x) {
bool t;
char b[21];
size_t i, j, k;
for (t = i = j = 0; j < m; ++j) {
for (t = false, i = j = 0; j < m; ++j) {
if (d[j].flag && d[j].flag != -1 && (x & d[j].flag) == d[j].flag) {
x &= ~d[j].flag;
if (t) {

View file

@ -9,7 +9,7 @@ struct thatispacked DescribeFlags {
const char *name;
};
const char *DescribeFlags(char *, size_t, struct DescribeFlags *, size_t,
const char *DescribeFlags(char *, size_t, const struct DescribeFlags *, size_t,
const char *, unsigned);
const char *DescribeArchPrctlCode(char[12], int);
@ -54,7 +54,7 @@ const char *DescribeRemapFlags(char[48], int);
const char *DescribeRlimitName(char[20], int);
const char *DescribeSchedPolicy(char[48], int);
const char *DescribeSeccompOperation(int);
const char *DescribeSiCode(char[17], int, int);
const char *DescribeSiCode(char[20], int, int);
const char *DescribeSleepFlags(char[16], int);
const char *DescribeSockLevel(char[12], int);
const char *DescribeSockOptname(char[32], int, int);
@ -105,7 +105,7 @@ const char *DescribeWhichPrio(char[12], int);
#define DescribeRemapFlags(x) DescribeRemapFlags(alloca(48), x)
#define DescribeRlimitName(rl) DescribeRlimitName(alloca(20), rl)
#define DescribeSchedPolicy(x) DescribeSchedPolicy(alloca(48), x)
#define DescribeSiCode(x, y) DescribeSiCode(alloca(17), x, y)
#define DescribeSiCode(x, y) DescribeSiCode(alloca(20), x, y)
#define DescribeSleepFlags(x) DescribeSleepFlags(alloca(16), x)
#define DescribeSockLevel(x) DescribeSockLevel(alloca(12), x)
#define DescribeSockOptname(x, y) DescribeSockOptname(alloca(32), x, y)

View file

@ -61,7 +61,6 @@ static const char *GetFrameName(int x) {
}
const char *(DescribeFrame)(char buf[32], int x) {
char *p;
if (IsShadowFrame(x)) {
ksnprintf(buf, 32, "%s %s %.8x", GetFrameName(x),
GetFrameName(FRAME(UNSHADOW(ADDR_32_TO_48(x)))),

View file

@ -20,8 +20,9 @@
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/str/str.h"
char *DescribeMagnum(char *b, const struct MagnumStr *m, const char *p, int x) {
char *s;
const char *DescribeMagnum(char *b, const struct MagnumStr *m, const char *p,
int x) {
const char *s;
if (x == 127) return "CLOCK_INVALID";
if ((s = GetMagnumStr(m, x))) {
stpcpy(stpcpy(b, p), s);

View file

@ -32,8 +32,7 @@
const char *(DescribePollFds)(char buf[N], ssize_t rc, struct pollfd *fds,
size_t nfds) {
char b64[64];
const char *d;
int i, j, o = 0;
int i, o = 0;
if (!fds) return "NULL";
if ((!IsAsan() && kisdangerous(fds)) ||

View file

@ -30,7 +30,7 @@ static bool IsSiUser(int si_code) {
}
}
static void NameIt(char p[17], const char *s, int si_code) {
static void NameIt(char p[20], const char *s, int si_code) {
p = stpcpy(p, s);
FormatInt32(p, si_code);
}
@ -38,7 +38,7 @@ static void NameIt(char p[17], const char *s, int si_code) {
/**
* Returns symbolic name for siginfo::si_code value.
*/
const char *(DescribeSiCode)(char b[17], int sig, int si_code) {
const char *(DescribeSiCode)(char b[20], int sig, int si_code) {
NameIt(b, "SI_", si_code);
if (si_code == SI_QUEUE) {
strcpy(b + 3, "QUEUE"); /* sent by sigqueue(2) */

View file

@ -26,8 +26,8 @@
* Describes setsockopt() optname arguments.
*/
const char *(DescribeSockOptname)(char buf[32], int l, int x) {
int i;
char *s, *p;
char *p;
const char *s;
const struct MagnumStr *ms;
p = buf;
if (x) {

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/struct/termios.h"
#include "libc/calls/struct/termios.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
@ -28,7 +29,8 @@
#define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__)
const char *(DescribeTermios)(char buf[N], ssize_t rc, struct termios *tio) {
const char *(DescribeTermios)(char buf[N], ssize_t rc,
const struct termios *tio) {
int o = 0;
char b128[128];

View file

@ -29,11 +29,8 @@
#define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__)
const char *(DescribeWinsize)(char buf[N], int rc, struct winsize *ws) {
char b64[64];
const char *d;
int i, j, o = 0;
const char *(DescribeWinsize)(char buf[N], int rc, const struct winsize *ws) {
int o = 0;
if (!ws) return "NULL";
if (rc == -1) return "n/a";
if ((!IsAsan() && kisdangerous(ws)) ||

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/ffs.h"
/**
* Finds lowest set bit in word.
@ -27,7 +28,7 @@ int ffs(int x) {
/**
* Finds lowest set bit in word.
*/
long ffsl(long x) {
int ffsl(long x) {
return __builtin_ffsl(x);
}

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/internal.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/struct/fd.internal.h"
#include "libc/calls/ttydefaults.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/extend.internal.h"
@ -26,12 +26,10 @@
#include "libc/intrin/nomultics.internal.h"
#include "libc/intrin/pushpop.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/macros.internal.h"
#include "libc/nt/runtime.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/thread/thread.h"

View file

@ -74,7 +74,7 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/thread/tls.h"
#include "libc/thread/tls2.h"
#include "libc/thread/tls2.internal.h"
#include "libc/vga/vga.internal.h"
#define KGETINT(x, va, t, s) \
@ -134,14 +134,13 @@ __msabi extern typeof(WriteFile) *const __imp_WriteFile;
long __klog_handle;
extern struct SymbolTable *__symtab;
privileged static inline char *kadvance(char *p, char *e, long n) {
__funline char *kadvance(char *p, char *e, long n) {
intptr_t t = (intptr_t)p;
if (ckd_add(&t, t, n)) t = (intptr_t)e;
return (char *)t;
}
privileged static char *kemitquote(char *p, char *e, signed char t,
unsigned c) {
__funline char *kemitquote(char *p, char *e, signed char t, unsigned c) {
if (t) {
if (p < e) {
*p = t < 0 ? 'u' : 'L';
@ -155,27 +154,27 @@ privileged static char *kemitquote(char *p, char *e, signed char t,
return p;
}
privileged static inline bool kiskernelpointer(const void *p) {
__funline bool kiskernelpointer(const void *p) {
return 0x7f0000000000 <= (intptr_t)p && (intptr_t)p < 0x800000000000;
}
privileged static inline bool kistextpointer(const void *p) {
__funline bool kistextpointer(const void *p) {
return __executable_start <= (const unsigned char *)p &&
(const unsigned char *)p < _etext;
}
privileged static inline bool kisimagepointer(const void *p) {
__funline bool kisimagepointer(const void *p) {
return __executable_start <= (const unsigned char *)p &&
(const unsigned char *)p < _end;
}
privileged static inline bool kischarmisaligned(const char *p, signed char t) {
__funline bool kischarmisaligned(const char *p, signed char t) {
if (t == -1) return (intptr_t)p & 1;
if (t >= 1) return !!((intptr_t)p & 3);
return false;
}
privileged static inline bool kismemtrackhosed(void) {
__funline bool kismemtrackhosed(void) {
return !((_weaken(_mmi)->i <= _weaken(_mmi)->n) &&
(_weaken(_mmi)->p == _weaken(_mmi)->s ||
_weaken(_mmi)->p == (struct MemoryInterval *)kMemtrackStart));
@ -319,7 +318,7 @@ privileged long kloghandle(void) {
hand = STDERR_FILENO;
} else if (IsWindows()) {
uint32_t e, n;
const char16_t path[512];
char16_t path[512];
e = __imp_GetLastError();
n = __imp_GetEnvironmentVariableW(u"KPRINTF_LOG", path, 512);
if (!n && __imp_GetLastError() == kNtErrorEnvvarNotFound) {
@ -389,7 +388,6 @@ privileged void klog(const char *b, size_t n) {
#ifdef __x86_64__
int e;
long h;
bool cf;
size_t i;
uint16_t dx;
uint32_t wrote;
@ -442,7 +440,7 @@ privileged void klog(const char *b, size_t n) {
privileged static size_t kformat(char *b, size_t n, const char *fmt,
va_list va) {
int si, y;
int si;
wint_t t, u;
const char *abet;
signed char type;

View file

@ -40,10 +40,8 @@ dontasan static inline const unsigned char *memchr_sse(const unsigned char *s,
unsigned char c,
size_t n) {
size_t i;
unsigned k;
unsigned m;
xmm_t v, *p;
xmm_t t = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
xmm_t v, t = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
for (; n >= 16; n -= 16, s += 16) {
v = *(const xmm_t *)s;
m = __builtin_ia32_pmovmskb128(v == t);

View file

@ -91,7 +91,7 @@ void *memmove(void *dst, const void *src, size_t n) {
size_t i;
const char *s;
uint64_t a, b;
xmm_t v, w, x, y, V, W, X, Y, wut;
xmm_t v, w, x, y, V, W, X, Y;
d = dst;
s = src;

View file

@ -40,7 +40,7 @@ dontasan static inline const unsigned char *memrchr_sse(const unsigned char *s,
unsigned char c,
size_t n) {
size_t i;
unsigned k, m;
unsigned m;
xmm_t v, t = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
for (i = n; i >= 16;) {
v = *(const xmm_t *)(s + (i -= 16));

View file

@ -210,7 +210,7 @@ dontasan void __unref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) {
*/
static dontasan textreal void __invert_memory(struct mman *mm,
uint64_t *pml4t) {
uint64_t i, j, *m, p, pe;
uint64_t i;
for (i = 0; i < mm->e820n; ++i) {
uint64_t ps = mm->e820[i].addr, size = mm->e820[i].size;
/* ape/ape.S has already mapped the first 2 MiB of physical memory. */
@ -261,8 +261,8 @@ dontasan textreal void __setup_mman(struct mman *mm, uint64_t *pml4t,
*/
dontasan textreal void __map_phdrs(struct mman *mm, uint64_t *pml4t, uint64_t b,
uint64_t top) {
uint64_t i, f, v, m;
struct Elf64_Phdr *p;
uint64_t i, f, v, m, *e;
extern char ape_phdrs[] __attribute__((__weak__));
extern char ape_phdrs_end[] __attribute__((__weak__));
__setup_mman(mm, pml4t, top);

View file

@ -32,8 +32,8 @@ static bool IsNoteworthyHole(unsigned i, const struct MemoryIntervals *mm) {
}
void PrintMemoryIntervals(int fd, const struct MemoryIntervals *mm) {
char *p, mappingbuf[8], framebuf[64], sb[16];
long i, w, frames, maptally = 0;
char mappingbuf[8], framebuf[64], sb[16];
for (w = i = 0; i < mm->i; ++i) {
w = MAX(w, LengthInt64Thousands(mm->p[i].y + 1 - mm->p[i].x));
}

View file

@ -34,7 +34,6 @@
* @return 0 on success, or errno on error
*/
int pthread_key_delete(pthread_key_t k) {
uint64_t mask;
unassert(0 <= k && k < PTHREAD_KEYS_MAX);
unassert(atomic_load_explicit(_pthread_key_dtor + k, memory_order_acquire));
atomic_store_explicit(_pthread_key_dtor + k, 0, memory_order_release);

View file

@ -65,7 +65,7 @@
* @vforksafe
*/
int pthread_mutex_lock(pthread_mutex_t *mutex) {
int c, d, t;
int t;
if (__vforked) return 0;

View file

@ -35,7 +35,7 @@
* @raise ENOTRECOVERABLE if `mutex` is corrupted
*/
errno_t pthread_mutex_trylock(pthread_mutex_t *mutex) {
int c, d, t;
int t;
if (__tls_enabled && //
mutex->_type == PTHREAD_MUTEX_NORMAL && //

View file

@ -37,7 +37,7 @@
* @vforksafe
*/
int pthread_mutex_unlock(pthread_mutex_t *mutex) {
int c, t;
int t;
if (__vforked) return 0;

View file

@ -37,6 +37,6 @@ int pthread_setspecific(pthread_key_t k, const void *val) {
// ──Quoth POSIX.1-2017
unassert(0 <= k && k < PTHREAD_KEYS_MAX);
unassert(atomic_load_explicit(_pthread_key_dtor + k, memory_order_acquire));
__get_tls()->tib_keys[k] = val;
__get_tls()->tib_keys[k] = (void *)val;
return 0;
}

View file

@ -28,7 +28,7 @@
* @asyncsignalsafe
*/
int sigcountset(const sigset_t *set) {
int r, i, x, y;
int x, y;
switch (_NSIG) {
case 32:
x = (uint32_t)set->__bits[0];

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