mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Backport main branch improvements (#658)
* Add sys_ prefix to unwrapped system calls * This change also implements getlogin() and getlogin_r(). * Add getgroups and setgroups (#619) * Fix getgroups / setgroups tests across platforms. See #619 * Change accept type to struct sockaddr * (#630) * vista: use old strace path
This commit is contained in:
parent
4381b3d925
commit
f4ff1729d1
831 changed files with 1381 additions and 1822 deletions
|
@ -99,11 +99,11 @@ int flock(int, int);
|
|||
int fork(void);
|
||||
int fsync(int);
|
||||
int ftruncate(int, int64_t);
|
||||
int getdents(unsigned, void *, unsigned, long *);
|
||||
int getdomainname(char *, size_t);
|
||||
int getegid(void) nosideeffect;
|
||||
int geteuid(void) nosideeffect;
|
||||
int getgid(void) nosideeffect;
|
||||
uint32_t getegid(void) nosideeffect;
|
||||
uint32_t geteuid(void) nosideeffect;
|
||||
uint32_t getgid(void) nosideeffect;
|
||||
int getgroups(int size, uint32_t list[]);
|
||||
int gethostname(char *, size_t);
|
||||
int getloadavg(double *, int);
|
||||
int getpgid(int) libcesque;
|
||||
|
@ -115,8 +115,8 @@ int getresgid(uint32_t *, uint32_t *, uint32_t *);
|
|||
int getresuid(uint32_t *, uint32_t *, uint32_t *);
|
||||
int getsid(int) nosideeffect libcesque;
|
||||
int gettid(void) libcesque;
|
||||
int getuid(void) libcesque;
|
||||
int iopl(int);
|
||||
uint32_t getuid(void) libcesque;
|
||||
int sys_iopl(int);
|
||||
int ioprio_get(int, int);
|
||||
int ioprio_set(int, int, int);
|
||||
int issetugid(void);
|
||||
|
@ -135,11 +135,11 @@ int mkfifo(const char *, uint32_t);
|
|||
int mkfifoat(int, const char *, uint32_t);
|
||||
int mknod(const char *, uint32_t, uint64_t);
|
||||
int mknodat(int, const char *, int32_t, uint64_t);
|
||||
int mlock(const void *, size_t);
|
||||
int mlock2(const void *, size_t, int);
|
||||
int mlockall(int);
|
||||
int munlock(const void *, size_t);
|
||||
int munlockall(void);
|
||||
int sys_mlock(const void *, size_t);
|
||||
int sys_mlock2(const void *, size_t, int);
|
||||
int sys_mlockall(int);
|
||||
int sys_munlock(const void *, size_t);
|
||||
int sys_munlockall(void);
|
||||
int nice(int);
|
||||
int open(const char *, int, ...);
|
||||
int openat(int, const char *, int, ...);
|
||||
|
@ -166,6 +166,7 @@ int seteuid(uint32_t);
|
|||
int setfsgid(int);
|
||||
int setfsuid(int);
|
||||
int setgid(int);
|
||||
int setgroups(size_t size, const uint32_t list[]);
|
||||
int setpgid(int, int);
|
||||
int setpgrp(void);
|
||||
int setpriority(int, unsigned, int);
|
||||
|
@ -181,7 +182,7 @@ int symlink(const char *, const char *);
|
|||
int symlinkat(const char *, int, const char *);
|
||||
int sync_file_range(int, int64_t, int64_t, unsigned);
|
||||
int sys_ptrace(int, ...);
|
||||
int sysctl(const int *, unsigned, void *, size_t *, void *, size_t);
|
||||
int sys_sysctl(const int *, unsigned, void *, size_t *, void *, size_t);
|
||||
int tcsetpgrp(int, int32_t);
|
||||
int tgkill(int, int, int);
|
||||
int tkill(int, int);
|
||||
|
|
|
@ -54,7 +54,7 @@ static unsigned GetCpuCountBsd(void) {
|
|||
} else {
|
||||
cmd[1] = HW_NCPU;
|
||||
}
|
||||
if (!sysctl(cmd, 2, &c, &n, 0, 0)) {
|
||||
if (!sys_sysctl(cmd, 2, &c, &n, 0, 0)) {
|
||||
return c;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
|
@ -26,13 +26,13 @@
|
|||
* Returns effective group ID of calling process.
|
||||
* @return group id
|
||||
*/
|
||||
int getegid(void) {
|
||||
int rc;
|
||||
uint32_t getegid(void) {
|
||||
uint32_t rc;
|
||||
if (!IsWindows()) {
|
||||
rc = sys_getegid();
|
||||
} else {
|
||||
rc = getgid();
|
||||
}
|
||||
STRACE("%s() → %d% m", "getegid", rc);
|
||||
STRACE("%s() → %u% m", "getegid", rc);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -25,13 +25,13 @@
|
|||
* Returns effective user ID of calling process.
|
||||
* @return user id
|
||||
*/
|
||||
int geteuid(void) {
|
||||
int rc;
|
||||
uint32_t geteuid(void) {
|
||||
uint32_t rc;
|
||||
if (!IsWindows()) {
|
||||
rc = sys_geteuid();
|
||||
} else {
|
||||
rc = getuid();
|
||||
}
|
||||
STRACE("%s() → %d% m", "geteuid", rc);
|
||||
STRACE("%s() → %u% m", "geteuid", rc);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- 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 2022 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2020 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 │
|
||||
|
@ -16,8 +16,30 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/groups.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
getdents64:
|
||||
jmp getdents
|
||||
.endfn getdents64,globl
|
||||
/**
|
||||
* Gets list of supplementary group IDs
|
||||
*
|
||||
* @param size - maximum number of items that can be stored in list
|
||||
* @param list - buffer to store output gid_t
|
||||
* @return -1 w/ EFAULT
|
||||
*/
|
||||
int getgroups(int size, uint32_t list[]) {
|
||||
int rc;
|
||||
if (IsAsan() && size && !__asan_is_valid(list, size * sizeof(list[0]))) {
|
||||
rc = efault();
|
||||
} else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
|
||||
rc = sys_getgroups(size, list);
|
||||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
STRACE("getgroups(%d, %s) → %d% m", size, DescribeGidList(rc, rc, list), rc);
|
||||
return rc;
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
int gethostname_bsd(char *name, size_t len, int kind) {
|
||||
int cmd[2] = {CTL_KERN, kind};
|
||||
if (sysctl(cmd, 2, name, &len, 0, 0) != -1) {
|
||||
if (sys_sysctl(cmd, 2, name, &len, 0, 0) != -1) {
|
||||
return 0;
|
||||
} else {
|
||||
if (errno == ENOMEM) {
|
||||
|
|
|
@ -62,7 +62,7 @@ int getloadavg(double *a, int n) {
|
|||
struct loadavg loadinfo;
|
||||
int mib[2] = {CTL_VM, VM_LOADAVG};
|
||||
size = sizeof(loadinfo);
|
||||
if ((rc = sysctl(mib, 2, &loadinfo, &size, 0, 0)) != -1) {
|
||||
if ((rc = sys_sysctl(mib, 2, &loadinfo, &size, 0, 0)) != -1) {
|
||||
for (i = 0; i < n; i++) {
|
||||
a[i] = (double)loadinfo.ldavg[i] / loadinfo.fscale;
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ static inline void GetProgramExecutableNameImpl(char *p, char *e) {
|
|||
}
|
||||
u.cmd[3] = -1; // current process
|
||||
n = e - p;
|
||||
if (sysctl(u.cmd, ARRAYLEN(u.cmd), p, &n, 0, 0) != -1) {
|
||||
if (sys_sysctl(u.cmd, ARRAYLEN(u.cmd), p, &n, 0, 0) != -1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,15 +50,15 @@ static textwindows dontinline uint32_t GetUserNameHash(void) {
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
int getuid(void) {
|
||||
int rc;
|
||||
uint32_t getuid(void) {
|
||||
uint32_t rc;
|
||||
if (!IsWindows()) {
|
||||
rc = sys_getuid();
|
||||
} else {
|
||||
rc = GetUserNameHash();
|
||||
}
|
||||
|
||||
STRACE("%s() → %d% m", "getuid", rc);
|
||||
STRACE("%s() → %u% m", "getuid", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -71,13 +71,13 @@ int getuid(void) {
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
int getgid(void) {
|
||||
int rc;
|
||||
uint32_t getgid(void) {
|
||||
uint32_t rc;
|
||||
if (!IsWindows()) {
|
||||
rc = sys_getgid();
|
||||
} else {
|
||||
rc = GetUserNameHash();
|
||||
}
|
||||
STRACE("%s() → %d% m", "getgid", rc);
|
||||
STRACE("%s() → %u% m", "getgid", rc);
|
||||
return rc;
|
||||
}
|
||||
|
|
16
libc/calls/groups.internal.h
Normal file
16
libc/calls/groups.internal.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_GROUPS_INTERNAL_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_GROUPS_INTERNAL_H_
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int sys_getgroups(int size, uint32_t list[]);
|
||||
int sys_setgroups(size_t size, uint32_t list[]);
|
||||
|
||||
const char *DescribeGidList(char[128], int, int, const uint32_t list[]);
|
||||
#define DescribeGidList(rc, length, gidlist) \
|
||||
DescribeGidList(alloca(128), rc, length, gidlist)
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_GROUPS_INTERNAL_H_ */
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- 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 2022 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2020 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 │
|
||||
|
@ -16,8 +16,37 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/groups.internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
prlimit64:
|
||||
jmp prlimit
|
||||
.endfn prlimit64,globl
|
||||
/**
|
||||
* Sets list of supplementary group IDs.
|
||||
*
|
||||
* On recent versions of Linux only, it's possible to say:
|
||||
*
|
||||
* setgroups(0, NULL);
|
||||
*
|
||||
* Which will cause subsequent calls to `EPERM`.
|
||||
*
|
||||
* @param size number of items in list
|
||||
* @param list input set of gid_t to set
|
||||
* @return -1 w/ EFAULT
|
||||
*/
|
||||
int setgroups(size_t size, const uint32_t list[]) {
|
||||
int rc;
|
||||
if (IsAsan() && size && !__asan_is_valid(list, size * sizeof(list[0]))) {
|
||||
rc = efault();
|
||||
} else if (IsLinux() || IsNetbsd() || IsOpenbsd() || IsFreebsd() || IsXnu()) {
|
||||
rc = sys_setgroups(size, list);
|
||||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
STRACE("setgroups(%u, %s) → %d% m", size, DescribeGidList(rc, size, list),
|
||||
rc);
|
||||
return rc;
|
||||
}
|
|
@ -39,7 +39,7 @@ static int64_t GetUptime(void) {
|
|||
struct timeval x;
|
||||
size_t n = sizeof(x);
|
||||
int mib[] = {CTL_KERN, KERN_BOOTTIME};
|
||||
if (sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) return 0;
|
||||
if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) return 0;
|
||||
return _timespec_real().tv_sec - x.tv_sec;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ static int64_t GetPhysmem(void) {
|
|||
uint64_t x;
|
||||
size_t n = sizeof(x);
|
||||
int mib[] = {CTL_HW, HW_PHYSMEM};
|
||||
if (sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) return 0;
|
||||
if (sys_sysctl(mib, ARRAYLEN(mib), &x, &n, 0, 0) == -1) return 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ static void GetBsdStr(int c0, int c1, char *s) {
|
|||
size_t n = SYS_NMLN;
|
||||
int cmd[2] = {c0, c1};
|
||||
bzero(s, n), --n;
|
||||
sysctl(cmd, 2, s, &n, NULL, 0);
|
||||
sys_sysctl(cmd, 2, s, &n, NULL, 0);
|
||||
errno = e;
|
||||
// sysctl kern.version is too verbose for uname
|
||||
if ((p = strchr(s, '\n'))) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue