diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 99e2feb4cf43..5036012fccad 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -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); diff --git a/lib/std/c.zig b/lib/std/c.zig index 149f3ab7e199..41075607c394 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -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 const max_align_t = if (builtin.abi == .msvc) f64 else if (builtin.target.isDarwin()) diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 0f60c2f841d4..9c1e1b1a2ffe 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -163,67 +163,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"; @@ -489,10 +435,6 @@ pub const VM_REGION_BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region pub const VM_REGION_EXTENDED_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_extended_info) / @sizeOf(natural_t); pub const VM_REGION_TOP_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_top_info) / @sizeOf(natural_t); -pub fn VM_MAKE_TAG(tag: u8) u32 { - return @as(u32, tag) << 24; -} - pub const vm_region_basic_info_64 = extern struct { protection: vm_prot_t, max_protection: vm_prot_t, @@ -907,21 +849,6 @@ pub const EAI = enum(c_int) { pub const EAI_MAX = 15; -pub const qos_class_t = enum(c_uint) { - /// highest priority QOS class for critical tasks - QOS_CLASS_USER_INTERACTIVE = 0x21, - /// slightly more moderate priority QOS class - QOS_CLASS_USER_INITIATED = 0x19, - /// default QOS class when none is set - QOS_CLASS_DEFAULT = 0x15, - /// more energy efficient QOS class than default - QOS_CLASS_UTILITY = 0x11, - /// QOS class more appropriate for background tasks - QOS_CLASS_BACKGROUND = 0x09, - /// QOS class as a return value - QOS_CLASS_UNSPECIFIED = 0x00, -}; - pub const pthread_mutex_t = extern struct { __sig: c_long = 0x32AAABA7, __opaque: [__PTHREAD_MUTEX_SIZE__]u8 = [_]u8{0} ** __PTHREAD_MUTEX_SIZE__, @@ -946,40 +873,8 @@ pub const pthread_attr_t = extern struct { pub extern "c" fn pthread_threadid_np(thread: ?std.c.pthread_t, thread_id: *u64) c_int; pub extern "c" fn pthread_setname_np(name: [*:0]const u8) E; pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; -pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int; -pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int; -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; @@ -3896,280 +3791,3 @@ pub fn machTaskForPid(pid: std.os.pid_t) MachError!MachTask { pub fn machTaskForSelf() MachTask { return .{ .port = mach_task_self() }; } - -pub const os_signpost_id_t = u64; - -pub const OS_SIGNPOST_ID_NULL: os_signpost_id_t = 0; -pub const OS_SIGNPOST_ID_INVALID: os_signpost_id_t = !0; -pub const OS_SIGNPOST_ID_EXCLUSIVE: os_signpost_id_t = 0xeeeeb0b5b2b2eeee; - -pub const os_log_t = opaque {}; -pub const os_log_type_t = enum(u8) { - /// default messages always captures - OS_LOG_TYPE_DEFAULT = 0x00, - /// messages with additional infos - OS_LOG_TYPE_INFO = 0x01, - /// debug messages - OS_LOG_TYPE_DEBUG = 0x02, - /// error messages - OS_LOG_TYPE_ERROR = 0x10, - /// unexpected conditions messages - OS_LOG_TYPE_FAULT = 0x11, -}; - -pub const OS_LOG_CATEGORY_POINTS_OF_INTEREST: *const u8 = "PointsOfInterest"; -pub const OS_LOG_CATEGORY_DYNAMIC_TRACING: *const u8 = "DynamicTracing"; -pub const OS_LOG_CATEGORY_DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing"; - -pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t; -pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool; -pub extern "c" fn os_signpost_id_generate(log: os_log_t) os_signpost_id_t; -pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void; -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; diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index f18e1932257b..d4f2867fda3a 100644 --- a/lib/std/c/dragonfly.zig +++ b/lib/std/c/dragonfly.zig @@ -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 {}; diff --git a/lib/std/c/emscripten.zig b/lib/std/c/emscripten.zig index 8b9fd8c2a27d..0d78d4d73f27 100644 --- a/lib/std/c/emscripten.zig +++ b/lib/std/c/emscripten.zig @@ -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; diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig index 16b404fbdaa0..84891be74cfc 100644 --- a/lib/std/c/freebsd.zig +++ b/lib/std/c/freebsd.zig @@ -5,80 +5,12 @@ const maxInt = std.math.maxInt; const iovec = std.os.iovec; const iovec_const = std.os.iovec_const; -pub const CPU_SETSIZE = 256; -pub const cpuset_t = extern struct { - __bits: [(CPU_SETSIZE + (@bitSizeOf(c_long) - 1)) / @bitSizeOf(c_long)]c_long, -}; - -fn __BIT_COUNT(bits: []const c_long) c_long { - var count: c_long = 0; - for (bits) |b| { - count += @popCount(b); - } - return count; -} - -fn __BIT_MASK(s: usize) c_long { - var x = s % CPU_SETSIZE; - return @as(c_long, @bitCast(@as(c_ulong, @intCast(1)) << @as(u6, @intCast(x)))); -} - -pub fn CPU_COUNT(set: cpuset_t) c_int { - return @as(c_int, @intCast(__BIT_COUNT(set.__bits[0..]))); -} - -pub fn CPU_ZERO(set: *cpuset_t) void { - @memset((set.*).__bits[0..], 0); -} - -pub fn CPU_SET(cpu: usize, set: *cpuset_t) void { - const x = cpu / @sizeOf(c_long); - if (x < @sizeOf(cpuset_t)) { - (set.*).__bits[x] |= __BIT_MASK(x); - } -} - -pub fn CPU_ISSET(cpu: usize, set: cpuset_t) bool { - const x = cpu / @sizeOf(c_long); - if (x < @sizeOf(cpuset_t)) { - return set.__bits[x] & __BIT_MASK(x) != 0; - } - return false; -} - -pub fn CPU_CLR(cpu: usize, set: *cpuset_t) void { - const x = cpu / @sizeOf(c_long); - if (x < @sizeOf(cpuset_t)) { - (set.*).__bits[x] &= !__BIT_MASK(x); - } -} - -pub const cpulevel_t = c_int; -pub const cpuwhich_t = c_int; -pub const id_t = i64; - -pub const CPU_LEVEL_ROOT: cpulevel_t = 1; -pub const CPU_LEVEL_CPUSET: cpulevel_t = 2; -pub const CPU_LEVEL_WHICH: cpulevel_t = 3; -pub const CPU_WHICH_TID: cpuwhich_t = 1; -pub const CPU_WHICH_PID: cpuwhich_t = 2; -pub const CPU_WHICH_CPUSET: cpuwhich_t = 3; -pub const CPU_WHICH_IRQ: cpuwhich_t = 4; -pub const CPU_WHICH_JAIL: cpuwhich_t = 5; -pub const CPU_WHICH_DOMAIN: cpuwhich_t = 6; -pub const CPU_WHICH_INTRHANDLER: cpuwhich_t = 7; -pub const CPU_WHICH_ITHREAD: cpuwhich_t = 8; -pub const CPU_WHICH_TIDPID: cpuwhich_t = 8; - extern "c" fn __error() *c_int; pub const _errno = __error; -pub extern "c" var malloc_options: [*:0]const u8; - -pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize; +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 getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize; -pub extern "c" fn getentropy(buf_ptr: [*]u8, buf_len: usize) c_int; pub extern "c" fn pthread_getthreadid_np() c_int; pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void; @@ -88,21 +20,10 @@ pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; 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 extern "c" fn reallocf(?*anyopaque, usize) ?*anyopaque; pub extern "c" fn getpid() pid_t; pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file; -pub extern "c" fn kinfo_getvmmap(pid: pid_t, cntp: *c_int) ?[*]kinfo_vmentry; -pub extern "c" fn kinfo_getproc(pid: pid_t) ?*kinfo_proc; -pub extern "c" fn kinfo_getvmobject(cntp: *c_int) ?[*]kinfo_vmobject; -pub extern "c" fn kinfo_getswapvmobject(cntp: *c_int) ?[*]kinfo_vmobject; - -pub extern "c" fn cpuset_getaffinity(level: cpulevel_t, which: cpuwhich_t, id: id_t, setsize: usize, mask: *cpuset_t) c_int; -pub extern "c" fn cpuset_setaffinity(level: cpulevel_t, which: cpuwhich_t, id: id_t, setsize: usize, mask: *const cpuset_t) c_int; -pub extern "c" fn sched_getaffinity(pid: pid_t, cpusetsz: usize, cpuset: *cpuset_t) c_int; -pub extern "c" fn sched_setaffinity(pid: pid_t, cpusetsz: usize, cpuset: *const cpuset_t) c_int; -pub extern "c" fn sched_getcpu() c_int; pub const sf_hdtr = extern struct { headers: [*]const iovec_const, @@ -355,36 +276,36 @@ 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, /// Number of elements in msg_iov. - iovlen: i32, + msg_iovlen: i32, /// Ancillary data. - control: ?*anyopaque, + msg_control: ?*anyopaque, /// Ancillary data buffer length. - 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: [*]iovec_const, + msg_iov: [*]iovec_const, /// Number of elements in msg_iov. - iovlen: i32, + msg_iovlen: i32, /// Ancillary data. - control: ?*anyopaque, + msg_control: ?*anyopaque, /// Ancillary data buffer length. - controllen: socklen_t, + msg_controllen: socklen_t, /// Flags on received message. - flags: i32, + msg_flags: i32, }; pub const Stat = extern struct { @@ -523,43 +444,10 @@ pub const sockaddr = extern struct { pub const CAP_RIGHTS_VERSION = 0; -pub const cap_rights_t = extern struct { - cr_rights: [CAP_RIGHTS_VERSION + 2]u64, +pub const cap_rights = extern struct { + rights: [CAP_RIGHTS_VERSION + 2]u64, }; -pub const CAP = struct { - pub fn RIGHT(idx: u6, bit: u64) u64 { - return (@as(u64, @intCast(1)) << (57 + idx)) | bit; - } - pub const READ = CAP.RIGHT(0, 0x0000000000000001); - pub const WRITE = CAP.RIGHT(0, 0x0000000000000002); - pub const SEEK_TELL = CAP.RIGHT(0, 0x0000000000000004); - pub const SEEK = CAP.SEEK_TELL | 0x0000000000000008; - pub const PREAD = CAP.SEEK | CAP.READ; - pub const PWRITE = CAP.SEEK | CAP.WRITE; - pub const MMAP = CAP.RIGHT(0, 0x0000000000000010); - pub const MMAP_R = CAP.MMAP | CAP.SEEK | CAP.READ; - pub const MMAP_W = CAP.MMAP | CAP.SEEK | CAP.WRITE; - pub const MMAP_X = CAP.MMAP | CAP.SEEK | 0x0000000000000020; - pub const MMAP_RW = CAP.MMAP_R | CAP.MMAP_W; - pub const MMAP_RX = CAP.MMAP_R | CAP.MMAP_X; - pub const MMAP_WX = CAP.MMAP_W | CAP.MMAP_X; - pub const MMAP_RWX = CAP.MMAP_R | CAP.MMAP_W | CAP.MMAP_X; - pub const CREATE = CAP.RIGHT(0, 0x0000000000000040); - pub const FEXECVE = CAP.RIGHT(0, 0x0000000000000080); - pub const FSYNC = CAP.RIGHT(0, 0x0000000000000100); - pub const FTRUNCATE = CAP.RIGHT(0, 0x0000000000000200); -}; - -pub extern "c" fn __cap_rights_init(version: c_int, rights: ?*cap_rights_t, ...) ?*cap_rights_t; -pub extern "c" fn __cap_rights_set(rights: ?*cap_rights_t, ...) ?*cap_rights_t; -pub extern "c" fn __cap_rights_clear(rights: ?*cap_rights_t, ...) ?*cap_rights_t; -pub extern "c" fn __cap_rights_is_set(rights: ?*const cap_rights_t, ...) bool; -pub extern "c" fn cap_rights_merge(dst: ?*cap_rights_t, src: ?*const cap_rights_t) ?*cap_rights_t; -pub extern "c" fn cap_rights_remove(dst: ?*cap_rights_t, src: ?*const cap_rights_t) ?*cap_rights_t; -pub extern "c" fn cap_rights_contains(dst: ?*const cap_rights_t, src: ?*const cap_rights_t) bool; -pub extern "c" fn cap_rights_is_valid(rights: ?*const cap_rights_t) bool; - pub const kinfo_file = extern struct { /// Size of this record. /// A zero value is for the sentinel record at the end of an array. @@ -661,7 +549,7 @@ pub const kinfo_file = extern struct { // Reserved for future use. _spare: c_int, /// Capability rights. - cap_rights: cap_rights_t, + cap_rights: cap_rights, /// Reserved for future cap_rights _cap_spare: u64, /// Path to file, if any. @@ -675,248 +563,6 @@ comptime { std.debug.assert(@alignOf(kinfo_file) == @sizeOf(u64)); } -pub const kinfo_vmentry = extern struct { - structsize: c_int, - type: c_int, - start: u64, - end: u64, - offset: u64, - vn_fileid: u64, - vn_fsid_freebsd11: u32, - flags: c_int, - resident: c_int, - private_resident: c_int, - protection: c_int, - ref_count: c_int, - shadow_count: c_int, - vn_type: c_int, - vn_size: u64, - vn_rdev_freebsd11: u32, - vn_mode: u16, - status: u16, - type_spec: extern union { - _vn_fsid: u64, - _obj: u64, - }, - vn_rdev: u64, - _ispare: [8]c_int, - rpath: [PATH_MAX]u8, -}; - -pub const KINFO_VMENTRY_SIZE = 1160; - -comptime { - std.debug.assert(@sizeOf(kinfo_vmentry) == KINFO_VMENTRY_SIZE); -} - -pub const WMESGLEN = 8; -pub const LOCKNAMELEN = 8; -pub const TDNAMLEN = 16; -pub const COMMLEN = 19; -pub const MAXCOMLEN = 19; -pub const KI_EMULNAMELEN = 16; -pub const KI_NGROUPS = 16; -pub const LOGNAMELEN = 17; -pub const LOGINCLASSLEN = 17; - -pub const KI_NSPARE_INT = 2; -pub const KI_NSPARE_LONG = 12; -pub const KI_NSPARE_PTR = 5; - -pub const RUSAGE_SELF = 0; -pub const RUSAGE_CHILDREN = -1; -pub const RUSAGE_THREAD = 1; - -pub const proc = opaque {}; -pub const thread = opaque {}; -pub const vnode = opaque {}; -pub const filedesc = opaque {}; -pub const pwddesc = opaque {}; -pub const vmspace = opaque {}; -pub const pcb = opaque {}; -pub const lwpid_t = i32; -pub const fixpt_t = u32; -pub const vm_size_t = usize; -pub const segsz_t = isize; - -pub const itimerval = extern struct { - interval: timeval, - value: timeval, -}; - -pub const pstats = extern struct { - cru: rusage, - timer: [3]itimerval, - prof: extern struct { - base: u8, - size: c_ulong, - off: c_ulong, - scale: c_ulong, - }, - start: timeval, -}; - -pub const user = extern struct { - stats: pstats, - kproc: kinfo_proc, -}; - -pub const pargs = extern struct { - ref: c_uint, - length: c_uint, - args: [1]u8, -}; - -pub const priority = extern struct { - class: u8, - level: u8, - native: u8, - user: u8, -}; - -pub const rusage = extern struct { - utime: timeval, - stime: timeval, - maxrss: c_long, - ixrss: c_long, - idrss: c_long, - isrss: c_long, - minflt: c_long, - majflt: c_long, - nswap: c_long, - inblock: c_long, - oublock: c_long, - msgsnd: c_long, - msgrcv: c_long, - nsignals: c_long, - nvcsw: c_long, - nivcsw: c_long, -}; - -pub const kinfo_proc = extern struct { - structsize: c_int, - layout: c_int, - args: *pargs, - paddr: *proc, - addr: *user, - tracep: *vnode, - textvp: *vnode, - fd: *filedesc, - vmspace: *vmspace, - wchan: ?*const anyopaque, - pid: pid_t, - ppid: pid_t, - pgid: pid_t, - tpgid: pid_t, - sid: pid_t, - tsid: pid_t, - jobc: c_short, - spare_short1: c_short, - tdev_freebsd11: u32, - siglist: sigset_t, - sigmask: sigset_t, - sigignore: sigset_t, - sigcatch: sigset_t, - uid: uid_t, - ruid: uid_t, - svuid: uid_t, - rgid: gid_t, - svgid: gid_t, - ngroups: c_short, - spare_short2: c_short, - groups: [KI_NGROUPS]gid_t, - size: vm_size_t, - rssize: segsz_t, - swrss: segsz_t, - tsize: segsz_t, - dsize: segsz_t, - ssize: segsz_t, - xstat: c_ushort, - acflag: c_ushort, - pctcpu: fixpt_t, - estcpu: c_uint, - slptime: c_uint, - swtime: c_uint, - cow: c_uint, - runtime: u64, - start: timeval, - childtime: timeval, - flag: c_long, - kiflag: c_long, - traceflag: c_int, - stat: u8, - nice: i8, - lock: u8, - rqindex: u8, - oncpu_old: u8, - lastcpu_old: u8, - tdname: [TDNAMLEN + 1]u8, - wmesg: [WMESGLEN + 1]u8, - login: [LOGNAMELEN + 1]u8, - lockname: [LOCKNAMELEN + 1]u8, - comm: [COMMLEN + 1]u8, - emul: [KI_EMULNAMELEN + 1]u8, - loginclass: [LOGINCLASSLEN + 1]u8, - moretdname: [MAXCOMLEN - TDNAMLEN + 1]u8, - sparestrings: [46]u8, - spareints: [KI_NSPARE_INT]c_int, - tdev: u64, - oncpu: c_int, - lastcpu: c_int, - tracer: c_int, - flag2: c_int, - fibnum: c_int, - cr_flags: c_uint, - jid: c_int, - numthreads: c_int, - tid: lwpid_t, - pri: priority, - rusage: rusage, - rusage_ch: rusage, - pcb: *pcb, - stack: ?*anyopaque, - udata: ?*anyopaque, - tdaddr: *thread, - pd: *pwddesc, - spareptrs: [KI_NSPARE_PTR]?*anyopaque, - sparelongs: [KI_NSPARE_LONG]c_long, - sflag: c_long, - tdflag: c_long, -}; - -pub const KINFO_PROC_SIZE = switch (builtin.cpu.arch) { - .x86 => 768, - .arm => 816, - else => 1088, -}; - -comptime { - assert(@sizeOf(kinfo_proc) == KINFO_PROC_SIZE); -} - -pub const kinfo_vmobject = extern struct { - structsize: c_int, - tpe: c_int, - size: u64, - vn_fileid: u64, - vn_fsid_freebsd11: u32, - ref_count: c_int, - shadow_count: c_int, - memattr: c_int, - resident: u64, - active: u64, - inactive: u64, - type_spec: extern union { - _vn_fsid: u64, - _backing_obj: u64, - }, - me: u64, - _qspare: [6]u64, - swapped: u32, - _ispare: [7]u32, - path: [PATH_MAX]u8, -}; - pub const CTL = struct { pub const KERN = 1; pub const DEBUG = 5; @@ -976,25 +622,6 @@ pub const MAP = struct { pub const NOCORE = 0x00020000; pub const PREFAULT_READ = 0x00040000; pub const @"32BIT" = 0x00080000; - - pub fn ALIGNED(alignment: u32) u32 { - return alignment << 24; - } - pub const ALIGNED_SUPER = ALIGNED(1); -}; - -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 FREE = 5; - pub const NOSYNC = 6; - pub const AUTOSYNC = 7; - pub const NOCORE = 8; - pub const CORE = 9; - pub const PROTECT = 10; }; pub const MSF = struct { @@ -1396,11 +1023,6 @@ pub const DT = struct { pub const WHT = 14; }; -pub const accept_filter = extern struct { - af_name: [16]u8, - af_args: [240]u8, -}; - /// add event to kq (implies enable) pub const EV_ADD = 0x0001; @@ -1682,47 +1304,15 @@ pub const mcontext_t = switch (builtin.cpu.arch) { rflags: u64, rsp: u64, ss: u64, - len: c_long, - fpformat: c_long, - ownedfp: c_long, - fpstate: [64]c_long align(16), + len: u64, + fpformat: u64, + ownedfp: u64, + fpstate: [64]u64 align(16), fsbase: u64, gsbase: u64, xfpustate: u64, xfpustate_len: u64, - spare: [4]c_long, - }, - .x86 => extern struct { - onstack: u32, - gs: u32, - fs: u32, - es: u32, - ds: u32, - edi: u32, - esi: u32, - ebp: u32, - isp: u32, - ebx: u32, - edx: u32, - ecx: u32, - eax: u32, - trapno: u32, - err: u32, - eip: u32, - cs: u32, - eflags: u32, - esp: u32, - ss: u32, - len: c_int, - fpformat: c_int, - ownedfp: c_int, - flags: u32, - fpstate: [128]c_int align(16), - fsbase: u32, - gsbase: u32, - xpustate: u32, - xpustate_len: u32, - spare2: [4]c_int, + spare: [4]u64, }, .aarch64 => extern struct { gpregs: extern struct { @@ -2002,45 +1592,6 @@ pub const AT = struct { pub const REMOVEDIR = 0x0800; /// Fail if not under dirfd pub const BENEATH = 0x1000; - /// elf_common constants - pub const NULL = 0; - pub const IGNORE = 1; - pub const EXECFD = 2; - pub const PHDR = 3; - pub const PHENT = 4; - pub const PHNUM = 5; - pub const PAGESZ = 6; - pub const BASE = 7; - pub const FLAGS = 8; - pub const ENTRY = 9; - pub const NOTELF = 10; - pub const UID = 11; - pub const EUID = 12; - pub const GID = 13; - pub const EGID = 14; - pub const EXECPATH = 15; - pub const CANARY = 16; - pub const CANARYLEN = 17; - pub const OSRELDATE = 18; - pub const NCPUS = 19; - pub const PAGESIZES = 20; - pub const PAGESIZESLEN = 21; - pub const TIMEKEEP = 22; - pub const STACKPROT = 23; - pub const EHDRFLAGS = 24; - pub const HWCAP = 25; - pub const HWCAP2 = 26; - pub const BSDFLAGS = 27; - pub const ARGC = 28; - pub const ARGV = 29; - pub const ENVC = 30; - pub const ENVV = 31; - pub const PS_STRINGS = 32; - pub const FXRNG = 33; - pub const KPRLOAD = 34; - pub const USRSTACKBASE = 35; - pub const USRSTACKLIM = 36; - pub const COUNT = 37; }; pub const addrinfo = extern struct { @@ -2373,468 +1924,7 @@ pub const NAME_MAX = 255; pub const MFD = struct { pub const CLOEXEC = 0x0001; pub const ALLOW_SEALING = 0x0002; - pub const HUGETLB = 0x00000004; - pub const HUGE_MASK = 0xFC000000; - pub const HUGE_SHIFT = 26; - pub const HUGE_64KB = 16 << HUGE_SHIFT; - pub const HUGE_512KB = 19 << HUGE_SHIFT; - pub const HUGE_1MB = 20 << HUGE_SHIFT; - pub const HUGE_2MB = 21 << HUGE_SHIFT; - pub const HUGE_8MB = 23 << HUGE_SHIFT; - pub const HUGE_16MB = 24 << HUGE_SHIFT; - pub const HUGE_32MB = 25 << HUGE_SHIFT; - pub const HUGE_256MB = 28 << HUGE_SHIFT; - pub const HUGE_512MB = 29 << HUGE_SHIFT; - pub const HUGE_1GB = 30 << HUGE_SHIFT; - pub const HUGE_2GB = 31 << HUGE_SHIFT; - pub const HUGE_16GB = 34 << HUGE_SHIFT; }; pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int; pub extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*off_t, fd_out: fd_t, off_out: ?*off_t, len: usize, flags: u32) usize; - -pub const idtype_t = enum(c_int) { - P_PID = 0, - P_PPID = 1, - P_PGID = 2, - P_SID = 3, - P_CID = 4, - P_UID = 5, - P_GID = 6, - P_ALL = 7, - P_LWPID = 8, - P_TASKID = 9, - P_PROJID = 10, - P_POOLID = 11, - P_JAILID = 12, - P_CTID = 13, - P_CPUID = 14, - P_PSETID = 15, -}; - -pub const PROC = struct { - // constants for the id_t argument - pub const SPROTECT: id_t = 1; - pub const REAP_ACQUIRE: id_t = 2; - pub const REAP_RELEASE: id_t = 3; - pub const REAP_STATUS: id_t = 4; - pub const REAP_GETPIDS: id_t = 5; - pub const REAP_KILL: id_t = 6; - pub const TRACE_CTL: id_t = 7; - pub const TRACE_STATUS: id_t = 8; - pub const TRACECAP_CTL = 9; - pub const TRACECAP_STATUS: id_t = 10; - pub const PDEATHSIG_CTL: id_t = 11; - pub const PDEATHSIG_STATUS: id_t = 12; - pub const ASLR_CTL: id_t = 13; - pub const ASLR_STATUS: id_t = 14; - pub const PROTMAX_CTL: id_t = 15; - pub const PROTMAX_STATUS: id_t = 16; - pub const STACKGAP_CTL: id_t = 17; - pub const STACKGAP_STATUS: id_t = 18; - pub const NO_NEW_PRIVS_CTL: id_t = 19; - pub const NO_NEW_PRIVS_STATUS: id_t = 20; - pub const WXMAP_CTL: id_t = 21; - pub const WXMAP_STATUS: id_t = 22; - - // constants for the operations - pub const TRACE_CTL_ENABLE = 1; - pub const TRACE_CTL_DISABLE = 2; - pub const TRACE_CTL_DISABLE_EXEC = 3; - pub const TRAPCAP_CTL_ENABLE = 1; - pub const TRAPCAP_CTL_DISABLE = 2; - pub const ASLR_FORCE_ENABLE = 1; - pub const ASLR_FORCE_DISABLE = 2; - pub const ASLR_FORCE_NOFORCE = 3; - pub const ASLR_FORCE_ACTIVE = 0x80000000; - pub const PROTMAX_FORCE_ENABLE = 1; - pub const PROTMAX_FORCE_DISABLE = 2; - pub const PROTMAX_FORCE_NOFORCE = 3; - pub const PROTMAX_FORCE_ACTIVE = 0x80000000; - pub const STACKGAP_ENABLE = 0x0001; - pub const STACKGAP_DISABLE = 0x0002; - pub const STACKGAP_ENABLE_EXEC = 0x0004; - pub const STACKGAP_DISABLE_EXEC = 0x0008; - pub const NO_NEW_PRIVS_ENABLE = 1; - pub const NO_NEW_PRIVS_DISABLE = 2; - pub const WX_MAPPINGS_PERMIT = 0x0001; - pub const WX_MAPPINGS_DISALLOW_EXEC = 0x0002; - pub const WX_MAPPINGS_ENFORCE = 0x80000000; - pub const PROCCTL_MD_MIN = 0x10000000; - // x86_64-only constants - pub const KPTI = switch (builtin.cpu.arch) { - .x86_64 => struct { - pub const CTL = PROC.PROCCTL_MD_MIN; - pub const STATUS = PROC.PROCCTL_MD_MIN + 1; - pub const CTL_ENABLE_ON_EXEC = 1; - pub const CTL_DISABLE_ON_EXEC = 2; - pub const STATUS_ACTIVE = 0x80000000; - }, - else => void, - }; - pub const LA = switch (builtin.cpu.arch) { - .x86_64 => struct { - pub const CTL = PROC.PROCCTL_MD_MIN + 2; - pub const STATUS = PROC.PROCCTL_MD_MIN + 3; - pub const CTL_LA48_ON_EXEC = 1; - pub const CTL_LA57_ON_EXEC = 2; - pub const CTL_DEFAULT_ON_EXEC = 3; - pub const STATUS_LA48 = 0x01000000; - pub const STATUS_LA57 = 0x02000000; - }, - else => void, - }; -}; - -pub const PPROT = struct { - pub fn OP(x: i32) i32 { - return x & 0xf; - } - pub const SET = 1; - pub const CLEAR = 2; - pub fn FLAGS(x: i32) i32 { - return x & !0xf; - } - pub const DESCEND = 0x10; - pub const INHERIT = 0x20; -}; - -pub const REAPER = struct { - pub const STATUS_OWNED = 0x00000001; - pub const STATUS_REALINIT = 0x00000002; - pub const PIDINFO_VALID = 0x00000001; - pub const PIDINFO_CHILD = 0x00000002; - pub const PIDINFO_REAPER = 0x00000004; - pub const KILL_CHILDREN = 0x00000001; - pub const KILL_SUBTREE = 0x00000002; -}; - -pub const procctl_reaper_status = extern struct { - rs_flags: u32, - rs_children: u32, - rs_descendants: u32, - rs_reaper: pid_t, - rs_pid: pid_t, - rs_pad0: [15]u32, -}; - -pub const procctl_reaper_pidinfo = extern struct { - pi_pid: pid_t, - pi_subtree: pid_t, - pi_flags: u32, - pi_pad0: [15]u32, -}; - -pub const procctl_reaper_pids = extern struct { - rp_count: u32, - rp_pad0: [15]u32, - rp_pids: [*]procctl_reaper_pidinfo, -}; - -pub const procctl_reaper_kill = extern struct { - rk_sig: c_int, - rk_flags: u32, - rk_subtree: pid_t, - rk_killed: u32, - rk_fpid: pid_t, - rk_pad0: [15]u32, -}; - -pub extern "c" fn procctl(idtype: idtype_t, id: id_t, cmd: c_int, data: ?*anyopaque) c_int; - -pub const SHM = struct { - pub const ALLOW_SEALING = 0x00000001; - pub const GROW_ON_WRWITE = 0x00000002; - pub const LARGEPAGE = 0x00000004; - pub const LARGEPAGE_ALLOC_DEFAULT = 0; - pub const LARGEPAGE_ALLOC_NOWAIT = 1; - pub const LARGEPAGE_ALLOC_HARD = 2; -}; - -pub const shm_largeconf = extern struct { - psind: c_int, - alloc_policy: c_int, - pad: [10]c_int, -}; - -pub extern "c" fn shm_create_largepage(path: [*:0]const u8, flags: c_int, psind: c_int, alloc_policy: c_int, mode: mode_t) c_int; - -pub extern "c" fn elf_aux_info(aux: c_int, buf: ?*anyopaque, buflen: c_int) c_int; - -pub const lwpid = i32; - -pub const SIGEV = struct { - pub const NONE = 0; - pub const SIGNAL = 1; - pub const THREAD = 2; - pub const KEVENT = 3; - pub const THREAD_ID = 4; -}; - -pub const sigevent = extern struct { - sigev_notify: c_int, - sigev_signo: c_int, - sigev_value: sigval, - _sigev_un: extern union { - _threadid: lwpid, - _sigev_thread: extern struct { - _function: ?*const fn (sigval) callconv(.C) void, - _attribute: ?**pthread_attr_t, - }, - _kevent_flags: c_ushort, - __spare__: [8]c_long, - }, -}; - -pub const timer_t = *opaque {}; - -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 SUPER = 0x60; - pub fn PSIND(i: u32) u32 { - return (i << 5) & SUPER; - } -}; - -pub extern "c" fn mincore( - addr: *align(std.mem.page_size) const anyopaque, - length: usize, - vec: [*]u8, -) c_int; - -pub const MAXMEMDOM = 8; -pub const domainid_t = u8; - -pub const LIST_ENTRY = opaque {}; - -pub const DOMAINSET = struct { - pub const POLICY_INVALID = 0; - pub const POLICY_ROUNDROBIN = 1; - pub const POLICY_FIRSTOUCH = 2; - pub const POLICY_PREFER = 3; - pub const POLICY_INTERLEAVE = 4; - pub const POLICY_MAX = DOMAINSET.POLICY_INTERLEAVE; -}; - -pub const DOMAINSET_SIZE = 256; -pub const domainset_t = extern struct { - __bits: [(DOMAINSET_SIZE + (@sizeOf(domainset) - 1)) / @bitSizeOf(domainset)]domainset, -}; - -pub fn DOMAINSET_COUNT(set: domainset_t) c_int { - return @as(c_int, @intCast(__BIT_COUNT(set.__bits[0..]))); -} - -pub const domainset = extern struct { - link: LIST_ENTRY, - mask: domainset_t, - policy: u16, - prefer: domainid_t, - cnt: domainid_t, - order: [MAXMEMDOM]domainid_t, -}; - -pub extern "c" fn cpuset_getdomain(level: cpulevel_t, which: cpuwhich_t, id: id_t, len: usize, domain: *domainset_t, r: *c_int) c_int; -pub extern "c" fn cpuset_setdomain(level: cpulevel_t, which: cpuwhich_t, id: id_t, len: usize, domain: *const domainset_t, r: c_int) c_int; - -const ioctl_cmd = enum(u32) { - VOID = 0x20000000, - OUT = 0x40000000, - IN = 0x80000000, - INOUT = ioctl_cmd.IN | ioctl_cmd.OUT, - DIRMASK = ioctl_cmd.VOID | ioctl_cmd.IN | ioctl_cmd.OUT, -}; - -fn ioImpl(cmd: ioctl_cmd, op: u8, nr: u8, comptime IT: type) u32 { - return @as(u32, @bitCast(@intFromEnum(cmd) | @as(u32, @intCast(@as(u8, @truncate(@sizeOf(IT))))) << 16 | @as(u32, @intCast(op)) << 8 | nr)); -} - -pub fn IO(op: u8, nr: u8) u32 { - return ioImpl(ioctl_cmd.VOID, op, nr, 0); -} - -pub fn IOR(op: u8, nr: u8, comptime IT: type) u32 { - return ioImpl(ioctl_cmd.OUT, op, nr, @sizeOf(IT)); -} - -pub fn IOW(op: u8, nr: u8, comptime IT: type) u32 { - return ioImpl(ioctl_cmd.IN, op, nr, @sizeOf(IT)); -} - -pub fn IOWR(op: u8, nr: u8, comptime IT: type) u32 { - return ioImpl(ioctl_cmd.INOUT, op, nr, @sizeOf(IT)); -} - -pub const RF = struct { - pub const NAMEG = 1 << 0; - pub const ENVG = 1 << 1; - /// copy file descriptors table - pub const FDG = 1 << 2; - pub const NOTEG = 1 << 3; - /// creates a new process - pub const PROC = 1 << 4; - /// shares address space - pub const MEM = 1 << 5; - /// detaches the child - pub const NOWAIT = 1 << 6; - pub const CNAMEG = 1 << 10; - pub const CENVG = 1 << 11; - /// distinct file descriptor table - pub const CFDG = 1 << 12; - /// thread support - pub const THREAD = 1 << 13; - /// shares signal handlers - pub const SIGSHARE = 1 << 14; - /// emits SIGUSR1 on exit - pub const LINUXTHPN = 1 << 16; - /// child in stopped state - pub const STOPPED = 1 << 17; - /// use high pid id - pub const HIGHPID = 1 << 18; - /// selects signal flag for parent notification - pub const SIGSZMB = 1 << 19; - pub fn SIGNUM(f: u32) u32 { - return f >> 20; - } - pub fn SIGFLAGS(f: u32) u32 { - return f << 20; - } -}; - -pub extern "c" fn rfork(flags: c_int) c_int; - -pub const PTRACE = struct { - pub const EXC = 0x0001; - pub const SCE = 0x0002; - pub const SCX = 0x0004; - pub const SYSCALL = (PTRACE.SCE | PTRACE.SCX); - pub const FORK = 0x0008; - pub const LWP = 0x0010; - pub const VFORK = 0x0020; - pub const DEFAULT = PTRACE.EXEC; -}; - -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 STEP = 9; - pub const ATTACH = 10; - pub const DETACH = 11; - pub const IO = 12; - pub const LWPINFO = 13; - pub const GETNUMLWPS = 14; - pub const GETLWPLIST = 15; - pub const CLEARSTEP = 16; - pub const SETSTEP = 17; - pub const SUSPEND = 18; - pub const RESUME = 19; - pub const TO_SCE = 20; - pub const TO_SCX = 21; - pub const SYSCALL = 22; - pub const FOLLOW_FORK = 23; - pub const LWP_EVENTS = 24; - pub const GET_EVENT_MASK = 25; - pub const SET_EVENT_MASK = 26; - pub const GET_SC_ARGS = 27; - pub const GET_SC_RET = 28; - pub const COREDUMP = 29; - pub const GETREGS = 33; - pub const SETREGS = 34; - pub const GETFPREGS = 35; - pub const SETFPREGS = 36; - pub const GETDBREGS = 37; - pub const SETDBREGS = 38; - pub const VM_TIMESTAMP = 40; - pub const VM_ENTRY = 41; - pub const GETREGSET = 42; - pub const SETREGSET = 43; - pub const SC_REMOTE = 44; - pub const FIRSTMACH = 64; -}; - -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 const ptrace_lwpinfo = extern struct { - lwpid: lwpid_t, - event: c_int, - flags: c_int, - sigmask: sigset_t, - siglist: sigset_t, - siginfo: siginfo_t, - tdname: [MAXCOMLEN + 1]u8, - child_pid: pid_t, - syscall_code: c_uint, - syscall_narg: c_uint, -}; - -pub const ptrace_sc_ret = extern struct { - retval: [2]isize, - err: c_int, -}; - -pub const ptrace_vm_entry = extern struct { - entry: c_int, - timestamp: c_int, - start: c_ulong, - end: c_ulong, - offset: c_ulong, - prot: c_uint, - pathlen: c_uint, - fileid: c_long, - fsid: u32, - pve_path: ?[*:0]u8, -}; - -pub const ptrace_coredump = extern struct { - fd: c_int, - flags: u32, - limit: isize, -}; - -pub const ptrace_cs_remote = extern struct { - ret: ptrace_sc_ret, - syscall: c_uint, - nargs: c_uint, - args: *isize, -}; - -pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: [*:0]u8, data: c_int) c_int; - -/// TODO refines if necessary -pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) { - .x86, .powerpc => 4 * 512, - else => 4 * 1024, -}; - -pub const SYS_NMLN = 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; diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig index d75bcbdc33a4..a64eb03b419f 100644 --- a/lib/std/c/haiku.zig +++ b/lib/std/c/haiku.zig @@ -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; diff --git a/lib/std/c/linux.zig b/lib/std/c/linux.zig index ddc488e11521..c4986101dfad 100644 --- a/lib/std/c/linux.zig +++ b/lib/std/c/linux.zig @@ -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; diff --git a/lib/std/c/minix.zig b/lib/std/c/minix.zig index 672f36ca86f1..62cefc14fb57 100644 --- a/lib/std/c/minix.zig +++ b/lib/std/c/minix.zig @@ -16,5 +16,3 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (builtin.abi) { }, else => unreachable, }; - -pub const PTHREAD_STACK_MIN = 16 * 1024; diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig index 3ab33cf9d528..4b627ed083b7 100644 --- a/lib/std/c/netbsd.zig +++ b/lib/std/c/netbsd.zig @@ -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 {}; diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig index b18978dfbb58..23478a42b450 100644 --- a/lib/std/c/openbsd.zig +++ b/lib/std/c/openbsd.zig @@ -251,48 +251,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: c_uint, + msg_iovlen: c_uint, /// ancillary data - control: ?*anyopaque, + msg_control: ?*anyopaque, /// ancillary data buffer len - controllen: socklen_t, + msg_controllen: socklen_t, /// flags on received message - flags: c_int, + msg_flags: c_int, }; 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: c_uint, + msg_iovlen: c_uint, /// 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: c_int, + msg_flags: c_int, }; pub const Stat = extern struct { @@ -466,16 +466,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; @@ -1137,18 +1127,6 @@ pub usingnamespace switch (builtin.cpu.arch) { 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, - }; - }, else => struct {}, }; @@ -1615,39 +1593,3 @@ pub const KERN = struct { pub const PROC_ENV = 3; pub const PROC_NENV = 4; }; - -pub const HW = struct { - pub const MACHINE = 1; - pub const MODEL = 2; - pub const NCPU = 3; - pub const BYTEORDER = 4; - pub const PHYSMEM = 5; - pub const USERMEM = 6; - pub const PAGESIZE = 7; - pub const DISKNAMES = 8; - pub const DISKSTATS = 9; - pub const DISKCOUNT = 10; - pub const SENSORS = 11; - pub const CPUSPEED = 12; - pub const SETPERF = 13; - pub const VENDOR = 14; - pub const PRODUCT = 15; - pub const VERSION = 16; - pub const SERIALNO = 17; - pub const UUID = 18; - pub const PHYSMEM64 = 19; - pub const USERMEM64 = 20; - pub const NCPUFOUND = 21; - pub const ALLOWPOWERDOWN = 22; - pub const PERFPOLICY = 23; - pub const SMT = 24; - pub const NCPUONLINE = 25; - pub const POWER = 26; -}; - -/// TODO refines if necessary -pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) { - .sparc64 => 1 << 13, - .mips64 => 1 << 14, - else => 1 << 12, -}; diff --git a/lib/std/c/solaris.zig b/lib/std/c/solaris.zig index d6014a7a991f..58d02416cbdb 100644 --- a/lib/std/c/solaris.zig +++ b/lib/std/c/solaris.zig @@ -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 {}; diff --git a/lib/std/c/wasi.zig b/lib/std/c/wasi.zig index 2cb0a32b062f..e1940054b6db 100644 --- a/lib/std/c/wasi.zig +++ b/lib/std/c/wasi.zig @@ -119,5 +119,3 @@ pub const POLL = struct { pub const HUP = 0x2000; pub const NVAL = 0x4000; }; - -pub const PTHREAD_STACK_MIN = 16 * 1024; diff --git a/lib/std/fs.zig b/lib/std/fs.zig index cb6ce2032ec7..a76da24713bc 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -2929,7 +2929,6 @@ pub const OpenSelfExeError = error{ /// On Windows, file paths cannot contain these characters: /// '/', '*', '?', '"', '<', '>', '|' BadPathName, - Overflow, Unexpected, } || os.OpenError || SelfExePathError || os.FlockError; @@ -3009,14 +3008,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; @@ -3115,7 +3107,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, diff --git a/lib/std/os.zig b/lib/std/os.zig index f170eec3671e..ef167cd24a4a 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -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 @as(usize, 0); const first = iov[0]; return pread(fd, first.iov_base[0..first.iov_len], offset); } @@ -4710,8 +4694,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; @@ -4732,8 +4719,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]; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 6362e9ece1a4..f116fc0dd8e5 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1519,28 +1519,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); } @@ -3596,11 +3574,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| { @@ -3609,32 +3582,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, diff --git a/lib/std/process.zig b/lib/std/process.zig index 28d4bfcb25c0..eef96b46d273 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1163,37 +1163,6 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize { .linux => { return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory; }, - .freebsd, .netbsd, .dragonfly, .macos => { - 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) { - error.NameTooLong, error.UnknownName => unreachable, - else => return error.UnknownTotalSystemMemory, - }; - return @as(usize, @intCast(physmem)); - }, - .openbsd => { - const mib: [2]c_int = [_]c_int{ - std.os.CTL.HW, - std.os.HW.PHYSMEM64, - }; - var physmem: i64 = undefined; - var len: usize = @sizeOf(@TypeOf(physmem)); - std.os.sysctl(&mib, &physmem, &len, null, 0) catch |err| switch (err) { - error.NameTooLong => unreachable, // constant, known good value - error.PermissionDenied => unreachable, // only when setting values, - error.SystemResources => unreachable, // memory already on the stack - error.UnknownName => unreachable, // constant, known good value - else => return error.UnknownTotalSystemMemory, - }; - assert(physmem >= 0); - return @as(usize, @bitCast(physmem)); - }, .windows => { var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined; const rc = std.os.windows.ntdll.NtQuerySystemInformation(