Merge pull request #16636 from ziglang/audit-devnexen

audit all contributions by @devnexen for correctness and delete unnecessary libc ABI bits
This commit is contained in:
Andrew Kelley 2023-07-31 15:33:54 -07:00 committed by GitHub
commit 8f5c333ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 147 additions and 1794 deletions

View File

@ -695,7 +695,7 @@ const PosixThreadImpl = struct {
defer assert(c.pthread_attr_destroy(&attr) == .SUCCESS);
// Use the same set of parameters used by the libc-less impl.
const stack_size = @max(config.stack_size, c.PTHREAD_STACK_MIN);
const stack_size = @max(config.stack_size, 16 * 1024);
assert(c.pthread_attr_setstacksize(&attr, stack_size) == .SUCCESS);
assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == .SUCCESS);

View File

@ -408,11 +408,6 @@ pub extern "c" fn setlogmask(maskpri: c_int) c_int;
pub extern "c" fn if_nametoindex([*:0]const u8) c_int;
pub extern "c" fn timer_create(clockid: c.clockid_t, sevp: *c.sigevent, timerid: *c.timer_t) c_int;
pub extern "c" fn timer_delete(timerid: c.timer_t) c_int;
pub extern "c" fn timer_settime(timerid: c.timer_t, flags: c_int, new_value: *const c.itimerspec, old_value: *c.itimerspec) c_int;
pub extern "c" fn timer_gettime(timerid: c.timer_t, flags: c_int, curr_value: *c.itimerspec) c_int;
pub usingnamespace if (builtin.os.tag == .linux and builtin.target.isMusl()) struct {
// musl does not implement getcontext
pub const getcontext = std.os.linux.getcontext;

View File

@ -161,67 +161,13 @@ pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;
pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8;
pub const COPYFILE = struct {
pub const ACL = 1 << 0;
pub const STAT = 1 << 1;
pub const XATTR = 1 << 2;
pub const DATA = 1 << 3;
pub const SECURITY = COPYFILE.STAT | COPYFILE.ACL;
pub const METADATA = COPYFILE.SECURITY | COPYFILE.XATTR;
pub const ALL = COPYFILE.METADATA | COPYFILE.DATA;
pub const RECURSIVE = 1 << 15;
pub const CHECK = 1 << 16;
pub const EXCL = 1 << 17;
pub const NOFOLLOW_SRC = 1 << 18;
pub const NOFOLLOW_DST = 1 << 19;
pub const MOVE = 1 << 20;
pub const UNLINK = 1 << 21;
pub const NOFOLLOW = COPYFILE.NOFOLLOW_SRC | NOFOLLOW_DST;
pub const PACK = 1 << 22;
pub const UNPACK = 1 << 23;
pub const CLONE = 1 << 24;
pub const CLONE_FORCE = 1 << 25;
pub const RUN_IN_PLACE = 1 << 26;
pub const DATA_SPARSE = 1 << 27;
pub const PRESERVE_DST_TRACKED = 1 << 28;
pub const VERBOSE = 1 << 30;
pub const RECURSE_ERROR = 0;
pub const RECURSE_FILE = 1;
pub const RECURSE_DIR = 2;
pub const RECURSE_DIR_CLEANUP = 3;
pub const COPY_DATA = 4;
pub const COPY_XATTR = 5;
pub const START = 1;
pub const FINISH = 2;
pub const ERR = 3;
pub const PROGRESS = 4;
pub const CONTINUE = 0;
pub const SKIP = 1;
pub const QUIT = 2;
pub const STATE_SRC_FD = 1;
pub const STATE_SRC_FILENAME = 2;
pub const STATE_DST_FD = 3;
pub const STATE_DST_FILENAME = 4;
pub const STATE_QUARANTINE = 5;
pub const STATE_STATUS_CB = 6;
pub const STATE_STATUS_CTX = 7;
pub const STATE_COPIED = 8;
pub const STATE_XATTRNAME = 9;
pub const STATE_WAS_CLONED = 10;
pub const STATE_SRC_BSIZE = 11;
pub const STATE_DST_BSIZE = 12;
pub const STATE_BSIZE = 13;
pub const DISABLE_VAR: [*]u8 = "COPYFILE_DISABLE";
};
pub const COPYFILE_ACL = 1 << 0;
pub const COPYFILE_STAT = 1 << 1;
pub const COPYFILE_XATTR = 1 << 2;
pub const COPYFILE_DATA = 1 << 3;
pub const copyfile_state_t = *opaque {};
pub const copyfile_flags_t = u32;
pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: copyfile_flags_t) c_int;
pub extern "c" fn copyfile(from: [*:0]u8, to: [*:0]u8, state: ?copyfile_state_t, flags: copyfile_flags_t) c_int;
pub extern "c" fn copyfile_state_alloc() copyfile_state_t;
pub extern "c" fn copyfile_state_free(state: copyfile_state_t) void;
pub extern "c" fn copyfile_state_get(s: copyfile_state_t, flag: u32, dst: ?*anyopaque) c_int;
pub extern "c" fn copyfile_state_set(s: copyfile_state_t, flag: u32, dst: ?*const anyopaque) c_int;
pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: u32) c_int;
pub extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
pub const realpath = @"realpath$DARWIN_EXTSN";
@ -949,35 +895,7 @@ pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class
pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
pub const CCryptorStatus = enum(i32) {
/// Operation completed
kCCSuccess = 0,
/// Illegal parameter
kCCParamError = -4300,
/// Provided buffer too small
kCCBufferTooSmall = -4301,
/// Failed memory allocation
kCCMemoryFailure = -4302,
/// Size alignment issue
kCCAlignmentError = -4303,
/// Decoding issue
kCCDecodeError = -4304,
/// Call not implemented
kCCUnimplemented = -4305,
kCCOverflow = -4306,
kCCRNGFailure = -4307,
/// Unspecified error
kCCUnspecifiedError = -4308,
kCCCallSequenceError = -4309,
kCCKeySizeError = -4310,
/// Invalid key
kCCInvalidKey = -4311,
};
pub const CCRNGStatus = CCryptorStatus;
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
pub extern "c" fn CCRandomGenerateBytes(bytes: ?*anyopaque, count: usize) CCRNGStatus;
// Grand Central Dispatch is exposed by libSystem.
pub extern "c" fn dispatch_release(object: *anyopaque) void;
@ -3926,248 +3844,3 @@ pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost
pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
pub extern "c" fn proc_listpids(tpe: u32, tinfo: u32, buffer: ?*anyopaque, buffersize: c_int) c_int;
pub extern "c" fn proc_listallpids(buffer: ?*anyopaque, buffersize: c_int) c_int;
pub extern "c" fn proc_listpgrppids(pgrpid: pid_t, buffer: ?*anyopaque, buffersize: c_int) c_int;
pub extern "c" fn proc_listchildpids(ppid: pid_t, buffer: ?*anyopaque, buffersize: c_int) c_int;
pub extern "c" fn proc_pidinfo(pid: c_int, flavor: c_int, arg: u64, buffer: ?*anyopaque, buffersize: c_int) c_int;
pub extern "c" fn proc_name(pid: c_int, buffer: ?*anyopaque, buffersize: u32) c_int;
pub extern "c" fn proc_pidpath(pid: c_int, buffer: ?*anyopaque, buffersize: u32) c_int;
pub const MIN = struct {
pub const INCORE = 0x1;
pub const REFERENCED = 0x2;
pub const MODIFIED = 0x4;
pub const REFERENCED_OTHER = 0x8;
pub const MODIFIED_OTHER = 0x10;
pub const PAGED_OUT = 0x20;
pub const COPIED = 0x40;
pub const ANONYMOUS = 0x80;
};
pub extern "c" fn mincore(addr: *align(std.mem.page_size) const anyopaque, length: usize, vec: [*]u8) c_int;
pub extern "c" fn os_proc_available_memory() usize;
pub const thread_affinity_policy = extern struct {
tag: integer_t,
};
pub const thread_policy_flavor_t = natural_t;
pub const thread_policy_t = [*]integer_t;
pub const thread_affinity_policy_data_t = thread_affinity_policy;
pub const thread_affinity_policy_t = [*]thread_affinity_policy;
pub const THREAD_AFFINITY = struct {
pub const POLICY = 0;
pub const POLICY_COUNT = @as(mach_msg_type_number_t, @intCast(@sizeOf(thread_affinity_policy_data_t) / @sizeOf(integer_t)));
};
/// cpu affinity api
/// albeit it is also available on arm64, it always fails as in this architecture there is no sense of
/// individual cpus (high performance cpus group and low consumption one), thus the pthread QOS api is more appropriate in this case.
pub extern "c" fn thread_affinity_get(thread: thread_act_t, flavor: thread_policy_flavor_t, info: thread_policy_t, infocnt: [*]mach_msg_type_number_t, default: *boolean_t) kern_return_t;
pub extern "c" fn thread_affinity_set(thread: thread_act_t, flavor: thread_policy_flavor_t, info: thread_policy_t, infocnt: mach_msg_type_number_t) kern_return_t;
pub const cpu_type_t = integer_t;
pub const cpu_subtype_t = integer_t;
pub const cpu_threadtype_t = integer_t;
pub const host_flavor_t = integer_t;
pub const host_info_t = *integer_t;
pub const host_info64_t = *integer_t;
pub const host_can_has_debugger_info = extern struct {
can_has_debugger: boolean_t,
};
pub const host_can_has_debugger_info_data_t = host_can_has_debugger_info;
pub const host_can_has_debugger_info_t = *host_can_has_debugger_info;
pub const host_sched_info = extern struct {
min_timeout: integer_t,
min_quantum: integer_t,
};
pub const host_sched_info_data_t = host_sched_info;
pub const host_sched_info_t = *host_sched_info;
pub const kernel_resource_sizes = extern struct {
task: natural_t,
thread: natural_t,
port: natural_t,
memory_region: natural_t,
memory_object: natural_t,
};
pub const kernel_resource_sizes_data_t = kernel_resource_sizes;
pub const kernel_resource_sizes_t = *kernel_resource_sizes;
pub const host_priority_info = extern struct {
kernel_priority: integer_t,
system_priority: integer_t,
server_priority: integer_t,
user_priority: integer_t,
depress_priority: integer_t,
idle_priority: integer_t,
minimum_priority: integer_t,
maximum_priority: integer_t,
};
pub const host_priority_info_data_t = host_priority_info;
pub const host_priority_info_t = *host_priority_info;
pub const CPU_STATE_MAX = 4;
pub const host_cpu_load_info = extern struct {
cpu_ticks: [CPU_STATE_MAX]natural_t,
};
pub const host_cpu_load_info_data_t = host_cpu_load_info;
pub const host_cpu_load_info_t = *host_cpu_load_info;
pub const host_load_info = extern struct {
avenrun: [3]integer_t,
mach_factor: [3]integer_t,
};
pub const host_load_info_data_t = host_load_info;
pub const host_load_info_t = *host_load_info;
pub const host_preferred_user_arch = extern struct {
cpu_type: cpu_type_t,
cpu_subtype: cpu_subtype_t,
};
pub const host_preferred_user_arch_data_t = host_preferred_user_arch;
pub const host_preferred_user_arch_t = *host_preferred_user_arch;
fn HostCount(comptime HT: type) mach_msg_type_number_t {
return @as(mach_msg_type_number_t, @intCast(@sizeOf(HT) / @sizeOf(integer_t)));
}
pub const HOST = struct {
pub const BASIC_INFO = 1;
pub const SCHED_INFO = 3;
pub const RESOURCE_SIZES = 4;
pub const PRIORITY_INFO = 5;
pub const SEMAPHORE_TRAPS = 7;
pub const MACH_MSG_TRAPS = 8;
pub const VM_PURGEABLE = 9;
pub const DEBUG_INFO_INTERNAL = 10;
pub const CAN_HAS_DEBUGGER = 11;
pub const PREFERRED_USER_ARCH = 12;
pub const LOAD_INFO = 1;
pub const VM_INFO = 2;
pub const CPU_LOAD_INFO = 3;
pub const VM_INFO64 = 4;
pub const EXTMOD_INFO64 = 5;
pub const EXPIRED_TASK_INFO = 6;
pub const CAN_HAS_DEBUGGER_COUNT = HostCount(host_can_has_debugger_info_data_t);
pub const SCHED_INFO_COUNT = HostCount(host_sched_info_data_t);
pub const RESOURCES_SIZES_COUNT = HostCount(kernel_resource_sizes_data_t);
pub const PRIORITY_INFO_COUNT = HostCount(host_priority_info_data_t);
pub const CPU_LOAD_INFO_COUNT = HostCount(host_cpu_load_info_data_t);
pub const LOAD_INFO_COUNT = HostCount(host_load_info_data_t);
pub const PREFERRED_USER_ARCH_COUNT = HostCount(host_preferred_user_arch_data_t);
pub const VM_INFO_COUNT = HostCount(vm_statistics_data_t);
pub const VM_INFO64_COUNT = HostCount(vm_statistics64_data_t);
pub const EXTMOD_INFO64_COUNT = HostCount(vm_extmod_statistics_data_t);
};
pub const host_basic_info = extern struct {
max_cpus: integer_t,
avail_cpus: integer_t,
memory_size: natural_t,
cpu_type: cpu_type_t,
cpu_subtype: cpu_subtype_t,
cpu_threadtype: cpu_threadtype_t,
physical_cpu: integer_t,
physical_cpu_max: integer_t,
logical_cpu: integer_t,
logical_cpu_max: integer_t,
max_mem: u64,
};
pub extern "c" fn host_info(host: host_t, flavor: host_flavor_t, info_out: host_info_t, info_outCnt: [*]mach_msg_type_number_t) kern_return_t;
pub extern "c" fn host_statistics(priv: host_t, flavor: host_flavor_t, info_out: host_info_t, info_outCnt: [*]mach_msg_type_number_t) kern_return_t;
pub extern "c" fn host_statistics64(priv: host_t, flavor: host_flavor_t, info_out: host_info64_t, info64_outCnt: [*]mach_msg_type_number_t) kern_return_t;
pub const vm_statistics = extern struct {
free_count: natural_t,
active_count: natural_t,
inactive_count: natural_t,
wire_count: natural_t,
zero_fill_count: natural_t,
reactivations: natural_t,
pageins: natural_t,
pageouts: natural_t,
faults: natural_t,
cow_faults: natural_t,
lookups: natural_t,
hits: natural_t,
purgeable_count: natural_t,
purges: natural_t,
speculative_count: natural_t,
};
pub const vm_statistics_t = *vm_statistics;
pub const vm_statistics_data_t = vm_statistics;
pub const vm_statistics64 align(8) = extern struct {
free_count: natural_t,
active_count: natural_t,
inactive_count: natural_t,
wire_count: natural_t,
zero_fill_count: u64,
reactivations: u64,
pageins: u64,
pageouts: u64,
faults: u64,
cow_faults: u64,
lookups: u64,
hits: u64,
purges: u64,
purgeable_count: natural_t,
speculative_count: natural_t,
decompressions: u64,
compressions: u64,
swapins: u64,
swapouts: u64,
compressor_page_count: natural_t,
throttled_count: natural_t,
external_page_count: natural_t,
internal_page_count: natural_t,
total_uncompressed_pages_in_compressor: u64,
};
pub const vm_statistics64_t = *vm_statistics64;
pub const vm_statistics64_data_t = vm_statistics64;
pub const vm_extmod_statistics align(8) = extern struct {
task_for_pid_count: i64,
task_for_pid_caller_count: i64,
thread_creation_count: i64,
thread_creation_caller_count: i64,
thread_set_state_count: i64,
thread_set_state_caller_count: i64,
};
pub const vm_extmod_statistics_t = *vm_extmod_statistics;
pub const vm_extmod_statistics_data_t = vm_extmod_statistics;
pub extern "c" fn vm_stats(info: ?*anyopaque, count: *c_uint) kern_return_t;
/// TODO refines if necessary
pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
.arm, .aarch64 => 16 * 1024,
else => 8 * 1024,
};
pub const _SYS_NAMELEN = 256;
pub const utsname = extern struct {
sysname: [255:0]u8,
nodename: [255:0]u8,
release: [255:0]u8,
version: [255:0]u8,
machine: [255:0]u8,
};
pub extern "c" fn uname(u: *utsname) c_int;

