Make important improvements

- Fix preadv() and pwritev() for old distros
- Introduce _npassert() and _unassert() macros
- Prove that file locks work properly on Windows
- Support fcntl(F_DUPFD_CLOEXEC) on more systems
This commit is contained in:
Justine Tunney 2022-09-14 21:29:50 -07:00
parent 1ad2f530f9
commit 3f49889841
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
130 changed files with 1225 additions and 431 deletions

View file

@ -18,13 +18,14 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/sched-sysv.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/calls/struct/cpuset.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/nt/enum/processaccess.h"
#include "libc/nt/enum/threadaccess.h"
#include "libc/nt/process.h"
@ -34,14 +35,14 @@
#include "libc/sysv/errfuns.h"
static textwindows dontinline int sys_sched_setaffinity_nt(int pid,
uint64_t bitsetsize,
uint64_t size,
const void *bitset) {
int rc;
uintptr_t mask;
int64_t handle;
uintptr_t mask;
typeof(SetThreadAffinityMask) *SetAffinityMask = SetThreadAffinityMask;
mask = 0;
memcpy(&mask, bitset, min(bitsetsize, sizeof(uintptr_t)));
memcpy(&mask, bitset, min(size, sizeof(uintptr_t)));
handle = 0;
if (!pid) pid = GetCurrentThreadId();
if (0 < pid && pid <= UINT32_MAX) {
@ -69,19 +70,21 @@ static textwindows dontinline int sys_sched_setaffinity_nt(int pid,
* Asks kernel to only schedule thread on particular CPUs.
*
* @param tid is the process or thread id (or 0 for caller)
* @param bitsetsize is byte length of bitset, which should be 128
* @param size is byte length of bitset, which should be 128
* @return 0 on success, or -1 w/ errno
* @raise ENOSYS if not Linux or Windows
* @raise ENOSYS if not Linux, NetBSD, or Windows
*/
int sched_setaffinity(int tid, size_t bitsetsize, const cpu_set_t *bitset) {
int sched_setaffinity(int tid, size_t size, const cpu_set_t *bitset) {
int rc;
if (bitsetsize != 128) {
if (size != 128) {
rc = einval();
} else if (IsWindows()) {
rc = sys_sched_setaffinity_nt(tid, bitsetsize, bitset);
rc = sys_sched_setaffinity_nt(tid, size, bitset);
} else if (IsNetbsd()) {
rc = sys_sched_setaffinity_netbsd(0, tid, MIN(size, 32), bitset);
} else {
rc = sys_sched_setaffinity(tid, bitsetsize, bitset);
rc = sys_sched_setaffinity(tid, size, bitset);
}
STRACE("sched_setaffinity(%d, %'zu, %p) → %d% m", tid, bitsetsize, bitset);
STRACE("sched_setaffinity(%d, %'zu, %p) → %d% m", tid, size, bitset);
return rc;
}