Make some system call fixes

- Fix minor ABI issue with SIOCGIFCONF
- Fix ABI translation issues with statfs() on BSDs
- Fix SQLite angled header line
This commit is contained in:
Justine Tunney 2023-02-12 22:16:34 -08:00
parent 0eb621f75e
commit 2b6261a52d
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
11 changed files with 88 additions and 37 deletions

View file

@ -27,13 +27,13 @@ dontinline void ShowIt(const char *path) {
"optimal transfer block size");
sizefmt(ibuf, sf.f_frsize, 1024);
printf("f_frsize = %,zu (%sb %s)\n", sf.f_frsize, ibuf, "fragment size");
sizefmt(ibuf, sf.f_blocks * sf.f_bsize, 1024);
sizefmt(ibuf, sf.f_blocks * sf.f_frsize, 1024);
printf("f_blocks = %,zu (%sb %s)\n", sf.f_blocks, ibuf,
"total data blocks in filesystem");
sizefmt(ibuf, sf.f_bfree * sf.f_bsize, 1024);
sizefmt(ibuf, sf.f_bfree * sf.f_frsize, 1024);
printf("f_bfree = %,zu (%sb %s)\n", sf.f_bfree, ibuf,
"free blocks in filesystem");
sizefmt(ibuf, sf.f_bavail * sf.f_bsize, 1024);
sizefmt(ibuf, sf.f_bavail * sf.f_frsize, 1024);
printf("f_bavail = %,zu (%sb %s)\n", sf.f_bavail, ibuf,
"free blocks available to use");
printf("f_files = %,zu (%s)\n", sf.f_files,

View file

@ -184,6 +184,10 @@ static const char *DescribeStatfsTypeLinux(int64_t x) {
return "xfs";
case 0x012fd16d:
return "_xiafs";
case 0x2fc12fc1:
return "zfs";
case 0x4253584e:
return "apfs";
default:
return "unknown";
}
@ -222,7 +226,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
} else if (IsFreebsd()) {
f_type = m->freebsd.f_type;
f_bsize = m->freebsd.f_bsize;
f_bsize = m->freebsd.f_iosize;
f_blocks = m->freebsd.f_blocks;
f_bfree = m->freebsd.f_bfree;
f_bavail = m->freebsd.f_bavail;
@ -237,14 +241,14 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
} else if (IsXnu()) {
f_type = m->xnu.f_type;
f_bsize = m->xnu.f_bsize;
f_bsize = m->xnu.f_iosize;
f_blocks = m->xnu.f_blocks;
f_bfree = m->xnu.f_bfree;
f_bavail = m->xnu.f_bavail;
f_files = m->xnu.f_files;
f_ffree = m->xnu.f_ffree;
f_fsid = m->xnu.f_fsid;
f_namelen = 4096;
f_namelen = 255;
f_frsize = m->xnu.f_bsize;
f_flags = m->xnu.f_flags;
f_owner = m->xnu.f_owner;
@ -252,7 +256,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
} else if (IsOpenbsd()) {
f_type = f->f_type;
f_bsize = m->openbsd.f_bsize;
f_bsize = m->openbsd.f_iosize;
f_blocks = m->openbsd.f_blocks;
f_bfree = m->openbsd.f_bfree;
f_bavail = m->openbsd.f_bavail;
@ -267,7 +271,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
} else if (IsNetbsd()) {
f_type = m->netbsd.f_type;
f_bsize = m->netbsd.f_bsize;
f_bsize = m->netbsd.f_iosize;
f_blocks = m->netbsd.f_blocks;
f_bfree = m->netbsd.f_bfree;
f_bavail = m->netbsd.f_bavail;

View file

@ -9,7 +9,7 @@ struct statfs_linux {
int64_t f_bsize; /* optimal transfer block size */
int64_t f_blocks; /* total data blocks in filesystem */
int64_t f_bfree; /* free blocks in filesystem */
int64_t f_bavail; /* free blocks available to */
int64_t f_bavail; /* free blocks available to unprivileged user */
int64_t f_files; /* total file nodes in filesystem */
int64_t f_ffree; /* free file nodes in filesystem */
fsid_t f_fsid; /* filesystem id */

View file

@ -19,6 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/sched_param.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/struct/termios.h"
#include "libc/calls/struct/utsname.h"
@ -166,6 +167,7 @@ textstartup void __printargs(const char *prologue) {
uintptr_t *auxp;
struct rlimit rlim;
struct utsname uts;
struct sigaction sa;
struct sched_param sp;
struct termios termios;
struct AuxiliaryValue *auxinfo;
@ -288,7 +290,7 @@ textstartup void __printargs(const char *prologue) {
if (!sigprocmask(SIG_BLOCK, 0, &ss)) {
PRINT("");
PRINT("SIGNALS {%#lx, %#lx}", ss.__bits[0], ss.__bits[1]);
PRINT("SIGNAL MASK {%#lx, %#lx}", ss.__bits[0], ss.__bits[1]);
if (ss.__bits[0] || ss.__bits[1]) {
for (i = 0; i < 32; ++i) {
if (ss.__bits[0] & (1u << i)) {
@ -304,6 +306,23 @@ textstartup void __printargs(const char *prologue) {
PRINT(" error: sigprocmask() failed %m");
}
PRINT("");
PRINT("SIGNALS");
for (gotsome = 0, i = 1; i <= 64; ++i) {
if (!sigaction(i, 0, &sa)) {
if (sa.sa_handler == SIG_IGN) {
PRINT(" ☼ %G is SIG_IGN", i);
gotsome = 1;
} else if (sa.sa_handler != SIG_DFL) {
PRINT(" ☼ %G is %p", i, sa.sa_handler);
gotsome = 1;
}
}
}
if (!gotsome) {
PRINT(" ☼ SIG_DFL");
}
if (PLEDGED(PROC)) {
PRINT("");
PRINT("SCHEDULER");
@ -419,10 +438,21 @@ textstartup void __printargs(const char *prologue) {
PRINT("");
PRINT("TERMIOS");
for (i = 0; i < 2; ++i) {
for (i = 0; i <= 2; ++i) {
if (!tcgetattr(i, &termios)) {
PRINT(" - stdin");
struct winsize ws;
if (i == 0) {
PRINT(" - stdin");
} else if (i == 1) {
PRINT(" - stdout");
} else {
PRINT(" - stderr");
}
kprintf(prologue);
if (!tcgetwinsize(i, &ws)) {
kprintf(" ws_row = %d\n", ws.ws_row);
kprintf(" ws_col = %d\n", ws.ws_col);
}
kprintf(" c_iflag =");
if (termios.c_iflag & IGNBRK) kprintf(" IGNBRK");
if (termios.c_iflag & BRKINT) kprintf(" BRKINT");

View file

@ -11,7 +11,8 @@ COSMOPOLITAN_C_START_
* must know all networks accessible).
*/
struct ifconf {
uint64_t ifc_len; /* size of buffer */
int32_t ifc_len; /* size of buffer */
int32_t padding;
union {
char *ifcu_buf;
struct ifreq *ifcu_req;

View file

@ -64,9 +64,9 @@ scall sys_sched_yield 0x15e12a14bf25d018 globl hidden # select() on XNU (previo
scall __sys_mremap 0x19bffffffffff019 globl hidden
scall sys_mincore 0x04e04e04e204e01b globl hidden
scall sys_madvise 0x04b04b04b204b01c globl hidden
scall sys_shmget 0x0e71210e7210901d globl # no wrapper; consider mmap
scall sys_shmat 0x0e40e40e4210601e globl # no wrapper; consider mmap
scall sys_shmctl 0x1bb128200210701f globl # no wrapper; consider mmap
scall sys_shmget 0x0e71210e7210901d globl # no wrapper
scall sys_shmat 0x0e40e40e4210601e globl # no wrapper
scall sys_shmctl 0x1bb128200210701f globl # no wrapper
scall sys_dup 0x0290290292029020 globl hidden
scall sys_dup2 0x05a05a05a205a021 globl hidden
scall sys_pause 0xfffffffffffff022 globl hidden
@ -107,14 +107,14 @@ scall sys_futex_cp 0x8a68539c6ffff8ca globl hidden # intended for futex wait op
scall sys_set_robust_list 0x0a7ffffffffff111 globl # no wrapper
scall sys_get_robust_list 0x0a8ffffffffff112 globl # no wrapper
scall sys_uname 0x0a4fff0a4ffff03f globl hidden
scall sys_semget 0x0dd0dd0dd20ff040 globl # no wrapper; won't polyfill for windows
scall sys_semop 0x0de1220de2100041 globl # no wrapper; won't polyfill for windows
scall sys_semctl 0xfff1271fe20fe042 globl # no wrapper; won't polyfill for windows
scall sys_shmdt 0x0e60e60e62108043 globl # no wrapper; won't polyfill for windows
scall sys_msgget 0x0e10e10e12103044 globl # no wrapper; won't polyfill for windows
scall sys_msgsnd 0x8e28e28e22904845 globl # no wrapper; won't polyfill for windows
scall sys_msgrcv 0x8e38e38e32905846 globl # no wrapper; won't polyfill for windows
scall sys_msgctl 0x1bc1291ff2102047 globl # no wrapper; won't polyfill for windows
scall sys_semget 0x0dd0dd0dd20ff040 globl # no wrapper
scall sys_semop 0x0de1220de2100041 globl # no wrapper
scall sys_semctl 0xfff1271fe20fe042 globl # no wrapper
scall sys_shmdt 0x0e60e60e62108043 globl # no wrapper
scall sys_msgget 0x0e10e10e12103044 globl # no wrapper
scall sys_msgsnd 0x8e28e28e22904845 globl # no wrapper
scall sys_msgrcv 0x8e38e38e32905846 globl # no wrapper
scall sys_msgctl 0x1bc1291ff2102047 globl # no wrapper
scall __sys_fcntl 0x05c05c05c205c048 globl hidden
scall __sys_fcntl_cp 0x85c85c85c285c848 globl hidden # intended for F_SETLKW and F_OFD_SETLKW
scall sys_flock 0x8838838832883849 globl hidden
@ -282,7 +282,7 @@ scall sys_request_key 0xfffffffffffff0f9 globl # no wrapper
scall sys_keyctl 0xfffffffffffff0fa globl # no wrapper
scall ioprio_set 0xfffffffffffff0fb globl
scall ioprio_get 0xfffffffffffff0fc globl
scall sys_inotify_init 0xfffffffffffff0fd globl # wicked # no wrapper
scall sys_inotify_init 0xfffffffffffff0fd globl # no wrapper
scall sys_inotify_add_watch 0xfffffffffffff0fe globl # no wrapper
scall sys_inotify_rm_watch 0xfffffffffffff0ff globl # no wrapper
scall __sys_openat 0x9d49419f329cf901 globl hidden # Linux 2.6.16+ (c. 2007)
@ -323,13 +323,13 @@ scall sys_epoll_create1 0xfffffffffffff123 globl hidden
scall sys_perf_event_open 0xfffffffffffff12a globl # no wrapper
scall sys_inotify_init1 0xfffffffffffff126 globl # no wrapper
scall sys_rt_tgsigqueueinfo 0xfffffffffffff129 globl # no wrapper
scall sys_signalfd 0xfffffffffffff11a globl # won't polyfill; see INTON/INTOFF tutorial in examples/unbourne.c
scall sys_signalfd4 0xfffffffffffff121 globl # won't polyfill; see INTON/INTOFF tutorial in examples/unbourne.c
scall sys_eventfd 0xfffffffffffff11c globl # won't polyfill; see INTON/INTOFF tutorial in examples/unbourne.c
scall sys_eventfd2 0xfffffffffffff122 globl # won't polyfill; see INTON/INTOFF tutorial in examples/unbourne.c
scall sys_timerfd_create 0xfffffffffffff11b globl # won't polyfill; see INTON/INTOFF tutorial in examples/unbourne.c
scall sys_timerfd_settime 0xfffffffffffff11e globl # won't polyfill; see INTON/INTOFF tutorial in examples/unbourne.c
scall sys_timerfd_gettime 0xfffffffffffff11f globl # won't polyfill; see INTON/INTOFF tutorial in examples/unbourne.c
scall sys_signalfd 0xfffffffffffff11a globl # no wrapper
scall sys_signalfd4 0xfffffffffffff121 globl # no wrapper
scall sys_eventfd 0xfffffffffffff11c globl # no wrapper
scall sys_eventfd2 0xfffffffffffff122 globl # no wrapper
scall sys_timerfd_create 0xfffffffffffff11b globl # no wrapper
scall sys_timerfd_settime 0xfffffffffffff11e globl # no wrapper
scall sys_timerfd_gettime 0xfffffffffffff11f globl # no wrapper
#──────────────────────RHEL 6.0 LIMIT──────────────────────── # ←┬─ modern glibc needs rhel6+ c. 2011
scall sys_recvmmsg 0x1dbffffffffff12b globl # ├─ end of life 2024-06-30 (extended)
scall sys_fanotify_init 0xfffffffffffff12c globl # ├─ last distro with the original gnome desktop

View file

@ -23,7 +23,9 @@
#include "libc/log/log.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/mlock.h"
#include "libc/sysv/consts/o.h"
#include "libc/testlib/testlib.h"
double g_avx2_juiceup_doubles_[4] forcealign(32);
@ -47,6 +49,15 @@ void testlib_benchwarmup(void) {
}
}
void EnableCruiseControlForCool(void) {
int fd, micros = 10;
if ((fd = open("/dev/cpu_dma_latency", O_WRONLY)) != -1) {
write(fd, &micros, sizeof(micros));
fcntl(fd, F_DUPFD_CLOEXEC, 123);
close(fd);
}
}
/**
* Runs all benchmark functions in sorted order.
*
@ -55,5 +66,6 @@ void testlib_benchwarmup(void) {
void testlib_runallbenchmarks(void) {
int e;
__log_level = kLogWarn;
EnableCruiseControlForCool();
testlib_runtestcases(__bench_start, __bench_end, testlib_benchwarmup);
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/str/blake2.h"
#include "libc/str/path.h"
@ -38,7 +39,9 @@ const char *sem_path_np(const char *name, char *buf, size_t size) {
const char *path, *a;
uint8_t digest[BLAKE2B256_DIGEST_LENGTH];
a = "/tmp/", n = 5;
if (IsLinux()) a = "/dev/shm/", n = 9;
if (IsLinux() && isdirectory("/dev/shm")) {
a = "/dev/shm/", n = 9;
}
if (n + BLAKE2B256_DIGEST_LENGTH * 2 + 4 < size) {
BLAKE2B256(name, strlen(name), digest);
p = mempcpy(buf, a, n);

View file

@ -1,4 +1,4 @@
// clang-format off
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5)
@ -5141,7 +5141,6 @@ static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(u64));
static void sqlite3Fts5ParserFree(void*, void (*freeProc)(void*));
static void sqlite3Fts5Parser(void*, int, Fts5Token, Fts5Parse*);
#ifndef NDEBUG
#include <stdio.h>
static void sqlite3Fts5ParserTrace(FILE*, char*);
#endif
static int sqlite3Fts5ParserFallback(int);

View file

@ -75,7 +75,7 @@
"noasan"
"nomsan"
"noubsan"
"smashmystack"
"nostackprotector"
"initarray"
"mayalias"
"noinstrument"

View file

@ -181,7 +181,9 @@
"i32"
"u32"
"i64"
"u64"))
"u64"
"off_t"
"rlim_t"))
(x86intrin
'("__v8hu"