View File

@ -21,7 +21,6 @@ pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*an
pub extern "c" fn lwp_gettid() c_int;
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
pub const pthread_mutex_t = extern struct {
inner: ?*anyopaque = null,
@ -889,13 +888,13 @@ pub const cmsghdr = extern struct {
cmsg_type: c_int,
};
pub const msghdr = extern struct {
name: ?*anyopaque,
namelen: socklen_t,
iov: [*]iovec,
iovlen: c_int,
control: ?*anyopaque,
controllen: socklen_t,
flags: c_int,
msg_name: ?*anyopaque,
msg_namelen: socklen_t,
msg_iov: [*]iovec,
msg_iovlen: c_int,
msg_control: ?*anyopaque,
msg_controllen: socklen_t,
msg_flags: c_int,
};
pub const cmsgcred = extern struct {
cmcred_pid: pid_t,
@ -1144,24 +1143,3 @@ pub const POLL = struct {
pub const HUP = 0x0010;
pub const NVAL = 0x0020;
};
pub const SIGEV = struct {
pub const NONE = 0;
pub const SIGNAL = 1;
pub const THREAD = 2;
};
pub const sigevent = extern struct {
sigev_notify: c_int,
__sigev_u: extern union {
__sigev_signo: c_int,
__sigev_notify_kqueue: c_int,
__sigev_notify_attributes: ?*pthread_attr_t,
},
sigev_value: sigval,
sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
};
pub const PTHREAD_STACK_MIN = 16 * 1024;
pub const timer_t = *opaque {};

View File

@ -9,5 +9,3 @@ pub const pthread_rwlock_t = extern struct {
};
const __SIZEOF_PTHREAD_COND_T = 48;
const __SIZEOF_PTHREAD_MUTEX_T = 28;
pub const PTHREAD_STACK_MIN = 2048;

File diff suppressed because it is too large Load Diff

View File

@ -5,15 +5,11 @@ const maxInt = std.math.maxInt;
const iovec = std.os.iovec;
const iovec_const = std.os.iovec_const;
const status_t = i32;
extern "c" fn _errnop() *c_int;
pub const _errno = _errnop;
pub extern "c" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) status_t;
pub extern "c" fn find_path(codePointer: ?*const u8, baseDirectory: path_base_directory, subPath: ?[*:0]const u8, pathBuffer: [*:0]u8, bufferSize: usize) status_t;
pub extern "c" fn find_directory(which: c_int, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
pub extern "c" fn find_thread(thread_name: ?*anyopaque) i32;
@ -173,25 +169,25 @@ pub const Flock = extern struct {
pub const msghdr = extern struct {
/// optional address
name: ?*sockaddr,
msg_name: ?*sockaddr,
/// size of address
namelen: socklen_t,
msg_namelen: socklen_t,
/// scatter/gather array
iov: [*]iovec,
msg_iov: [*]iovec,
/// # elements in msg_iov
iovlen: i32,
msg_iovlen: i32,
/// ancillary data
control: ?*anyopaque,
msg_control: ?*anyopaque,
/// ancillary data buffer len
controllen: socklen_t,
msg_controllen: socklen_t,
/// flags on received message
flags: i32,
msg_flags: i32,
};
pub const off_t = i64;
@ -1024,13 +1020,6 @@ pub const directory_which = enum(c_int) {
_,
};
// TODO fill out if needed
pub const path_base_directory = enum(c_int) {
B_FIND_PATH_IMAGE_PATH = 1000,
};
pub const B_APP_IMAGE_SYMBOL = null;
pub const cc_t = u8;
pub const speed_t = u8;
pub const tcflag_t = u32;
@ -1049,27 +1038,3 @@ pub const termios = extern struct {
};
pub const MSG_NOSIGNAL = 0x0800;
pub const SIGEV = struct {
pub const NONE = 0;
pub const SIGNAL = 1;
pub const THREAD = 2;
};
pub const sigval = extern union {
int: c_int,
ptr: ?*anyopaque,
};
pub const sigevent = extern struct {
sigev_notify: c_int,
sigev_signo: c_int,
sigev_value: sigval,
sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
sigev_notify_attributes: ?*pthread_attr_t,
};
/// TODO refines if necessary
pub const PTHREAD_STACK_MIN = 2 * 4096;
pub extern "c" fn malloc_usable_size(?*anyopaque) usize;

View File

@ -13,10 +13,6 @@ pub const ARCH = linux.ARCH;
pub const AT = linux.AT;
pub const CLOCK = linux.CLOCK;
pub const CPU_COUNT = linux.CPU_COUNT;
pub const CPU_SET = linux.CPU_SET;
pub const CPU_ISSET = linux.CPU_ISSET;
pub const CPU_CLR = linux.CPU_CLR;
pub const CPU_ZERO = linux.CPU_ZERO;
pub const E = linux.E;
pub const Elf_Symndx = linux.Elf_Symndx;
pub const F = linux.F;
@ -100,7 +96,6 @@ pub const stack_t = linux.stack_t;
pub const tcflag_t = linux.tcflag_t;
pub const termios = linux.termios;
pub const time_t = linux.time_t;
pub const timer_t = linux.timer_t;
pub const timespec = linux.timespec;
pub const timeval = linux.timeval;
pub const timezone = linux.timezone;
@ -250,7 +245,6 @@ pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
pub extern "c" fn sched_setaffinity(pid: c_int, size: usize, set: *const cpu_set_t) c_int;
pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
pub extern "c" fn epoll_create1(flags: c_uint) c_int;
@ -351,18 +345,6 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (native_abi) {
};
const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
/// TODO refines if necessary
pub const PTHREAD_STACK_MIN = switch (native_abi) {
.musl, .musleabi, .musleabihf => 2048,
.gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (native_arch) {
.aarch64, .arm, .armeb, .powerpc, .powerpc64, .powerpc64le, .loongarch32, .loongarch64 => 131072,
.sparc64 => 24576,
else => 16 * 1024,
},
.android => if (@sizeOf(usize) == 8) 16 * 1024 else 8 * 1024,
else => 16 * 1024,
};
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
@ -389,19 +371,3 @@ pub const dirent64 = struct {
d_type: u8,
d_name: [256]u8,
};
pub const MPOL = struct {
pub const F_NODE = 1 << 0;
pub const F_ADDR = 1 << 1;
pub const F_MEMS_ALLOWED = 1 << 2;
/// flags for SYS_mbind
pub const MF_STRICT = 1 << 0;
pub const MF_MOVE = 1 << 1;
pub const MF_MOVE_ALL = 1 << 2;
pub const MF_LAZY = 1 << 3;
pub const MF_INTERNAL = 1 << 4;
pub const MF_VALID = MPOL.MF_STRICT | MPOL.MF_MOVE | MPOL.MOVE_ALL;
};
pub extern "c" fn getcpu(cpu: *c_uint, node: *c_uint) c_int;
pub extern "c" fn sched_getcpu() c_int;

View File

@ -16,5 +16,3 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (builtin.abi) {
},
else => unreachable,
};
pub const PTHREAD_STACK_MIN = 16 * 1024;

View File

@ -121,21 +121,9 @@ pub const pthread_attr_t = extern struct {
};
pub const sem_t = ?*opaque {};
pub const cpuset_t = opaque {};
pub const cpuid_t = c_ulong;
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub extern "c" fn pthread_setaffinity_np(thread: std.c.pthread_t, size: usize, set: ?*cpuset_t) c_int;
pub extern "c" fn pthread_getaffinity_np(thread: std.c.pthread_t, size: usize, set: ?*cpuset_t) c_int;
pub extern "c" fn cpuset_create() ?*cpuset_t;
pub extern "c" fn cpuset_destroy(set: ?*cpuset_t) void;
pub extern "c" fn cpuset_zero(set: ?*cpuset_t) void;
pub extern "c" fn cpuset_set(cpu: cpuid_t, set: ?*cpuset_t) c_int;
pub extern "c" fn cpuset_clr(cpu: cpuid_t, set: ?*cpuset_t) c_int;
pub extern "c" fn cpuset_isset(cpu: cpuid_t, set: ?*const cpuset_t) c_int;
pub extern "c" fn cpuset_size(set: ?*cpuset_t) usize;
pub const blkcnt_t = i64;
pub const blksize_t = i32;
@ -253,48 +241,48 @@ pub const EAI_MAX = 15;
pub const msghdr = extern struct {
/// optional address
name: ?*sockaddr,
msg_name: ?*sockaddr,
/// size of address
namelen: socklen_t,
msg_namelen: socklen_t,
/// scatter/gather array
iov: [*]iovec,
msg_iov: [*]iovec,
/// # elements in msg_iov
iovlen: i32,
msg_iovlen: i32,
/// ancillary data
control: ?*anyopaque,
msg_control: ?*anyopaque,
/// ancillary data buffer len
controllen: socklen_t,
msg_controllen: socklen_t,
/// flags on received message
flags: i32,
msg_flags: i32,
};
pub const msghdr_const = extern struct {
/// optional address
name: ?*const sockaddr,
msg_name: ?*const sockaddr,
/// size of address
namelen: socklen_t,
msg_namelen: socklen_t,
/// scatter/gather array
iov: [*]const iovec_const,
msg_iov: [*]const iovec_const,
/// # elements in msg_iov
iovlen: i32,
msg_iovlen: i32,
/// ancillary data
control: ?*const anyopaque,
msg_control: ?*const anyopaque,
/// ancillary data buffer len
controllen: socklen_t,
msg_controllen: socklen_t,
/// flags on received message
flags: i32,
msg_flags: i32,
};
/// The stat structure used by libc.
@ -485,11 +473,6 @@ pub const AF = struct {
pub const MAX = 37;
};
pub const accept_filter_arg = extern struct {
af_name: [16]u8,
af_args: [240]u8,
};
pub const in_port_t = u16;
pub const sa_family_t = u8;
@ -579,12 +562,6 @@ pub const PROT = struct {
pub const READ = 1;
pub const WRITE = 2;
pub const EXEC = 4;
pub fn MPROTECT(flag: u32) u32 {
return flag << 3;
}
pub fn MPROTECT_EXTRACT(flag: u32) u32 {
return (flag >> 3) & 0x7;
}
};
pub const CLOCK = struct {
@ -614,27 +591,6 @@ pub const MAP = struct {
pub const ANON = 0x1000;
pub const ANONYMOUS = ANON;
pub const STACK = 0x2000;
pub const ALIGNMENT_SHIFT = 24;
pub fn ALIGNED(n: u32) u32 {
return n << ALIGNMENT_SHIFT;
}
pub const ALIGNMENT_64KB = MAP.ALIGNED(0xff);
pub const ALIGNMENT_16MB = MAP.ALIGNED(16);
pub const ALIGNMENT_4GB = MAP.ALIGNED(32);
pub const ALIGNMENT_1TB = MAP.ALIGNED(40);
pub const ALIGNMENT_256TB = MAP.ALIGNED(48);
pub const ALIGNMENT_64PB = MAP.ALIGNED(56);
};
pub const MADV = struct {
pub const NORMAL = 0;
pub const RANDOM = 1;
pub const SEQUENTIAL = 2;
pub const WILLNEED = 3;
pub const DONTNEED = 4;
pub const SPACEAVAIL = 5;
pub const FREE = 6;
};
pub const MSF = struct {
@ -1665,79 +1621,3 @@ pub const POLL = struct {
pub const HUP = 0x0010;
pub const NVAL = 0x0020;
};
pub const SIGEV = struct {
pub const NONE = 0;
pub const SIGNAL = 1;
pub const THREAD = 2;
};
pub const sigval = extern union {
int: c_int,
ptr: ?*anyopaque,
};
pub const sigevent = extern struct {
sigev_notify: c_int,
sigev_signo: c_int,
sigev_value: sigval,
sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
sigev_notify_attributes: ?*pthread_attr_t,
};
pub const PTRACE = struct {
pub const FORK = 0x0001;
pub const VFORK = 0x0002;
pub const VFORK_DONE = 0x0004;
pub const LWP_CREATE = 0x0008;
pub const LWP_EXIT = 0x0010;
pub const POSIX_SPAWN = 0x0020;
};
pub const PT = struct {
pub const TRACE_ME = 0;
pub const READ_I = 1;
pub const READ_D = 2;
pub const WRITE_I = 4;
pub const WRITE_D = 5;
pub const CONTINUE = 7;
pub const KILL = 8;
pub const ATTACH = 9;
pub const DETACH = 10;
pub const IO = 11;
pub const DUMPCORE = 11;
pub const LWPINFO = 12;
};
pub const ptrace_event = extern struct {
set_event: c_int,
};
pub const ptrace_state = extern struct {
report_event: c_int,
_option: extern union {
other_pid: pid_t,
lwp: lwpid_t,
},
};
pub const ptrace_io_desc = extern struct {
op: c_int,
offs: ?*anyopaque,
addr: ?*anyopaque,
len: usize,
};
pub const PIOD = struct {
pub const READ_D = 1;
pub const WRITE_D = 2;
pub const READ_I = 3;
pub const WRITE_I = 4;
};
pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: ?*anyopaque, data: c_int) c_int;
/// TODO refines if necessary
pub const PTHREAD_STACK_MIN = 16 * 1024;
pub const timer_t = *opaque {};

View File

@ -252,22 +252,16 @@ pub const EAI_MAX = 15;
pub const msghdr = extern struct {
/// optional address
name: ?*sockaddr,
/// size of address
namelen: socklen_t,
/// scatter/gather array
iov: [*]iovec,
/// # elements in msg_iov
/// # elements in iov
iovlen: c_uint,
/// ancillary data
control: ?*anyopaque,
/// ancillary data buffer len
controllen: socklen_t,
/// flags on received message
flags: c_int,
};
@ -275,22 +269,16 @@ pub const msghdr = extern struct {
pub const msghdr_const = extern struct {
/// optional address
name: ?*const sockaddr,
/// size of address
namelen: socklen_t,
/// scatter/gather array
iov: [*]const iovec_const,
/// # elements in msg_iov
/// # elements in iov
iovlen: c_uint,
/// ancillary data
control: ?*const anyopaque,
/// ancillary data buffer len
controllen: socklen_t,
/// flags on received message
flags: c_int,
};
@ -466,16 +454,6 @@ pub const MAP = struct {
pub const CONCEAL = 0x8000;
};
pub const MADV = struct {
pub const NORMAL = 0;
pub const RANDOM = 1;
pub const SEQUENTIAL = 2;
pub const WILLNEED = 3;
pub const DONTNEED = 4;
pub const SPACEAVAIL = 5;
pub const FREE = 6;
};
pub const MSF = struct {
pub const ASYNC = 1;
pub const INVALIDATE = 2;
@ -1102,56 +1080,57 @@ comptime {
}
pub usingnamespace switch (builtin.cpu.arch) {
.x86_64 => struct {
pub const ucontext_t = extern struct {
sc_rdi: c_long,
sc_rsi: c_long,
sc_rdx: c_long,
sc_rcx: c_long,
sc_r8: c_long,
sc_r9: c_long,
sc_r10: c_long,
sc_r11: c_long,
sc_r12: c_long,
sc_r13: c_long,
sc_r14: c_long,
sc_r15: c_long,
sc_rbp: c_long,
sc_rbx: c_long,
sc_rax: c_long,
sc_gs: c_long,
sc_fs: c_long,
sc_es: c_long,
sc_ds: c_long,
sc_trapno: c_long,
sc_err: c_long,
sc_rip: c_long,
sc_cs: c_long,
sc_rflags: c_long,
sc_rsp: c_long,
sc_ss: c_long,
sc_fpstate: *anyopaque, // struct fxsave64 *
__sc_unused: c_int,
sc_mask: c_int,
sc_cookie: c_long,
};
},
.aarch64 => struct {
pub const ucontext_t = extern struct {
__sc_unused: c_int,
sc_mask: c_int,
sc_sp: c_ulong,
sc_lr: c_ulong,
sc_elr: c_ulong,
sc_spsr: c_ulong,
sc_x: [30]c_ulong,
sc_cookie: c_long,
};
},
.x86_64 => struct {},
else => struct {},
};
pub const ucontext_t = switch (builtin.cpu.arch) {
.x86_64 => extern struct {
sc_rdi: c_long,
sc_rsi: c_long,
sc_rdx: c_long,
sc_rcx: c_long,
sc_r8: c_long,
sc_r9: c_long,
sc_r10: c_long,
sc_r11: c_long,
sc_r12: c_long,
sc_r13: c_long,
sc_r14: c_long,
sc_r15: c_long,
sc_rbp: c_long,
sc_rbx: c_long,
sc_rax: c_long,
sc_gs: c_long,
sc_fs: c_long,
sc_es: c_long,
sc_ds: c_long,
sc_trapno: c_long,
sc_err: c_long,
sc_rip: c_long,
sc_cs: c_long,
sc_rflags: c_long,
sc_rsp: c_long,
sc_ss: c_long,
sc_fpstate: *anyopaque, // struct fxsave64 *
__sc_unused: c_int,
sc_mask: c_int,
sc_cookie: c_long,
},
.aarch64 => extern struct {
__sc_unused: c_int,
sc_mask: c_int,
sc_sp: c_ulong,
sc_lr: c_ulong,
sc_elr: c_ulong,
sc_spsr: c_ulong,
sc_x: [30]c_ulong,
sc_cookie: c_long,
},
else => @compileError("missing ucontext_t type definition"),
};
pub const sigset_t = c_uint;
pub const empty_sigset: sigset_t = 0;
@ -1645,7 +1624,6 @@ pub const HW = struct {
pub const POWER = 26;
};
/// TODO refines if necessary
pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
.sparc64 => 1 << 13,
.mips64 => 1 << 14,

View File

@ -16,7 +16,6 @@ pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
pub extern "c" fn sysconf(sc: c_int) i64;
pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) c_int;
@ -183,36 +182,36 @@ pub const EAI_MAX = 14;
pub const msghdr = extern struct {
/// optional address
name: ?*sockaddr,
msg_name: ?*sockaddr,
/// size of address
namelen: socklen_t,
msg_namelen: socklen_t,
/// scatter/gather array
iov: [*]iovec,
msg_iov: [*]iovec,
/// # elements in msg_iov
iovlen: i32,
msg_iovlen: i32,
/// ancillary data
control: ?*anyopaque,
msg_control: ?*anyopaque,
/// ancillary data buffer len
controllen: socklen_t,
msg_controllen: socklen_t,
/// flags on received message
flags: i32,
msg_flags: i32,
};
pub const msghdr_const = extern struct {
/// optional address
name: ?*const sockaddr,
msg_name: ?*const sockaddr,
/// size of address
namelen: socklen_t,
msg_namelen: socklen_t,
/// scatter/gather array
iov: [*]const iovec_const,
msg_iov: [*]const iovec_const,
/// # elements in msg_iov
iovlen: i32,
msg_iovlen: i32,
/// ancillary data
control: ?*const anyopaque,
msg_control: ?*const anyopaque,
/// ancillary data buffer len
controllen: socklen_t,
msg_controllen: socklen_t,
/// flags on received message
flags: i32,
msg_flags: i32,
};
pub const cmsghdr = extern struct {
@ -1927,26 +1926,3 @@ pub fn IOW(io_type: u8, nr: u8, comptime IOT: type) i32 {
pub fn IOWR(io_type: u8, nr: u8, comptime IOT: type) i32 {
return ioImpl(.read_write, io_type, nr, IOT);
}
pub const SIGEV = struct {
pub const NONE = 0;
pub const SIGNAL = 1;
pub const THREAD = 2;
};
pub const sigval = extern union {
int: c_int,
ptr: ?*anyopaque,
};
pub const sigevent = extern struct {
sigev_notify: c_int,
sigev_signo: c_int,
sigev_value: sigval,
sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
sigev_notify_attributes: ?*pthread_attr_t,
};
pub const PTHREAD_STACK_MIN = if (@sizeOf(usize) == 8) 8 * 1024 else 4 * 1024;
pub const timer_t = *opaque {};

View File

@ -119,5 +119,3 @@ pub const POLL = struct {
pub const HUP = 0x2000;
pub const NVAL = 0x4000;
};
pub const PTHREAD_STACK_MIN = 16 * 1024;

View File

@ -2934,7 +2934,6 @@ pub const OpenSelfExeError = error{
/// On Windows, file paths cannot contain these characters:
/// '/', '*', '?', '"', '<', '>', '|'
BadPathName,
Overflow,
Unexpected,
} || os.OpenError || SelfExePathError || os.FlockError;
@ -3014,14 +3013,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
// TODO could this slice from 0 to out_len instead?
return mem.sliceTo(out_buffer, 0);
},
.haiku => {
// The only possible issue when looking for the self image path is
// when the buffer is too short.
if (os.find_path(os.B_APP_IMAGE_SYMBOL, os.path_base_directory.B_FIND_IMAGE_PATH, null, out_buffer.ptr, out_buffer.len) != 0)
return error.Overflow;
return mem.sliceTo(out_buffer, 0);
},
.openbsd => {
.openbsd, .haiku => {
// OpenBSD doesn't support getting the path of a running process, so try to guess it
if (os.argv.len == 0)
return error.FileNotFound;
@ -3120,7 +3112,7 @@ const CopyFileRawError = error{SystemResources} || os.CopyFileRangeError || os.S
// No metadata is transferred over.
fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t, maybe_size: ?u64) CopyFileRawError!void {
if (comptime builtin.target.isDarwin()) {
const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE.DATA);
const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);
switch (os.errno(rc)) {
.SUCCESS => return,
.INVAL => unreachable,

View File

@ -146,12 +146,7 @@ pub const addrinfo = system.addrinfo;
pub const blkcnt_t = system.blkcnt_t;
pub const blksize_t = system.blksize_t;
pub const clock_t = system.clock_t;
pub const cpu_set_t = if (builtin.os.tag == .linux)
system.cpu_set_t
else if (builtin.os.tag == .freebsd)
freebsd.cpuset_t
else
u32;
pub const cpu_set_t = system.cpu_set_t;
pub const dev_t = system.dev_t;
pub const dl_phdr_info = system.dl_phdr_info;
pub const empty_sigset = system.empty_sigset;
@ -517,18 +512,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
return;
}
switch (builtin.os.tag) {
.macos, .ios => {
const rc = darwin.CCRandomGenerateBytes(buffer.ptr, buffer.len);
if (rc != darwin.CCRNGStatus.kCCSuccess) {
if (rc == darwin.CCRNGStatus.kCCParamError or rc == darwin.CCRNGStatus.kCCBufferTooSmall) {
return error.InvalidHandle;
} else {
return error.SystemResources;
}
}
return;
},
.netbsd, .openbsd, .tvos, .watchos => {
.netbsd, .openbsd, .macos, .ios, .tvos, .watchos => {
system.arc4random_buf(buffer.ptr, buffer.len);
return;
},
@ -1001,7 +985,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
if (have_pread_but_not_preadv) {
// We could loop here; but proper usage of `preadv` must handle partial reads anyway.
// So we simply read into the first vector only.
if (iov.len == 0) return @as(usize, @intCast(0));
if (iov.len == 0) return 0;
const first = iov[0];
return pread(fd, first.iov_base[0..first.iov_len], offset);
}
@ -4707,8 +4691,11 @@ pub fn sysctl(
newp: ?*anyopaque,
newlen: usize,
) SysCtlError!void {
if (builtin.os.tag == .wasi or builtin.os.tag == .haiku) {
@compileError("unsupported OS");
if (builtin.os.tag == .wasi) {
@panic("unsupported"); // TODO should be compile error, not panic
}
if (builtin.os.tag == .haiku) {
@panic("unsupported"); // TODO should be compile error, not panic
}
const name_len = math.cast(c_uint, name.len) orelse return error.NameTooLong;
@ -4729,8 +4716,11 @@ pub fn sysctlbynameZ(
newp: ?*anyopaque,
newlen: usize,
) SysCtlError!void {
if (builtin.os.tag == .wasi or builtin.os.tag == .haiku) {
@compileError("unsupported OS");
if (builtin.os.tag == .wasi) {
@panic("unsupported"); // TODO should be compile error, not panic
}
if (builtin.os.tag == .haiku) {
@panic("unsupported"); // TODO should be compile error, not panic
}
switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) {
@ -5494,64 +5484,16 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
}
pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
pub const SchedSetAffinityError = error{ InvalidCpu, PermissionDenied } || UnexpectedError;
pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
var set: cpu_set_t = undefined;
if (builtin.os.tag == .linux) {
switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
.SUCCESS => return set,
.FAULT => unreachable,
.INVAL => unreachable,
.SRCH => unreachable,
.PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
} else if (builtin.os.tag == .freebsd) {
switch (errno(freebsd.cpuset_getaffinity(freebsd.CPU_LEVEL_WHICH, freebsd.CPU_WHICH_PID, pid, @sizeOf(cpu_set_t), &set))) {
.SUCCESS => return set,
.FAULT => unreachable,
.INVAL => unreachable,
.SRCH => unreachable,
.EDEADLK => unreachable,
.PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
} else {
@compileError("unsupported platform");
}
}
pub fn sched_setaffinity(pid: pid_t, cpus: []usize) SchedSetAffinityError!cpu_set_t {
var set: cpu_set_t = undefined;
if (builtin.os.tag == .linux) {
system.CPU_ZERO(&set);
for (cpus) |cpu| {
system.CPU_SET(cpu, &set);
}
switch (errno(system.sched_setaffinity(pid, @sizeOf(cpu_set_t), &set))) {
.SUCCESS => return set,
.FAULT => unreachable,
.SRCH => unreachable,
.INVAL => return error.InvalidCpu,
.PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
} else if (builtin.os.tag == .freebsd) {
freebsd.CPU_ZERO(&set);
for (cpus) |cpu| {
freebsd.CPU_SET(cpu, &set);
}
switch (errno(freebsd.cpuset_setaffinity(freebsd.CPU_LEVEL_WHICH, freebsd.CPU_WHICH_PID, pid, @sizeOf(cpu_set_t), &set))) {
.SUCCESS => return set,
.FAULT => unreachable,
.SRCH => unreachable,
.INVAL => return error.InvalidCpu,
.PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
} else {
@compileError("unsupported platform");
switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
.SUCCESS => return set,
.FAULT => unreachable,
.INVAL => unreachable,
.SRCH => unreachable,
.PERM => return error.PermissionDenied,
else => |err| return unexpectedErrno(err),
}
}
@ -5695,7 +5637,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
else => |err| return unexpectedErrno(err),
}
}
if (builtin.os.tag == .linux or builtin.os.tag == .macos or builtin.os.tag == .freebsd) {
if (builtin.os.tag == .linux) {
const uts = uname();
const hostname = mem.sliceTo(&uts.nodename, 0);
const result = name_buffer[0..hostname.len];

View File

@ -1520,28 +1520,6 @@ pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize {
return 0;
}
pub fn getcpu(cpu: *u32, node: *u32) usize {
return syscall3(.getcpu, @intFromPtr(cpu), @intFromPtr(node), 0);
}
pub fn sched_getcpu() usize {
var cpu: u32 = undefined;
const rc = syscall3(.getcpu, @intFromPtr(&cpu), 0, 0);
if (@as(isize, @bitCast(rc)) < 0) return rc;
return @as(usize, @intCast(cpu));
}
/// libc has no wrapper for this syscall
pub fn mbind(addr: ?*anyopaque, len: u32, mode: i32, nodemask: *const u32, maxnode: u32, flags: u32) usize {
return syscall6(.mbind, @intFromPtr(addr), len, @as(usize, @bitCast(@as(isize, mode))), @intFromPtr(nodemask), maxnode, flags);
}
pub fn sched_setaffinity(pid: pid_t, size: usize, set: *const cpu_set_t) usize {
const rc = syscall3(.sched_setaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set));
if (@as(isize, @bitCast(rc)) < 0) return rc;
return 0;
}
pub fn epoll_create() usize {
return epoll_create1(0);
}
@ -1591,43 +1569,6 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_va
return syscall4(.timerfd_settime, @as(usize, @bitCast(@as(isize, fd))), flags, @intFromPtr(new_value), @intFromPtr(old_value));
}
pub const sigevent = extern struct {
value: sigval,
signo: i32,
inotify: i32,
libc_priv_impl: opaque {},
};
// Flags for sigevent sigev_inotify's field
pub const SIGEV = enum(i32) {
NONE = 0,
SIGNAL = 1,
THREAD = 2,
THREAD_ID = 4,
};
pub const timer_t = ?*anyopaque;
pub fn timer_create(clockid: i32, sevp: *sigevent, timerid: *timer_t) usize {
var t: timer_t = undefined;
const rc = syscall3(.timer_create, @as(usize, @bitCast(@as(isize, clockid))), @intFromPtr(sevp), @intFromPtr(&t));
if (@as(isize, @bitCast(rc)) < 0) return rc;
timerid.* = t;
return rc;
}
pub fn timer_delete(timerid: timer_t) usize {
return syscall1(.timer_delete, timerid);
}
pub fn timer_gettime(timerid: timer_t, curr_value: *itimerspec) usize {
return syscall2(.timer_gettime, @intFromPtr(timerid), @intFromPtr(curr_value));
}
pub fn timer_settime(timerid: timer_t, flags: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
return syscall4(.timer_settime, @intFromPtr(timerid), @as(usize, @bitCast(@as(isize, flags))), @intFromPtr(new_value), @intFromPtr(old_value));
}
// Flags for the 'setitimer' system call
pub const ITIMER = enum(i32) {
REAL = 0,
@ -3597,11 +3538,6 @@ pub const CPU_SETSIZE = 128;
pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));
fn cpu_mask(s: usize) cpu_count_t {
var x = s & (CPU_SETSIZE * 8);
return @as(cpu_count_t, @intCast(1)) << @as(u4, @intCast(x));
}
pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
var sum: cpu_count_t = 0;
for (set) |x| {
@ -3610,32 +3546,6 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
return sum;
}
pub fn CPU_ZERO(set: *cpu_set_t) void {
@memset(set, 0);
}
pub fn CPU_SET(cpu: usize, set: *cpu_set_t) void {
const x = cpu / @sizeOf(usize);
if (x < @sizeOf(cpu_set_t)) {
(set.*)[x] |= cpu_mask(x);
}
}
pub fn CPU_ISSET(cpu: usize, set: cpu_set_t) bool {
const x = cpu / @sizeOf(usize);
if (x < @sizeOf(cpu_set_t)) {
return set[x] & cpu_mask(x) != 0;
}
return false;
}
pub fn CPU_CLR(cpu: usize, set: *cpu_set_t) void {
const x = cpu / @sizeOf(usize);
if (x < @sizeOf(cpu_set_t)) {
(set.*)[x] &= !cpu_mask(x);
}
}
pub const MINSIGSTKSZ = switch (native_arch) {
.x86, .x86_64, .arm, .mipsel => 2048,
.aarch64 => 5120,

View File

@ -1163,17 +1163,12 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
.linux => {
return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory;
},
.freebsd, .netbsd, .dragonfly, .macos => {
.freebsd => {
var physmem: c_ulong = undefined;
var len: usize = @sizeOf(c_ulong);
const name = switch (builtin.os.tag) {
.macos => "hw.memsize",
.netbsd => "hw.physmem64",
else => "hw.physmem",
};
os.sysctlbynameZ(name, &physmem, &len, null, 0) catch |err| switch (err) {
os.sysctlbynameZ("hw.physmem", &physmem, &len, null, 0) catch |err| switch (err) {
error.NameTooLong, error.UnknownName => unreachable,
else => return error.UnknownTotalSystemMemory,
else => |e| return e,
};
return @as(usize, @intCast(physmem));
},