Add sysctlbyname() for MacOS

This commit is contained in:
Justine Tunney 2024-05-02 23:21:43 -07:00
parent 5c6877b02b
commit 181cd4cbe8
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
21 changed files with 193 additions and 35 deletions

View file

@ -31,6 +31,8 @@
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/random.h> #include <sys/random.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
@ -39,7 +41,7 @@
/* maximum path size that cosmo can take */ /* maximum path size that cosmo can take */
#define PATHSIZE (PATH_MAX < 1024 ? PATH_MAX : 1024) #define PATHSIZE (PATH_MAX < 1024 ? PATH_MAX : 1024)
#define SYSLIB_MAGIC ('s' | 'l' << 8 | 'i' << 16 | 'b' << 24) #define SYSLIB_MAGIC ('s' | 'l' << 8 | 'i' << 16 | 'b' << 24)
#define SYSLIB_VERSION 9 /* sync with libc/runtime/syslib.internal.h */ #define SYSLIB_VERSION 10 /* sync with libc/runtime/syslib.internal.h */
struct Syslib { struct Syslib {
int magic; int magic;
@ -106,6 +108,10 @@ struct Syslib {
OPTIONAL (cosmo lib should check __syslib->version) */ OPTIONAL (cosmo lib should check __syslib->version) */
/* v9 (2024-01-31) */ /* v9 (2024-01-31) */
int (*pthread_cpu_number_np)(size_t *); int (*pthread_cpu_number_np)(size_t *);
/* v10 (2024-05-02) */
long (*sysctl)(int *, u_int, void *, size_t *, void *, size_t);
long (*sysctlbyname)(const char *, void *, size_t *, void *, size_t);
long (*sysctlnametomib)(const char *, int *, size_t *);
}; };
#define ELFCLASS32 1 #define ELFCLASS32 1
@ -148,8 +154,8 @@ struct Syslib {
#define _COMM_PAGE_APRR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110) #define _COMM_PAGE_APRR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS + 0x110)
#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118) #define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS + 0x118)
#define MIN(X, Y) ((Y) > (X) ? (X) : (Y)) #define Min(X, Y) ((Y) > (X) ? (X) : (Y))
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y)) #define Max(X, Y) ((Y) < (X) ? (X) : (Y))
#define READ32(S) \ #define READ32(S) \
((unsigned)(255 & (S)[3]) << 030 | (unsigned)(255 & (S)[2]) << 020 | \ ((unsigned)(255 & (S)[3]) << 030 | (unsigned)(255 & (S)[2]) << 020 | \
@ -552,6 +558,20 @@ static long sys_pselect(int nfds, fd_set *readfds, fd_set *writefds,
return sysret(pselect(nfds, readfds, writefds, errorfds, timeout, sigmask)); return sysret(pselect(nfds, readfds, writefds, errorfds, timeout, sigmask));
} }
static long sys_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen) {
return sysret(sysctl(name, namelen, oldp, oldlenp, newp, newlen));
}
static long sys_sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
void *newp, size_t newlen) {
return sysret(sysctlbyname(name, oldp, oldlenp, newp, newlen));
}
static long sys_sysctlnametomib(const char *name, int *mibp, size_t *sizep) {
return sysret(sysctlnametomib(name, mibp, sizep));
}
__attribute__((__noreturn__)) static void Spawn(const char *exe, int fd, __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd,
long *sp, struct ElfEhdr *e, long *sp, struct ElfEhdr *e,
struct ElfPhdr *p, struct ElfPhdr *p,
@ -596,7 +616,7 @@ __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd,
continue; continue;
c = p[j].p_vaddr & -pagesz; c = p[j].p_vaddr & -pagesz;
d = (p[j].p_vaddr + p[j].p_memsz + (pagesz - 1)) & -pagesz; d = (p[j].p_vaddr + p[j].p_memsz + (pagesz - 1)) & -pagesz;
if (MAX(a, c) < MIN(b, d)) { if (Max(a, c) < Min(b, d)) {
Pexit(exe, 0, "ELF segments overlap each others virtual memory"); Pexit(exe, 0, "ELF segments overlap each others virtual memory");
} }
} }
@ -670,7 +690,7 @@ __attribute__((__noreturn__)) static void Spawn(const char *exe, int fd,
a = p[i].p_vaddr + p[i].p_filesz; /* end of file content */ a = p[i].p_vaddr + p[i].p_filesz; /* end of file content */
b = (a + (pagesz - 1)) & -pagesz; /* first pure bss page */ b = (a + (pagesz - 1)) & -pagesz; /* first pure bss page */
c = p[i].p_vaddr + p[i].p_memsz; /* end of segment data */ c = p[i].p_vaddr + p[i].p_memsz; /* end of segment data */
wipe = MIN(b - a, c - a); wipe = Min(b - a, c - a);
if (wipe && (~prot1 & PROT_WRITE)) { if (wipe && (~prot1 & PROT_WRITE)) {
prot1 = PROT_READ | PROT_WRITE; prot1 = PROT_READ | PROT_WRITE;
} }
@ -970,6 +990,9 @@ int main(int argc, char **argv, char **envp) {
M->lib.dlclose = dlclose; M->lib.dlclose = dlclose;
M->lib.dlerror = dlerror; M->lib.dlerror = dlerror;
M->lib.pthread_cpu_number_np = pthread_cpu_number_np; M->lib.pthread_cpu_number_np = pthread_cpu_number_np;
M->lib.sysctl = sys_sysctl;
M->lib.sysctlbyname = sys_sysctlbyname;
M->lib.sysctlnametomib = sys_sysctlnametomib;
/* getenv("_") is close enough to at_execfn */ /* getenv("_") is close enough to at_execfn */
execfn = 0; execfn = 0;

View file

@ -237,7 +237,9 @@ int sys_munlock(const void *, size_t) libcesque;
int sys_munlockall(void) libcesque; int sys_munlockall(void) libcesque;
int sys_personality(uint64_t) libcesque; int sys_personality(uint64_t) libcesque;
int sys_ptrace(int, ...) libcesque; int sys_ptrace(int, ...) libcesque;
int sys_sysctl(const int *, unsigned, void *, size_t *, void *, size_t); int sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque;
int sysctlbyname(const char *, void *, size_t *, void *, size_t) libcesque;
int sysctlnametomib(const char *, int *, size_t *) libcesque;
int tmpfd(void) libcesque; int tmpfd(void) libcesque;
int touch(const char *, unsigned) libcesque; int touch(const char *, unsigned) libcesque;
int unveil(const char *, const char *) libcesque; int unveil(const char *, const char *) libcesque;

View file

@ -53,7 +53,7 @@ static dontinline int __clk_tck_init(void) {
cmd[0] = 1; // CTL_KERN cmd[0] = 1; // CTL_KERN
cmd[1] = 12; // KERN_CLOCKRATE cmd[1] = 12; // KERN_CLOCKRATE
len = sizeof(clock); len = sizeof(clock);
if (sys_sysctl(cmd, 2, &clock, &len, NULL, 0) != -1) { if (sysctl(cmd, 2, &clock, &len, NULL, 0) != -1) {
x = clock.hz; x = clock.hz;
} else { } else {
x = -1; x = -1;

View file

@ -67,7 +67,7 @@ int sys_clock_gettime_xnu(int clock, struct timespec *ts) {
struct timeval x; struct timeval x;
size_t n = sizeof(x); size_t n = sizeof(x);
int mib[] = {CTL_KERN, KERN_BOOTTIME}; int mib[] = {CTL_KERN, KERN_BOOTTIME};
if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) if (sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1)
return -1; return -1;
if (ts) if (ts)
*ts = timeval_totimespec(timeval_sub(timeval_real(), x)); *ts = timeval_totimespec(timeval_sub(timeval_real(), x));

View file

@ -51,7 +51,7 @@ static int __get_cpu_count_bsd(void) {
} else { } else {
cmd[1] = HW_NCPU; cmd[1] = HW_NCPU;
} }
if (!sys_sysctl(cmd, 2, &c, &n, 0, 0)) { if (!sysctl(cmd, 2, &c, &n, 0, 0)) {
return c; return c;
} else { } else {
return -1; return -1;

View file

@ -24,7 +24,7 @@
int gethostname_bsd(char *name, size_t len, int kind) { int gethostname_bsd(char *name, size_t len, int kind) {
int cmd[2] = {CTL_KERN, kind}; int cmd[2] = {CTL_KERN, kind};
if (sys_sysctl(cmd, 2, name, &len, 0, 0) != -1) { if (sysctl(cmd, 2, name, &len, 0, 0) != -1) {
return 0; return 0;
} else { } else {
if (errno == ENOMEM) { if (errno == ENOMEM) {

View file

@ -64,7 +64,7 @@ int getloadavg(double *a, int n) {
struct loadavg loadinfo; struct loadavg loadinfo;
int mib[2] = {CTL_VM, VM_LOADAVG}; int mib[2] = {CTL_VM, VM_LOADAVG};
size = sizeof(loadinfo); size = sizeof(loadinfo);
if ((rc = sys_sysctl(mib, 2, &loadinfo, &size, 0, 0)) != -1) { if ((rc = sysctl(mib, 2, &loadinfo, &size, 0, 0)) != -1) {
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
a[i] = (double)loadinfo.ldavg[i] / loadinfo.fscale; a[i] = (double)loadinfo.ldavg[i] / loadinfo.fscale;
} }

View file

@ -195,7 +195,7 @@ static inline void InitProgramExecutableNameImpl(void) {
cmd[2] = KERN_PROC_PATHNAME_NETBSD; cmd[2] = KERN_PROC_PATHNAME_NETBSD;
} }
cmd[3] = -1; // current process cmd[3] = -1; // current process
if (sys_sysctl(cmd, ARRAYLEN(cmd), b, &n, 0, 0) != -1) { if (sysctl(cmd, ARRAYLEN(cmd), b, &n, 0, 0) != -1) {
if (!OldApeLoader(b)) { if (!OldApeLoader(b)) {
goto UseBuf; goto UseBuf;
} }

View file

@ -70,7 +70,7 @@ static void GetRandomArnd(char *p, size_t n) {
cmd[0] = 1; // CTL_KERN cmd[0] = 1; // CTL_KERN
cmd[1] = IsFreebsd() ? 37 : 81; // KERN_ARND cmd[1] = IsFreebsd() ? 37 : 81; // KERN_ARND
unassert((m = n) <= 256); unassert((m = n) <= 256);
if (sys_sysctl(cmd, 2, p, &n, 0, 0) == -1) if (sysctl(cmd, 2, p, &n, 0, 0) == -1)
notpossible; notpossible;
if (m != n) if (m != n)
notpossible; notpossible;

33
libc/calls/sysctl.c Normal file
View file

@ -0,0 +1,33 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2024 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/runtime/syslib.internal.h"
int sys_sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque;
int sysctl(int *name, unsigned namelen, void *oldp, size_t *oldlenp, void *newp,
size_t newlen) {
if (__syslib && __syslib->__version >= 10) {
return _sysret(
__syslib->__sysctl(name, namelen, oldp, oldlenp, newp, newlen));
} else {
return sys_sysctl(name, namelen, oldp, oldlenp, newp, newlen);
}
}

31
libc/calls/sysctlbyname.c Normal file
View file

@ -0,0 +1,31 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2024 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/runtime/syslib.internal.h"
#include "libc/sysv/errfuns.h"
int sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp,
size_t newlen) {
if (__syslib && __syslib->__version >= 10) {
return _sysret(__syslib->__sysctlbyname(name, oldp, oldlenp, newp, newlen));
} else {
return enosys();
}
}

View file

@ -0,0 +1,30 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2024 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/runtime/syslib.internal.h"
#include "libc/sysv/errfuns.h"
int sysctlnametomib(const char *name, int *mibp, size_t *sizep) {
if (__syslib && __syslib->__version >= 10) {
return _sysret(__syslib->__sysctlnametomib(name, mibp, sizep));
} else {
return enosys();
}
}

View file

@ -46,7 +46,7 @@ static int64_t GetUptime(void) {
struct timeval x; struct timeval x;
size_t n = sizeof(x); size_t n = sizeof(x);
int mib[] = {CTL_KERN, KERN_BOOTTIME}; int mib[] = {CTL_KERN, KERN_BOOTTIME};
if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) if (sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1)
return 0; return 0;
return timespec_real().tv_sec - x.tv_sec; return timespec_real().tv_sec - x.tv_sec;
} }
@ -55,7 +55,7 @@ static int64_t GetPhysmem(void) {
uint64_t x = 0; uint64_t x = 0;
size_t n = sizeof(x); size_t n = sizeof(x);
int mib[] = {CTL_HW, HW_PHYSMEM}; int mib[] = {CTL_HW, HW_PHYSMEM};
if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) if (sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1)
return 0; return 0;
return x; return x;
} }
@ -65,7 +65,7 @@ static void GetLoads(uint64_t loads[3]) {
struct loadavg loadinfo; struct loadavg loadinfo;
int mib[2] = {CTL_VM, VM_LOADAVG}; int mib[2] = {CTL_VM, VM_LOADAVG};
size = sizeof(loadinfo); size = sizeof(loadinfo);
if (sys_sysctl(mib, 2, &loadinfo, &size, 0, 0) != -1) { if (sysctl(mib, 2, &loadinfo, &size, 0, 0) != -1) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
loads[i] = (double)loadinfo.ldavg[i] / loadinfo.fscale * 65536; loads[i] = (double)loadinfo.ldavg[i] / loadinfo.fscale * 65536;
} }

View file

@ -62,7 +62,7 @@ static void GetBsdStr(int c0, int c1, char *s) {
size_t n = SYS_NMLN; size_t n = SYS_NMLN;
int cmd[2] = {c0, c1}; int cmd[2] = {c0, c1};
bzero(s, n), --n; bzero(s, n), --n;
sys_sysctl(cmd, 2, s, &n, NULL, 0); sysctl(cmd, 2, s, &n, NULL, 0);
errno = e; errno = e;
// sysctl kern.version is too verbose for uname // sysctl kern.version is too verbose for uname
if ((p = strchr(s, '\n'))) { if ((p = strchr(s, '\n'))) {

View file

@ -254,10 +254,28 @@ static relegated void ShowCrashReport(int err, int sig, struct siginfo *si,
kprintf("\n"); kprintf("\n");
} }
static inline void SpinLock(atomic_uint *lock) {
int x;
for (;;) {
x = atomic_exchange_explicit(lock, 1, memory_order_acquire);
if (!x)
break;
}
}
static inline void SpinUnlock(atomic_uint *lock) {
atomic_store_explicit(lock, 0, memory_order_release);
}
relegated void __oncrash(int sig, struct siginfo *si, void *arg) { relegated void __oncrash(int sig, struct siginfo *si, void *arg) {
static atomic_uint lock;
BLOCK_CANCELATION;
SpinLock(&lock);
int err = errno; int err = errno;
__restore_tty(); __restore_tty();
ShowCrashReport(err, sig, si, arg); ShowCrashReport(err, sig, si, arg);
SpinUnlock(&lock);
ALLOW_CANCELATION;
} }
#endif /* __x86_64__ */ #endif /* __x86_64__ */

View file

@ -18,6 +18,7 @@
*/ */
#include "ape/sections.internal.h" #include "ape/sections.internal.h"
#include "libc/assert.h" #include "libc/assert.h"
#include "libc/atomic.h"
#include "libc/calls/blockcancel.internal.h" #include "libc/calls/blockcancel.internal.h"
#include "libc/calls/calls.h" #include "libc/calls/calls.h"
#include "libc/calls/struct/aarch64.internal.h" #include "libc/calls/struct/aarch64.internal.h"
@ -32,6 +33,7 @@
#include "libc/calls/ucontext.h" #include "libc/calls/ucontext.h"
#include "libc/cxxabi.h" #include "libc/cxxabi.h"
#include "libc/errno.h" #include "libc/errno.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/describebacktrace.internal.h" #include "libc/intrin/describebacktrace.internal.h"
#include "libc/intrin/describeflags.internal.h" #include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
@ -377,10 +379,25 @@ static relegated void __oncrash_impl(int sig, struct siginfo *si,
klog(b->p, MIN(b->i, b->n)); klog(b->p, MIN(b->i, b->n));
} }
static inline void SpinLock(atomic_uint *lock) {
int x;
for (;;) {
x = atomic_exchange_explicit(lock, 1, memory_order_acquire);
if (!x)
break;
}
}
static inline void SpinUnlock(atomic_uint *lock) {
atomic_store_explicit(lock, 0, memory_order_release);
}
relegated void __oncrash(int sig, struct siginfo *si, void *arg) { relegated void __oncrash(int sig, struct siginfo *si, void *arg) {
ucontext_t *ctx = arg; static atomic_uint lock;
BLOCK_CANCELATION; BLOCK_CANCELATION;
__oncrash_impl(sig, si, ctx); SpinLock(&lock);
__oncrash_impl(sig, si, arg);
SpinUnlock(&lock);
ALLOW_CANCELATION; ALLOW_CANCELATION;
} }

View file

@ -76,7 +76,7 @@ char *GetInterpreterExecutableName(char *p, size_t n) {
cmd[2] = 5; // KERN_PROC_PATHNAME cmd[2] = 5; // KERN_PROC_PATHNAME
} // } //
cmd[3] = -1; // current process cmd[3] = -1; // current process
if (sys_sysctl(cmd, ARRAYLEN(cmd), p, &n, 0, 0) != -1) { if (sysctl(cmd, ARRAYLEN(cmd), p, &n, 0, 0) != -1) {
errno = e; errno = e;
return p; return p;
} }

View file

@ -23,7 +23,7 @@ long __get_sysctl(int x, int y) {
int value; int value;
int mib[2] = {x, y}; int mib[2] = {x, y};
size_t len = sizeof(value); size_t len = sizeof(value);
if (sys_sysctl(mib, 2, &value, &len, 0, 0) != -1) { if (sysctl(mib, 2, &value, &len, 0, 0) != -1) {
return value; return value;
} else { } else {
return -1; return -1;

View file

@ -12,7 +12,7 @@ COSMOPOLITAN_C_START_
#define SYSLIB_MAGIC ('s' | 'l' << 8 | 'i' << 16 | 'b' << 24) #define SYSLIB_MAGIC ('s' | 'l' << 8 | 'i' << 16 | 'b' << 24)
#define SYSLIB_VERSION 9 /* sync with ape/ape-m1.c */ #define SYSLIB_VERSION 10 /* sync with ape/ape-m1.c */
/* if this number increases, then everyone on macos arm will need to /* if this number increases, then everyone on macos arm will need to
reinstall ape loader in order to run newer ape binaries so please reinstall ape loader in order to run newer ape binaries so please
@ -82,6 +82,9 @@ struct Syslib {
char *(*__dlerror)(void); char *(*__dlerror)(void);
/* v9 (2024-01-31) */ /* v9 (2024-01-31) */
int (*__pthread_cpu_number_np)(size_t *); int (*__pthread_cpu_number_np)(size_t *);
long (*__sysctl)(int *, unsigned, void *, size_t *, void *, size_t);
long (*__sysctlbyname)(const char *, void *, size_t *, void *, size_t);
long (*__sysctlnametomib)(const char *, int *, size_t *);
}; };
extern struct Syslib *__syslib; extern struct Syslib *__syslib;

1
third_party/awk/b.c vendored
View file

@ -1463,6 +1463,7 @@ rescan:
} }
break; break;
} }
__builtin_unreachable();
} }
int cgoto(fa *f, int s, int c) int cgoto(fa *f, int s, int c)

View file

@ -215,7 +215,7 @@
(runs (format "o/$m/%s%s V=5 TESTARGS=-b" name runsuffix)) (runs (format "o/$m/%s%s V=5 TESTARGS=-b" name runsuffix))
(buns (format "o/$m/test/%s_test%s V=5 TESTARGS=-b" name runsuffix))) (buns (format "o/$m/test/%s_test%s V=5 TESTARGS=-b" name runsuffix)))
(cond ((not (member ext '("c" "cc" "cpp" "s" "S" "rl" "f" "cu"))) (cond ((not (member ext '("c" "cc" "cpp" "s" "S" "rl" "f" "cu")))
(format "m=%s; make -j32 MODE=$m o/$m/%s" (format "m=%s; make -j96 MODE=$m o/$m/%s"
mode mode
(directory-file-name (directory-file-name
(or (file-name-directory (or (file-name-directory
@ -226,7 +226,7 @@
(cosmo-join (cosmo-join
" && " " && "
`("m=%s; f=o/$m/%s" `("m=%s; f=o/$m/%s"
,(concat "make -j32 $f MODE=$m") ,(concat "make -j96 $f MODE=$m")
"scp $f $f.dbg win10:; ssh win10 ./%s")) "scp $f $f.dbg win10:; ssh win10 ./%s"))
mode name (file-name-nondirectory name))) mode name (file-name-nondirectory name)))
((eq kind 'run-xnu) ((eq kind 'run-xnu)
@ -234,19 +234,19 @@
(cosmo-join (cosmo-join
" && " " && "
`("m=%s; f=o/$m/%s" `("m=%s; f=o/$m/%s"
,(concat "make -j32 $f MODE=$m") ,(concat "make -j96 $f MODE=$m")
"scp $f $f.dbg xnu:" "scp $f $f.dbg xnu:"
"ssh xnu ./%s")) "ssh xnu ./%s"))
mode name (file-name-nondirectory name))) mode name (file-name-nondirectory name)))
((and (equal suffix "") ((and (equal suffix "")
(cosmo-contains "_test." (buffer-file-name))) (cosmo-contains "_test." (buffer-file-name)))
(format "m=%s; make -j32 MODE=$m %s" (format "m=%s; make -j96 MODE=$m %s"
mode runs)) mode runs))
((and (equal suffix "") ((and (equal suffix "")
(file-exists-p (format "%s" buddy))) (file-exists-p (format "%s" buddy)))
(format (cosmo-join (format (cosmo-join
" && " " && "
'("m=%s; n=%s; make -j32 o/$m/$n%s.o MODE=$m" '("m=%s; n=%s; make -j96 o/$m/$n%s.o MODE=$m"
;; "bloat o/$m/%s.o | head" ;; "bloat o/$m/%s.o | head"
;; "nm -C --size o/$m/%s.o | sort -r" ;; "nm -C --size o/$m/%s.o | sort -r"
"echo" "echo"
@ -258,11 +258,11 @@
(cosmo-join (cosmo-join
" && " " && "
`("m=%s; f=o/$m/%s" `("m=%s; f=o/$m/%s"
,(concat "make -j32 $f MODE=$m") ,(concat "make -j96 $f MODE=$m")
"build/run ./$f")) "build/run ./$f"))
mode name)) mode name))
((eq kind 'test) ((eq kind 'test)
(format `"m=%s; f=o/$m/%s.ok && make -j32 $f MODE=$m" mode name)) (format `"m=%s; f=o/$m/%s.ok && make -j96 $f MODE=$m" mode name))
((and (file-regular-p this) ((and (file-regular-p this)
(file-executable-p this)) (file-executable-p this))
(format "build/run ./%s" file)) (format "build/run ./%s" file))
@ -271,7 +271,7 @@
(cosmo-join (cosmo-join
" && " " && "
`("m=%s; f=o/$m/%s%s.o" `("m=%s; f=o/$m/%s%s.o"
,(concat "make -j32 $f MODE=$m") ,(concat "make -j96 $f MODE=$m")
;; "nm -C --size $f | sort -r" ;; "nm -C --size $f | sort -r"
"echo" "echo"
"size -A $f | grep '^[.T]' | grep -v 'debug\\|command.line\\|stack' | sort -rnk2" "size -A $f | grep '^[.T]' | grep -v 'debug\\|command.line\\|stack' | sort -rnk2"
@ -481,7 +481,7 @@
(error "don't know how to show assembly for non c/c++ source file")) (error "don't know how to show assembly for non c/c++ source file"))
(let* ((default-directory root) (let* ((default-directory root)
(compile-command (compile-command
(format "make %s -j32 MODE=%s %s %s" (format "make %s -j96 MODE=%s %s %s"
(or extra-make-flags "") mode asm-gcc asm-clang))) (or extra-make-flags "") mode asm-gcc asm-clang)))
(save-buffer) (save-buffer)
(set-visited-file-modtime (current-time)) (set-visited-file-modtime (current-time))
@ -641,11 +641,11 @@
(compile (format "sh -c %s" file))) (compile (format "sh -c %s" file)))
((eq major-mode 'lua-mode) ((eq major-mode 'lua-mode)
(let* ((mode (cosmo--make-mode arg))) (let* ((mode (cosmo--make-mode arg)))
(compile (format "make -j32 MODE=%s o/%s/tool/net/redbean && build/run o/%s/tool/net/redbean -i %s" mode mode mode file)))) (compile (format "make -j96 MODE=%s o/%s/tool/net/redbean && build/run o/%s/tool/net/redbean -i %s" mode mode mode file))))
((and (eq major-mode 'python-mode) ((and (eq major-mode 'python-mode)
(cosmo-startswith "third_party/python/Lib/test/" file)) (cosmo-startswith "third_party/python/Lib/test/" file))
(let ((mode (cosmo--make-mode arg))) (let ((mode (cosmo--make-mode arg)))
(compile (format "make -j32 MODE=%s PYHARNESSARGS=-vv PYTESTARGS=-v o/%s/%s.py.runs" (compile (format "make -j96 MODE=%s PYHARNESSARGS=-vv PYTESTARGS=-v o/%s/%s.py.runs"
mode mode (file-name-sans-extension file))))) mode mode (file-name-sans-extension file)))))
((eq major-mode 'python-mode) ((eq major-mode 'python-mode)
(compile (format "python %s" file))) (compile (format "python %s" file)))