mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 18:28:30 +00:00
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:
parent
e2b3c3618e
commit
0d748ad58e
571 changed files with 1306 additions and 1888 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) || //
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) \
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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]) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 &&
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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))) ||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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_
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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$",
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue