mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Fix small matters and improve sysconf()
- Fix mkdeps.com out of memory error - Remove static memory from __get_cpu_count() - Add support for passing hyphen to cat in cocmd - Change more ZipOS errors from ENOTSUP to EROFS - Specify mem_unit in sysinfo() output on BSD OSes
This commit is contained in:
parent
eebc24b9cd
commit
3a9cac4892
55 changed files with 411 additions and 262 deletions
|
@ -7,9 +7,26 @@
|
||||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||||
╚─────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
#endif
|
#endif
|
||||||
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/errno.h"
|
||||||
|
#include "libc/fmt/itoa.h"
|
||||||
#include "libc/intrin/kprintf.h"
|
#include "libc/intrin/kprintf.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/stdio/stdio.h"
|
||||||
|
|
||||||
|
// this implementation uses cosmopolitan specific apis so that the
|
||||||
|
// resulting program will be 28kb in size. the proper way to do it
|
||||||
|
// though is use sysconf(_SC_NPROCESSORS_ONLN), which is humongous
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
kprintf("%d\n", _getcpucount());
|
int count;
|
||||||
|
if ((count = __get_cpu_count()) != -1) {
|
||||||
|
char ibuf[12];
|
||||||
|
FormatInt32(ibuf, count);
|
||||||
|
tinyprint(1, ibuf, "\n", NULL);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
perror("__get_cpu_count");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,7 +298,7 @@ int main(int argc, char *argv[]) {
|
||||||
PORT);
|
PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
threads = argc > 1 ? atoi(argv[1]) : _getcpucount();
|
threads = argc > 1 ? atoi(argv[1]) : __get_cpu_count();
|
||||||
if (!(1 <= threads && threads <= 100000)) {
|
if (!(1 <= threads && threads <= 100000)) {
|
||||||
kprintf("error: invalid number of threads: %d\n", threads);
|
kprintf("error: invalid number of threads: %d\n", threads);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
25
examples/sysconf.c
Normal file
25
examples/sysconf.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#if 0
|
||||||
|
/*─────────────────────────────────────────────────────────────────╗
|
||||||
|
│ To the extent possible under law, Justine Tunney has waived │
|
||||||
|
│ all copyright and related or neighboring rights to this file, │
|
||||||
|
│ as it is written in the following disclaimers: │
|
||||||
|
│ • http://unlicense.org/ │
|
||||||
|
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||||
|
╚─────────────────────────────────────────────────────────────────*/
|
||||||
|
#endif
|
||||||
|
#include "libc/runtime/sysconf.h"
|
||||||
|
#include "libc/stdio/stdio.h"
|
||||||
|
|
||||||
|
#define SYSCONF(NAME) printf("%s %,ld\n", #NAME, sysconf(NAME))
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
SYSCONF(_SC_CLK_TCK);
|
||||||
|
SYSCONF(_SC_PAGESIZE);
|
||||||
|
SYSCONF(_SC_ARG_MAX);
|
||||||
|
SYSCONF(_SC_CHILD_MAX);
|
||||||
|
SYSCONF(_SC_OPEN_MAX);
|
||||||
|
SYSCONF(_SC_NPROCESSORS_CONF);
|
||||||
|
SYSCONF(_SC_NPROCESSORS_ONLN);
|
||||||
|
SYSCONF(_SC_PHYS_PAGES);
|
||||||
|
SYSCONF(_SC_AVPHYS_PAGES);
|
||||||
|
}
|
|
@ -24,6 +24,7 @@
|
||||||
#define _POSIX_SEMAPHORES _POSIX_VERSION
|
#define _POSIX_SEMAPHORES _POSIX_VERSION
|
||||||
#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION
|
#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION
|
||||||
#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION
|
#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION
|
||||||
|
#define _POSIX_SPAWN _POSIX_VERSION
|
||||||
|
|
||||||
#define EOF -1 /* end of file */
|
#define EOF -1 /* end of file */
|
||||||
#define WEOF -1u /* end of file (multibyte) */
|
#define WEOF -1u /* end of file (multibyte) */
|
||||||
|
|
|
@ -29,6 +29,6 @@
|
||||||
* @see chmod()
|
* @see chmod()
|
||||||
*/
|
*/
|
||||||
int fchmod(int fd, uint32_t mode) {
|
int fchmod(int fd, uint32_t mode) {
|
||||||
/* TODO(jart): Windows */
|
// TODO(jart): Windows
|
||||||
return sys_fchmod(fd, mode);
|
return sys_fchmod(fd, mode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
|
||||||
#include "libc/runtime/zipos.internal.h"
|
#include "libc/runtime/zipos.internal.h"
|
||||||
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
int sys_fchmodat_linux(int, const char *, unsigned, int);
|
int sys_fchmodat_linux(int, const char *, unsigned, int);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ int sys_fchmodat_linux(int, const char *, unsigned, int);
|
||||||
* @param path must exist
|
* @param path must exist
|
||||||
* @param mode contains octal flags (base 8)
|
* @param mode contains octal flags (base 8)
|
||||||
* @param flags can have `AT_SYMLINK_NOFOLLOW`
|
* @param flags can have `AT_SYMLINK_NOFOLLOW`
|
||||||
* @raise ENOTSUP if `dirfd` or `path` use zip file system
|
* @raise EROFS if `dirfd` or `path` use zip file system
|
||||||
* @errors ENOENT, ENOTDIR, ENOSYS
|
* @errors ENOENT, ENOTDIR, ENOSYS
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
* @see fchmod()
|
* @see fchmod()
|
||||||
|
@ -50,7 +50,7 @@ int fchmodat(int dirfd, const char *path, uint32_t mode, int flags) {
|
||||||
rc = efault();
|
rc = efault();
|
||||||
} else if (_weaken(__zipos_notat) &&
|
} else if (_weaken(__zipos_notat) &&
|
||||||
(rc = __zipos_notat(dirfd, path)) == -1) {
|
(rc = __zipos_notat(dirfd, path)) == -1) {
|
||||||
rc = enotsup();
|
rc = erofs();
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
if (IsLinux() && flags) {
|
if (IsLinux() && flags) {
|
||||||
rc = sys_fchmodat_linux(dirfd, path, mode, flags);
|
rc = sys_fchmodat_linux(dirfd, path, mode, flags);
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
|
||||||
#include "libc/runtime/zipos.internal.h"
|
#include "libc/runtime/zipos.internal.h"
|
||||||
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes owner and/or group of path.
|
* Changes owner and/or group of path.
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
* @param gid is group id, or -1 to not change
|
* @param gid is group id, or -1 to not change
|
||||||
* @param flags can have AT_SYMLINK_NOFOLLOW, etc.
|
* @param flags can have AT_SYMLINK_NOFOLLOW, etc.
|
||||||
* @return 0 on success, or -1 w/ errno
|
* @return 0 on success, or -1 w/ errno
|
||||||
* @raise ENOTSUP if `dirfd` or `path` use zip file system
|
* @raise EROFS if `dirfd` or `path` use zip file system
|
||||||
* @see chown(), lchown() for shorthand notation
|
* @see chown(), lchown() for shorthand notation
|
||||||
* @see /etc/passwd for user ids
|
* @see /etc/passwd for user ids
|
||||||
* @see /etc/group for group ids
|
* @see /etc/group for group ids
|
||||||
|
@ -47,7 +47,7 @@ int fchownat(int dirfd, const char *path, uint32_t uid, uint32_t gid,
|
||||||
rc = efault();
|
rc = efault();
|
||||||
} else if (_weaken(__zipos_notat) &&
|
} else if (_weaken(__zipos_notat) &&
|
||||||
(rc = __zipos_notat(dirfd, path)) == -1) {
|
(rc = __zipos_notat(dirfd, path)) == -1) {
|
||||||
rc = enotsup();
|
rc = erofs();
|
||||||
} else {
|
} else {
|
||||||
rc = sys_fchownat(dirfd, path, uid, gid, flags);
|
rc = sys_fchownat(dirfd, path, uid, gid, flags);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,10 +53,10 @@
|
||||||
* @raise ECANCELED if thread was cancelled in masked mode
|
* @raise ECANCELED if thread was cancelled in masked mode
|
||||||
* @raise EIO if a low-level i/o error happened
|
* @raise EIO if a low-level i/o error happened
|
||||||
* @raise EFBIG or EINVAL if `length` is too huge
|
* @raise EFBIG or EINVAL if `length` is too huge
|
||||||
* @raise ENOTSUP if `fd` is a zip file descriptor
|
|
||||||
* @raise EBADF if `fd` isn't an open file descriptor
|
* @raise EBADF if `fd` isn't an open file descriptor
|
||||||
* @raise EINVAL if `fd` is a non-file, e.g. pipe, socket
|
* @raise EINVAL if `fd` is a non-file, e.g. pipe, socket
|
||||||
* @raise EINVAL if `fd` wasn't opened in a writeable mode
|
* @raise EINVAL if `fd` wasn't opened in a writeable mode
|
||||||
|
* @raise EROFS if `fd` is on a read-only filesystem (e.g. zipos)
|
||||||
* @raise ENOSYS on bare metal
|
* @raise ENOSYS on bare metal
|
||||||
* @cancellationpoint
|
* @cancellationpoint
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
|
@ -69,7 +69,7 @@ int ftruncate(int fd, int64_t length) {
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
rc = ebadf();
|
rc = ebadf();
|
||||||
} else if (__isfdkind(fd, kFdZip)) {
|
} else if (__isfdkind(fd, kFdZip)) {
|
||||||
rc = enotsup();
|
rc = erofs();
|
||||||
} else if (IsMetal()) {
|
} else if (IsMetal()) {
|
||||||
rc = enosys();
|
rc = enosys();
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
|
|
|
@ -32,10 +32,10 @@
|
||||||
* @param fd is file descriptor of file whose timestamps will change
|
* @param fd is file descriptor of file whose timestamps will change
|
||||||
* @param ts is {access, modified} timestamps, or null for current time
|
* @param ts is {access, modified} timestamps, or null for current time
|
||||||
* @return 0 on success, or -1 w/ errno
|
* @return 0 on success, or -1 w/ errno
|
||||||
* @raise ENOTSUP if `fd` is on the zip filesystem
|
|
||||||
* @raise EINVAL if `flags` had an unrecognized value
|
* @raise EINVAL if `flags` had an unrecognized value
|
||||||
* @raise EPERM if pledge() is in play without `fattr` promise
|
* @raise EPERM if pledge() is in play without `fattr` promise
|
||||||
* @raise EINVAL if `ts` specifies a nanosecond value that's out of range
|
* @raise EINVAL if `ts` specifies a nanosecond value that's out of range
|
||||||
|
* @raise EROFS if `fd` is a zip file or on a read-only filesystem
|
||||||
* @raise EBADF if `fd` isn't an open file descriptor
|
* @raise EBADF if `fd` isn't an open file descriptor
|
||||||
* @raise EFAULT if `ts` memory was invalid
|
* @raise EFAULT if `ts` memory was invalid
|
||||||
* @raise ENOSYS on RHEL5 or bare metal
|
* @raise ENOSYS on RHEL5 or bare metal
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
*
|
*
|
||||||
* @param ts is atime/mtime, or null for current time
|
* @param ts is atime/mtime, or null for current time
|
||||||
* @return 0 on success, or -1 w/ errno
|
* @return 0 on success, or -1 w/ errno
|
||||||
* @raise ENOTSUP if `fd` is on zip filesystem
|
|
||||||
* @raise EBADF if `fd` isn't an open file descriptor
|
* @raise EBADF if `fd` isn't an open file descriptor
|
||||||
|
* @raise EROFS if `fd` is on zip or read-only filesystem
|
||||||
* @raise EPERM if pledge() is in play without `fattr` promise
|
* @raise EPERM if pledge() is in play without `fattr` promise
|
||||||
* @raise EINVAL if `tv` specifies a microsecond value that's out of range
|
* @raise EINVAL if `tv` specifies a microsecond value that's out of range
|
||||||
* @raise ENOSYS on RHEL5 or bare metal
|
* @raise ENOSYS on RHEL5 or bare metal
|
||||||
|
|
|
@ -19,13 +19,9 @@
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/sched-sysv.internal.h"
|
#include "libc/calls/sched-sysv.internal.h"
|
||||||
#include "libc/calls/struct/cpuset.h"
|
#include "libc/calls/struct/cpuset.h"
|
||||||
#include "libc/calls/weirdtypes.h"
|
#include "libc/calls/syscall_support-nt.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/macros.internal.h"
|
|
||||||
#include "libc/nt/accounting.h"
|
#include "libc/nt/accounting.h"
|
||||||
#include "libc/nt/dll.h"
|
|
||||||
#include "libc/nt/struct/systeminfo.h"
|
|
||||||
#include "libc/nt/systeminfo.h"
|
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
||||||
#define CTL_HW 6
|
#define CTL_HW 6
|
||||||
|
@ -34,16 +30,16 @@
|
||||||
#define HW_NCPUONLINE_NETBSD 16
|
#define HW_NCPUONLINE_NETBSD 16
|
||||||
#define ALL_PROCESSOR_GROUPS 0xffff
|
#define ALL_PROCESSOR_GROUPS 0xffff
|
||||||
|
|
||||||
static unsigned _getcpucount_linux(void) {
|
static int __get_cpu_count_linux(void) {
|
||||||
cpu_set_t s = {0};
|
cpu_set_t cs = {0};
|
||||||
if (sys_sched_getaffinity(0, sizeof(s), &s) != -1) {
|
if (sys_sched_getaffinity(0, sizeof(cs), &cs) != -1) {
|
||||||
return CPU_COUNT(&s);
|
return CPU_COUNT(&cs);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned _getcpucount_bsd(void) {
|
static int __get_cpu_count_bsd(void) {
|
||||||
size_t n;
|
size_t n;
|
||||||
int c, cmd[2];
|
int c, cmd[2];
|
||||||
n = sizeof(c);
|
n = sizeof(c);
|
||||||
|
@ -58,27 +54,17 @@ static unsigned _getcpucount_bsd(void) {
|
||||||
if (!sys_sysctl(cmd, 2, &c, &n, 0, 0)) {
|
if (!sys_sysctl(cmd, 2, &c, &n, 0, 0)) {
|
||||||
return c;
|
return c;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned _getcpucount_impl(void) {
|
static textwindows int __get_cpu_count_nt(void) {
|
||||||
if (!IsWindows()) {
|
uint32_t res;
|
||||||
if (!IsBsd()) {
|
if ((res = GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS))) {
|
||||||
return _getcpucount_linux();
|
return res;
|
||||||
} else {
|
} else {
|
||||||
return _getcpucount_bsd();
|
return __winerr();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return GetMaximumProcessorCount(ALL_PROCESSOR_GROUPS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int g_cpucount;
|
|
||||||
|
|
||||||
// precompute because process affinity on linux may change later
|
|
||||||
__attribute__((__constructor__)) static void _getcpucount_init(void) {
|
|
||||||
g_cpucount = _getcpucount_impl();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,13 +74,20 @@ __attribute__((__constructor__)) static void _getcpucount_init(void) {
|
||||||
*
|
*
|
||||||
* sysconf(_SC_NPROCESSORS_ONLN);
|
* sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
*
|
*
|
||||||
* Except this function isn't a bloated diamond dependency.
|
|
||||||
*
|
|
||||||
* On Intel systems with HyperThreading this will return the number of
|
* On Intel systems with HyperThreading this will return the number of
|
||||||
* cores multiplied by two.
|
* cores multiplied by two. On Linux, if you change cpu affinity it'll
|
||||||
|
* change the cpu count, which also gets inherited by child processes.
|
||||||
*
|
*
|
||||||
* @return cpu count or 0 if it couldn't be determined
|
* @return cpu count, or -1 w/ errno
|
||||||
*/
|
*/
|
||||||
int _getcpucount(void) {
|
int __get_cpu_count(void) {
|
||||||
return g_cpucount;
|
if (!IsWindows()) {
|
||||||
|
if (!IsBsd()) {
|
||||||
|
return __get_cpu_count_linux();
|
||||||
|
} else {
|
||||||
|
return __get_cpu_count_bsd();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return __get_cpu_count_nt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ static textstartup void sys_getloadavg_nt_init(void) {
|
||||||
double a[3];
|
double a[3];
|
||||||
if (IsWindows()) {
|
if (IsWindows()) {
|
||||||
load = 1;
|
load = 1;
|
||||||
cpus = _getcpucount() / 2;
|
cpus = __get_cpu_count() / 2;
|
||||||
cpus = MAX(1, cpus);
|
cpus = MAX(1, cpus);
|
||||||
GetSystemTimes(&idle1, &kern1, &user1);
|
GetSystemTimes(&idle1, &kern1, &user1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/sysinfo.h"
|
#include "libc/calls/struct/sysinfo.h"
|
||||||
|
#include "libc/calls/struct/sysinfo.internal.h"
|
||||||
#include "libc/calls/syscall-nt.internal.h"
|
#include "libc/calls/syscall-nt.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
|
@ -40,7 +41,7 @@ struct loadavg {
|
||||||
* @raise ENOSYS on metal
|
* @raise ENOSYS on metal
|
||||||
*/
|
*/
|
||||||
int getloadavg(double *a, int n) {
|
int getloadavg(double *a, int n) {
|
||||||
/* cat /proc/loadavg */
|
// cat /proc/loadavg
|
||||||
int i, rc;
|
int i, rc;
|
||||||
if (n > 3) n = 3;
|
if (n > 3) n = 3;
|
||||||
if (!n) {
|
if (!n) {
|
||||||
|
@ -51,7 +52,7 @@ int getloadavg(double *a, int n) {
|
||||||
return sys_getloadavg_nt(a, n);
|
return sys_getloadavg_nt(a, n);
|
||||||
} else if (IsLinux()) {
|
} else if (IsLinux()) {
|
||||||
struct sysinfo si;
|
struct sysinfo si;
|
||||||
if ((rc = sysinfo(&si)) != -1) {
|
if ((rc = sys_sysinfo(&si)) != -1) {
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
a[i] = 1. / 65536 * si.loads[i];
|
a[i] = 1. / 65536 * si.loads[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
* Creates session and sets the process group id.
|
* Creates session and sets the process group id.
|
||||||
*/
|
*/
|
||||||
int getsid(int pid) {
|
int getsid(int pid) {
|
||||||
int rc;
|
int rc = sys_getsid(pid);
|
||||||
rc = sys_getsid(pid);
|
|
||||||
STRACE("%s(%d) → %d% m", "getsid", pid, rc);
|
STRACE("%s(%d) → %d% m", "getsid", pid, rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,14 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/calls/internal.h"
|
||||||
|
#include "libc/calls/struct/fd.internal.h"
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/calls/termios.h"
|
#include "libc/calls/termios.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
#define TIOCPTYGRANT 0x20007454
|
#define TIOCPTYGRANT 0x20007454
|
||||||
|
|
||||||
|
@ -34,7 +37,9 @@
|
||||||
*/
|
*/
|
||||||
int grantpt(int fd) {
|
int grantpt(int fd) {
|
||||||
int rc;
|
int rc;
|
||||||
if (IsXnu()) {
|
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||||
|
rc = enotty();
|
||||||
|
} else if (IsXnu()) {
|
||||||
rc = sys_ioctl(fd, TIOCPTYGRANT);
|
rc = sys_ioctl(fd, TIOCPTYGRANT);
|
||||||
} else {
|
} else {
|
||||||
rc = _isptmaster(fd);
|
rc = _isptmaster(fd);
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
#ifndef COSMOPOLITAN_LIBC_CALLS_NANOS_H_
|
|
||||||
#define COSMOPOLITAN_LIBC_CALLS_NANOS_H_
|
|
||||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
||||||
COSMOPOLITAN_C_START_
|
|
||||||
|
|
||||||
int128_t _nanos(int);
|
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
||||||
#endif /* COSMOPOLITAN_LIBC_CALLS_NANOS_H_ */
|
|
|
@ -27,6 +27,12 @@
|
||||||
/**
|
/**
|
||||||
* Creates file-less file descriptors for interprocess communication.
|
* Creates file-less file descriptors for interprocess communication.
|
||||||
*
|
*
|
||||||
|
* This function offers atomic operation on all supported platforms
|
||||||
|
* except for XNU and RHEL5 where it's polyfilled.
|
||||||
|
*
|
||||||
|
* @params flags may contain `O_CLOEXEC`, `O_NONBLOCK`, and `O_DIRECT`
|
||||||
|
* @raise EINVAL if flags has invalid or unsupported bits
|
||||||
|
* @raise EFAULT if `pipefd` doesn't point to valid memory
|
||||||
* @raise EMFILE if process `RLIMIT_NOFILE` has been reached
|
* @raise EMFILE if process `RLIMIT_NOFILE` has been reached
|
||||||
* @raise ENFILE if system-wide file limit has been reached
|
* @raise ENFILE if system-wide file limit has been reached
|
||||||
* @param pipefd is used to return (reader, writer) file descriptors
|
* @param pipefd is used to return (reader, writer) file descriptors
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
|
#include "libc/calls/internal.h"
|
||||||
|
#include "libc/calls/struct/fd.internal.h"
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/calls/termios.h"
|
#include "libc/calls/termios.h"
|
||||||
#include "libc/errno.h"
|
#include "libc/errno.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
static char g_ptsname[16];
|
static char g_ptsname[16];
|
||||||
|
|
||||||
|
@ -30,7 +33,10 @@ static char g_ptsname[16];
|
||||||
*/
|
*/
|
||||||
char *ptsname(int fd) {
|
char *ptsname(int fd) {
|
||||||
char *res;
|
char *res;
|
||||||
if (!_ptsname(fd, g_ptsname, sizeof(g_ptsname))) {
|
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||||
|
enotty();
|
||||||
|
res = 0;
|
||||||
|
} else if (!_ptsname(fd, g_ptsname, sizeof(g_ptsname))) {
|
||||||
res = g_ptsname;
|
res = g_ptsname;
|
||||||
} else {
|
} else {
|
||||||
res = 0;
|
res = 0;
|
||||||
|
|
|
@ -53,6 +53,8 @@ static int64_t GetPhysmem(void) {
|
||||||
static int sys_sysinfo_bsd(struct sysinfo *info) {
|
static int sys_sysinfo_bsd(struct sysinfo *info) {
|
||||||
info->uptime = GetUptime();
|
info->uptime = GetUptime();
|
||||||
info->totalram = GetPhysmem();
|
info->totalram = GetPhysmem();
|
||||||
|
info->bufferram = GetPhysmem();
|
||||||
|
info->mem_unit = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
#include "libc/intrin/asan.internal.h"
|
#include "libc/intrin/asan.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
|
||||||
#include "libc/runtime/zipos.internal.h"
|
#include "libc/runtime/zipos.internal.h"
|
||||||
|
#include "libc/sysv/errfuns.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes size of file.
|
* Changes size of file.
|
||||||
|
@ -50,15 +50,14 @@
|
||||||
* @raise ECANCELED if thread was cancelled in masked mode
|
* @raise ECANCELED if thread was cancelled in masked mode
|
||||||
* @raise EFBIG or EINVAL if `length` is too huge
|
* @raise EFBIG or EINVAL if `length` is too huge
|
||||||
* @raise EFAULT if `path` points to invalid memory
|
* @raise EFAULT if `path` points to invalid memory
|
||||||
* @raise ENOTSUP if `path` is a zip filesystem path
|
|
||||||
* @raise EACCES if we don't have permission to search a component of `path`
|
* @raise EACCES if we don't have permission to search a component of `path`
|
||||||
* @raise ENOTDIR if a directory component in `path` exists as non-directory
|
* @raise ENOTDIR if a directory component in `path` exists as non-directory
|
||||||
* @raise ENAMETOOLONG if symlink-resolved `path` length exceeds `PATH_MAX`
|
* @raise ENAMETOOLONG if symlink-resolved `path` length exceeds `PATH_MAX`
|
||||||
* @raise ENAMETOOLONG if component in `path` exists longer than `NAME_MAX`
|
* @raise ENAMETOOLONG if component in `path` exists longer than `NAME_MAX`
|
||||||
* @raise ELOOP if a loop was detected resolving components of `path`
|
* @raise ELOOP if a loop was detected resolving components of `path`
|
||||||
|
* @raise EROFS if `path` is on a read-only filesystem (e.g. zip)
|
||||||
* @raise ENOENT if `path` doesn't exist or is an empty string
|
* @raise ENOENT if `path` doesn't exist or is an empty string
|
||||||
* @raise ETXTBSY if `path` is an executable being executed
|
* @raise ETXTBSY if `path` is an executable being executed
|
||||||
* @raise EROFS if `path` is on a read-only filesystem
|
|
||||||
* @raise ENOSYS on bare metal
|
* @raise ENOSYS on bare metal
|
||||||
* @cancellationpoint
|
* @cancellationpoint
|
||||||
* @see ftruncate()
|
* @see ftruncate()
|
||||||
|
@ -75,7 +74,7 @@ int truncate(const char *path, int64_t length) {
|
||||||
rc = efault();
|
rc = efault();
|
||||||
} else if (_weaken(__zipos_parseuri) &&
|
} else if (_weaken(__zipos_parseuri) &&
|
||||||
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
|
_weaken(__zipos_parseuri)(path, &zipname) != -1) {
|
||||||
rc = enotsup();
|
rc = erofs();
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
rc = sys_truncate(path, length, length);
|
rc = sys_truncate(path, length, length);
|
||||||
if (IsNetbsd() && rc == -1 && errno == ENOSPC) {
|
if (IsNetbsd() && rc == -1 && errno == ENOSPC) {
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/internal.h"
|
||||||
|
#include "libc/calls/struct/fd.internal.h"
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||||
#include "libc/calls/termios.h"
|
#include "libc/calls/termios.h"
|
||||||
|
@ -37,7 +39,9 @@
|
||||||
*/
|
*/
|
||||||
int unlockpt(int fd) {
|
int unlockpt(int fd) {
|
||||||
int rc, unlock = 0;
|
int rc, unlock = 0;
|
||||||
if (IsFreebsd() || IsOpenbsd() || IsNetbsd()) {
|
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||||
|
rc = enotty();
|
||||||
|
} else if (IsFreebsd() || IsOpenbsd() || IsNetbsd()) {
|
||||||
rc = _isptmaster(fd);
|
rc = _isptmaster(fd);
|
||||||
} else if (IsXnu()) {
|
} else if (IsXnu()) {
|
||||||
rc = sys_ioctl(fd, TIOCPTYUNLK);
|
rc = sys_ioctl(fd, TIOCPTYUNLK);
|
||||||
|
|
|
@ -28,9 +28,9 @@
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
|
#include "libc/runtime/zipos.internal.h"
|
||||||
#include "libc/sysv/consts/at.h"
|
#include "libc/sysv/consts/at.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/runtime/zipos.internal.h"
|
|
||||||
|
|
||||||
int __utimens(int fd, const char *path, const struct timespec ts[2],
|
int __utimens(int fd, const char *path, const struct timespec ts[2],
|
||||||
int flags) {
|
int flags) {
|
||||||
|
@ -47,7 +47,7 @@ int __utimens(int fd, const char *path, const struct timespec ts[2],
|
||||||
} else if (__isfdkind(fd, kFdZip) ||
|
} else if (__isfdkind(fd, kFdZip) ||
|
||||||
(path && (_weaken(__zipos_parseuri) &&
|
(path && (_weaken(__zipos_parseuri) &&
|
||||||
_weaken(__zipos_parseuri)(path, &zipname) != -1))) {
|
_weaken(__zipos_parseuri)(path, &zipname) != -1))) {
|
||||||
rc = enotsup();
|
rc = erofs();
|
||||||
} else if (IsLinux() && !__is_linux_2_6_23() && fd == AT_FDCWD && !flags) {
|
} else if (IsLinux() && !__is_linux_2_6_23() && fd == AT_FDCWD && !flags) {
|
||||||
rc = sys_utimes(path, (void *)ts); // rhel5 truncates to seconds
|
rc = sys_utimes(path, (void *)ts); // rhel5 truncates to seconds
|
||||||
} else if (!IsWindows()) {
|
} else if (!IsWindows()) {
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
|
#include "libc/runtime/zipos.internal.h"
|
||||||
#include "libc/sysv/consts/at.h"
|
#include "libc/sysv/consts/at.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/runtime/zipos.internal.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets access/modified time on file, the modern way.
|
* Sets access/modified time on file, the modern way.
|
||||||
|
@ -48,13 +48,12 @@
|
||||||
* @raise EINVAL if `flags` had an unrecognized value
|
* @raise EINVAL if `flags` had an unrecognized value
|
||||||
* @raise EPERM if pledge() is in play without `fattr` promise
|
* @raise EPERM if pledge() is in play without `fattr` promise
|
||||||
* @raise EACCES if unveil() is in play and `path` isn't unveiled
|
* @raise EACCES if unveil() is in play and `path` isn't unveiled
|
||||||
* @raise ENOTSUP if `path` is a zip filesystem path or `dirfd` is zip
|
|
||||||
* @raise EINVAL if `ts` specifies a nanosecond value that's out of range
|
* @raise EINVAL if `ts` specifies a nanosecond value that's out of range
|
||||||
* @raise ENAMETOOLONG if symlink-resolved `path` length exceeds `PATH_MAX`
|
* @raise ENAMETOOLONG if symlink-resolved `path` length exceeds `PATH_MAX`
|
||||||
* @raise ENAMETOOLONG if component in `path` exists longer than `NAME_MAX`
|
* @raise ENAMETOOLONG if component in `path` exists longer than `NAME_MAX`
|
||||||
* @raise EBADF if `dirfd` isn't a valid fd or `AT_FDCWD`
|
* @raise EBADF if `dirfd` isn't a valid fd or `AT_FDCWD`
|
||||||
* @raise EFAULT if `path` or `ts` memory was invalid
|
* @raise EFAULT if `path` or `ts` memory was invalid
|
||||||
* @raise EROFS if `path` is on read-only filesystem
|
* @raise EROFS if `path` is on read-only filesystem (e.g. zipos)
|
||||||
* @raise ENOSYS on bare metal or on rhel5 when `dirfd` or `flags` is used
|
* @raise ENOSYS on bare metal or on rhel5 when `dirfd` or `flags` is used
|
||||||
* @asyncsignalsafe
|
* @asyncsignalsafe
|
||||||
* @threadsafe
|
* @threadsafe
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
* @return quotient or result of division
|
* @return quotient or result of division
|
||||||
* @note rounds towards zero
|
* @note rounds towards zero
|
||||||
*/
|
*/
|
||||||
COMPILER_RT_ABI ti_int __divmodti4(ti_int a, ti_int b, tu_int *opt_out_rem) {
|
ti_int __divmodti4(ti_int a, ti_int b, tu_int *opt_out_rem) {
|
||||||
int k;
|
int k;
|
||||||
tu_int r;
|
tu_int r;
|
||||||
ti_int sa, sb, sq, sr, x, y, q;
|
ti_int sa, sb, sq, sr, x, y, q;
|
||||||
|
|
|
@ -17,6 +17,6 @@
|
||||||
* @return quotient or result of division
|
* @return quotient or result of division
|
||||||
* @note rounds towards zero
|
* @note rounds towards zero
|
||||||
*/
|
*/
|
||||||
COMPILER_RT_ABI ti_int __divti3(ti_int a, ti_int b) {
|
ti_int __divti3(ti_int a, ti_int b) {
|
||||||
return __divmodti4(a, b, NULL);
|
return __divmodti4(a, b, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ static void critbit0_clear_traverse(void *top) {
|
||||||
struct CritbitNode *q = (void *)(p - 1);
|
struct CritbitNode *q = (void *)(p - 1);
|
||||||
critbit0_clear_traverse(q->child[0]);
|
critbit0_clear_traverse(q->child[0]);
|
||||||
critbit0_clear_traverse(q->child[1]);
|
critbit0_clear_traverse(q->child[1]);
|
||||||
free(q), q = NULL;
|
free(q);
|
||||||
} else {
|
} else {
|
||||||
free(p), p = NULL;
|
free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,64 +218,69 @@ static const char *GetOptArg(int c, int *i, int j) {
|
||||||
static int Echo(void) {
|
static int Echo(void) {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
bool once = false;
|
bool once = false;
|
||||||
const char *l = " ";
|
bool print_newline = true;
|
||||||
if (i < n && !strcmp(args[i], "-l")) {
|
if (i < n && args[i][0] == '-' && args[i][1] == 'n' && !args[i][2]) {
|
||||||
++i, l = "\n";
|
++i, print_newline = false;
|
||||||
}
|
}
|
||||||
for (; i < n; ++i) {
|
for (; i < n; ++i) {
|
||||||
if (once) {
|
if (once) {
|
||||||
Write(1, l);
|
Write(1, " ");
|
||||||
} else {
|
} else {
|
||||||
once = true;
|
once = true;
|
||||||
}
|
}
|
||||||
Write(1, args[i]);
|
Write(1, args[i]);
|
||||||
}
|
}
|
||||||
|
if (print_newline) {
|
||||||
Write(1, "\n");
|
Write(1, "\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int CatDump(const char *path, int fd, bool dontclose) {
|
||||||
|
ssize_t rc;
|
||||||
|
char buf[512];
|
||||||
|
for (;;) {
|
||||||
|
rc = read(fd, buf, sizeof(buf));
|
||||||
|
if (rc == -1) {
|
||||||
|
perror(path);
|
||||||
|
if (!dontclose) {
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!rc) break;
|
||||||
|
rc = write(1, buf, rc);
|
||||||
|
if (rc == -1) {
|
||||||
|
perror("write");
|
||||||
|
if (!dontclose) {
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!dontclose && close(fd)) {
|
||||||
|
perror(path);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Cat(void) {
|
static int Cat(void) {
|
||||||
int i, fd;
|
int i, fd, rc;
|
||||||
ssize_t rc;
|
|
||||||
char buf[512];
|
|
||||||
if (n < 2) {
|
if (n < 2) {
|
||||||
for (;;) {
|
return CatDump("<stdin>", 0, true);
|
||||||
rc = read(0, buf, sizeof(buf));
|
|
||||||
if (rc == -1) {
|
|
||||||
perror("read");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!rc) break;
|
|
||||||
rc = write(1, buf, rc);
|
|
||||||
if (rc == -1) {
|
|
||||||
perror("write");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (i = 1; i < n; ++i) {
|
for (i = 1; i < n; ++i) {
|
||||||
if ((fd = open(args[i], O_RDONLY)) == -1) {
|
bool dontclose = false;
|
||||||
|
if (args[i][0] == '-' && !args[i][1]) {
|
||||||
|
dontclose = true;
|
||||||
|
fd = 0;
|
||||||
|
} else if ((fd = open(args[i], O_RDONLY)) == -1) {
|
||||||
perror(args[i]);
|
perror(args[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
for (;;) {
|
if ((rc = CatDump(args[i], fd, dontclose))) {
|
||||||
rc = read(fd, buf, sizeof(buf));
|
return rc;
|
||||||
if (rc == -1) {
|
|
||||||
perror(args[i]);
|
|
||||||
close(fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!rc) break;
|
|
||||||
rc = write(1, buf, rc);
|
|
||||||
if (rc == -1) {
|
|
||||||
perror("write");
|
|
||||||
close(fd);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (close(fd)) {
|
|
||||||
perror(args[i]);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,17 +17,50 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
|
#include "libc/macros.internal.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/sysv/consts/limits.h"
|
||||||
|
#include "libc/sysv/consts/rlimit.h"
|
||||||
|
|
||||||
|
#define CTL_KERN 1
|
||||||
|
#define KERN_ARGMAX 8
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `ARG_MAX` for host platform.
|
* Returns expensive but more correct version of `ARG_MAX`.
|
||||||
*/
|
*/
|
||||||
int __arg_max(void) {
|
int __get_arg_max(void) {
|
||||||
if (IsWindows()) return 32767;
|
if (IsLinux()) {
|
||||||
if (IsLinux()) return 128 * 1024;
|
// You might think that just returning a constant 128KiB (ARG_MAX)
|
||||||
if (IsNetbsd()) return 256 * 1024;
|
// would make sense, as this guy did:
|
||||||
if (IsFreebsd()) return 512 * 1024;
|
//
|
||||||
if (IsOpenbsd()) return 512 * 1024;
|
// https://lkml.org/lkml/2017/11/15/813...
|
||||||
if (IsXnu()) return 1024 * 1024;
|
//
|
||||||
return ARG_MAX;
|
// I suspect a 128kB sysconf(_SC_ARG_MAX) is the sanest bet, simply
|
||||||
|
// because of that "conservative is better than aggressive".
|
||||||
|
//
|
||||||
|
// Especially since _technically_ we're still limiting things to that
|
||||||
|
// 128kB due to the single-string limit.
|
||||||
|
//
|
||||||
|
// Linus
|
||||||
|
//
|
||||||
|
// In practice that caused us trouble with toybox tests for xargs
|
||||||
|
// edge cases. The tests assume that they can at least reach the
|
||||||
|
// kernel's "minimum maximum" of 128KiB, but if we report 128KiB for
|
||||||
|
// _SC_ARG_MAX and xargs starts subtracting the environment space
|
||||||
|
// and so on from that, then xargs will think it's run out of space
|
||||||
|
// when given 128KiB of data, which should always work. See this
|
||||||
|
// thread for more:
|
||||||
|
//
|
||||||
|
// http://lists.landley.net/pipermail/toybox-landley.net/2019-November/011229.html
|
||||||
|
//
|
||||||
|
// So let's resign ourselves to tracking what the kernel actually
|
||||||
|
// does. Right now (2019, Linux 5.3) that amounts to:
|
||||||
|
uint64_t stacksz;
|
||||||
|
stacksz = __get_rlimit(RLIMIT_STACK);
|
||||||
|
return MAX(MIN(stacksz / 4, 3 * (8 * 1024 * 1024) / 4), _ARG_MAX);
|
||||||
|
} else if (IsBsd()) {
|
||||||
|
return __get_sysctl(CTL_KERN, KERN_ARGMAX);
|
||||||
|
} else {
|
||||||
|
return _ARG_MAX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -16,22 +16,11 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/struct/sysinfo.h"
|
||||||
#include "libc/dce.h"
|
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/sysv/consts/rlimit.h"
|
|
||||||
|
|
||||||
#define F_MAXFD 11
|
long __get_avphys_pages(void) {
|
||||||
|
struct sysinfo si;
|
||||||
/**
|
if (sysinfo(&si) == -1) return -1;
|
||||||
* Returns maximum number of open files.
|
return (((int64_t)si.freeram + si.bufferram) * si.mem_unit) / FRAMESIZE;
|
||||||
*/
|
|
||||||
long _GetMaxFd(void) {
|
|
||||||
int rc;
|
|
||||||
if (IsNetbsd()) {
|
|
||||||
if ((rc = __sys_fcntl(0, F_MAXFD, 0)) != -1) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _GetResourceLimit(RLIMIT_NOFILE);
|
|
||||||
}
|
}
|
26
libc/runtime/getphyspages.c
Normal file
26
libc/runtime/getphyspages.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
|
│ Copyright 2023 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/struct/sysinfo.h"
|
||||||
|
#include "libc/runtime/runtime.h"
|
||||||
|
|
||||||
|
long __get_phys_pages(void) {
|
||||||
|
struct sysinfo si;
|
||||||
|
if (sysinfo(&si) == -1) return -1;
|
||||||
|
return ((int64_t)si.totalram * si.mem_unit) / FRAMESIZE;
|
||||||
|
}
|
|
@ -21,9 +21,9 @@
|
||||||
#include "libc/macros.internal.h"
|
#include "libc/macros.internal.h"
|
||||||
#include "libc/sysv/consts/rlim.h"
|
#include "libc/sysv/consts/rlim.h"
|
||||||
|
|
||||||
long _GetResourceLimit(int resource) {
|
long __get_rlimit(int resource) {
|
||||||
struct rlimit rl;
|
struct rlimit rl;
|
||||||
getrlimit(resource, &rl);
|
if (getrlimit(resource, &rl) == -1) return -1;
|
||||||
if (rl.rlim_cur == RLIM_INFINITY) return -1;
|
if (rl.rlim_cur == RLIM_INFINITY) return -1;
|
||||||
return MIN(rl.rlim_cur, LONG_MAX);
|
return MIN(rl.rlim_cur, LONG_MAX);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||||
│ any purpose with or without fee is hereby granted, provided that the │
|
│ any purpose with or without fee is hereby granted, provided that the │
|
||||||
|
@ -17,18 +17,15 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
#include "libc/calls/struct/timespec.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/time/time.h"
|
|
||||||
|
|
||||||
/**
|
long __get_sysctl(int x, int y) {
|
||||||
* Returns nanoseconds since UNIX epoch.
|
int value;
|
||||||
*/
|
int mib[2] = {x, y};
|
||||||
int128_t _nanos(int timer) {
|
size_t len = sizeof(value);
|
||||||
int128_t nanos;
|
if (sys_sysctl(mib, 2, &value, &len, 0, 0) != -1) {
|
||||||
struct timespec ts;
|
return value;
|
||||||
clock_gettime(timer, &ts);
|
} else {
|
||||||
nanos = ts.tv_sec;
|
return -1;
|
||||||
nanos *= 1000000000;
|
}
|
||||||
nanos += ts.tv_nsec;
|
|
||||||
return nanos;
|
|
||||||
}
|
}
|
|
@ -129,9 +129,14 @@ bool IsCygwin(void);
|
||||||
const char *GetCpuidOs(void);
|
const char *GetCpuidOs(void);
|
||||||
const char *GetCpuidEmulator(void);
|
const char *GetCpuidEmulator(void);
|
||||||
void GetCpuidBrand(char[13], uint32_t);
|
void GetCpuidBrand(char[13], uint32_t);
|
||||||
long _GetResourceLimit(int);
|
long __get_rlimit(int);
|
||||||
|
int __set_rlimit(int, int64_t);
|
||||||
const char *__describe_os(void);
|
const char *__describe_os(void);
|
||||||
int __arg_max(void);
|
long __get_sysctl(int, int);
|
||||||
|
int __get_arg_max(void) pureconst;
|
||||||
|
int __get_cpu_count(void) pureconst;
|
||||||
|
long __get_avphys_pages(void) pureconst;
|
||||||
|
long __get_phys_pages(void) pureconst;
|
||||||
#endif /* _COSMO_SOURCE */
|
#endif /* _COSMO_SOURCE */
|
||||||
|
|
||||||
COSMOPOLITAN_C_END_
|
COSMOPOLITAN_C_END_
|
||||||
|
|
|
@ -17,10 +17,21 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/runtime/sysconf.h"
|
#include "libc/runtime/sysconf.h"
|
||||||
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/struct/rlimit.h"
|
||||||
|
#include "libc/calls/struct/sysinfo.h"
|
||||||
|
#include "libc/calls/struct/sysinfo.internal.h"
|
||||||
|
#include "libc/dce.h"
|
||||||
|
#include "libc/limits.h"
|
||||||
|
#include "libc/macros.internal.h"
|
||||||
#include "libc/runtime/clktck.h"
|
#include "libc/runtime/clktck.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/runtime/sysconf.h"
|
||||||
|
#include "libc/sysv/consts/_posix.h"
|
||||||
#include "libc/sysv/consts/limits.h"
|
#include "libc/sysv/consts/limits.h"
|
||||||
#include "libc/sysv/consts/rlimit.h"
|
#include "libc/sysv/consts/rlimit.h"
|
||||||
|
#include "libc/sysv/errfuns.h"
|
||||||
|
#include "libc/thread/thread.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns configuration value about system.
|
* Returns configuration value about system.
|
||||||
|
@ -28,30 +39,58 @@
|
||||||
* The following parameters are supported:
|
* The following parameters are supported:
|
||||||
*
|
*
|
||||||
* - `_SC_CLK_TCK` returns number of clock ticks per second
|
* - `_SC_CLK_TCK` returns number of clock ticks per second
|
||||||
* - `_SC_ARG_MAX` currently always returns 32768 due to Windows
|
* - `_SC_ARG_MAX` will perform expensive rlimit calculations
|
||||||
* - `_SC_PAGESIZE` currently always returns 65536 due to Windows
|
* - `_SC_PAGESIZE` currently always returns 65536 due to Windows
|
||||||
* - `_SC_NPROCESSORS_ONLN` returns number of CPUs in the system
|
* - `_SC_AVPHYS_PAGES` returns average physical memory pages
|
||||||
* - `_SC_OPEN_MAX` returns maximum number of open files
|
* - `_SC_PHYS_PAGES` returns physical memory pages available
|
||||||
|
* - `_SC_NPROCESSORS_ONLN` returns number of effective CPUs
|
||||||
* - `_SC_CHILD_MAX` returns maximum number of processes
|
* - `_SC_CHILD_MAX` returns maximum number of processes
|
||||||
|
* - `_SC_OPEN_MAX` returns maximum number of open files
|
||||||
*
|
*
|
||||||
|
* @return value on success, or -1 w/ errno
|
||||||
|
* @raise EINVAL if `name` isn't valid
|
||||||
*/
|
*/
|
||||||
long sysconf(int name) {
|
long sysconf(int name) {
|
||||||
int n;
|
int n;
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case _SC_ARG_MAX:
|
|
||||||
return _ARG_MAX;
|
|
||||||
case _SC_CHILD_MAX:
|
|
||||||
return _GetResourceLimit(RLIMIT_NPROC);
|
|
||||||
case _SC_CLK_TCK:
|
case _SC_CLK_TCK:
|
||||||
return CLK_TCK;
|
return CLK_TCK;
|
||||||
case _SC_OPEN_MAX:
|
|
||||||
return _GetMaxFd();
|
|
||||||
case _SC_PAGESIZE:
|
case _SC_PAGESIZE:
|
||||||
return FRAMESIZE;
|
return FRAMESIZE;
|
||||||
|
case _SC_ARG_MAX:
|
||||||
|
return __get_arg_max();
|
||||||
|
case _SC_CHILD_MAX:
|
||||||
|
return __get_rlimit(RLIMIT_NPROC);
|
||||||
|
case _SC_OPEN_MAX:
|
||||||
|
return __get_rlimit(RLIMIT_NOFILE);
|
||||||
|
case _SC_NPROCESSORS_CONF:
|
||||||
case _SC_NPROCESSORS_ONLN:
|
case _SC_NPROCESSORS_ONLN:
|
||||||
n = _getcpucount();
|
return __get_cpu_count();
|
||||||
return n > 0 ? n : -1;
|
case _SC_PHYS_PAGES:
|
||||||
|
return __get_phys_pages();
|
||||||
|
case _SC_AVPHYS_PAGES:
|
||||||
|
return __get_avphys_pages();
|
||||||
|
case _SC_THREADS:
|
||||||
|
return _POSIX_THREADS;
|
||||||
|
case _SC_THREAD_DESTRUCTOR_ITERATIONS:
|
||||||
|
return PTHREAD_DESTRUCTOR_ITERATIONS;
|
||||||
|
case _SC_THREAD_KEYS_MAX:
|
||||||
|
return PTHREAD_KEYS_MAX;
|
||||||
|
case _SC_THREAD_STACK_MIN:
|
||||||
|
return PTHREAD_STACK_MIN;
|
||||||
|
case _SC_THREAD_THREADS_MAX:
|
||||||
|
return LONG_MAX;
|
||||||
|
case _SC_LINE_MAX:
|
||||||
|
return _POSIX2_LINE_MAX;
|
||||||
|
case _SC_MONOTONIC_CLOCK:
|
||||||
|
return _POSIX_MONOTONIC_CLOCK;
|
||||||
|
case _SC_HOST_NAME_MAX:
|
||||||
|
return _POSIX_HOST_NAME_MAX;
|
||||||
|
case _SC_SPAWN:
|
||||||
|
return _POSIX_SPAWN;
|
||||||
|
case _SC_SYMLOOP_MAX:
|
||||||
|
return _POSIX_SYMLOOP_MAX;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return einval();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,10 @@ struct appendz appendz(char *p) {
|
||||||
unassert(z.n >= W * 2 && !(z.n & (W - 1)));
|
unassert(z.n >= W * 2 && !(z.n & (W - 1)));
|
||||||
z.i = *(size_t *)(p + z.n - W);
|
z.i = *(size_t *)(p + z.n - W);
|
||||||
if (!IsTiny() && W == 8) {
|
if (!IsTiny() && W == 8) {
|
||||||
/*
|
// This check should fail if an append*() function was passed a
|
||||||
* This check should fail if an append*() function was passed a
|
// pointer that was allocated manually by malloc(). Append ptrs
|
||||||
* pointer that was allocated manually by malloc(). Append ptrs
|
// can be free()'d safely, but they need to be allocated by the
|
||||||
* can be free()'d safely, but they need to be allocated by the
|
// append library, because we write a special value to the end.
|
||||||
* append library, because we write a special value to the end.
|
|
||||||
*/
|
|
||||||
unassert((z.i >> 48) == APPEND_COOKIE);
|
unassert((z.i >> 48) == APPEND_COOKIE);
|
||||||
z.i &= 0x0000ffffffffffff;
|
z.i &= 0x0000ffffffffffff;
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,24 +413,6 @@ static struct dirent *readdir_zipos(DIR *dir) {
|
||||||
return ent;
|
return ent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *golden(void *a, const void *b, size_t n) {
|
|
||||||
size_t i;
|
|
||||||
char *volatile d = a;
|
|
||||||
const char *volatile s = b;
|
|
||||||
if (d > s) {
|
|
||||||
for (i = n; i--;) {
|
|
||||||
d[i] = s[i];
|
|
||||||
asm volatile("" ::: "memory");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < n; ++i) {
|
|
||||||
d[i] = s[i];
|
|
||||||
asm volatile("" ::: "memory");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct dirent *readdir_unix(DIR *dir) {
|
static struct dirent *readdir_unix(DIR *dir) {
|
||||||
if (dir->buf_pos >= dir->buf_end) {
|
if (dir->buf_pos >= dir->buf_end) {
|
||||||
long basep = dir->tell;
|
long basep = dir->tell;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
|
||||||
static inline int PutsImpl(const char *s, FILE *f) {
|
static inline int puts_unlocked(const char *s, FILE *f) {
|
||||||
size_t n, r;
|
size_t n, r;
|
||||||
if ((n = strlen(s))) {
|
if ((n = strlen(s))) {
|
||||||
r = fwrite_unlocked(s, 1, n, f);
|
r = fwrite_unlocked(s, 1, n, f);
|
||||||
|
@ -45,7 +45,7 @@ int puts(const char *s) {
|
||||||
int bytes;
|
int bytes;
|
||||||
f = stdout;
|
f = stdout;
|
||||||
flockfile(f);
|
flockfile(f);
|
||||||
bytes = PutsImpl(s, f);
|
bytes = puts_unlocked(s, f);
|
||||||
funlockfile(f);
|
funlockfile(f);
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
errno_t pthread_attr_init(pthread_attr_t *attr) {
|
errno_t pthread_attr_init(pthread_attr_t *attr) {
|
||||||
*attr = (pthread_attr_t){
|
*attr = (pthread_attr_t){
|
||||||
.__stacksize = GetStackSize(),
|
.__stacksize = GetStackSize(),
|
||||||
.__guardsize = getauxval(AT_PAGESZ),
|
.__guardsize = GetGuardSize(),
|
||||||
};
|
};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1916,7 +1916,7 @@ int main(int argc, char *argv[]) {
|
||||||
// we don't have proper futexes on these platforms
|
// we don't have proper futexes on these platforms
|
||||||
// we'll be somewhat less aggressive about workers
|
// we'll be somewhat less aggressive about workers
|
||||||
if (IsXnu() || IsNetbsd()) {
|
if (IsXnu() || IsNetbsd()) {
|
||||||
g_workers = MIN(g_workers, _getcpucount());
|
g_workers = MIN(g_workers, (unsigned)__get_cpu_count());
|
||||||
}
|
}
|
||||||
|
|
||||||
// user interface
|
// user interface
|
||||||
|
|
|
@ -51,7 +51,7 @@ TEST(sched_getaffinity, firstOnly) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(sched_getaffinity, secondOnly) {
|
TEST(sched_getaffinity, secondOnly) {
|
||||||
if (_getcpucount() < 2) return;
|
if (__get_cpu_count() < 2) return;
|
||||||
cpu_set_t x, y;
|
cpu_set_t x, y;
|
||||||
CPU_ZERO(&x);
|
CPU_ZERO(&x);
|
||||||
CPU_SET(1, &x);
|
CPU_SET(1, &x);
|
||||||
|
|
|
@ -17,11 +17,14 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/mem/critbit0.h"
|
#include "libc/mem/critbit0.h"
|
||||||
|
#include "libc/fmt/itoa.h"
|
||||||
#include "libc/intrin/bits.h"
|
#include "libc/intrin/bits.h"
|
||||||
#include "libc/mem/critbit0.h"
|
#include "libc/mem/critbit0.h"
|
||||||
#include "libc/mem/mem.h"
|
#include "libc/mem/mem.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
|
#include "libc/stdio/rand.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
|
#include "libc/testlib/ezbench.h"
|
||||||
#include "libc/testlib/testlib.h"
|
#include "libc/testlib/testlib.h"
|
||||||
|
|
||||||
struct Bog {
|
struct Bog {
|
||||||
|
@ -143,3 +146,26 @@ TEST(critbit0, manual_clear) {
|
||||||
ASSERT_TRUE(critbit0_delete(&tree, "hi"));
|
ASSERT_TRUE(critbit0_delete(&tree, "hi"));
|
||||||
ASSERT_EQ(NULL, tree.root);
|
ASSERT_EQ(NULL, tree.root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define N 500
|
||||||
|
|
||||||
|
char words[N][16];
|
||||||
|
|
||||||
|
void GenerateWords(void) {
|
||||||
|
for (int i = 0; i < N; ++i) {
|
||||||
|
FormatInt32(words[i], rand());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildTree(void) {
|
||||||
|
struct critbit0 tree = {0};
|
||||||
|
for (int i = 0; i < N; ++i) {
|
||||||
|
critbit0_insert(&tree, words[i]);
|
||||||
|
}
|
||||||
|
critbit0_clear(&tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCH(critbit0, bench) {
|
||||||
|
GenerateWords();
|
||||||
|
EZBENCH2("critbit0", donothing, BuildTree());
|
||||||
|
}
|
||||||
|
|
|
@ -214,7 +214,7 @@ void *Worker(void *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCH(malloc, torture) {
|
BENCH(malloc, torture) {
|
||||||
int i, n = _getcpucount() * 2;
|
int i, n = __get_cpu_count() * 2;
|
||||||
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
|
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
|
||||||
if (!n) return;
|
if (!n) return;
|
||||||
printf("\nmalloc torture test w/ %d threads and %d iterations\n", n,
|
printf("\nmalloc torture test w/ %d threads and %d iterations\n", n,
|
||||||
|
|
|
@ -79,7 +79,7 @@ TEST(popen, semicolon) {
|
||||||
|
|
||||||
TEST(popen, singleQuotes) {
|
TEST(popen, singleQuotes) {
|
||||||
setenv("there", "a b c", true);
|
setenv("there", "a b c", true);
|
||||||
ASSERT_NE(NULL, (f = popen("echo -l 'hello $there' yo", "r")));
|
ASSERT_NE(NULL, (f = popen("echo 'hello $there'; echo yo", "r")));
|
||||||
ASSERT_STREQ("hello $there\n", fgets(buf, sizeof(buf), f));
|
ASSERT_STREQ("hello $there\n", fgets(buf, sizeof(buf), f));
|
||||||
ASSERT_STREQ("yo\n", fgets(buf, sizeof(buf), f));
|
ASSERT_STREQ("yo\n", fgets(buf, sizeof(buf), f));
|
||||||
ASSERT_EQ(0, pclose(f));
|
ASSERT_EQ(0, pclose(f));
|
||||||
|
@ -88,7 +88,7 @@ TEST(popen, singleQuotes) {
|
||||||
|
|
||||||
TEST(popen, doubleQuotes) {
|
TEST(popen, doubleQuotes) {
|
||||||
setenv("hello", "a b c", true);
|
setenv("hello", "a b c", true);
|
||||||
ASSERT_NE(NULL, (f = popen("echo -l \"$hello there\"", "r")));
|
ASSERT_NE(NULL, (f = popen("echo \"$hello there\"", "r")));
|
||||||
ASSERT_STREQ("a b c there\n", fgets(buf, sizeof(buf), f));
|
ASSERT_STREQ("a b c there\n", fgets(buf, sizeof(buf), f));
|
||||||
ASSERT_EQ(0, pclose(f));
|
ASSERT_EQ(0, pclose(f));
|
||||||
CheckForFdLeaks();
|
CheckForFdLeaks();
|
||||||
|
@ -96,7 +96,7 @@ TEST(popen, doubleQuotes) {
|
||||||
|
|
||||||
TEST(popen, quoteless) {
|
TEST(popen, quoteless) {
|
||||||
setenv("there", "a b c", true);
|
setenv("there", "a b c", true);
|
||||||
ASSERT_NE(NULL, (f = popen("echo -l hello a$there yo", "r")));
|
ASSERT_NE(NULL, (f = popen("echo hello; echo a$there; echo yo", "r")));
|
||||||
ASSERT_STREQ("hello\n", fgets(buf, sizeof(buf), f));
|
ASSERT_STREQ("hello\n", fgets(buf, sizeof(buf), f));
|
||||||
ASSERT_STREQ("aa b c\n", fgets(buf, sizeof(buf), f)); // mixed feelings
|
ASSERT_STREQ("aa b c\n", fgets(buf, sizeof(buf), f)); // mixed feelings
|
||||||
ASSERT_STREQ("yo\n", fgets(buf, sizeof(buf), f));
|
ASSERT_STREQ("yo\n", fgets(buf, sizeof(buf), f));
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "libc/paths.h"
|
#include "libc/paths.h"
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/stdio/stdio.h"
|
#include "libc/stdio/stdio.h"
|
||||||
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/o.h"
|
#include "libc/sysv/consts/o.h"
|
||||||
#include "libc/sysv/consts/sig.h"
|
#include "libc/sysv/consts/sig.h"
|
||||||
#include "libc/testlib/ezbench.h"
|
#include "libc/testlib/ezbench.h"
|
||||||
|
@ -45,6 +46,22 @@ void SetUp(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pipefd[2];
|
||||||
|
int stdoutBack;
|
||||||
|
|
||||||
|
void CaptureStdout(void) {
|
||||||
|
ASSERT_NE(-1, (stdoutBack = dup(1)));
|
||||||
|
ASSERT_SYS(0, 0, pipe(pipefd));
|
||||||
|
ASSERT_NE(-1, dup2(pipefd[1], 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RestoreStdout(void) {
|
||||||
|
ASSERT_SYS(0, 1, dup2(stdoutBack, 1));
|
||||||
|
ASSERT_SYS(0, 0, close(stdoutBack));
|
||||||
|
ASSERT_SYS(0, 0, close(pipefd[1]));
|
||||||
|
ASSERT_SYS(0, 0, close(pipefd[0]));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(system, haveShell) {
|
TEST(system, haveShell) {
|
||||||
ASSERT_TRUE(system(0));
|
ASSERT_TRUE(system(0));
|
||||||
}
|
}
|
||||||
|
@ -71,20 +88,14 @@ TEST(system, testStdoutRedirect_withSpacesInFilename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(system, testStderrRedirect_toStdout) {
|
TEST(system, testStderrRedirect_toStdout) {
|
||||||
if (IsAsan()) return; // TODO(jart): fix me
|
CaptureStdout();
|
||||||
int pipefd[2];
|
|
||||||
int stdoutBack = dup(1);
|
|
||||||
ASSERT_NE(-1, stdoutBack);
|
|
||||||
ASSERT_EQ(0, pipe(pipefd));
|
|
||||||
ASSERT_NE(-1, dup2(pipefd[1], 1));
|
|
||||||
int stderrBack = dup(2);
|
int stderrBack = dup(2);
|
||||||
ASSERT_NE(-1, stderrBack);
|
ASSERT_NE(-1, stderrBack);
|
||||||
char buf[5] = {0};
|
char buf[5] = {0};
|
||||||
|
|
||||||
ASSERT_NE(-1, dup2(1, 2));
|
ASSERT_NE(-1, dup2(1, 2));
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if (WEXITSTATUS(system("echo aaa 2>&1")) == 0) {
|
if (WEXITSTATUS(system("echo aaa 2>&1")) == 0) {
|
||||||
success = read(pipefd[0], buf, sizeof(buf) - 1) == (sizeof(buf) - 1);
|
success = read(pipefd[0], buf, 4) == (4);
|
||||||
}
|
}
|
||||||
ASSERT_NE(-1, dup2(stderrBack, 2));
|
ASSERT_NE(-1, dup2(stderrBack, 2));
|
||||||
ASSERT_EQ(true, success);
|
ASSERT_EQ(true, success);
|
||||||
|
@ -97,15 +108,12 @@ TEST(system, testStderrRedirect_toStdout) {
|
||||||
ASSERT_NE(-1, dup2(1, 2));
|
ASSERT_NE(-1, dup2(1, 2));
|
||||||
success = false;
|
success = false;
|
||||||
if (WEXITSTATUS(system("./echo.com aaa 2>&1")) == 0) {
|
if (WEXITSTATUS(system("./echo.com aaa 2>&1")) == 0) {
|
||||||
success = read(pipefd[0], buf, sizeof(buf) - 1) == (sizeof(buf) - 1);
|
success = read(pipefd[0], buf, 4) == (4);
|
||||||
}
|
}
|
||||||
ASSERT_NE(-1, dup2(stderrBack, 2));
|
ASSERT_NE(-1, dup2(stderrBack, 2));
|
||||||
ASSERT_EQ(true, success);
|
ASSERT_EQ(true, success);
|
||||||
ASSERT_STREQ("aaa\n", buf);
|
ASSERT_STREQ("aaa\n", buf);
|
||||||
|
RestoreStdout();
|
||||||
ASSERT_NE(-1, dup2(stdoutBack, 1));
|
|
||||||
ASSERT_EQ(0, close(pipefd[1]));
|
|
||||||
ASSERT_EQ(0, close(pipefd[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(system, and) {
|
TEST(system, and) {
|
||||||
|
@ -168,49 +176,43 @@ TEST(system, exitStatusPreservedAfterSemiColon) {
|
||||||
ASSERT_EQ(1, WEXITSTATUS(system("false; ")));
|
ASSERT_EQ(1, WEXITSTATUS(system("false; ")));
|
||||||
ASSERT_EQ(1, WEXITSTATUS(system("./false.com;")));
|
ASSERT_EQ(1, WEXITSTATUS(system("./false.com;")));
|
||||||
ASSERT_EQ(1, WEXITSTATUS(system("./false.com;")));
|
ASSERT_EQ(1, WEXITSTATUS(system("./false.com;")));
|
||||||
int pipefd[2];
|
CaptureStdout();
|
||||||
int stdoutBack = dup(1);
|
|
||||||
ASSERT_NE(-1, stdoutBack);
|
|
||||||
ASSERT_EQ(0, pipe(pipefd));
|
|
||||||
ASSERT_NE(-1, dup2(pipefd[1], 1));
|
|
||||||
ASSERT_EQ(0, WEXITSTATUS(system("false; echo $?")));
|
ASSERT_EQ(0, WEXITSTATUS(system("false; echo $?")));
|
||||||
char buf[3] = {0};
|
char buf[9] = {0};
|
||||||
ASSERT_EQ(2, read(pipefd[0], buf, 2));
|
ASSERT_EQ(2, read(pipefd[0], buf, 8));
|
||||||
ASSERT_STREQ("1\n", buf);
|
ASSERT_STREQ("1\n", buf);
|
||||||
ASSERT_EQ(0, WEXITSTATUS(system("./false.com; echo $?")));
|
ASSERT_EQ(0, WEXITSTATUS(system("./false.com; echo $?")));
|
||||||
buf[0] = 0;
|
ASSERT_EQ(2, read(pipefd[0], buf, 8));
|
||||||
buf[1] = 0;
|
|
||||||
ASSERT_EQ(2, read(pipefd[0], buf, 2));
|
|
||||||
ASSERT_STREQ("1\n", buf);
|
ASSERT_STREQ("1\n", buf);
|
||||||
ASSERT_NE(-1, dup2(stdoutBack, 1));
|
ASSERT_EQ(0, WEXITSTATUS(system("echo -n hi")));
|
||||||
ASSERT_EQ(0, close(pipefd[1]));
|
EXPECT_EQ(2, read(pipefd[0], buf, 8));
|
||||||
ASSERT_EQ(0, close(pipefd[0]));
|
ASSERT_STREQ("hi", buf);
|
||||||
|
RestoreStdout();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(system, globio) {
|
||||||
|
char buf[9] = {0};
|
||||||
|
CaptureStdout();
|
||||||
|
ASSERT_SYS(0, 0, touch("a", 0644));
|
||||||
|
ASSERT_SYS(0, 0, touch("b", 0644));
|
||||||
|
ASSERT_EQ(0, WEXITSTATUS(system("echo *")));
|
||||||
|
EXPECT_EQ(4, read(pipefd[0], buf, 8));
|
||||||
|
ASSERT_STREQ("a b\n", buf);
|
||||||
|
RestoreStdout();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(system, allowsLoneCloseCurlyBrace) {
|
TEST(system, allowsLoneCloseCurlyBrace) {
|
||||||
int pipefd[2];
|
CaptureStdout();
|
||||||
int stdoutBack = dup(1);
|
|
||||||
ASSERT_NE(-1, stdoutBack);
|
|
||||||
ASSERT_EQ(0, pipe(pipefd));
|
|
||||||
ASSERT_NE(-1, dup2(pipefd[1], 1));
|
|
||||||
char buf[6] = {0};
|
char buf[6] = {0};
|
||||||
|
|
||||||
ASSERT_EQ(0, WEXITSTATUS(system("echo \"aaa\"}")));
|
ASSERT_EQ(0, WEXITSTATUS(system("echo \"aaa\"}")));
|
||||||
ASSERT_EQ(sizeof(buf) - 1, read(pipefd[0], buf, sizeof(buf) - 1));
|
ASSERT_EQ(5, read(pipefd[0], buf, 5));
|
||||||
ASSERT_STREQ("aaa}\n", buf);
|
ASSERT_STREQ("aaa}\n", buf);
|
||||||
buf[0] = 0;
|
bzero(buf, 6);
|
||||||
buf[1] = 0;
|
|
||||||
buf[2] = 0;
|
|
||||||
buf[3] = 0;
|
|
||||||
buf[4] = 0;
|
|
||||||
testlib_extract("/zip/echo.com", "echo.com", 0755);
|
testlib_extract("/zip/echo.com", "echo.com", 0755);
|
||||||
ASSERT_EQ(0, WEXITSTATUS(system("./echo.com \"aaa\"}")));
|
ASSERT_EQ(0, WEXITSTATUS(system("./echo.com \"aaa\"}")));
|
||||||
ASSERT_EQ(sizeof(buf) - 1, read(pipefd[0], buf, sizeof(buf) - 1));
|
ASSERT_EQ(5, read(pipefd[0], buf, 5));
|
||||||
ASSERT_STREQ("aaa}\n", buf);
|
ASSERT_STREQ("aaa}\n", buf);
|
||||||
|
RestoreStdout();
|
||||||
ASSERT_NE(-1, dup2(stdoutBack, 1));
|
|
||||||
ASSERT_EQ(0, close(pipefd[1]));
|
|
||||||
ASSERT_EQ(0, close(pipefd[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(system, glob) {
|
TEST(system, glob) {
|
||||||
|
|
2
third_party/ggml/common.cc
vendored
2
third_party/ggml/common.cc
vendored
|
@ -88,7 +88,7 @@ static bool append_file_to_prompt(const char *path, gpt_params & params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
params.n_threads = std::min(20, std::max(1, _getcpucount() >> 1));
|
params.n_threads = std::min(20., (unsigned)__get_cpu_count() * .75);
|
||||||
|
|
||||||
bool invalid_param = false;
|
bool invalid_param = false;
|
||||||
std::string arg;
|
std::string arg;
|
||||||
|
|
2
third_party/ggml/common.h
vendored
2
third_party/ggml/common.h
vendored
|
@ -21,7 +21,7 @@
|
||||||
struct gpt_params {
|
struct gpt_params {
|
||||||
int32_t seed = -1; // RNG seed
|
int32_t seed = -1; // RNG seed
|
||||||
int32_t verbose = 0; // Logging verbosity
|
int32_t verbose = 0; // Logging verbosity
|
||||||
int32_t n_threads = std::max(1, _getcpucount() >> 1);
|
int32_t n_threads = std::max(20., (unsigned)__get_cpu_count() * .75);
|
||||||
int32_t n_predict = -1; // new tokens to predict
|
int32_t n_predict = -1; // new tokens to predict
|
||||||
int32_t n_parts = -1; // amount of model parts (-1 = determine from model dimensions)
|
int32_t n_parts = -1; // amount of model parts (-1 = determine from model dimensions)
|
||||||
int32_t n_ctx = 512; // context size
|
int32_t n_ctx = 512; // context size
|
||||||
|
|
2
third_party/ggml/quantize.cc
vendored
2
third_party/ggml/quantize.cc
vendored
|
@ -92,7 +92,7 @@ int main(int argc, char ** argv) {
|
||||||
ftype = (enum llama_ftype)atoi(argv[3]);
|
ftype = (enum llama_ftype)atoi(argv[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int nthread = argc > 4 ? atoi(argv[4]) : std::min(20, std::max(1, _getcpucount() >> 1));
|
int nthread = argc > 4 ? atoi(argv[4]) : std::min(20, std::max(1, __get_cpu_count() >> 1));
|
||||||
|
|
||||||
const int64_t t_main_start_us = ggml_time_us();
|
const int64_t t_main_start_us = ggml_time_us();
|
||||||
|
|
||||||
|
|
2
third_party/lua/lunix.c
vendored
2
third_party/lua/lunix.c
vendored
|
@ -3532,7 +3532,7 @@ int LuaUnix(lua_State *L) {
|
||||||
LuaSetIntField(L, "RUSAGE_CHILDREN", RUSAGE_CHILDREN);
|
LuaSetIntField(L, "RUSAGE_CHILDREN", RUSAGE_CHILDREN);
|
||||||
LuaSetIntField(L, "RUSAGE_BOTH", RUSAGE_BOTH);
|
LuaSetIntField(L, "RUSAGE_BOTH", RUSAGE_BOTH);
|
||||||
|
|
||||||
LuaSetIntField(L, "ARG_MAX", __arg_max());
|
LuaSetIntField(L, "ARG_MAX", __get_arg_max());
|
||||||
LuaSetIntField(L, "BUFSIZ", BUFSIZ);
|
LuaSetIntField(L, "BUFSIZ", BUFSIZ);
|
||||||
LuaSetIntField(L, "CLK_TCK", CLK_TCK);
|
LuaSetIntField(L, "CLK_TCK", CLK_TCK);
|
||||||
LuaSetIntField(L, "NAME_MAX", _NAME_MAX);
|
LuaSetIntField(L, "NAME_MAX", _NAME_MAX);
|
||||||
|
|
2
third_party/python/Modules/posixmodule.c
vendored
2
third_party/python/Modules/posixmodule.c
vendored
|
@ -10509,7 +10509,7 @@ os_cpu_count_impl(PyObject *module)
|
||||||
/*[clinic end generated code: output=5fc29463c3936a9c input=e7c8f4ba6dbbadd3]*/
|
/*[clinic end generated code: output=5fc29463c3936a9c input=e7c8f4ba6dbbadd3]*/
|
||||||
{
|
{
|
||||||
int ncpu;
|
int ncpu;
|
||||||
ncpu = _getcpucount();
|
ncpu = __get_cpu_count();
|
||||||
if (ncpu >= 1)
|
if (ncpu >= 1)
|
||||||
return PyLong_FromLong(ncpu);
|
return PyLong_FromLong(ncpu);
|
||||||
else
|
else
|
||||||
|
|
2
third_party/radpajama/common-gptneox.cc
vendored
2
third_party/radpajama/common-gptneox.cc
vendored
|
@ -39,7 +39,7 @@
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
|
||||||
params.n_threads = std::min(20, std::max(1, (int)(_getcpucount() * 0.75)));
|
params.n_threads = std::min(20., (unsigned)__get_cpu_count() * 0.75);
|
||||||
|
|
||||||
bool invalid_param = false;
|
bool invalid_param = false;
|
||||||
std::string arg;
|
std::string arg;
|
||||||
|
|
2
third_party/radpajama/common-gptneox.h
vendored
2
third_party/radpajama/common-gptneox.h
vendored
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
struct gpt_params {
|
struct gpt_params {
|
||||||
int32_t seed = -1; // RNG seed
|
int32_t seed = -1; // RNG seed
|
||||||
int32_t n_threads = MIN(4, (int32_t) _getcpucount() * 0.75);
|
int32_t n_threads = MIN(20., (unsigned) __get_cpu_count() * 0.75);
|
||||||
int32_t n_predict = 128; // new tokens to predict
|
int32_t n_predict = 128; // new tokens to predict
|
||||||
int32_t n_parts = -1; // amount of model parts (-1 = determine from model dimensions)
|
int32_t n_parts = -1; // amount of model parts (-1 = determine from model dimensions)
|
||||||
int32_t n_ctx = 512; // context size
|
int32_t n_ctx = 512; // context size
|
||||||
|
|
|
@ -314,7 +314,7 @@ void PrintMakeCommand(void) {
|
||||||
appends(&output, "make MODE=");
|
appends(&output, "make MODE=");
|
||||||
appends(&output, mode);
|
appends(&output, mode);
|
||||||
appends(&output, " -j");
|
appends(&output, " -j");
|
||||||
appendd(&output, buf, FormatUint64(buf, _getcpucount()) - buf);
|
appendd(&output, buf, FormatUint64(buf, __get_cpu_count()) - buf);
|
||||||
appendw(&output, ' ');
|
appendw(&output, ' ');
|
||||||
appends(&output, target);
|
appends(&output, target);
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,8 +206,8 @@ static void Crunch(void) {
|
||||||
free(sources.p);
|
free(sources.p);
|
||||||
sources.p = 0;
|
sources.p = 0;
|
||||||
sources.i = j;
|
sources.i = j;
|
||||||
if (!radix_sort_int64((const long *)sauces, sources.i) ||
|
if (radix_sort_int64((const long *)sauces, sources.i) == -1 ||
|
||||||
!radix_sort_int64((const long *)edges.p, edges.i)) {
|
radix_sort_int64((const long *)edges.p, edges.i) == -1) {
|
||||||
DieOom();
|
DieOom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,9 +163,9 @@ static void GetOpts(int argc, char *argv[]) {
|
||||||
g_fszquota = 256 * 1000 * 1000;
|
g_fszquota = 256 * 1000 * 1000;
|
||||||
if (!sysinfo(&si)) {
|
if (!sysinfo(&si)) {
|
||||||
g_memquota = si.totalram;
|
g_memquota = si.totalram;
|
||||||
g_proquota = _getcpucount() + si.procs;
|
g_proquota = __get_cpu_count() + si.procs;
|
||||||
} else {
|
} else {
|
||||||
g_proquota = _getcpucount() * 100;
|
g_proquota = __get_cpu_count() * 100;
|
||||||
g_memquota = 4L * 1024 * 1024 * 1024;
|
g_memquota = 4L * 1024 * 1024 * 1024;
|
||||||
}
|
}
|
||||||
while ((opt = getopt(argc, argv, "hnqkNVT:p:u:g:c:C:D:P:M:F:O:v:")) != -1) {
|
while ((opt = getopt(argc, argv, "hnqkNVT:p:u:g:c:C:D:P:M:F:O:v:")) != -1) {
|
||||||
|
|
|
@ -131,7 +131,7 @@ int LuaGetCpuCore(lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaGetCpuCount(lua_State *L) {
|
int LuaGetCpuCount(lua_State *L) {
|
||||||
lua_pushinteger(L, _getcpucount());
|
lua_pushinteger(L, __get_cpu_count());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue