Apply clang-format update to repo (#1154)

Commit bc6c183 introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)

I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.

My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.

It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.

fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
This commit is contained in:
Jōshin 2024-04-25 10:38:00 -07:00 committed by GitHub
parent 342d0c81e5
commit 6e6fc38935
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
863 changed files with 9201 additions and 4627 deletions

View file

@ -26,8 +26,10 @@ privileged struct Env __getenv(char **p, const char *k) {
for (i = 0; (t = p[i]); ++i) {
for (j = 0;; ++j) {
if (!k[j] || k[j] == '=') {
if (!t[j]) return (struct Env){t + j, i};
if (t[j] == '=') return (struct Env){t + j + 1, i};
if (!t[j])
return (struct Env){t + j, i};
if (t[j] == '=')
return (struct Env){t + j + 1, i};
break;
}
if (k[j] != t[j]) {

View file

@ -204,7 +204,8 @@ static uint64_t __asan_roundup2pow(uint64_t x) {
static char *__asan_utf8cpy(char *p, unsigned c) {
uint64_t z;
z = tpenc(c);
do *p++ = z;
do
*p++ = z;
while ((z >>= 8));
return p;
}
@ -267,7 +268,8 @@ void __asan_memset(void *p, char c, size_t n) {
asm volatile("" ::: "memory");
__builtin_memcpy(b + i + 8, &x, 8);
} while ((i += 16) + 16 <= n);
for (; i < n; ++i) b[i] = x;
for (; i < n; ++i)
b[i] = x;
break;
}
}
@ -331,7 +333,8 @@ static void *__asan_mempcpy(void *dst, const void *src, size_t n) {
asm volatile("" ::: "memory");
__builtin_memcpy(d + i, &a, 8);
} while ((i += 8) + 8 <= n);
for (; i < n; ++i) d[i] = s[i];
for (; i < n; ++i)
d[i] = s[i];
return d + i;
}
}
@ -342,7 +345,8 @@ void *__asan_memcpy(void *dst, const void *src, size_t n) {
}
static char *__asan_hexcpy(char *p, uint64_t x, uint8_t k) {
while (k) *p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15];
while (k)
*p++ = "0123456789abcdef"[(x >> (k -= 4)) & 15];
return p;
}
@ -371,14 +375,16 @@ void __asan_poison(void *p, long n, signed char t) {
signed char k, *s;
s = (signed char *)(((intptr_t)p >> 3) + 0x7fff8000);
if ((k = (intptr_t)p & 7)) {
if ((!*s && n >= 8 - k) || *s > k) *s = k;
if ((!*s && n >= 8 - k) || *s > k)
*s = k;
n -= MIN(8 - k, n);
s += 1;
}
__asan_memset(s, t, n >> 3);
if ((k = n & 7)) {
s += n >> 3;
if (*s < 0 || (*s > 0 && *s <= k)) *s = t;
if (*s < 0 || (*s > 0 && *s <= k))
*s = t;
}
}
@ -388,7 +394,8 @@ void __asan_unpoison(void *p, long n) {
s = (signed char *)(((intptr_t)p >> 3) + 0x7fff8000);
if (UNLIKELY(k)) {
if (k + n < 8) {
if (n > 0) *s = MAX(*s, k + n);
if (n > 0)
*s = MAX(*s, k + n);
return;
}
n -= MIN(8 - k, n);
@ -397,8 +404,10 @@ void __asan_unpoison(void *p, long n) {
__asan_memset(s, 0, n >> 3);
if ((k = n & 7)) {
s += n >> 3;
if (*s < 0) *s = k;
if (*s > 0) *s = MAX(*s, k);
if (*s < 0)
*s = k;
if (*s > 0)
*s = MAX(*s, k);
}
}
@ -438,7 +447,8 @@ static struct AsanFault __asan_checka(const signed char *s, long ndiv8) {
uint64_t w;
const signed char *e = s + ndiv8;
for (; ((intptr_t)s & 7) && s < e; ++s) {
if (*s) return __asan_fault(s - 1, kAsanHeapOverrun);
if (*s)
return __asan_fault(s - 1, kAsanHeapOverrun);
}
for (; s + 8 <= e; s += 8) {
if (UNLIKELY(!((intptr_t)s & (FRAMESIZE - 1))) && kisdangerous(s)) {
@ -450,7 +460,8 @@ static struct AsanFault __asan_checka(const signed char *s, long ndiv8) {
}
}
for (; s < e; ++s) {
if (*s) return __asan_fault(s - 1, kAsanHeapOverrun);
if (*s)
return __asan_fault(s - 1, kAsanHeapOverrun);
}
return (struct AsanFault){0};
}
@ -586,9 +597,12 @@ bool __asan_is_valid_str(const char *p) {
*/
bool __asan_is_valid_strlist(char *const *p) {
for (;; ++p) {
if (!__asan_is_valid(p, sizeof(char *))) return false;
if (!*p) return true;
if (!__asan_is_valid_str(*p)) return false;
if (!__asan_is_valid(p, sizeof(char *)))
return false;
if (!*p)
return true;
if (!__asan_is_valid_str(*p))
return false;
}
}
@ -877,7 +891,8 @@ static __wur __asan_die_f *__asan_report(const void *addr, int size,
}
*p++ = '\e', *p++ = '[', *p++ = '3', *p++ = '9', *p++ = 'm';
*p++ = '\n';
for (i = 0; (intptr_t)(base + i) & 7; ++i) *p++ = ' ';
for (i = 0; (intptr_t)(base + i) & 7; ++i)
*p++ = ' ';
for (; i + 8 <= 80; i += 8) {
q = p + 8;
*p++ = '|';
@ -891,7 +906,8 @@ static __wur __asan_die_f *__asan_report(const void *addr, int size,
*p++ = ' ';
}
}
for (; i < 80; ++i) *p++ = ' ';
for (; i < 80; ++i)
*p++ = ' ';
*p++ = '\n';
for (i = 0; i < 80; ++i) {
p = __asan_utf8cpy(p, __asan_exists(base + i)
@ -909,9 +925,11 @@ static __wur __asan_die_f *__asan_report(const void *addr, int size,
y = m->p[i].y;
p = __asan_format_interval(p, x << 16, (y << 16) + (FRAMESIZE - 1));
z = (intptr_t)addr >> 16;
if (x <= z && z <= y) p = __asan_stpcpy(p, " ←address");
if (x <= z && z <= y)
p = __asan_stpcpy(p, " ←address");
z = (((intptr_t)addr >> 3) + 0x7fff8000) >> 16;
if (x <= z && z <= y) p = __asan_stpcpy(p, " ←shadow");
if (x <= z && z <= y)
p = __asan_stpcpy(p, " ←shadow");
*p++ = '\n';
}
__mmi_unlock();
@ -937,13 +955,15 @@ static wontreturn void __asan_verify_failed(const void *p, size_t n,
void __asan_verify(const void *p, size_t n) {
struct AsanFault f;
if (!(f = __asan_check(p, n)).kind) return;
if (!(f = __asan_check(p, n)).kind)
return;
__asan_verify_failed(p, n, f);
}
void __asan_verify_str(const char *p) {
struct AsanFault f;
if (!(f = __asan_check_str(p)).kind) return;
if (!(f = __asan_check_str(p)).kind)
return;
__asan_verify_failed(UNSHADOW(f.shadow), 8, f);
}
@ -998,7 +1018,8 @@ static bool __asan_read48(uint64_t value, uint64_t *x) {
static void __asan_rawtrace(struct AsanTrace *bt, const struct StackFrame *bp) {
size_t i;
for (i = 0; bp && i < ARRAYLEN(bt->p); ++i, bp = bp->next) {
if (kisdangerous(bp)) break;
if (kisdangerous(bp))
break;
bt->p[i] = bp->addr;
}
for (; i < ARRAYLEN(bt->p); ++i) {
@ -1015,14 +1036,16 @@ static void __asan_trace(struct AsanTrace *bt, const struct StackFrame *bp) {
gi = garbage ? garbage->i : 0;
for (f1 = -1, i = 0; bp && i < ARRAYLEN(bt->p); ++i, bp = bp->next) {
if (f1 != (f2 = ((intptr_t)bp >> 16))) {
if (kisdangerous(bp)) break;
if (kisdangerous(bp))
break;
f1 = f2;
}
if (!__asan_checka(SHADOW(bp), sizeof(*bp) >> 3).kind) {
addr = bp->addr;
#ifdef __x86_64__
if (addr == (uintptr_t)_weaken(__gc) && (uintptr_t)_weaken(__gc)) {
do --gi;
do
--gi;
while ((addr = garbage->p[gi].ret) == (uintptr_t)_weaken(__gc));
}
#endif
@ -1129,13 +1152,19 @@ int __asan_is_leaky(void *p) {
intptr_t f, *l;
struct AsanExtra *e;
struct SymbolTable *st;
if (!_weaken(GetSymbolTable)) notpossible;
if (!(e = __asan_get_extra(p, &c))) return 0;
if (!__asan_read48(e->size, &n)) return 0;
if (!__asan_is_mapped((((intptr_t)p >> 3) + 0x7fff8000) >> 16)) return 0;
if (!(st = GetSymbolTable())) return 0;
if (!_weaken(GetSymbolTable))
notpossible;
if (!(e = __asan_get_extra(p, &c)))
return 0;
if (!__asan_read48(e->size, &n))
return 0;
if (!__asan_is_mapped((((intptr_t)p >> 3) + 0x7fff8000) >> 16))
return 0;
if (!(st = GetSymbolTable()))
return 0;
for (i = 0; i < ARRAYLEN(e->bt.p) && e->bt.p[i]; ++i) {
if ((sym = _weaken(__get_symbol)(st, e->bt.p[i])) == -1) continue;
if ((sym = _weaken(__get_symbol)(st, e->bt.p[i])) == -1)
continue;
f = st->addr_base + st->symbols[sym].x;
for (l = _leaky_start; l < _leaky_end; ++l) {
if (f == *l) {
@ -1167,7 +1196,8 @@ static void __asan_deallocate(char *p, long kind) {
}
void __asan_free(void *p) {
if (!p) return;
if (!p)
return;
__asan_deallocate(p, kAsanHeapFree);
}
@ -1236,7 +1266,8 @@ void *__asan_memalign(size_t align, size_t size) {
void *__asan_calloc(size_t n, size_t m) {
struct AsanTrace bt;
__asan_trace(&bt, RBP);
if (ckd_mul(&n, n, m)) n = -1;
if (ckd_mul(&n, n, m))
n = -1;
return __asan_allocate(16, n, &bt, kAsanHeapUnderrun, kAsanHeapOverrun, 0x00);
}
@ -1342,7 +1373,8 @@ void __asan_alloca_poison(char *addr, uintptr_t size) {
void __asan_allocas_unpoison(uintptr_t x, uintptr_t y) {
ASAN_LOG("__asan_allocas_unpoison(%p, %p)\n", x, y);
if (!x || x > y) return;
if (!x || x > y)
return;
__asan_unpoison((char *)x, y - x);
}
@ -1455,7 +1487,8 @@ static textstartup void __asan_shadow_existing_mappings(void) {
static size_t __asan_strlen(const char *s) {
size_t i = 0;
while (s[i]) ++i;
while (s[i])
++i;
return i;
}
@ -1465,7 +1498,8 @@ forceinline ssize_t __write_str(const char *s) {
void __asan_init(int argc, char **argv, char **envp, unsigned long *auxv) {
static bool once;
if (!_cmpxchg(&once, false, true)) return;
if (!_cmpxchg(&once, false, true))
return;
if (IsWindows() && NtGetVersion() < kNtVersionWindows10) {
__write_str("error: asan binaries require windows10\r\n");
_Exit(0); /* So `make MODE=dbg test` passes w/ Windows7 */

View file

@ -34,7 +34,8 @@ textwindows bool32 CreateDirectory(const char16_t *lpPathName,
const struct NtSecurityAttributes *lpSec) {
bool32 ok;
ok = __imp_CreateDirectoryW(lpPathName, lpSec);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("CreateDirectory(%#hs, %s) → %hhhd% m", lpPathName,
DescribeNtSecurityAttributes(lpSec), ok);
return ok;

View file

@ -66,8 +66,10 @@ TryAgain:
if (hHandle == -1) {
switch (__imp_GetLastError()) {
case kNtErrorPipeBusy:
if (micros >= 1024) __imp_Sleep(micros / 1024);
if (micros < 1024 * 1024) micros <<= 1;
if (micros >= 1024)
__imp_Sleep(micros / 1024);
if (micros < 1024 * 1024)
micros <<= 1;
goto TryAgain;
case kNtErrorAccessDenied:
// GetNtOpenFlags() always greedily requests execute permissions

View file

@ -42,7 +42,8 @@ textwindows int64_t CreateFileMapping(
hHandle = __imp_CreateFileMappingW(opt_hFile, opt_lpFileMappingAttributes,
flProtect, dwMaximumSizeHigh,
dwMaximumSizeLow, opt_lpName);
if (!hHandle) __winerr();
if (!hHandle)
__winerr();
NTTRACE("CreateFileMapping(%ld, %s, %s, %'zu, %#hs) → %ld% m", opt_hFile,
DescribeNtSecurityAttributes(opt_lpFileMappingAttributes),
DescribeNtPageFlags(flProtect),

View file

@ -43,7 +43,8 @@ textwindows int64_t CreateFileMappingNuma(
hHandle = __imp_CreateFileMappingNumaW(
opt_hFile, opt_lpFileMappingAttributes, flProtect, dwMaximumSizeHigh,
dwMaximumSizeLow, opt_lpName, nndDesiredNumaNode);
if (!hHandle) __winerr();
if (!hHandle)
__winerr();
NTTRACE("CreateFileMappingNuma(%ld, %s, %s, %'zu, %#hs) → %ld% m", opt_hFile,
DescribeNtSecurityAttributes(opt_lpFileMappingAttributes),
DescribeNtPageFlags(flProtect),

View file

@ -49,11 +49,14 @@ TryAgain:
nMaxInstances, nOutBufferSize, nInBufferSize,
nDefaultTimeOutMs, opt_lpSecurityAttributes);
if (hServer == -1 && __imp_GetLastError() == kNtErrorPipeBusy) {
if (micros >= 1024) __imp_Sleep(micros / 1024);
if (micros < 1024 * 1024) micros <<= 1;
if (micros >= 1024)
__imp_Sleep(micros / 1024);
if (micros < 1024 * 1024)
micros <<= 1;
goto TryAgain;
}
if (hServer == -1) __winerr();
if (hServer == -1)
__winerr();
NTTRACE("CreateNamedPipe(%#hs, %s, %s, %u, %'u, %'u, %'u, %s) → %ld% m",
lpName, DescribeNtPipeOpenFlags(dwOpenMode),
DescribeNtPipeModeFlags(dwPipeMode), nMaxInstances, nOutBufferSize,

View file

@ -35,7 +35,8 @@ textwindows bool32 CreatePipe(
bool32 ok;
ok = __imp_CreatePipe(out_hReadPipe, out_hWritePipe, opt_lpPipeAttributes,
nSize);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("CreatePipe([%ld], [%ld], %s, %'zu) → %hhhd% m", *out_hReadPipe,
*out_hWritePipe, DescribeNtSecurityAttributes(opt_lpPipeAttributes),
nSize, ok);

View file

@ -44,7 +44,8 @@ CreateProcess(const char16_t *opt_lpApplicationName, char16_t *lpCommandLine,
bInheritHandles, dwCreationFlags, opt_lpEnvironment,
opt_lpCurrentDirectory, lpStartupInfo,
opt_out_lpProcessInformation);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("CreateProcess(%#!hs, %#!hs, %s, %s, %hhhd, %u, %p, %#!hs, %p, %p) → "
"%hhhd% m",
opt_lpApplicationName, lpCommandLine,

View file

@ -32,7 +32,8 @@ bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName,
const char16_t *lpTargetPathName, uint32_t dwFlags) {
bool32 ok;
ok = __imp_CreateSymbolicLinkW(lpSymlinkFileName, lpTargetPathName, dwFlags);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("CreateSymbolicLink(%#hs, %#hs, %s) → %hhhd% m", lpSymlinkFileName,
lpTargetPathName, DescribeNtSymlinkFlags(dwFlags), ok);
return ok;

View file

@ -47,7 +47,8 @@ int __cxa_atexit(void *fp, void *arg, void *pred) {
struct CxaAtexitBlock *b, *b2;
__cxa_lock();
b = __cxa_blocks.p;
if (!b) b = __cxa_blocks.p = &__cxa_blocks.root;
if (!b)
b = __cxa_blocks.p = &__cxa_blocks.root;
if (!~b->mask) {
if (_weaken(calloc) &&
(b2 = _weaken(calloc)(1, sizeof(struct CxaAtexitBlock)))) {

View file

@ -30,7 +30,8 @@ __msabi extern typeof(DeleteFile) *const __imp_DeleteFileW;
textwindows bool32 DeleteFile(const char16_t *lpPathName) {
bool32 ok;
ok = __imp_DeleteFileW(lpPathName);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("DeleteFile(%#hs) → %hhhd% m", lpPathName, ok);
return ok;
}

View file

@ -22,10 +22,14 @@
#include "libc/sysv/consts/arch.h"
const char *(DescribeArchPrctlCode)(char buf[12], int x) {
if (x == ARCH_SET_FS) return "ARCH_SET_FS";
if (x == ARCH_GET_FS) return "ARCH_GET_FS";
if (x == ARCH_SET_GS) return "ARCH_SET_GS";
if (x == ARCH_GET_GS) return "ARCH_GET_GS";
if (x == ARCH_SET_FS)
return "ARCH_SET_FS";
if (x == ARCH_GET_FS)
return "ARCH_GET_FS";
if (x == ARCH_SET_GS)
return "ARCH_SET_GS";
if (x == ARCH_GET_GS)
return "ARCH_GET_GS";
FormatInt32(buf, x);
return buf;
}

View file

@ -21,11 +21,16 @@
#include "libc/thread/thread.h"
const char *(DescribeCancelState)(char buf[12], int err, int *state) {
if (err) return "n/a";
if (!state) return "NULL";
if (*state == PTHREAD_CANCEL_ENABLE) return "PTHREAD_CANCEL_ENABLE";
if (*state == PTHREAD_CANCEL_DISABLE) return "PTHREAD_CANCEL_DISABLE";
if (*state == PTHREAD_CANCEL_MASKED) return "PTHREAD_CANCEL_MASKED";
if (err)
return "n/a";
if (!state)
return "NULL";
if (*state == PTHREAD_CANCEL_ENABLE)
return "PTHREAD_CANCEL_ENABLE";
if (*state == PTHREAD_CANCEL_DISABLE)
return "PTHREAD_CANCEL_DISABLE";
if (*state == PTHREAD_CANCEL_MASKED)
return "PTHREAD_CANCEL_MASKED";
FormatInt32(buf, *state);
return buf;
}

View file

@ -21,7 +21,8 @@
#include "libc/sysv/consts/at.h"
const char *(DescribeDirfd)(char buf[12], int dirfd) {
if (dirfd == AT_FDCWD) return "AT_FDCWD";
if (dirfd == AT_FDCWD)
return "AT_FDCWD";
FormatInt32(buf, dirfd);
return buf;
}

View file

@ -30,7 +30,8 @@
const char *(DescribeFdSet)(char buf[N], ssize_t rc, int nfds, fd_set *fds) {
int o = 0;
if (!fds) return "NULL";
if (!fds)
return "NULL";
if ((!IsAsan() && kisdangerous(fds)) ||
(IsAsan() && !__asan_is_valid(fds, sizeof(*fds) * nfds))) {
ksnprintf(buf, N, "%p", fds);

View file

@ -27,32 +27,41 @@ const char *DescribeFlags(char *p, size_t n, const struct DescribeFlags *d,
if (d[j].flag && d[j].flag != -1 && (x & d[j].flag) == d[j].flag) {
x &= ~d[j].flag;
if (t) {
if (i + 1 < n) p[i++] = '|';
if (i + 1 < n)
p[i++] = '|';
} else {
t = true;
}
for (k = 0; prefix && prefix[k]; ++k) {
if (i + 1 < n) p[i++] = prefix[k];
if (i + 1 < n)
p[i++] = prefix[k];
}
for (k = 0; d[j].name[k]; ++k) {
if (i + 1 < n) p[i++] = d[j].name[k];
if (i + 1 < n)
p[i++] = d[j].name[k];
}
}
}
if (x || !t) {
if (t && i + 1 < n) p[i++] = '|';
if (i + 1 < n) p[i++] = '0';
if (t && i + 1 < n)
p[i++] = '|';
if (i + 1 < n)
p[i++] = '0';
if (x) {
if (i + 1 < n) p[i++] = 'x';
if (i + 1 < n)
p[i++] = 'x';
k = 0;
do {
if (i + 1 < n) b[k++] = "0123456789abcdef"[x % 16];
if (i + 1 < n)
b[k++] = "0123456789abcdef"[x % 16];
} while ((x /= 16));
while (k--) {
if (i + 1 < n) p[i++] = b[k];
if (i + 1 < n)
p[i++] = b[k];
}
}
}
if (i < n) p[i] = 0;
if (i < n)
p[i] = 0;
return p;
}

View file

@ -31,7 +31,8 @@
const char *(DescribeFlock)(char buf[N], int cmd, const struct flock *l) {
int o = 0;
if (!l) return "NULL";
if (!l)
return "NULL";
if ((!IsAsan() && kisdangerous(l)) ||
(IsAsan() && !__asan_is_valid(l, sizeof(*l)))) {
ksnprintf(buf, N, "%p", l);

View file

@ -20,9 +20,12 @@
#include "libc/sysv/consts/f.h"
const char *(DescribeFlockType)(char buf[12], int x) {
if (x == F_RDLCK) return "F_RDLCK";
if (x == F_WRLCK) return "F_WRLCK";
if (x == F_UNLCK) return "F_UNLCK";
if (x == F_RDLCK)
return "F_RDLCK";
if (x == F_WRLCK)
return "F_WRLCK";
if (x == F_UNLCK)
return "F_UNLCK";
FormatInt32(buf, x);
return buf;
}

View file

@ -28,9 +28,12 @@
const char *(DescribeGidList)(char buf[N], int rc, int size,
const uint32_t list[]) {
if ((rc == -1) || (size < 0)) return "n/a";
if (!size) return "{}";
if (!list) return "NULL";
if ((rc == -1) || (size < 0))
return "n/a";
if (!size)
return "{}";
if (!list)
return "NULL";
if ((!IsAsan() && kisdangerous(list)) ||
(IsAsan() && !__asan_is_valid(list, size * sizeof(list[0])))) {
ksnprintf(buf, N, "%p", list);
@ -43,8 +46,10 @@ const char *(DescribeGidList)(char buf[N], int rc, int size,
i += ksnprintf(buf + i, MAX(0, n - i), "%u, ", list[c]);
}
if (c == size) {
if (buf[i - 1] == ' ') i--;
if (buf[i - 1] == ',') i--;
if (buf[i - 1] == ' ')
i--;
if (buf[i - 1] == ',')
i--;
i += ksnprintf(buf + i, MAX(0, n - i), "}");
}
return buf;

View file

@ -21,9 +21,12 @@
#include "libc/sysv/consts/sig.h"
const char *(DescribeHow)(char buf[12], int how) {
if (how == SIG_BLOCK) return "SIG_BLOCK";
if (how == SIG_UNBLOCK) return "SIG_UNBLOCK";
if (how == SIG_SETMASK) return "SIG_SETMASK";
if (how == SIG_BLOCK)
return "SIG_BLOCK";
if (how == SIG_UNBLOCK)
return "SIG_UNBLOCK";
if (how == SIG_SETMASK)
return "SIG_SETMASK";
FormatInt32(buf, how);
return buf;
}

View file

@ -21,9 +21,11 @@
#include "libc/intrin/describeflags.internal.h"
const char *(DescribeInOutInt64)(char buf[23], ssize_t rc, int64_t *x) {
if (!x) return "NULL";
if (!x)
return "NULL";
char *p = buf;
if (rc != -1) *p++ = '[';
if (rc != -1)
*p++ = '[';
if (rc == -1 && errno == EFAULT) {
*p++ = '!';
*p++ = '!';
@ -31,7 +33,8 @@ const char *(DescribeInOutInt64)(char buf[23], ssize_t rc, int64_t *x) {
} else {
p = FormatInt64(p, *x);
}
if (rc != -1) *p++ = ']';
if (rc != -1)
*p++ = ']';
*p = 0;
return buf;
}

View file

@ -33,9 +33,12 @@ const char *(DescribeIovec)(char buf[N], ssize_t rc, const struct iovec *iov,
const char *d;
int i, j, o = 0;
if (!iov) return "NULL";
if (rc == -1) return "n/a";
if (rc == -2) rc = SSIZE_MAX;
if (!iov)
return "NULL";
if (rc == -1)
return "n/a";
if (rc == -2)
rc = SSIZE_MAX;
if ((!IsAsan() && kisdangerous(iov)) ||
(IsAsan() && !__asan_is_valid(iov, sizeof(*iov) * iovlen))) {
ksnprintf(buf, N, "%p", iov);

View file

@ -21,9 +21,12 @@
#include "libc/sysv/consts/itimer.h"
const char *(DescribeItimer)(char buf[12], int which) {
if (which == ITIMER_REAL) return "ITIMER_REAL";
if (which == ITIMER_VIRTUAL) return "ITIMER_VIRTUAL";
if (which == ITIMER_PROF) return "ITIMER_PROF";
if (which == ITIMER_REAL)
return "ITIMER_REAL";
if (which == ITIMER_VIRTUAL)
return "ITIMER_VIRTUAL";
if (which == ITIMER_PROF)
return "ITIMER_PROF";
FormatInt32(buf, which);
return buf;
}

View file

@ -28,8 +28,10 @@
const char *(DescribeItimerval)(char buf[N], int rc,
const struct itimerval *it) {
if (!it) return "NULL";
if (rc == -1) return "n/a";
if (!it)
return "NULL";
if (rc == -1)
return "n/a";
if ((!IsAsan() && kisdangerous(it)) ||
(IsAsan() && !__asan_is_valid(it, sizeof(*it)))) {
ksnprintf(buf, N, "%p", it);

View file

@ -23,7 +23,8 @@
const char *DescribeMagnum(char *b, const struct MagnumStr *m, const char *p,
int x) {
const char *s;
if (x == 127) return "CLOCK_INVALID";
if (x == 127)
return "CLOCK_INVALID";
if ((s = GetMagnumStr(m, x))) {
stpcpy(stpcpy(b, p), s);
return b;

View file

@ -51,7 +51,8 @@ static const struct DescribeFlags kFileFlags[] = {
};
const char *(DescribeNtFileFlagAttr)(char buf[256], uint32_t x) {
if (x == -1u) return "-1u";
if (x == -1u)
return "-1u";
return DescribeFlags(buf, 256, kFileFlags, ARRAYLEN(kFileFlags), "kNtFile",
x);
}

View file

@ -23,7 +23,8 @@
const char *(DescribeNtOverlapped)(char b[128], const struct NtOverlapped *o) {
int i = 0, n = 128;
bool gotsome = false;
if (!o) return "NULL";
if (!o)
return "NULL";
i += ksnprintf(b + i, MAX(0, n - i), "{");
if (o->hEvent) {

View file

@ -35,7 +35,8 @@ const char *(DescribeOpenFlags)(char buf[128], int x) {
int i, n;
const char *pipe;
struct DescribeFlags d[N];
if (x == -1) return "-1";
if (x == -1)
return "-1";
p = buf;
switch (x & O_ACCMODE) {
case O_RDONLY:
@ -60,7 +61,8 @@ const char *(DescribeOpenFlags)(char buf[128], int x) {
if (x) {
p = stpcpy(p, pipe);
for (n = 0; kOpenFlags[n].x != MAGNUM_TERMINATOR; ++n) {
if (n == N) notpossible;
if (n == N)
notpossible;
}
for (i = 0; i < n; ++i) {
d[i].flag = MAGNUM_NUMBER(kOpenFlags, i);

View file

@ -34,7 +34,8 @@ const char *(DescribePollFds)(char buf[N], ssize_t rc, struct pollfd *fds,
char b64[64];
int i, o = 0;
if (!fds) return "NULL";
if (!fds)
return "NULL";
if ((!IsAsan() && kisdangerous(fds)) ||
(IsAsan() && !__asan_is_valid(fds, sizeof(*fds) * nfds))) {
ksnprintf(buf, N, "%p", fds);
@ -44,7 +45,8 @@ const char *(DescribePollFds)(char buf[N], ssize_t rc, struct pollfd *fds,
append("{");
for (i = 0; i < nfds; ++i) {
if (i) append(", ");
if (i)
append(", ");
append("{%d, %s", fds[i].fd, (DescribePollFlags)(b64, fds[i].events));
if (rc >= 0) {
append(", [%s]", (DescribePollFlags)(b64, fds[i].revents));

View file

@ -21,38 +21,70 @@
#include "libc/sysv/consts/ptrace.h"
const char *(DescribePtrace)(char buf[12], int x) {
if (x == -1) return "-1";
if (x == PTRACE_TRACEME) return "PTRACE_TRACEME";
if (x == PTRACE_PEEKDATA) return "PTRACE_PEEKDATA";
if (x == PTRACE_GETFPREGS) return "PTRACE_GETFPREGS";
if (x == PTRACE_PEEKTEXT) return "PTRACE_PEEKTEXT";
if (x == PTRACE_POKEDATA) return "PTRACE_POKEDATA";
if (x == PTRACE_PEEKUSER) return "PTRACE_PEEKUSER";
if (x == PTRACE_POKETEXT) return "PTRACE_POKETEXT";
if (x == PTRACE_POKEUSER) return "PTRACE_POKEUSER";
if (x == PTRACE_GETREGS) return "PTRACE_GETREGS";
if (x == PTRACE_GETREGSET) return "PTRACE_GETREGSET";
if (x == PTRACE_SETFPREGS) return "PTRACE_SETFPREGS";
if (x == PTRACE_SETREGS) return "PTRACE_SETREGS";
if (x == PTRACE_SETREGSET) return "PTRACE_SETREGSET";
if (x == PTRACE_GETSIGINFO) return "PTRACE_GETSIGINFO";
if (x == PTRACE_SETSIGINFO) return "PTRACE_SETSIGINFO";
if (x == PTRACE_PEEKSIGINFO) return "PTRACE_PEEKSIGINFO";
if (x == PTRACE_GETSIGMASK) return "PTRACE_GETSIGMASK";
if (x == PTRACE_SETSIGMASK) return "PTRACE_SETSIGMASK";
if (x == PTRACE_SETOPTIONS) return "PTRACE_SETOPTIONS";
if (x == PTRACE_GETEVENTMSG) return "PTRACE_GETEVENTMSG";
if (x == PTRACE_CONT) return "PTRACE_CONT";
if (x == PTRACE_SINGLESTEP) return "PTRACE_SINGLESTEP";
if (x == PTRACE_SYSCALL) return "PTRACE_SYSCALL";
if (x == PTRACE_LISTEN) return "PTRACE_LISTEN";
if (x == PTRACE_KILL) return "PTRACE_KILL";
if (x == PTRACE_INTERRUPT) return "PTRACE_INTERRUPT";
if (x == PTRACE_ATTACH) return "PTRACE_ATTACH";
if (x == PTRACE_SEIZE) return "PTRACE_SEIZE";
if (x == PTRACE_SECCOMP_GET_FILTER) return "PTRACE_SECCOMP_GET_FILTER";
if (x == PTRACE_SECCOMP_GET_METADATA) return "PTRACE_SECCOMP_GET_METADATA";
if (x == PTRACE_DETACH) return "PTRACE_DETACH";
if (x == -1)
return "-1";
if (x == PTRACE_TRACEME)
return "PTRACE_TRACEME";
if (x == PTRACE_PEEKDATA)
return "PTRACE_PEEKDATA";
if (x == PTRACE_GETFPREGS)
return "PTRACE_GETFPREGS";
if (x == PTRACE_PEEKTEXT)
return "PTRACE_PEEKTEXT";
if (x == PTRACE_POKEDATA)
return "PTRACE_POKEDATA";
if (x == PTRACE_PEEKUSER)
return "PTRACE_PEEKUSER";
if (x == PTRACE_POKETEXT)
return "PTRACE_POKETEXT";
if (x == PTRACE_POKEUSER)
return "PTRACE_POKEUSER";
if (x == PTRACE_GETREGS)
return "PTRACE_GETREGS";
if (x == PTRACE_GETREGSET)
return "PTRACE_GETREGSET";
if (x == PTRACE_SETFPREGS)
return "PTRACE_SETFPREGS";
if (x == PTRACE_SETREGS)
return "PTRACE_SETREGS";
if (x == PTRACE_SETREGSET)
return "PTRACE_SETREGSET";
if (x == PTRACE_GETSIGINFO)
return "PTRACE_GETSIGINFO";
if (x == PTRACE_SETSIGINFO)
return "PTRACE_SETSIGINFO";
if (x == PTRACE_PEEKSIGINFO)
return "PTRACE_PEEKSIGINFO";
if (x == PTRACE_GETSIGMASK)
return "PTRACE_GETSIGMASK";
if (x == PTRACE_SETSIGMASK)
return "PTRACE_SETSIGMASK";
if (x == PTRACE_SETOPTIONS)
return "PTRACE_SETOPTIONS";
if (x == PTRACE_GETEVENTMSG)
return "PTRACE_GETEVENTMSG";
if (x == PTRACE_CONT)
return "PTRACE_CONT";
if (x == PTRACE_SINGLESTEP)
return "PTRACE_SINGLESTEP";
if (x == PTRACE_SYSCALL)
return "PTRACE_SYSCALL";
if (x == PTRACE_LISTEN)
return "PTRACE_LISTEN";
if (x == PTRACE_KILL)
return "PTRACE_KILL";
if (x == PTRACE_INTERRUPT)
return "PTRACE_INTERRUPT";
if (x == PTRACE_ATTACH)
return "PTRACE_ATTACH";
if (x == PTRACE_SEIZE)
return "PTRACE_SEIZE";
if (x == PTRACE_SECCOMP_GET_FILTER)
return "PTRACE_SECCOMP_GET_FILTER";
if (x == PTRACE_SECCOMP_GET_METADATA)
return "PTRACE_SECCOMP_GET_METADATA";
if (x == PTRACE_DETACH)
return "PTRACE_DETACH";
FormatInt32(buf, x);
return buf;
}

View file

@ -21,14 +21,22 @@
#include "libc/sysv/consts/ptrace.h"
const char *(DescribePtraceEvent)(char buf[32], int x) {
if (x == PTRACE_EVENT_FORK) return "PTRACE_EVENT_FORK";
if (x == PTRACE_EVENT_VFORK) return "PTRACE_EVENT_VFORK";
if (x == PTRACE_EVENT_CLONE) return "PTRACE_EVENT_CLONE";
if (x == PTRACE_EVENT_EXEC) return "PTRACE_EVENT_EXEC";
if (x == PTRACE_EVENT_VFORK_DONE) return "PTRACE_EVENT_VFORK_DONE";
if (x == PTRACE_EVENT_EXIT) return "PTRACE_EVENT_EXIT";
if (x == PTRACE_EVENT_SECCOMP) return "PTRACE_EVENT_SECCOMP";
if (x == PTRACE_EVENT_STOP) return "PTRACE_EVENT_STOP";
if (x == PTRACE_EVENT_FORK)
return "PTRACE_EVENT_FORK";
if (x == PTRACE_EVENT_VFORK)
return "PTRACE_EVENT_VFORK";
if (x == PTRACE_EVENT_CLONE)
return "PTRACE_EVENT_CLONE";
if (x == PTRACE_EVENT_EXEC)
return "PTRACE_EVENT_EXEC";
if (x == PTRACE_EVENT_VFORK_DONE)
return "PTRACE_EVENT_VFORK_DONE";
if (x == PTRACE_EVENT_EXIT)
return "PTRACE_EVENT_EXIT";
if (x == PTRACE_EVENT_SECCOMP)
return "PTRACE_EVENT_SECCOMP";
if (x == PTRACE_EVENT_STOP)
return "PTRACE_EVENT_STOP";
FormatInt32(buf, x);
return buf;
}

View file

@ -23,8 +23,10 @@
#include "libc/intrin/strace.internal.h"
const char *DescribeRlimit(char buf[64], int rc, const struct rlimit *rlim) {
if (rc == -1) return "n/a";
if (!rlim) return "NULL";
if (rc == -1)
return "n/a";
if (!rlim)
return "NULL";
if ((!IsAsan() && kisdangerous(rlim)) ||
(IsAsan() && !__asan_is_valid(rlim, sizeof(*rlim)))) {
ksnprintf(buf, 64, "%p", rlim);

View file

@ -23,6 +23,7 @@
* Describes setrlimit() / getrlimit() argument.
*/
const char *(DescribeRlimitName)(char buf[20], int x) {
if (x == 127) return "n/a";
if (x == 127)
return "n/a";
return DescribeMagnum(buf, kRlimitNames, "RLIMIT_", x);
}

View file

@ -26,7 +26,8 @@
*/
const char *(DescribeSchedParam)(char buf[32], const struct sched_param *x) {
char *p;
if (!x) return "0";
if (!x)
return "0";
p = buf;
*p++ = '{';
p = FormatInt32(p, x->sched_priority);

View file

@ -28,9 +28,12 @@
#include "libc/sysv/consts/sa.h"
static const char *DescribeSigHandler(char buf[64], void f(int)) {
if (f == SIG_ERR) return "SIG_ERR";
if (f == SIG_DFL) return "SIG_DFL";
if (f == SIG_IGN) return "SIG_IGN";
if (f == SIG_ERR)
return "SIG_ERR";
if (f == SIG_DFL)
return "SIG_DFL";
if (f == SIG_IGN)
return "SIG_IGN";
ksnprintf(buf, 64, "%t", f);
return buf;
}
@ -60,8 +63,10 @@ const char *(DescribeSigaction)(char buf[N], int rc,
int o = 0;
char b64[64];
if (rc == -1) return "n/a";
if (!sa) return "NULL";
if (rc == -1)
return "n/a";
if (!sa)
return "NULL";
if ((!IsAsan() && kisdangerous(sa)) ||
(IsAsan() && !__asan_is_valid(sa, sizeof(*sa)))) {
ksnprintf(buf, N, "%p", sa);

View file

@ -24,8 +24,10 @@
const char *(DescribeSigaltstk)(char buf[128], int rc,
const struct sigaltstack *ss) {
if (rc == -1) return "n/a";
if (!ss) return "NULL";
if (rc == -1)
return "n/a";
if (!ss)
return "NULL";
if ((!IsAsan() && kisdangerous(ss)) ||
(IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) {
ksnprintf(buf, 128, "%p", ss);

View file

@ -33,8 +33,10 @@
const char *(DescribeSiginfo)(char buf[N], int rc, const siginfo_t *si) {
int i = 0;
if (rc == -1) return "n/a";
if (!si) return "NULL";
if (rc == -1)
return "n/a";
if (!si)
return "NULL";
if ((!IsAsan() && kisdangerous(si)) ||
(IsAsan() && !__asan_is_valid(si, sizeof(*si)))) {
ksnprintf(buf, N, "%p", si);

View file

@ -39,8 +39,10 @@ const char *(DescribeSigset)(char buf[N], int rc, const sigset_t *ss) {
int sig, o = 0;
sigset_t sigset;
if (rc == -1) return "n/a";
if (!ss) return "NULL";
if (rc == -1)
return "n/a";
if (!ss)
return "NULL";
if ((!IsAsan() && kisdangerous(ss)) ||
(IsAsan() && !__asan_is_valid(ss, sizeof(*ss)))) {
ksnprintf(buf, N, "%p", ss);

View file

@ -21,9 +21,12 @@
#include "libc/sysv/consts/af.h"
const char *(DescribeSocketFamily)(char buf[12], int family) {
if (family == AF_UNIX) return "AF_UNIX";
if (family == AF_INET) return "AF_INET";
if (family == AF_INET6) return "AF_INET6";
if (family == AF_UNIX)
return "AF_UNIX";
if (family == AF_INET)
return "AF_INET";
if (family == AF_INET6)
return "AF_INET6";
FormatInt32(buf, family);
return buf;
}

View file

@ -21,13 +21,20 @@
#include "libc/sysv/consts/ipproto.h"
const char *(DescribeSocketProtocol)(char buf[12], int family) {
if (family == IPPROTO_IP) return "IPPROTO_IP";
if (family == IPPROTO_ICMP) return "IPPROTO_ICMP";
if (family == IPPROTO_TCP) return "IPPROTO_TCP";
if (family == IPPROTO_UDP) return "IPPROTO_UDP";
if (family == IPPROTO_RAW) return "IPPROTO_RAW";
if (family == IPPROTO_IPV6) return "IPPROTO_IPv6";
if (family == IPPROTO_ICMPV6) return "IPPROTO_ICMPV6";
if (family == IPPROTO_IP)
return "IPPROTO_IP";
if (family == IPPROTO_ICMP)
return "IPPROTO_ICMP";
if (family == IPPROTO_TCP)
return "IPPROTO_TCP";
if (family == IPPROTO_UDP)
return "IPPROTO_UDP";
if (family == IPPROTO_RAW)
return "IPPROTO_RAW";
if (family == IPPROTO_IPV6)
return "IPPROTO_IPv6";
if (family == IPPROTO_ICMPV6)
return "IPPROTO_ICMPV6";
FormatInt32(buf, family);
return buf;
}

View file

@ -39,7 +39,9 @@ const char *(DescribeSocketType)(char buf[64], int type) {
} else {
p = FormatInt32(p, x);
}
if (type & SOCK_CLOEXEC) p = stpcpy(p, "|SOCK_CLOEXEC");
if (type & SOCK_NONBLOCK) p = stpcpy(p, "|SOCK_NONBLOCK");
if (type & SOCK_CLOEXEC)
p = stpcpy(p, "|SOCK_CLOEXEC");
if (type & SOCK_NONBLOCK)
p = stpcpy(p, "|SOCK_NONBLOCK");
return buf;
}

View file

@ -24,14 +24,22 @@
* Describes setsockopt() level arguments.
*/
const char *(DescribeSockLevel)(char buf[12], int x) {
if (x == SOL_SOCKET) return "SOL_SOCKET";
if (x == SOL_IP) return "SOL_IP";
if (x == SOL_ICMP) return "SOL_ICMP";
if (x == SOL_TCP) return "SOL_TCP";
if (x == SOL_UDP) return "SOL_UDP";
if (x == SOL_IPV6) return "SOL_IPV6";
if (x == SOL_ICMPV6) return "SOL_ICMPV6";
if (x == SOL_RAW) return "SOL_RAW";
if (x == SOL_SOCKET)
return "SOL_SOCKET";
if (x == SOL_IP)
return "SOL_IP";
if (x == SOL_ICMP)
return "SOL_ICMP";
if (x == SOL_TCP)
return "SOL_TCP";
if (x == SOL_UDP)
return "SOL_UDP";
if (x == SOL_IPV6)
return "SOL_IPV6";
if (x == SOL_ICMPV6)
return "SOL_ICMPV6";
if (x == SOL_RAW)
return "SOL_RAW";
FormatInt32(buf, x);
return buf;
}

View file

@ -29,8 +29,10 @@
const char *(DescribeStat)(char buf[N], int rc, const struct stat *st) {
int o = 0;
if (rc == -1) return "n/a";
if (!st) return "NULL";
if (rc == -1)
return "n/a";
if (!st)
return "NULL";
if ((!IsAsan() && kisdangerous(st)) ||
(IsAsan() && !__asan_is_valid(st, sizeof(*st)))) {
ksnprintf(buf, N, "%p", st);

View file

@ -33,8 +33,10 @@ const char *(DescribeStatfs)(char buf[N], int rc, const struct statfs *f) {
char ibuf[21];
int64_t flags;
if (rc == -1) return "n/a";
if (!f) return "NULL";
if (rc == -1)
return "n/a";
if (!f)
return "NULL";
if ((!IsAsan() && kisdangerous(f)) ||
(IsAsan() && !__asan_is_valid(f, sizeof(*f)))) {
ksnprintf(buf, N, "%p", f);

View file

@ -22,9 +22,12 @@
#include "libc/str/str.h"
const char *(DescribeStdioState)(char buf[12], int x) {
if (!x) return "";
if (x == -1) return "EOF";
if (x > 0) return _strerrno(x);
if (!x)
return "";
if (x == -1)
return "EOF";
if (x > 0)
return _strerrno(x);
FormatInt32(buf, x);
return buf;
}

View file

@ -28,7 +28,8 @@
const char *(DescribeStringList)(char buf[N], char *const list[]) {
int i, o = 0;
if (!list) return "NULL";
if (!list)
return "NULL";
if (IsAsan() && !__asan_is_valid_strlist(list)) {
ksnprintf(buf, N, "%p", list);
return buf;
@ -37,7 +38,8 @@ const char *(DescribeStringList)(char buf[N], char *const list[]) {
append("{");
i = 0;
do {
if (i++) append(", ");
if (i++)
append(", ");
append("%#s", *list);
} while (*list++);
append("}");

View file

@ -35,7 +35,8 @@ const char *(DescribeTermios)(char buf[N], ssize_t rc,
int o = 0;
char b128[128];
if (!tio) return "NULL";
if (!tio)
return "NULL";
if ((!IsAsan() && kisdangerous(tio)) ||
(IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) {
ksnprintf(buf, N, "%p", tio);

View file

@ -25,8 +25,10 @@
const char *(DescribeTimespec)(char buf[45], int rc,
const struct timespec *ts) {
if (rc == -1) return "n/a";
if (!ts) return "NULL";
if (rc == -1)
return "n/a";
if (!ts)
return "NULL";
if ((!IsAsan() && kisdangerous(ts)) ||
(IsAsan() && !__asan_is_valid(ts, sizeof(*ts)))) {
ksnprintf(buf, 45, "%p", ts);

View file

@ -23,8 +23,10 @@
#include "libc/intrin/kprintf.h"
const char *(DescribeTimeval)(char buf[45], int rc, const struct timeval *tv) {
if (!tv) return "NULL";
if (rc == -1) return "n/a";
if (!tv)
return "NULL";
if (rc == -1)
return "n/a";
if ((!IsAsan() && kisdangerous(tv)) ||
(IsAsan() && !__asan_is_valid(tv, sizeof(*tv)))) {
ksnprintf(buf, 45, "%p", tv);

View file

@ -21,9 +21,12 @@
#include "libc/intrin/describeflags.internal.h"
const char *(DescribeWhence)(char buf[12], int whence) {
if (whence == SEEK_SET) return "SEEK_SET";
if (whence == SEEK_CUR) return "SEEK_CUR";
if (whence == SEEK_END) return "SEEK_END";
if (whence == SEEK_SET)
return "SEEK_SET";
if (whence == SEEK_CUR)
return "SEEK_CUR";
if (whence == SEEK_END)
return "SEEK_END";
FormatInt32(buf, whence);
return buf;
}

View file

@ -21,9 +21,12 @@
#include "libc/sysv/consts/prio.h"
const char *(DescribeWhichPrio)(char buf[12], int x) {
if (x == PRIO_PROCESS) return "PRIO_PROCESS";
if (x == PRIO_PGRP) return "PRIO_PGRP";
if (x == PRIO_USER) return "PRIO_USER";
if (x == PRIO_PROCESS)
return "PRIO_PROCESS";
if (x == PRIO_PGRP)
return "PRIO_PGRP";
if (x == PRIO_USER)
return "PRIO_USER";
FormatInt32(buf, x);
return buf;
}

View file

@ -31,8 +31,10 @@
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 (!ws)
return "NULL";
if (rc == -1)
return "n/a";
if ((!IsAsan() && kisdangerous(ws)) ||
(IsAsan() && !__asan_is_valid(ws, sizeof(*ws)))) {
ksnprintf(buf, N, "%p", ws);

View file

@ -40,7 +40,8 @@ textwindows bool32 DeviceIoControl(int64_t hDevice, uint32_t dwIoControlCode,
ok = __imp_DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer,
nInBufferSize, lpOutBuffer, nOutBufferSize,
lpBytesReturned, lpOverlapped);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("DeviceIoControl(%ld, %#x, %p, %'zu, %p, %'zu, %p, %s) → %hhhd% m",
hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer,
nOutBufferSize, lpBytesReturned, DescribeNtOverlapped(lpOverlapped),

View file

@ -53,15 +53,19 @@ struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot, int flags,
if (!(flags & MAP_ANONYMOUS_linux)) {
struct Fd *sfd;
struct MetalFile *file;
if (off < 0 || fd < 0 || fd >= g_fds.n) return bad_mmap();
if (off < 0 || fd < 0 || fd >= g_fds.n)
return bad_mmap();
sfd = &g_fds.p[fd];
if (sfd->kind != kFdFile) return bad_mmap();
if (sfd->kind != kFdFile)
return bad_mmap();
file = (struct MetalFile *)sfd->handle;
/* TODO: allow mapping partial page at end of file, if file size not
* multiple of page size */
if (off > file->size || size > file->size - off) return bad_mmap();
if (off > file->size || size > file->size - off)
return bad_mmap();
faddr = (uint64_t)file->base + off;
if (faddr % 4096 != 0) return bad_mmap();
if (faddr % 4096 != 0)
return bad_mmap();
}
if (!(flags & MAP_FIXED_linux)) {
if (!addr) {
@ -83,20 +87,24 @@ struct DirectMap sys_mmap_metal(void *vaddr, size_t size, int prot, int flags,
if (pte) {
if ((flags & MAP_ANONYMOUS_linux)) {
page = __new_page(mm);
if (!page) return bad_mmap();
if (!page)
return bad_mmap();
__clear_page(BANE + page);
e = page | PAGE_RSRV | PAGE_U;
if ((prot & PROT_WRITE))
e |= PAGE_V | PAGE_RW;
else if ((prot & (PROT_READ | PROT_EXEC)))
e |= PAGE_V;
if (!(prot & PROT_EXEC)) e |= PAGE_XD;
if (!(prot & PROT_EXEC))
e |= PAGE_XD;
} else {
fdpte = __get_virtual(mm, pml4t, faddr + i, false);
e = *fdpte | PAGE_RSRV | PAGE_U;
page = e & PAGE_TA;
if (!(prot & PROT_WRITE)) e &= ~PAGE_RW;
if (!(prot & PROT_EXEC)) e |= PAGE_XD;
if (!(prot & PROT_WRITE))
e &= ~PAGE_RW;
if (!(prot & PROT_EXEC))
e |= PAGE_XD;
}
__ref_page(mm, pml4t, page);
*pte = e;

View file

@ -36,7 +36,8 @@ ti_int __divmodti4(ti_int a, ti_int b, tu_int *opt_out_rem) {
q = __udivmodti4(x, y, &r); // unsigned divide
q = (tu_int)(q ^ sq) - sq; // fix quotient sign
r = (tu_int)(r ^ sr) - sr; // fix remainder sign
if (opt_out_rem) *opt_out_rem = r;
if (opt_out_rem)
*opt_out_rem = r;
return q;
}

View file

@ -109,7 +109,8 @@ wontreturn void _Exit(int exitcode) {
"push\t$0\n\t"
"cli\n\t"
"lidt\t(%rsp)");
for (;;) asm("ud2");
for (;;)
asm("ud2");
#else
__builtin_unreachable();
#endif

View file

@ -85,19 +85,24 @@ static void *_mapframe(void *p, int f) {
void *_extend(void *p, size_t n, void *e, int f, intptr_t h) {
char *q;
#ifndef NDEBUG
if ((uintptr_t)SHADOW(p) & (G - 1)) notpossible;
if ((uintptr_t)p + (G << kAsanScale) > h) notpossible;
if ((uintptr_t)SHADOW(p) & (G - 1))
notpossible;
if ((uintptr_t)p + (G << kAsanScale) > h)
notpossible;
#endif
// TODO(jart): Make this spin less in non-ASAN mode.
for (q = e; q < ((char *)p + n); q += 8) {
if (!((uintptr_t)q & (G - 1))) {
#ifndef NDEBUG
if (q + G > (char *)h) notpossible;
if (q + G > (char *)h)
notpossible;
#endif
if (!_mapframe(q, f)) return 0;
if (!_mapframe(q, f))
return 0;
if (IsAsan()) {
if (!((uintptr_t)SHADOW(q) & (G - 1))) {
if (!_mapframe(SHADOW(q), f)) return 0;
if (!_mapframe(SHADOW(q), f))
return 0;
__asan_poison(q, G << kAsanScale, kAsanProtected);
}
}

View file

@ -30,7 +30,8 @@ __msabi extern typeof(FindClose) *const __imp_FindClose;
textwindows bool32 FindClose(int64_t hFindFile) {
bool32 ok;
ok = __imp_FindClose(hFindFile);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("FindClose(%ld) → %hhhd% m", hFindFile, ok);
return ok;
}

View file

@ -46,7 +46,8 @@ textwindows bool32 FindNextFile(int64_t hFindFile,
DescribeNtFileFlagAttr(out_lpFindFileData->dwFileAttributes),
DescribeNtFiletypeFlags(out_lpFindFileData->dwFileType), ok);
} else {
if (GetLastError() != kNtErrorNoMoreFiles) __winerr();
if (GetLastError() != kNtErrorNoMoreFiles)
__winerr();
NTTRACE("FindNextFile(%ld) → %hhhd% m", hFindFile, ok);
}
return ok;

View file

@ -36,7 +36,8 @@ textwindows bool32 FlushViewOfFile(const void *lpBaseAddress,
size_t dwNumberOfBytesToFlush) {
bool32 ok;
ok = __imp_FlushViewOfFile(lpBaseAddress, dwNumberOfBytesToFlush);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("FlushViewOfFile(%p, %'zu) → %hhhd% m", lpBaseAddress,
dwNumberOfBytesToFlush, ok);
return ok;

View file

@ -26,8 +26,10 @@
* signed zeroes.
*/
double fmax(double x, double y) {
if (isnan(x)) return y;
if (isnan(y)) return x;
if (isnan(x))
return y;
if (isnan(y))
return x;
if (signbit(x) != signbit(y)) {
return signbit(x) ? y : x; /* C99 Annex F.9.9.2 */
}

View file

@ -26,8 +26,10 @@
* signed zeroes.
*/
float fmaxf(float x, float y) {
if (isnan(x)) return y;
if (isnan(y)) return x;
if (isnan(x))
return y;
if (isnan(y))
return x;
if (signbit(x) != signbit(y)) {
return signbit(x) ? y : x; /* C99 Annex F.9.9.2 */
}

View file

@ -27,8 +27,10 @@
* signed zeroes.
*/
long double fmaxl(long double x, long double y) {
if (isnan(x)) return y;
if (isnan(y)) return x;
if (isnan(x))
return y;
if (isnan(y))
return x;
if (signbit(x) != signbit(y)) {
return signbit(x) ? y : x; /* C99 Annex F.9.9.2 */
}

View file

@ -23,10 +23,12 @@
static inline int PickGoodWidth(unsigned x, char z) {
if (z) {
if (x < 16) {
if (x < 8) return 8;
if (x < 8)
return 8;
return 16;
} else {
if (x < 32) return 32;
if (x < 32)
return 32;
return 64;
}
} else {

View file

@ -50,6 +50,7 @@ dontinline char *FormatUint32(char p[hasatleast 12], uint32_t x) {
* @return pointer to nul byte
*/
char *FormatInt32(char p[hasatleast 12], int32_t x) {
if (x < 0) *p++ = '-', x = -(uint32_t)x;
if (x < 0)
*p++ = '-', x = -(uint32_t)x;
return FormatUint32(p, x);
}

View file

@ -50,6 +50,7 @@ dontinline char *FormatUint64(char p[static 21], uint64_t x) {
* @return pointer to nul byte
*/
char *FormatInt64(char p[static 21], int64_t x) {
if (x < 0) *p++ = '-', x = -(uint64_t)x;
if (x < 0)
*p++ = '-', x = -(uint64_t)x;
return FormatUint64(p, x);
}

View file

@ -34,7 +34,8 @@ char *FormatOctal32(char p[hasatleast 13], uint32_t x, bool32 z) {
p[i++] = x % 8 + '0';
x = x / 8;
} while (x > 0);
if (z) p[i++] = '0';
if (z)
p[i++] = '0';
p[i] = '\0';
if (i) {
for (a = 0, b = i - 1; a < b; ++a, --b) {

View file

@ -71,7 +71,8 @@ static textwindows void SetupWinStd(struct Fds *fds, int i, uint32_t x) {
int64_t h;
uint32_t cm;
h = GetStdHandle(x);
if (!h || h == -1) return;
if (!h || h == -1)
return;
fds->p[i].kind = GetConsoleMode(h, &cm) ? kFdConsole : kFdFile;
fds->p[i].handle = h;
atomic_store_explicit(&fds->f, i + 1, memory_order_relaxed);
@ -124,15 +125,24 @@ textstartup void __init_fds(int argc, char **argv, char **envp) {
unsetenv("_COSMO_FDS");
for (;;) {
long fd, kind, flags, mode, handle, pointer, type, family, protocol;
if (!TokAtoi(&fdspec, &fd)) break;
if (!TokAtoi(&fdspec, &handle)) break;
if (!TokAtoi(&fdspec, &kind)) break;
if (!TokAtoi(&fdspec, &flags)) break;
if (!TokAtoi(&fdspec, &mode)) break;
if (!TokAtoi(&fdspec, &pointer)) break;
if (!TokAtoi(&fdspec, &type)) break;
if (!TokAtoi(&fdspec, &family)) break;
if (!TokAtoi(&fdspec, &protocol)) break;
if (!TokAtoi(&fdspec, &fd))
break;
if (!TokAtoi(&fdspec, &handle))
break;
if (!TokAtoi(&fdspec, &kind))
break;
if (!TokAtoi(&fdspec, &flags))
break;
if (!TokAtoi(&fdspec, &mode))
break;
if (!TokAtoi(&fdspec, &pointer))
break;
if (!TokAtoi(&fdspec, &type))
break;
if (!TokAtoi(&fdspec, &family))
break;
if (!TokAtoi(&fdspec, &protocol))
break;
__ensurefds_unlocked(fd);
struct Fd *f = fds->p + fd;
if (f->handle && f->handle != -1 && f->handle != handle) {

View file

@ -34,7 +34,8 @@ textwindows bool32 GenerateConsoleCtrlEvent(uint32_t dwCtrlEvent,
uint32_t dwProcessGroupId) {
bool32 ok;
ok = __imp_GenerateConsoleCtrlEvent(dwCtrlEvent, dwProcessGroupId);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("GenerateConsoleCtrlEvent(%x, %d) → %hhhd% m", dwCtrlEvent,
dwProcessGroupId, ok);
return ok;

View file

@ -31,7 +31,8 @@
char *getenv(const char *s) {
char **p;
struct Env e;
if (!(p = environ)) return 0;
if (!(p = environ))
return 0;
e = __getenv(p, s);
#if SYSDEBUG
// if (!(s[0] == 'T' && s[1] == 'Z' && !s[2])) {

View file

@ -30,7 +30,8 @@ __msabi extern typeof(GetExitCodeProcess) *const __imp_GetExitCodeProcess;
textwindows int32_t GetExitCodeProcess(int64_t hProcess, uint32_t *lpExitCode) {
int32_t rc;
rc = __imp_GetExitCodeProcess(hProcess, lpExitCode);
if (!rc) __winerr();
if (!rc)
__winerr();
NTTRACE("GetExitCodeProcess(%ld, [%u]) → %u% m", hProcess, *lpExitCode, rc);
return rc;
}

View file

@ -71,7 +71,8 @@ static char *__get_last(char **list) {
static int __get_length(const char *s) {
int n = 0;
while (*s++) ++n;
while (*s++)
++n;
return n;
}
@ -82,7 +83,8 @@ static uintptr_t __get_main_top(int pagesz) {
top = (uintptr_t)s + __get_length(s);
} else {
unsigned long *xp = __auxv;
while (*xp) xp += 2;
while (*xp)
xp += 2;
top = (uintptr_t)xp;
}
return ROUNDUP(top, pagesz);
@ -92,7 +94,8 @@ static size_t __get_stack_size(int pagesz, uintptr_t start, uintptr_t top) {
size_t size, max = 8 * 1024 * 1024;
struct rlimit rlim = {RLIM_INFINITY};
sys_getrlimit(RLIMIT_STACK, &rlim);
if ((size = rlim.rlim_cur) > max) size = max;
if ((size = rlim.rlim_cur) > max)
size = max;
return MAX(ROUNDUP(size, pagesz), ROUNDUP(top - start, pagesz));
}

View file

@ -33,7 +33,8 @@
* allocation would likely cause a stack overflow
*/
privileged long __get_safe_size(long want, long extraspace) {
if (!__tls_enabled) return want;
if (!__tls_enabled)
return want;
struct PosixThread *pt;
struct CosmoTib *tib = __get_tls_privileged();
if (!IsAutoFrame((uintptr_t)tib >> 16) &&
@ -52,6 +53,7 @@ privileged long __get_safe_size(long want, long extraspace) {
return want;
}
long size = sp - bottom - extraspace;
if (size > want) size = want;
if (size > want)
size = want;
return size;
}

View file

@ -49,11 +49,16 @@ bool32 IsDebuggerPresent(bool32 force) {
ssize_t got;
int e, fd, res;
char *p, buf[1024];
if (!force && IsGenuineBlink()) return 0;
if (!force && environ && __getenv(environ, "HEISENDEBUG").s) return 0;
if (IsWindows()) return IsBeingDebugged();
if (__isworker) return false;
if (!PLEDGED(RPATH)) return false;
if (!force && IsGenuineBlink())
return 0;
if (!force && environ && __getenv(environ, "HEISENDEBUG").s)
return 0;
if (IsWindows())
return IsBeingDebugged();
if (__isworker)
return false;
if (!PLEDGED(RPATH))
return false;
res = 0;
e = errno;
BLOCK_CANCELATION;

View file

@ -35,8 +35,10 @@
*/
bool __iswsl1(void) {
static char res;
if (res) return res & 1;
if (!IsLinux()) return res = 2, false;
if (res)
return res & 1;
if (!IsLinux())
return res = 2, false;
int e = errno;
unassert(__sys_mmap((void *)1, 4096, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_PRIVATE | ANONYMOUS | GROWSDOWN, -1, 0,

View file

@ -121,7 +121,8 @@ extern struct SymbolTable *__symtab;
__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;
if (ckd_add(&t, t, n))
t = (intptr_t)e;
return (char *)t;
}
@ -154,8 +155,10 @@ __funline bool kisimagepointer(const void *p) {
}
__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);
if (t == -1)
return (intptr_t)p & 1;
if (t >= 1)
return !!((intptr_t)p & 3);
return false;
}
@ -168,8 +171,10 @@ __funline bool kismemtrackhosed(void) {
privileged static bool kismapped(int x) {
// xxx: we can't lock because no reentrant locks yet
size_t m, r, l = 0;
if (!_weaken(_mmi)) return true;
if (kismemtrackhosed()) return false;
if (!_weaken(_mmi))
return true;
if (kismemtrackhosed())
return false;
r = _weaken(_mmi)->i;
while (l < r) {
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
@ -188,13 +193,18 @@ privileged static bool kismapped(int x) {
privileged bool32 kisdangerous(const void *p) {
int frame;
if (kisimagepointer(p)) return false;
if (kiskernelpointer(p)) return false;
if (IsOldStack(p)) return false;
if (kisimagepointer(p))
return false;
if (kiskernelpointer(p))
return false;
if (IsOldStack(p))
return false;
if (IsLegalPointer(p)) {
frame = (uintptr_t)p >> 16;
if (IsStackFrame(frame)) return false;
if (kismapped(frame)) return false;
if (IsStackFrame(frame))
return false;
if (kismapped(frame))
return false;
}
if (GetStackAddr() + GetGuardSize() <= (uintptr_t)p &&
(uintptr_t)p < GetStackAddr() + GetStackSize()) {
@ -228,7 +238,8 @@ privileged static long klogfcntl(long fd, long cmd, long arg) {
: CFLAG_CONSTRAINT(cf), "+a"(ax), "+D"(fd), "+S"(cmd), "+d"(arg)
: /* inputs already specified */
: "rcx", "r8", "r9", "r10", "r11", "memory");
if (cf) ax = -ax;
if (cf)
ax = -ax;
return ax;
#elif defined(__aarch64__)
register long x0 asm("x0") = fd;
@ -264,7 +275,8 @@ privileged static long klogopen(const char *path) {
"+d"(flags), "+r"(r10)
: /* inputs already specified */
: "rcx", "r8", "r9", "r11", "memory");
if (cf) ax = -ax;
if (cf)
ax = -ax;
return ax;
#elif defined(__aarch64__)
register long x0 asm("x0") = dirfd;
@ -376,7 +388,8 @@ privileged void _klog_serial(const char *b, size_t n) {
for (;;) {
dx = 0x3F8 + UART_LSR;
asm("inb\t%1,%0" : "=a"(al) : "dN"(dx));
if (al & UART_TTYTXR) break;
if (al & UART_TTYTXR)
break;
asm("pause");
}
dx = 0x3F8;
@ -448,19 +461,24 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
unsigned long long x;
unsigned i, j, m, rem, sign, hash, cols, prec;
char c, *p, *e, pdot, zero, flip, dang, base, quot, uppr, ansi, z[128];
if (kistextpointer(b) || kisdangerous(b)) n = 0;
if (!kistextpointer(fmt)) fmt = "!!WONTFMT";
if (kistextpointer(b) || kisdangerous(b))
n = 0;
if (!kistextpointer(fmt))
fmt = "!!WONTFMT";
p = b;
f = fmt;
e = p + n; // assume if n was negative e < p will be the case
for (;;) {
for (;;) {
if (!(c = *f++) || c == '%') break;
if (!(c = *f++) || c == '%')
break;
EmitFormatByte:
if (p < e) *p = c;
if (p < e)
*p = c;
++p;
}
if (!c) break;
if (!c)
break;
pdot = 0;
flip = 0;
dang = 0;
@ -632,21 +650,26 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
sign = '-';
}
FormatUnsigned:
if (x && hash) sign = hash;
if (x && hash)
sign = hash;
for (i = j = 0;;) {
x = __divmod10(x, &rem);
z[i++ & 127] = '0' + rem;
if (pdot ? i >= prec : !x) break;
if (pdot ? i >= prec : !x)
break;
if (quot && ++j == 3) {
z[i++ & 127] = quot;
j = 0;
}
}
EmitNumber:
if (flip || pdot) zero = 0;
if (flip || pdot)
zero = 0;
while (zero && sign) {
if (p < e) *p = sign;
if (cols) --cols;
if (p < e)
*p = sign;
if (cols)
--cols;
sign >>= 8;
++p;
}
@ -662,7 +685,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
}
}
while (sign) {
if (p < e) *p = sign;
if (p < e)
*p = sign;
sign >>= 8;
++p;
}
@ -686,14 +710,17 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
case 'b':
base = 1;
if (hash) hash = '0' | 'b' << 8;
if (hash)
hash = '0' | 'b' << 8;
BinaryNumber:
KGETINT(x, va, type, false);
FormatNumber:
i = 0;
m = (1 << base) - 1;
if (hash && x) sign = hash;
do z[i++ & 127] = abet[x & m];
if (hash && x)
sign = hash;
do
z[i++ & 127] = abet[x & m];
while ((x >>= base) || (pdot && i < prec));
goto EmitNumber;
@ -702,7 +729,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
/* fallthrough */
case 'x':
base = 4;
if (hash) hash = '0' | 'x' << 8;
if (hash)
hash = '0' | 'x' << 8;
goto BinaryNumber;
case 'o':
@ -711,7 +739,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
case 'p':
x = va_arg(va, intptr_t);
if (!x && pdot) pdot = 0;
if (!x && pdot)
pdot = 0;
if ((long)x == -1) {
pdot = 0;
goto FormatDecimal;
@ -730,14 +759,18 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
x = 0;
s = (const char *)&x;
t = va_arg(va, int);
if (!type) t &= 255;
if (!type)
t &= 255;
if (hash) {
quot = 1;
hash = '\'';
p = kemitquote(p, e, type, hash);
if (cols && type) --cols; // u/L
if (cols) --cols; // start quote
if (cols) --cols; // end quote
if (cols && type)
--cols; // u/L
if (cols)
--cols; // start quote
if (cols)
--cols; // end quote
}
goto EmitChar;
@ -771,7 +804,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
x = va_arg(va, intptr_t);
if (_weaken(__symtab) && *_weaken(__symtab) &&
(idx = _weaken(__get_symbol)(0, x)) != -1) {
if (p + 1 <= e) *p++ = '&';
if (p + 1 <= e)
*p++ = '&';
s = (*_weaken(__symtab))->name_base +
(*_weaken(__symtab))->names[idx];
goto FormatString;
@ -783,7 +817,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
case 'n':
// nonstandard %n specifier
if (p < e) *p = '\n';
if (p < e)
*p = '\n';
++p;
break;
@ -806,7 +841,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
type = 0;
} else if (!dang && (kisdangerous(s) || kischarmisaligned(s, type))) {
if (sign == ' ') {
if (p < e) *p = ' ';
if (p < e)
*p = ' ';
++p;
}
x = (intptr_t)s;
@ -816,22 +852,29 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
} else if (hash) {
quot = 1;
hash = '"';
if (cols && type) --cols; // u/L
if (cols) --cols; // start quote
if (cols) --cols; // end quote
if (cols && type)
--cols; // u/L
if (cols)
--cols; // start quote
if (cols)
--cols; // end quote
p = kemitquote(p, e, type, hash);
}
if (sign == ' ' && (!pdot || prec) && s && *s) {
if (p < e) *p = ' ';
if (p < e)
*p = ' ';
++p;
}
for (i = j = 0; !pdot || j < prec; ++j) {
if (UNLIKELY(!((intptr_t)s & 4095))) {
if (!dang && kisdangerous(s)) break;
if (!dang && kisdangerous(s))
break;
}
if (!type) {
if (!(t = *s++ & 255)) break;
if ((t & 0300) == 0200) goto ActuallyEmitByte;
if (!(t = *s++ & 255))
break;
if ((t & 0300) == 0200)
goto ActuallyEmitByte;
++i;
EmitByte:
if (uppr && 'a' <= t && t <= 'z') {
@ -851,7 +894,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
(t != 0x7F && (t >= 0x20 || (t == '\n' || t == '\t' ||
t == '\r' || t == '\e')))) {
ActuallyEmitByte:
if (p < e) *p = t;
if (p < e)
*p = t;
p += 1;
continue;
} else if (quot) {
@ -889,7 +933,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
if (IsHighSurrogate(t)) {
if (!pdot || j + 1 < prec) {
if (UNLIKELY(!((intptr_t)s & 4095))) {
if (!dang && kisdangerous(s)) break;
if (!dang && kisdangerous(s))
break;
}
u = *(const char16_t *)s;
if (IsLowSurrogate(u)) {
@ -907,10 +952,12 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
t = *(const wchar_t *)s;
s += sizeof(wchar_t);
}
if (!t) break;
if (!t)
break;
++i;
EmitChar:
if (t <= 0x7f) goto EmitByte;
if (t <= 0x7f)
goto EmitByte;
if (uppr) {
if (_weaken(towupper)) {
t = _weaken(towupper)(t);
@ -948,7 +995,8 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt,
}
}
if (hash) {
if (p < e) *p = hash;
if (p < e)
*p = hash;
++p;
}
while (cols > i) {

View file

@ -44,7 +44,8 @@ bool32 LockFileEx(int64_t hFile, uint32_t dwFlags, uint32_t dwReserved,
}
ok = __imp_LockFileEx(hFile, dwFlags, dwReserved, nNumberOfBytesToLockLow,
nNumberOfBytesToLockHigh, lpOverlapped);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("LockFileEx(%ld, %s, %#x, %'zu, [%s]) → %hhhd% m", hFile,
DescribeNtLockFileFlags(dwFlags), dwReserved,
(uint64_t)nNumberOfBytesToLockHigh << 32 | nNumberOfBytesToLockLow,

View file

@ -44,7 +44,8 @@ textwindows void *MapViewOfFileEx(int64_t hFileMappingObject,
pStartingAddress = __imp_MapViewOfFileEx(
hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow,
dwNumberOfBytesToMap, opt_lpDesiredBaseAddress);
if (!pStartingAddress) __winerr();
if (!pStartingAddress)
__winerr();
NTTRACE("MapViewOfFileEx(%ld, %s, %'ld, %'zu, %p) → %p% m",
hFileMappingObject, DescribeNtFileMapFlags(dwDesiredAccess),
(uint64_t)dwFileOffsetHigh << 32 | dwFileOffsetLow,

View file

@ -46,7 +46,8 @@ textwindows void *MapViewOfFileExNuma(int64_t hFileMappingObject,
pStartingAddress = __imp_MapViewOfFileExNuma(
hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow,
dwNumberOfBytesToMap, opt_lpDesiredBaseAddress, nndDesiredNumaNode);
if (!pStartingAddress) __winerr();
if (!pStartingAddress)
__winerr();
NTTRACE("MapViewOfFileExNuma(%ld, %s, %'ld, %'zu, %p) → %p% m",
hFileMappingObject, DescribeNtFileMapFlags(dwDesiredAccess),
(uint64_t)dwFileOffsetHigh << 32 | dwFileOffsetLow,

View file

@ -143,8 +143,10 @@ int memcmp(const void *a, const void *b, size_t n) {
uint64_t w, x, y;
#endif
const unsigned char *p, *q;
if ((p = a) == (q = b) || !n) return 0;
if ((c = *p - *q)) return c;
if ((p = a) == (q = b) || !n)
return 0;
if ((c = *p - *q))
return c;
#if defined(__x86_64__) && !defined(__chibicc__)
if (!IsTiny()) {
if (n <= 16) {

View file

@ -153,7 +153,8 @@ static __vex void *__memmove(void *dst, const void *src, size_t n) {
*(xmm_t *)(d + n - 16) = Y;
return d;
default:
if (d == s) return d;
if (d == s)
return d;
#if defined(__x86_64__) && !defined(__chibicc__)
if (n < kHalfCache3 || !kHalfCache3) {

View file

@ -71,10 +71,12 @@ static bool __extend_memory(struct MemoryIntervals *mm) {
if (1 || IsAsan()) {
shad = (char *)(((intptr_t)base >> 3) + 0x7fff8000);
dm = sys_mmap(shad, gran >> 3, prot, flags, -1, 0);
if (!dm.addr) return false;
if (!dm.addr)
return false;
}
dm = sys_mmap(base, gran, prot, flags, -1, 0);
if (!dm.addr) return false;
if (!dm.addr)
return false;
__shove_memory(dm.addr, mm->p, mm->i);
mm->p = dm.addr;
mm->n = gran / sizeof(*mm->p);
@ -84,10 +86,12 @@ static bool __extend_memory(struct MemoryIntervals *mm) {
if (IsAsan()) {
shad = (char *)(((intptr_t)base >> 3) + 0x7fff8000);
dm = sys_mmap(shad, gran >> 3, prot, flags, -1, 0);
if (!dm.addr) return false;
if (!dm.addr)
return false;
}
dm = sys_mmap(base, gran, prot, flags, -1, 0);
if (!dm.addr) return false;
if (!dm.addr)
return false;
mm->n = (size + gran) / sizeof(*mm->p);
}
return true;
@ -97,13 +101,15 @@ static int __mint_memory(struct MemoryIntervals *mm, int i) {
unassert(i >= 0);
unassert(i <= mm->i);
unassert(mm->n >= 0);
if (mm->i == mm->n && !__extend_memory(mm)) return enomem();
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 __punch_memory(struct MemoryIntervals *mm, int x, int y, int i) {
if (__mint_memory(mm, i) == -1) return -1;
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;
@ -115,15 +121,19 @@ int __untrack_memory(struct MemoryIntervals *mm, int x, int y,
void wf(struct MemoryIntervals *, int, int)) {
unsigned l, r;
unassert(y >= x);
if (!mm->i) return 0;
if (!mm->i)
return 0;
// binary search for the lefthand side
l = __find_memory(mm, x);
if (l == mm->i) return 0;
if (y < mm->p[l].x) return 0;
if (l == mm->i)
return 0;
if (y < mm->p[l].x)
return 0;
// binary search for the righthand side
r = __find_memory(mm, y);
if (r == mm->i || (r > l && y < mm->p[r].x)) --r;
if (r == mm->i || (r > l && y < mm->p[r].x))
--r;
unassert(r >= l);
unassert(x <= mm->p[r].y);
@ -147,7 +157,8 @@ int __untrack_memory(struct MemoryIntervals *mm, int x, int y,
//
if (x > mm->p[l].x && x <= mm->p[l].y) {
unassert(y >= mm->p[l].y);
if (IsWindows()) return einval();
if (IsWindows())
return einval();
mm->p[l].size -= (size_t)(mm->p[l].y - (x - 1)) * FRAMESIZE;
mm->p[l].y = x - 1;
unassert(mm->p[l].x <= mm->p[l].y);
@ -162,7 +173,8 @@ int __untrack_memory(struct MemoryIntervals *mm, int x, int y,
//
if (y >= mm->p[r].x && y < mm->p[r].y) {
unassert(x <= mm->p[r].x);
if (IsWindows()) return einval();
if (IsWindows())
return einval();
mm->p[r].size -= (size_t)((y + 1) - mm->p[r].x) * FRAMESIZE;
mm->p[r].x = y + 1;
unassert(mm->p[r].x <= mm->p[r].y);
@ -214,7 +226,8 @@ int __track_memory(struct MemoryIntervals *mm, int x, int y, long h, int prot,
// otherwise, create a new entry and memmove the items
else {
if (__mint_memory(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

@ -79,7 +79,8 @@ texthead uint64_t __new_page(struct mman *mm) {
return 0;
}
while (mm->pdp >= mm->e820[mm->pdpi].addr + mm->e820[mm->pdpi].size) {
if (++mm->pdpi == mm->e820n) return 0;
if (++mm->pdpi == mm->e820n)
return 0;
mm->pdp = MAX(mm->pdp, mm->e820[mm->pdpi].addr);
}
p = mm->pdp;
@ -98,10 +99,13 @@ textreal uint64_t *__get_virtual(struct mman *mm, uint64_t *t, int64_t vaddr,
unsigned char h;
for (h = 39;; h -= 9) {
e = t + ((vaddr >> h) & 511);
if (h == 12) return e;
if (h == 12)
return e;
if (!(*e & (PAGE_V | PAGE_RSRV))) {
if (!maketables) return NULL;
if (!(p = __new_page(mm))) return NULL;
if (!maketables)
return NULL;
if (!(p = __new_page(mm)))
return NULL;
__clear_page(BANE + p);
*e = p | PAGE_V | PAGE_RW;
}
@ -215,7 +219,8 @@ void __unref_page(struct mman *mm, uint64_t *pml4t, uint64_t p) {
if ((e & PAGE_REFC) != PAGE_REFC) {
e -= PAGE_1REF;
*m = e;
if ((e & PAGE_REFC) == 0) __reclaim_page(mm, p);
if ((e & PAGE_REFC) == 0)
__reclaim_page(mm, p);
}
}
}
@ -229,7 +234,8 @@ static textreal void __invert_memory(struct mman *mm, uint64_t *pml4t) {
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. */
if (ps < 0x200000 && ps + size <= 0x200000) continue;
if (ps < 0x200000 && ps + size <= 0x200000)
continue;
__invert_memory_area(mm, pml4t, ps, size, PAGE_RW | PAGE_XD);
}
}
@ -275,13 +281,15 @@ static textreal uint64_t __map_phdr(struct mman *mm, uint64_t *pml4t,
uint64_t b, uint64_t m,
struct Elf64_Phdr *p) {
uint64_t i, f, v;
if (p->p_type != PT_LOAD) return m;
if (p->p_type != PT_LOAD)
return m;
f = PAGE_RSRV | PAGE_U;
if (p->p_flags & PF_W)
f |= PAGE_V | PAGE_RW;
else if (p->p_flags & (PF_R | PF_X))
f |= PAGE_V;
if (!(p->p_flags & PF_X)) f |= PAGE_XD;
if (!(p->p_flags & PF_X))
f |= PAGE_XD;
for (i = 0; i < p->p_memsz; i += 4096) {
if (i < p->p_filesz) {
v = b + p->p_offset + i;
@ -336,14 +344,16 @@ textreal void __reclaim_boot_pages(struct mman *mm, uint64_t skip_start,
uint64_t p = mm->frp, q = IMAGE_BASE_REAL, i, n = mm->e820n, b, e;
for (i = 0; i < n; ++i) {
b = mm->e820[i].addr;
if (b >= IMAGE_BASE_PHYSICAL) break;
if (b >= IMAGE_BASE_PHYSICAL)
break;
e = MIN(IMAGE_BASE_PHYSICAL, b + mm->e820[i].size);
q = MAX(IMAGE_BASE_REAL, b);
while (q < e) {
struct ReclaimedPage *rp;
if (q == skip_start) {
q = skip_end;
if (q >= e) break;
if (q >= e)
break;
}
rp = (struct ReclaimedPage *)(BANE + q);
rp->next = p;

View file

@ -33,7 +33,8 @@ textwindows bool32 MoveFileEx(const char16_t *lpExistingFileName,
const char16_t *lpNewFileName, int dwFlags) {
bool32 ok;
ok = __imp_MoveFileExW(lpExistingFileName, lpNewFileName, dwFlags);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("MoveFileEx(%#hs, %#hs, %s) → %hhhd% m", lpExistingFileName,
lpNewFileName, DescribeNtMovFileInpFlags(dwFlags), ok);
return ok;

View file

@ -30,6 +30,7 @@ int128_t __mulvti3(int128_t x, int128_t y) {
int o;
int128_t z;
z = __muloti4(x, y, &o);
if (o) __on_arithmetic_overflow();
if (o)
__on_arithmetic_overflow();
return z;
}

View file

@ -23,7 +23,8 @@
#ifdef __x86_64__
textwindows void _ntcontext2linux(ucontext_t *ctx, const struct NtContext *cr) {
if (!cr) return;
if (!cr)
return;
ctx->uc_mcontext.eflags = cr->EFlags;
ctx->uc_mcontext.rax = cr->Rax;
ctx->uc_mcontext.rbx = cr->Rbx;
@ -50,7 +51,8 @@ textwindows void _ntcontext2linux(ucontext_t *ctx, const struct NtContext *cr) {
}
textwindows void _ntlinux2context(struct NtContext *cr, const ucontext_t *ctx) {
if (!cr) return;
if (!cr)
return;
cr->EFlags = ctx->uc_mcontext.eflags;
cr->Rax = ctx->uc_mcontext.rax;
cr->Rbx = ctx->uc_mcontext.rbx;

View file

@ -38,7 +38,8 @@ textwindows int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle,
uint32_t dwProcessId) {
int64_t hHandle;
hHandle = __imp_OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
if (!hHandle) __winerr();
if (!hHandle)
__winerr();
NTTRACE("OpenProcess(%s, %hhhd, %u) → %ld% m",
DescribeNtProcAccessFlags(dwDesiredAccess), bInheritHandle,
dwProcessId, hHandle);

View file

@ -32,7 +32,9 @@
void(packsswb)(int8_t a[16], const int16_t b[8], const int16_t c[8]) {
unsigned i;
int8_t r[16];
for (i = 0; i < 8; ++i) r[i + 0] = MIN(INT8_MAX, MAX(INT8_MIN, b[i]));
for (i = 0; i < 8; ++i) r[i + 8] = MIN(INT8_MAX, MAX(INT8_MIN, c[i]));
for (i = 0; i < 8; ++i)
r[i + 0] = MIN(INT8_MAX, MAX(INT8_MIN, b[i]));
for (i = 0; i < 8; ++i)
r[i + 8] = MIN(INT8_MAX, MAX(INT8_MIN, c[i]));
__builtin_memcpy(a, r, 16);
}

View file

@ -32,7 +32,9 @@
void(packuswb)(uint8_t a[16], const int16_t b[8], const int16_t c[8]) {
unsigned i;
uint8_t r[16];
for (i = 0; i < 8; ++i) r[i + 0] = MIN(UINT8_MAX, MAX(UINT8_MIN, b[i]));
for (i = 0; i < 8; ++i) r[i + 8] = MIN(UINT8_MAX, MAX(UINT8_MIN, c[i]));
for (i = 0; i < 8; ++i)
r[i + 0] = MIN(UINT8_MAX, MAX(UINT8_MIN, b[i]));
for (i = 0; i < 8; ++i)
r[i + 8] = MIN(UINT8_MAX, MAX(UINT8_MIN, c[i]));
__builtin_memcpy(a, r, 16);
}

View file

@ -32,6 +32,7 @@
void(pcmpgtb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) {
unsigned i;
int8_t r[16];
for (i = 0; i < 16; ++i) r[i] = -(b[i] > c[i]);
for (i = 0; i < 16; ++i)
r[i] = -(b[i] > c[i]);
__builtin_memcpy(a, r, 16);
}

View file

@ -30,6 +30,7 @@
void(pcmpgtw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) {
unsigned i;
int16_t r[8];
for (i = 0; i < 8; ++i) r[i] = -(b[i] > c[i]);
for (i = 0; i < 8; ++i)
r[i] = -(b[i] > c[i]);
__builtin_memcpy(a, r, 16);
}

View file

@ -27,7 +27,8 @@
uint32_t(pmovmskb)(const uint8_t p[16]) {
uint32_t i, m;
for (m = i = 0; i < 16; ++i) {
if (p[i] & 0x80) m |= 1 << i;
if (p[i] & 0x80)
m |= 1 << i;
}
return m;
}

View file

@ -30,6 +30,7 @@
void(pmulhrsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) {
unsigned i;
int16_t r[8];
for (i = 0; i < 8; ++i) r[i] = (((b[i] * c[i]) >> 14) + 1) >> 1;
for (i = 0; i < 8; ++i)
r[i] = (((b[i] * c[i]) >> 14) + 1) >> 1;
__builtin_memcpy(a, r, 16);
}

View file

@ -43,8 +43,10 @@ void PrintMemoryIntervals(int fd, const struct MemoryIntervals *mm) {
kprintf("%08x-%08x %s %'*ldx %s", mm->p[i].x, mm->p[i].y,
(DescribeMapping)(mappingbuf, mm->p[i].prot, mm->p[i].flags), w,
frames, (DescribeFrame)(framebuf, mm->p[i].x));
if (mm->p[i].iscow) kprintf(" cow");
if (mm->p[i].readonlyfile) kprintf(" readonlyfile");
if (mm->p[i].iscow)
kprintf(" cow");
if (mm->p[i].readonlyfile)
kprintf(" readonlyfile");
sizefmt(sb, mm->p[i].size, 1024);
kprintf(" %sB", sb);
if (i + 1 < mm->i) {

View file

@ -27,7 +27,8 @@
*/
void(psraw)(int16_t a[8], const int16_t b[8], unsigned char k) {
unsigned i;
if (k > 15) k = 15;
if (k > 15)
k = 15;
for (i = 0; i < 8; ++i) {
a[i] = b[i] >> k;
}

View file

@ -27,7 +27,8 @@ intptr_t _pthread_syshand(struct PosixThread *pt) {
unassert(IsWindows() || IsXnuSilicon());
for (;;) {
syshand = atomic_load_explicit(&pt->tib->tib_syshand, memory_order_acquire);
if (syshand) return syshand;
if (syshand)
return syshand;
pthread_pause_np();
}
}

View file

@ -46,7 +46,8 @@ static struct {
uint64_t _rand64(void) {
void *p;
uint128_t s;
if (__threaded) pthread_spin_lock(&g_rand64.lock);
if (__threaded)
pthread_spin_lock(&g_rand64.lock);
if (__pid == g_rand64.thepid) {
s = g_rand64.thepool; // normal path
} else {

View file

@ -36,7 +36,8 @@
*/
int __ensurefds_unlocked(int fd) {
size_t n;
if (fd < g_fds.n) return fd;
if (fd < g_fds.n)
return fd;
n = fd + 1;
g_fds.e = _extend(g_fds.p, n * sizeof(*g_fds.p), g_fds.e, MAP_PRIVATE,
kMemtrackFdsStart + kMemtrackFdsSize);

View file

@ -31,7 +31,8 @@ __msabi extern typeof(SetCurrentDirectory) *const __imp_SetCurrentDirectoryW;
textwindows bool32 SetCurrentDirectory(const char16_t *lpPathName) {
bool32 ok;
ok = __imp_SetCurrentDirectoryW(lpPathName);
if (!ok) __winerr();
if (!ok)
__winerr();
NTTRACE("SetCurrentDirectory(%#hs) → %hhhd% m", lpPathName, ok);
return ok;
}

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