authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-31 15:33:54-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-31 15:33:54-07:00
log8f5c333ebe6631629be3b88d797a03b1d677d439
tree4efdeeee8434dcbc0f694eff367adecee521f00f
parent928d43f61a9b08fd9c83964c34a29cca85839226
parent04d5e07d407af5382ec5e721dee485855928318f
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16636 from ziglang/audit-devnexen

audit all contributions by @devnexen for correctness and delete unnecessary libc ABI bits

17 files changed, 146 insertions(+), 1793 deletions(-)

lib/std/Thread.zig+1-1
...@@ -695,7 +695,7 @@ const PosixThreadImpl = struct {...@@ -695,7 +695,7 @@ const PosixThreadImpl = struct {
695 defer assert(c.pthread_attr_destroy(&attr) == .SUCCESS);695 defer assert(c.pthread_attr_destroy(&attr) == .SUCCESS);
696696
697 // Use the same set of parameters used by the libc-less impl.697 // Use the same set of parameters used by the libc-less impl.
698 const stack_size = @max(config.stack_size, c.PTHREAD_STACK_MIN);698 const stack_size = @max(config.stack_size, 16 * 1024);
699 assert(c.pthread_attr_setstacksize(&attr, stack_size) == .SUCCESS);699 assert(c.pthread_attr_setstacksize(&attr, stack_size) == .SUCCESS);
700 assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == .SUCCESS);700 assert(c.pthread_attr_setguardsize(&attr, std.mem.page_size) == .SUCCESS);
701701
lib/std/c.zig-5
...@@ -408,11 +408,6 @@ pub extern "c" fn setlogmask(maskpri: c_int) c_int;...@@ -408,11 +408,6 @@ pub extern "c" fn setlogmask(maskpri: c_int) c_int;
408408
409pub extern "c" fn if_nametoindex([*:0]const u8) c_int;409pub extern "c" fn if_nametoindex([*:0]const u8) c_int;
410410
411pub extern "c" fn timer_create(clockid: c.clockid_t, sevp: *c.sigevent, timerid: *c.timer_t) c_int;
412pub extern "c" fn timer_delete(timerid: c.timer_t) c_int;
413pub extern "c" fn timer_settime(timerid: c.timer_t, flags: c_int, new_value: *const c.itimerspec, old_value: *c.itimerspec) c_int;
414pub extern "c" fn timer_gettime(timerid: c.timer_t, flags: c_int, curr_value: *c.itimerspec) c_int;
415
416pub usingnamespace if (builtin.os.tag == .linux and builtin.target.isMusl()) struct {411pub usingnamespace if (builtin.os.tag == .linux and builtin.target.isMusl()) struct {
417 // musl does not implement getcontext412 // musl does not implement getcontext
418 pub const getcontext = std.os.linux.getcontext;413 pub const getcontext = std.os.linux.getcontext;
lib/std/c/darwin.zig+5-332
...@@ -161,67 +161,13 @@ pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;...@@ -161,67 +161,13 @@ pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
161pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;161pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;
162pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8;162pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8;
163163
164pub const COPYFILE = struct {164pub const COPYFILE_ACL = 1 << 0;
165 pub const ACL = 1 << 0;165pub const COPYFILE_STAT = 1 << 1;
166 pub const STAT = 1 << 1;166pub const COPYFILE_XATTR = 1 << 2;
167 pub const XATTR = 1 << 2;167pub const COPYFILE_DATA = 1 << 3;
168 pub const DATA = 1 << 3;
169 pub const SECURITY = COPYFILE.STAT | COPYFILE.ACL;
170 pub const METADATA = COPYFILE.SECURITY | COPYFILE.XATTR;
171 pub const ALL = COPYFILE.METADATA | COPYFILE.DATA;
172 pub const RECURSIVE = 1 << 15;
173 pub const CHECK = 1 << 16;
174 pub const EXCL = 1 << 17;
175 pub const NOFOLLOW_SRC = 1 << 18;
176 pub const NOFOLLOW_DST = 1 << 19;
177 pub const MOVE = 1 << 20;
178 pub const UNLINK = 1 << 21;
179 pub const NOFOLLOW = COPYFILE.NOFOLLOW_SRC | NOFOLLOW_DST;
180 pub const PACK = 1 << 22;
181 pub const UNPACK = 1 << 23;
182 pub const CLONE = 1 << 24;
183 pub const CLONE_FORCE = 1 << 25;
184 pub const RUN_IN_PLACE = 1 << 26;
185 pub const DATA_SPARSE = 1 << 27;
186 pub const PRESERVE_DST_TRACKED = 1 << 28;
187 pub const VERBOSE = 1 << 30;
188 pub const RECURSE_ERROR = 0;
189 pub const RECURSE_FILE = 1;
190 pub const RECURSE_DIR = 2;
191 pub const RECURSE_DIR_CLEANUP = 3;
192 pub const COPY_DATA = 4;
193 pub const COPY_XATTR = 5;
194 pub const START = 1;
195 pub const FINISH = 2;
196 pub const ERR = 3;
197 pub const PROGRESS = 4;
198 pub const CONTINUE = 0;
199 pub const SKIP = 1;
200 pub const QUIT = 2;
201 pub const STATE_SRC_FD = 1;
202 pub const STATE_SRC_FILENAME = 2;
203 pub const STATE_DST_FD = 3;
204 pub const STATE_DST_FILENAME = 4;
205 pub const STATE_QUARANTINE = 5;
206 pub const STATE_STATUS_CB = 6;
207 pub const STATE_STATUS_CTX = 7;
208 pub const STATE_COPIED = 8;
209 pub const STATE_XATTRNAME = 9;
210 pub const STATE_WAS_CLONED = 10;
211 pub const STATE_SRC_BSIZE = 11;
212 pub const STATE_DST_BSIZE = 12;
213 pub const STATE_BSIZE = 13;
214 pub const DISABLE_VAR: [*]u8 = "COPYFILE_DISABLE";
215};
216168
217pub const copyfile_state_t = *opaque {};169pub const copyfile_state_t = *opaque {};
218pub const copyfile_flags_t = u32;170pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: u32) c_int;
219pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: copyfile_flags_t) c_int;
220pub extern "c" fn copyfile(from: [*:0]u8, to: [*:0]u8, state: ?copyfile_state_t, flags: copyfile_flags_t) c_int;
221pub extern "c" fn copyfile_state_alloc() copyfile_state_t;
222pub extern "c" fn copyfile_state_free(state: copyfile_state_t) void;
223pub extern "c" fn copyfile_state_get(s: copyfile_state_t, flag: u32, dst: ?*anyopaque) c_int;
224pub extern "c" fn copyfile_state_set(s: copyfile_state_t, flag: u32, dst: ?*const anyopaque) c_int;
225171
226pub extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;172pub extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
227pub const realpath = @"realpath$DARWIN_EXTSN";173pub 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...@@ -949,35 +895,7 @@ pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class
949pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;895pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
950pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;896pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
951897
952pub const CCryptorStatus = enum(i32) {
953 /// Operation completed
954 kCCSuccess = 0,
955 /// Illegal parameter
956 kCCParamError = -4300,
957 /// Provided buffer too small
958 kCCBufferTooSmall = -4301,
959 /// Failed memory allocation
960 kCCMemoryFailure = -4302,
961 /// Size alignment issue
962 kCCAlignmentError = -4303,
963 /// Decoding issue
964 kCCDecodeError = -4304,
965 /// Call not implemented
966 kCCUnimplemented = -4305,
967 kCCOverflow = -4306,
968 kCCRNGFailure = -4307,
969 /// Unspecified error
970 kCCUnspecifiedError = -4308,
971 kCCCallSequenceError = -4309,
972 kCCKeySizeError = -4310,
973 /// Invalid key
974 kCCInvalidKey = -4311,
975};
976
977pub const CCRNGStatus = CCryptorStatus;
978
979pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;898pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
980pub extern "c" fn CCRandomGenerateBytes(bytes: ?*anyopaque, count: usize) CCRNGStatus;
981899
982// Grand Central Dispatch is exposed by libSystem.900// Grand Central Dispatch is exposed by libSystem.
983pub extern "c" fn dispatch_release(object: *anyopaque) void;901pub 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...@@ -3926,248 +3844,3 @@ pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost
3926pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;3844pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
3927pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;3845pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
3928pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;3846pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
3929
3930pub extern "c" fn proc_listpids(tpe: u32, tinfo: u32, buffer: ?*anyopaque, buffersize: c_int) c_int;
3931pub extern "c" fn proc_listallpids(buffer: ?*anyopaque, buffersize: c_int) c_int;
3932pub extern "c" fn proc_listpgrppids(pgrpid: pid_t, buffer: ?*anyopaque, buffersize: c_int) c_int;
3933pub extern "c" fn proc_listchildpids(ppid: pid_t, buffer: ?*anyopaque, buffersize: c_int) c_int;
3934pub extern "c" fn proc_pidinfo(pid: c_int, flavor: c_int, arg: u64, buffer: ?*anyopaque, buffersize: c_int) c_int;
3935pub extern "c" fn proc_name(pid: c_int, buffer: ?*anyopaque, buffersize: u32) c_int;
3936pub extern "c" fn proc_pidpath(pid: c_int, buffer: ?*anyopaque, buffersize: u32) c_int;
3937
3938pub const MIN = struct {
3939 pub const INCORE = 0x1;
3940 pub const REFERENCED = 0x2;
3941 pub const MODIFIED = 0x4;
3942 pub const REFERENCED_OTHER = 0x8;
3943 pub const MODIFIED_OTHER = 0x10;
3944 pub const PAGED_OUT = 0x20;
3945 pub const COPIED = 0x40;
3946 pub const ANONYMOUS = 0x80;
3947};
3948
3949pub extern "c" fn mincore(addr: *align(std.mem.page_size) const anyopaque, length: usize, vec: [*]u8) c_int;
3950pub extern "c" fn os_proc_available_memory() usize;
3951
3952pub const thread_affinity_policy = extern struct {
3953 tag: integer_t,
3954};
3955
3956pub const thread_policy_flavor_t = natural_t;
3957pub const thread_policy_t = [*]integer_t;
3958pub const thread_affinity_policy_data_t = thread_affinity_policy;
3959pub const thread_affinity_policy_t = [*]thread_affinity_policy;
3960
3961pub const THREAD_AFFINITY = struct {
3962 pub const POLICY = 0;
3963 pub const POLICY_COUNT = @as(mach_msg_type_number_t, @intCast(@sizeOf(thread_affinity_policy_data_t) / @sizeOf(integer_t)));
3964};
3965
3966/// cpu affinity api
3967/// albeit it is also available on arm64, it always fails as in this architecture there is no sense of
3968/// individual cpus (high performance cpus group and low consumption one), thus the pthread QOS api is more appropriate in this case.
3969pub 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;
3970pub 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;
3971
3972pub const cpu_type_t = integer_t;
3973pub const cpu_subtype_t = integer_t;
3974pub const cpu_threadtype_t = integer_t;
3975pub const host_flavor_t = integer_t;
3976pub const host_info_t = *integer_t;
3977pub const host_info64_t = *integer_t;
3978pub const host_can_has_debugger_info = extern struct {
3979 can_has_debugger: boolean_t,
3980};
3981pub const host_can_has_debugger_info_data_t = host_can_has_debugger_info;
3982pub const host_can_has_debugger_info_t = *host_can_has_debugger_info;
3983
3984pub const host_sched_info = extern struct {
3985 min_timeout: integer_t,
3986 min_quantum: integer_t,
3987};
3988pub const host_sched_info_data_t = host_sched_info;
3989pub const host_sched_info_t = *host_sched_info;
3990
3991pub const kernel_resource_sizes = extern struct {
3992 task: natural_t,
3993 thread: natural_t,
3994 port: natural_t,
3995 memory_region: natural_t,
3996 memory_object: natural_t,
3997};
3998
3999pub const kernel_resource_sizes_data_t = kernel_resource_sizes;
4000pub const kernel_resource_sizes_t = *kernel_resource_sizes;
4001
4002pub const host_priority_info = extern struct {
4003 kernel_priority: integer_t,
4004 system_priority: integer_t,
4005 server_priority: integer_t,
4006 user_priority: integer_t,
4007 depress_priority: integer_t,
4008 idle_priority: integer_t,
4009 minimum_priority: integer_t,
4010 maximum_priority: integer_t,
4011};
4012
4013pub const host_priority_info_data_t = host_priority_info;
4014pub const host_priority_info_t = *host_priority_info;
4015
4016pub const CPU_STATE_MAX = 4;
4017
4018pub const host_cpu_load_info = extern struct {
4019 cpu_ticks: [CPU_STATE_MAX]natural_t,
4020};
4021
4022pub const host_cpu_load_info_data_t = host_cpu_load_info;
4023pub const host_cpu_load_info_t = *host_cpu_load_info;
4024
4025pub const host_load_info = extern struct {
4026 avenrun: [3]integer_t,
4027 mach_factor: [3]integer_t,
4028};
4029
4030pub const host_load_info_data_t = host_load_info;
4031pub const host_load_info_t = *host_load_info;
4032
4033pub const host_preferred_user_arch = extern struct {
4034 cpu_type: cpu_type_t,
4035 cpu_subtype: cpu_subtype_t,
4036};
4037
4038pub const host_preferred_user_arch_data_t = host_preferred_user_arch;
4039pub const host_preferred_user_arch_t = *host_preferred_user_arch;
4040
4041fn HostCount(comptime HT: type) mach_msg_type_number_t {
4042 return @as(mach_msg_type_number_t, @intCast(@sizeOf(HT) / @sizeOf(integer_t)));
4043}
4044
4045pub const HOST = struct {
4046 pub const BASIC_INFO = 1;
4047 pub const SCHED_INFO = 3;
4048 pub const RESOURCE_SIZES = 4;
4049 pub const PRIORITY_INFO = 5;
4050 pub const SEMAPHORE_TRAPS = 7;
4051 pub const MACH_MSG_TRAPS = 8;
4052 pub const VM_PURGEABLE = 9;
4053 pub const DEBUG_INFO_INTERNAL = 10;
4054 pub const CAN_HAS_DEBUGGER = 11;
4055 pub const PREFERRED_USER_ARCH = 12;
4056 pub const LOAD_INFO = 1;
4057 pub const VM_INFO = 2;
4058 pub const CPU_LOAD_INFO = 3;
4059 pub const VM_INFO64 = 4;
4060 pub const EXTMOD_INFO64 = 5;
4061 pub const EXPIRED_TASK_INFO = 6;
4062 pub const CAN_HAS_DEBUGGER_COUNT = HostCount(host_can_has_debugger_info_data_t);
4063 pub const SCHED_INFO_COUNT = HostCount(host_sched_info_data_t);
4064 pub const RESOURCES_SIZES_COUNT = HostCount(kernel_resource_sizes_data_t);
4065 pub const PRIORITY_INFO_COUNT = HostCount(host_priority_info_data_t);
4066 pub const CPU_LOAD_INFO_COUNT = HostCount(host_cpu_load_info_data_t);
4067 pub const LOAD_INFO_COUNT = HostCount(host_load_info_data_t);
4068 pub const PREFERRED_USER_ARCH_COUNT = HostCount(host_preferred_user_arch_data_t);
4069 pub const VM_INFO_COUNT = HostCount(vm_statistics_data_t);
4070 pub const VM_INFO64_COUNT = HostCount(vm_statistics64_data_t);
4071 pub const EXTMOD_INFO64_COUNT = HostCount(vm_extmod_statistics_data_t);
4072};
4073
4074pub const host_basic_info = extern struct {
4075 max_cpus: integer_t,
4076 avail_cpus: integer_t,
4077 memory_size: natural_t,
4078 cpu_type: cpu_type_t,
4079 cpu_subtype: cpu_subtype_t,
4080 cpu_threadtype: cpu_threadtype_t,
4081 physical_cpu: integer_t,
4082 physical_cpu_max: integer_t,
4083 logical_cpu: integer_t,
4084 logical_cpu_max: integer_t,
4085 max_mem: u64,
4086};
4087
4088pub 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;
4089pub 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;
4090pub 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;
4091
4092pub const vm_statistics = extern struct {
4093 free_count: natural_t,
4094 active_count: natural_t,
4095 inactive_count: natural_t,
4096 wire_count: natural_t,
4097 zero_fill_count: natural_t,
4098 reactivations: natural_t,
4099 pageins: natural_t,
4100 pageouts: natural_t,
4101 faults: natural_t,
4102 cow_faults: natural_t,
4103 lookups: natural_t,
4104 hits: natural_t,
4105 purgeable_count: natural_t,
4106 purges: natural_t,
4107 speculative_count: natural_t,
4108};
4109
4110pub const vm_statistics_t = *vm_statistics;
4111pub const vm_statistics_data_t = vm_statistics;
4112
4113pub const vm_statistics64 align(8) = extern struct {
4114 free_count: natural_t,
4115 active_count: natural_t,
4116 inactive_count: natural_t,
4117 wire_count: natural_t,
4118 zero_fill_count: u64,
4119 reactivations: u64,
4120 pageins: u64,
4121 pageouts: u64,
4122 faults: u64,
4123 cow_faults: u64,
4124 lookups: u64,
4125 hits: u64,
4126 purges: u64,
4127 purgeable_count: natural_t,
4128 speculative_count: natural_t,
4129 decompressions: u64,
4130 compressions: u64,
4131 swapins: u64,
4132 swapouts: u64,
4133 compressor_page_count: natural_t,
4134 throttled_count: natural_t,
4135 external_page_count: natural_t,
4136 internal_page_count: natural_t,
4137 total_uncompressed_pages_in_compressor: u64,
4138};
4139
4140pub const vm_statistics64_t = *vm_statistics64;
4141pub const vm_statistics64_data_t = vm_statistics64;
4142
4143pub const vm_extmod_statistics align(8) = extern struct {
4144 task_for_pid_count: i64,
4145 task_for_pid_caller_count: i64,
4146 thread_creation_count: i64,
4147 thread_creation_caller_count: i64,
4148 thread_set_state_count: i64,
4149 thread_set_state_caller_count: i64,
4150};
4151
4152pub const vm_extmod_statistics_t = *vm_extmod_statistics;
4153pub const vm_extmod_statistics_data_t = vm_extmod_statistics;
4154
4155pub extern "c" fn vm_stats(info: ?*anyopaque, count: *c_uint) kern_return_t;
4156
4157/// TODO refines if necessary
4158pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
4159 .arm, .aarch64 => 16 * 1024,
4160 else => 8 * 1024,
4161};
4162
4163pub const _SYS_NAMELEN = 256;
4164
4165pub const utsname = extern struct {
4166 sysname: [255:0]u8,
4167 nodename: [255:0]u8,
4168 release: [255:0]u8,
4169 version: [255:0]u8,
4170 machine: [255:0]u8,
4171};
4172
4173pub extern "c" fn uname(u: *utsname) c_int;
lib/std/c/dragonfly.zig+7-29
...@@ -21,7 +21,6 @@ pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*an...@@ -21,7 +21,6 @@ pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*an
21pub extern "c" fn lwp_gettid() c_int;21pub extern "c" fn lwp_gettid() c_int;
2222
23pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;23pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
24pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
2524
26pub const pthread_mutex_t = extern struct {25pub const pthread_mutex_t = extern struct {
27 inner: ?*anyopaque = null,26 inner: ?*anyopaque = null,
...@@ -889,13 +888,13 @@ pub const cmsghdr = extern struct {...@@ -889,13 +888,13 @@ pub const cmsghdr = extern struct {
889 cmsg_type: c_int,888 cmsg_type: c_int,
890};889};
891pub const msghdr = extern struct {890pub const msghdr = extern struct {
892 name: ?*anyopaque,891 msg_name: ?*anyopaque,
893 namelen: socklen_t,892 msg_namelen: socklen_t,
894 iov: [*]iovec,893 msg_iov: [*]iovec,
895 iovlen: c_int,894 msg_iovlen: c_int,
896 control: ?*anyopaque,895 msg_control: ?*anyopaque,
897 controllen: socklen_t,896 msg_controllen: socklen_t,
898 flags: c_int,897 msg_flags: c_int,
899};898};
900pub const cmsgcred = extern struct {899pub const cmsgcred = extern struct {
901 cmcred_pid: pid_t,900 cmcred_pid: pid_t,
...@@ -1144,24 +1143,3 @@ pub const POLL = struct {...@@ -1144,24 +1143,3 @@ pub const POLL = struct {
1144 pub const HUP = 0x0010;1143 pub const HUP = 0x0010;
1145 pub const NVAL = 0x0020;1144 pub const NVAL = 0x0020;
1146};1145};
1147
1148pub const SIGEV = struct {
1149 pub const NONE = 0;
1150 pub const SIGNAL = 1;
1151 pub const THREAD = 2;
1152};
1153
1154pub const sigevent = extern struct {
1155 sigev_notify: c_int,
1156 __sigev_u: extern union {
1157 __sigev_signo: c_int,
1158 __sigev_notify_kqueue: c_int,
1159 __sigev_notify_attributes: ?*pthread_attr_t,
1160 },
1161 sigev_value: sigval,
1162 sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
1163};
1164
1165pub const PTHREAD_STACK_MIN = 16 * 1024;
1166
1167pub const timer_t = *opaque {};
lib/std/c/emscripten.zig-2
...@@ -9,5 +9,3 @@ pub const pthread_rwlock_t = extern struct {...@@ -9,5 +9,3 @@ pub const pthread_rwlock_t = extern struct {
9};9};
10const __SIZEOF_PTHREAD_COND_T = 48;10const __SIZEOF_PTHREAD_COND_T = 48;
11const __SIZEOF_PTHREAD_MUTEX_T = 28;11const __SIZEOF_PTHREAD_MUTEX_T = 28;
12
13pub const PTHREAD_STACK_MIN = 2048;
lib/std/c/freebsd.zig+22-913
...@@ -5,80 +5,12 @@ const maxInt = std.math.maxInt;...@@ -5,80 +5,12 @@ const maxInt = std.math.maxInt;
5const iovec = std.os.iovec;5const iovec = std.os.iovec;
6const iovec_const = std.os.iovec_const;6const iovec_const = std.os.iovec_const;
77
8pub const CPU_SETSIZE = 256;
9pub const cpuset_t = extern struct {
10 __bits: [(CPU_SETSIZE + (@bitSizeOf(c_long) - 1)) / @bitSizeOf(c_long)]c_long,
11};
12
13fn __BIT_COUNT(bits: []const c_long) c_long {
14 var count: c_long = 0;
15 for (bits) |b| {
16 count += @popCount(b);
17 }
18 return count;
19}
20
21fn __BIT_MASK(s: usize) c_long {
22 var x = s % CPU_SETSIZE;
23 return @as(c_long, @bitCast(@as(c_ulong, @intCast(1)) << @as(u6, @intCast(x))));
24}
25
26pub fn CPU_COUNT(set: cpuset_t) c_int {
27 return @as(c_int, @intCast(__BIT_COUNT(set.__bits[0..])));
28}
29
30pub fn CPU_ZERO(set: *cpuset_t) void {
31 @memset((set.*).__bits[0..], 0);
32}
33
34pub fn CPU_SET(cpu: usize, set: *cpuset_t) void {
35 const x = cpu / @sizeOf(c_long);
36 if (x < @sizeOf(cpuset_t)) {
37 (set.*).__bits[x] |= __BIT_MASK(x);
38 }
39}
40
41pub fn CPU_ISSET(cpu: usize, set: cpuset_t) bool {
42 const x = cpu / @sizeOf(c_long);
43 if (x < @sizeOf(cpuset_t)) {
44 return set.__bits[x] & __BIT_MASK(x) != 0;
45 }
46 return false;
47}
48
49pub fn CPU_CLR(cpu: usize, set: *cpuset_t) void {
50 const x = cpu / @sizeOf(c_long);
51 if (x < @sizeOf(cpuset_t)) {
52 (set.*).__bits[x] &= !__BIT_MASK(x);
53 }
54}
55
56pub const cpulevel_t = c_int;
57pub const cpuwhich_t = c_int;
58pub const id_t = i64;
59
60pub const CPU_LEVEL_ROOT: cpulevel_t = 1;
61pub const CPU_LEVEL_CPUSET: cpulevel_t = 2;
62pub const CPU_LEVEL_WHICH: cpulevel_t = 3;
63pub const CPU_WHICH_TID: cpuwhich_t = 1;
64pub const CPU_WHICH_PID: cpuwhich_t = 2;
65pub const CPU_WHICH_CPUSET: cpuwhich_t = 3;
66pub const CPU_WHICH_IRQ: cpuwhich_t = 4;
67pub const CPU_WHICH_JAIL: cpuwhich_t = 5;
68pub const CPU_WHICH_DOMAIN: cpuwhich_t = 6;
69pub const CPU_WHICH_INTRHANDLER: cpuwhich_t = 7;
70pub const CPU_WHICH_ITHREAD: cpuwhich_t = 8;
71pub const CPU_WHICH_TIDPID: cpuwhich_t = 8;
72
73extern "c" fn __error() *c_int;8extern "c" fn __error() *c_int;
74pub const _errno = __error;9pub const _errno = __error;
7510
76pub extern "c" var malloc_options: [*:0]const u8;
77
78pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize;11pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize;
79pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;12pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
80pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;13pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
81pub extern "c" fn getentropy(buf_ptr: [*]u8, buf_len: usize) c_int;
8214
83pub extern "c" fn pthread_getthreadid_np() c_int;15pub extern "c" fn pthread_getthreadid_np() c_int;
84pub extern "c" fn pthread_set_name_np(thread: std.c.pthread_t, name: [*:0]const u8) void;16pub 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;...@@ -88,21 +20,10 @@ pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
8820
89pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;21pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
90pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;22pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
91pub extern "c" fn reallocf(?*anyopaque, usize) ?*anyopaque;
9223
93pub extern "c" fn getpid() pid_t;24pub extern "c" fn getpid() pid_t;
9425
95pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file;26pub extern "c" fn kinfo_getfile(pid: pid_t, cntp: *c_int) ?[*]kinfo_file;
96pub extern "c" fn kinfo_getvmmap(pid: pid_t, cntp: *c_int) ?[*]kinfo_vmentry;
97pub extern "c" fn kinfo_getproc(pid: pid_t) ?*kinfo_proc;
98pub extern "c" fn kinfo_getvmobject(cntp: *c_int) ?[*]kinfo_vmobject;
99pub extern "c" fn kinfo_getswapvmobject(cntp: *c_int) ?[*]kinfo_vmobject;
100
101pub extern "c" fn cpuset_getaffinity(level: cpulevel_t, which: cpuwhich_t, id: id_t, setsize: usize, mask: *cpuset_t) c_int;
102pub extern "c" fn cpuset_setaffinity(level: cpulevel_t, which: cpuwhich_t, id: id_t, setsize: usize, mask: *const cpuset_t) c_int;
103pub extern "c" fn sched_getaffinity(pid: pid_t, cpusetsz: usize, cpuset: *cpuset_t) c_int;
104pub extern "c" fn sched_setaffinity(pid: pid_t, cpusetsz: usize, cpuset: *const cpuset_t) c_int;
105pub extern "c" fn sched_getcpu() c_int;
10627
107pub const sf_hdtr = extern struct {28pub const sf_hdtr = extern struct {
108 headers: [*]const iovec_const,29 headers: [*]const iovec_const,
...@@ -355,36 +276,36 @@ pub const Flock = extern struct {...@@ -355,36 +276,36 @@ pub const Flock = extern struct {
355276
356pub const msghdr = extern struct {277pub const msghdr = extern struct {
357 /// Optional address.278 /// Optional address.
358 name: ?*sockaddr,279 msg_name: ?*sockaddr,
359 /// Size of address.280 /// Size of address.
360 namelen: socklen_t,281 msg_namelen: socklen_t,
361 /// Scatter/gather array.282 /// Scatter/gather array.
362 iov: [*]iovec,283 msg_iov: [*]iovec,
363 /// Number of elements in msg_iov.284 /// Number of elements in msg_iov.
364 iovlen: i32,285 msg_iovlen: i32,
365 /// Ancillary data.286 /// Ancillary data.
366 control: ?*anyopaque,287 msg_control: ?*anyopaque,
367 /// Ancillary data buffer length.288 /// Ancillary data buffer length.
368 controllen: socklen_t,289 msg_controllen: socklen_t,
369 /// Flags on received message.290 /// Flags on received message.
370 flags: i32,291 msg_flags: i32,
371};292};
372293
373pub const msghdr_const = extern struct {294pub const msghdr_const = extern struct {
374 /// Optional address.295 /// Optional address.
375 name: ?*const sockaddr,296 msg_name: ?*const sockaddr,
376 /// Size of address.297 /// Size of address.
377 namelen: socklen_t,298 msg_namelen: socklen_t,
378 /// Scatter/gather array.299 /// Scatter/gather array.
379 iov: [*]iovec_const,300 msg_iov: [*]iovec_const,
380 /// Number of elements in msg_iov.301 /// Number of elements in msg_iov.
381 iovlen: i32,302 msg_iovlen: i32,
382 /// Ancillary data.303 /// Ancillary data.
383 control: ?*anyopaque,304 msg_control: ?*anyopaque,
384 /// Ancillary data buffer length.305 /// Ancillary data buffer length.
385 controllen: socklen_t,306 msg_controllen: socklen_t,
386 /// Flags on received message.307 /// Flags on received message.
387 flags: i32,308 msg_flags: i32,
388};309};
389310
390pub const Stat = extern struct {311pub const Stat = extern struct {
...@@ -523,43 +444,10 @@ pub const sockaddr = extern struct {...@@ -523,43 +444,10 @@ pub const sockaddr = extern struct {
523444
524pub const CAP_RIGHTS_VERSION = 0;445pub const CAP_RIGHTS_VERSION = 0;
525446
526pub const cap_rights_t = extern struct {447pub const cap_rights = extern struct {
527 cr_rights: [CAP_RIGHTS_VERSION + 2]u64,448 rights: [CAP_RIGHTS_VERSION + 2]u64,
528};449};
529450
530pub const CAP = struct {
531 pub fn RIGHT(idx: u6, bit: u64) u64 {
532 return (@as(u64, @intCast(1)) << (57 + idx)) | bit;
533 }
534 pub const READ = CAP.RIGHT(0, 0x0000000000000001);
535 pub const WRITE = CAP.RIGHT(0, 0x0000000000000002);
536 pub const SEEK_TELL = CAP.RIGHT(0, 0x0000000000000004);
537 pub const SEEK = CAP.SEEK_TELL | 0x0000000000000008;
538 pub const PREAD = CAP.SEEK | CAP.READ;
539 pub const PWRITE = CAP.SEEK | CAP.WRITE;
540 pub const MMAP = CAP.RIGHT(0, 0x0000000000000010);
541 pub const MMAP_R = CAP.MMAP | CAP.SEEK | CAP.READ;
542 pub const MMAP_W = CAP.MMAP | CAP.SEEK | CAP.WRITE;
543 pub const MMAP_X = CAP.MMAP | CAP.SEEK | 0x0000000000000020;
544 pub const MMAP_RW = CAP.MMAP_R | CAP.MMAP_W;
545 pub const MMAP_RX = CAP.MMAP_R | CAP.MMAP_X;
546 pub const MMAP_WX = CAP.MMAP_W | CAP.MMAP_X;
547 pub const MMAP_RWX = CAP.MMAP_R | CAP.MMAP_W | CAP.MMAP_X;
548 pub const CREATE = CAP.RIGHT(0, 0x0000000000000040);
549 pub const FEXECVE = CAP.RIGHT(0, 0x0000000000000080);
550 pub const FSYNC = CAP.RIGHT(0, 0x0000000000000100);
551 pub const FTRUNCATE = CAP.RIGHT(0, 0x0000000000000200);
552};
553
554pub extern "c" fn __cap_rights_init(version: c_int, rights: ?*cap_rights_t, ...) ?*cap_rights_t;
555pub extern "c" fn __cap_rights_set(rights: ?*cap_rights_t, ...) ?*cap_rights_t;
556pub extern "c" fn __cap_rights_clear(rights: ?*cap_rights_t, ...) ?*cap_rights_t;
557pub extern "c" fn __cap_rights_is_set(rights: ?*const cap_rights_t, ...) bool;
558pub extern "c" fn cap_rights_merge(dst: ?*cap_rights_t, src: ?*const cap_rights_t) ?*cap_rights_t;
559pub extern "c" fn cap_rights_remove(dst: ?*cap_rights_t, src: ?*const cap_rights_t) ?*cap_rights_t;
560pub extern "c" fn cap_rights_contains(dst: ?*const cap_rights_t, src: ?*const cap_rights_t) bool;
561pub extern "c" fn cap_rights_is_valid(rights: ?*const cap_rights_t) bool;
562
563pub const kinfo_file = extern struct {451pub const kinfo_file = extern struct {
564 /// Size of this record.452 /// Size of this record.
565 /// A zero value is for the sentinel record at the end of an array.453 /// A zero value is for the sentinel record at the end of an array.
...@@ -661,7 +549,7 @@ pub const kinfo_file = extern struct {...@@ -661,7 +549,7 @@ pub const kinfo_file = extern struct {
661 // Reserved for future use.549 // Reserved for future use.
662 _spare: c_int,550 _spare: c_int,
663 /// Capability rights.551 /// Capability rights.
664 cap_rights: cap_rights_t,552 cap_rights: cap_rights,
665 /// Reserved for future cap_rights553 /// Reserved for future cap_rights
666 _cap_spare: u64,554 _cap_spare: u64,
667 /// Path to file, if any.555 /// Path to file, if any.
...@@ -675,248 +563,6 @@ comptime {...@@ -675,248 +563,6 @@ comptime {
675 std.debug.assert(@alignOf(kinfo_file) == @sizeOf(u64));563 std.debug.assert(@alignOf(kinfo_file) == @sizeOf(u64));
676}564}
677565
678pub const kinfo_vmentry = extern struct {
679 structsize: c_int,
680 type: c_int,
681 start: u64,
682 end: u64,
683 offset: u64,
684 vn_fileid: u64,
685 vn_fsid_freebsd11: u32,
686 flags: c_int,
687 resident: c_int,
688 private_resident: c_int,
689 protection: c_int,
690 ref_count: c_int,
691 shadow_count: c_int,
692 vn_type: c_int,
693 vn_size: u64,
694 vn_rdev_freebsd11: u32,
695 vn_mode: u16,
696 status: u16,
697 type_spec: extern union {
698 _vn_fsid: u64,
699 _obj: u64,
700 },
701 vn_rdev: u64,
702 _ispare: [8]c_int,
703 rpath: [PATH_MAX]u8,
704};
705
706pub const KINFO_VMENTRY_SIZE = 1160;
707
708comptime {
709 std.debug.assert(@sizeOf(kinfo_vmentry) == KINFO_VMENTRY_SIZE);
710}
711
712pub const WMESGLEN = 8;
713pub const LOCKNAMELEN = 8;
714pub const TDNAMLEN = 16;
715pub const COMMLEN = 19;
716pub const MAXCOMLEN = 19;
717pub const KI_EMULNAMELEN = 16;
718pub const KI_NGROUPS = 16;
719pub const LOGNAMELEN = 17;
720pub const LOGINCLASSLEN = 17;
721
722pub const KI_NSPARE_INT = 2;
723pub const KI_NSPARE_LONG = 12;
724pub const KI_NSPARE_PTR = 5;
725
726pub const RUSAGE_SELF = 0;
727pub const RUSAGE_CHILDREN = -1;
728pub const RUSAGE_THREAD = 1;
729
730pub const proc = opaque {};
731pub const thread = opaque {};
732pub const vnode = opaque {};
733pub const filedesc = opaque {};
734pub const pwddesc = opaque {};
735pub const vmspace = opaque {};
736pub const pcb = opaque {};
737pub const lwpid_t = i32;
738pub const fixpt_t = u32;
739pub const vm_size_t = usize;
740pub const segsz_t = isize;
741
742pub const itimerval = extern struct {
743 interval: timeval,
744 value: timeval,
745};
746
747pub const pstats = extern struct {
748 cru: rusage,
749 timer: [3]itimerval,
750 prof: extern struct {
751 base: u8,
752 size: c_ulong,
753 off: c_ulong,
754 scale: c_ulong,
755 },
756 start: timeval,
757};
758
759pub const user = extern struct {
760 stats: pstats,
761 kproc: kinfo_proc,
762};
763
764pub const pargs = extern struct {
765 ref: c_uint,
766 length: c_uint,
767 args: [1]u8,
768};
769
770pub const priority = extern struct {
771 class: u8,
772 level: u8,
773 native: u8,
774 user: u8,
775};
776
777pub const rusage = extern struct {
778 utime: timeval,
779 stime: timeval,
780 maxrss: c_long,
781 ixrss: c_long,
782 idrss: c_long,
783 isrss: c_long,
784 minflt: c_long,
785 majflt: c_long,
786 nswap: c_long,
787 inblock: c_long,
788 oublock: c_long,
789 msgsnd: c_long,
790 msgrcv: c_long,
791 nsignals: c_long,
792 nvcsw: c_long,
793 nivcsw: c_long,
794};
795
796pub const kinfo_proc = extern struct {
797 structsize: c_int,
798 layout: c_int,
799 args: *pargs,
800 paddr: *proc,
801 addr: *user,
802 tracep: *vnode,
803 textvp: *vnode,
804 fd: *filedesc,
805 vmspace: *vmspace,
806 wchan: ?*const anyopaque,
807 pid: pid_t,
808 ppid: pid_t,
809 pgid: pid_t,
810 tpgid: pid_t,
811 sid: pid_t,
812 tsid: pid_t,
813 jobc: c_short,
814 spare_short1: c_short,
815 tdev_freebsd11: u32,
816 siglist: sigset_t,
817 sigmask: sigset_t,
818 sigignore: sigset_t,
819 sigcatch: sigset_t,
820 uid: uid_t,
821 ruid: uid_t,
822 svuid: uid_t,
823 rgid: gid_t,
824 svgid: gid_t,
825 ngroups: c_short,
826 spare_short2: c_short,
827 groups: [KI_NGROUPS]gid_t,
828 size: vm_size_t,
829 rssize: segsz_t,
830 swrss: segsz_t,
831 tsize: segsz_t,
832 dsize: segsz_t,
833 ssize: segsz_t,
834 xstat: c_ushort,
835 acflag: c_ushort,
836 pctcpu: fixpt_t,
837 estcpu: c_uint,
838 slptime: c_uint,
839 swtime: c_uint,
840 cow: c_uint,
841 runtime: u64,
842 start: timeval,
843 childtime: timeval,
844 flag: c_long,
845 kiflag: c_long,
846 traceflag: c_int,
847 stat: u8,
848 nice: i8,
849 lock: u8,
850 rqindex: u8,
851 oncpu_old: u8,
852 lastcpu_old: u8,
853 tdname: [TDNAMLEN + 1]u8,
854 wmesg: [WMESGLEN + 1]u8,
855 login: [LOGNAMELEN + 1]u8,
856 lockname: [LOCKNAMELEN + 1]u8,
857 comm: [COMMLEN + 1]u8,
858 emul: [KI_EMULNAMELEN + 1]u8,
859 loginclass: [LOGINCLASSLEN + 1]u8,
860 moretdname: [MAXCOMLEN - TDNAMLEN + 1]u8,
861 sparestrings: [46]u8,
862 spareints: [KI_NSPARE_INT]c_int,
863 tdev: u64,
864 oncpu: c_int,
865 lastcpu: c_int,
866 tracer: c_int,
867 flag2: c_int,
868 fibnum: c_int,
869 cr_flags: c_uint,
870 jid: c_int,
871 numthreads: c_int,
872 tid: lwpid_t,
873 pri: priority,
874 rusage: rusage,
875 rusage_ch: rusage,
876 pcb: *pcb,
877 stack: ?*anyopaque,
878 udata: ?*anyopaque,
879 tdaddr: *thread,
880 pd: *pwddesc,
881 spareptrs: [KI_NSPARE_PTR]?*anyopaque,
882 sparelongs: [KI_NSPARE_LONG]c_long,
883 sflag: c_long,
884 tdflag: c_long,
885};
886
887pub const KINFO_PROC_SIZE = switch (builtin.cpu.arch) {
888 .x86 => 768,
889 .arm => 816,
890 else => 1088,
891};
892
893comptime {
894 assert(@sizeOf(kinfo_proc) == KINFO_PROC_SIZE);
895}
896
897pub const kinfo_vmobject = extern struct {
898 structsize: c_int,
899 tpe: c_int,
900 size: u64,
901 vn_fileid: u64,
902 vn_fsid_freebsd11: u32,
903 ref_count: c_int,
904 shadow_count: c_int,
905 memattr: c_int,
906 resident: u64,
907 active: u64,
908 inactive: u64,
909 type_spec: extern union {
910 _vn_fsid: u64,
911 _backing_obj: u64,
912 },
913 me: u64,
914 _qspare: [6]u64,
915 swapped: u32,
916 _ispare: [7]u32,
917 path: [PATH_MAX]u8,
918};
919
920pub const CTL = struct {566pub const CTL = struct {
921 pub const KERN = 1;567 pub const KERN = 1;
922 pub const DEBUG = 5;568 pub const DEBUG = 5;
...@@ -1396,11 +1042,6 @@ pub const DT = struct {...@@ -1396,11 +1042,6 @@ pub const DT = struct {
1396 pub const WHT = 14;1042 pub const WHT = 14;
1397};1043};
13981044
1399pub const accept_filter = extern struct {
1400 af_name: [16]u8,
1401 af_args: [240]u8,
1402};
1403
1404/// add event to kq (implies enable)1045/// add event to kq (implies enable)
1405pub const EV_ADD = 0x0001;1046pub const EV_ADD = 0x0001;
14061047
...@@ -1682,47 +1323,15 @@ pub const mcontext_t = switch (builtin.cpu.arch) {...@@ -1682,47 +1323,15 @@ pub const mcontext_t = switch (builtin.cpu.arch) {
1682 rflags: u64,1323 rflags: u64,
1683 rsp: u64,1324 rsp: u64,
1684 ss: u64,1325 ss: u64,
1685 len: c_long,1326 len: u64,
1686 fpformat: c_long,1327 fpformat: u64,
1687 ownedfp: c_long,1328 ownedfp: u64,
1688 fpstate: [64]c_long align(16),1329 fpstate: [64]u64 align(16),
1689 fsbase: u64,1330 fsbase: u64,
1690 gsbase: u64,1331 gsbase: u64,
1691 xfpustate: u64,1332 xfpustate: u64,
1692 xfpustate_len: u64,1333 xfpustate_len: u64,
1693 spare: [4]c_long,1334 spare: [4]u64,
1694 },
1695 .x86 => extern struct {
1696 onstack: u32,
1697 gs: u32,
1698 fs: u32,
1699 es: u32,
1700 ds: u32,
1701 edi: u32,
1702 esi: u32,
1703 ebp: u32,
1704 isp: u32,
1705 ebx: u32,
1706 edx: u32,
1707 ecx: u32,
1708 eax: u32,
1709 trapno: u32,
1710 err: u32,
1711 eip: u32,
1712 cs: u32,
1713 eflags: u32,
1714 esp: u32,
1715 ss: u32,
1716 len: c_int,
1717 fpformat: c_int,
1718 ownedfp: c_int,
1719 flags: u32,
1720 fpstate: [128]c_int align(16),
1721 fsbase: u32,
1722 gsbase: u32,
1723 xpustate: u32,
1724 xpustate_len: u32,
1725 spare2: [4]c_int,
1726 },1335 },
1727 .aarch64 => extern struct {1336 .aarch64 => extern struct {
1728 gpregs: extern struct {1337 gpregs: extern struct {
...@@ -2002,45 +1611,6 @@ pub const AT = struct {...@@ -2002,45 +1611,6 @@ pub const AT = struct {
2002 pub const REMOVEDIR = 0x0800;1611 pub const REMOVEDIR = 0x0800;
2003 /// Fail if not under dirfd1612 /// Fail if not under dirfd
2004 pub const BENEATH = 0x1000;1613 pub const BENEATH = 0x1000;
2005 /// elf_common constants
2006 pub const NULL = 0;
2007 pub const IGNORE = 1;
2008 pub const EXECFD = 2;
2009 pub const PHDR = 3;
2010 pub const PHENT = 4;
2011 pub const PHNUM = 5;
2012 pub const PAGESZ = 6;
2013 pub const BASE = 7;
2014 pub const FLAGS = 8;
2015 pub const ENTRY = 9;
2016 pub const NOTELF = 10;
2017 pub const UID = 11;
2018 pub const EUID = 12;
2019 pub const GID = 13;
2020 pub const EGID = 14;
2021 pub const EXECPATH = 15;
2022 pub const CANARY = 16;
2023 pub const CANARYLEN = 17;
2024 pub const OSRELDATE = 18;
2025 pub const NCPUS = 19;
2026 pub const PAGESIZES = 20;
2027 pub const PAGESIZESLEN = 21;
2028 pub const TIMEKEEP = 22;
2029 pub const STACKPROT = 23;
2030 pub const EHDRFLAGS = 24;
2031 pub const HWCAP = 25;
2032 pub const HWCAP2 = 26;
2033 pub const BSDFLAGS = 27;
2034 pub const ARGC = 28;
2035 pub const ARGV = 29;
2036 pub const ENVC = 30;
2037 pub const ENVV = 31;
2038 pub const PS_STRINGS = 32;
2039 pub const FXRNG = 33;
2040 pub const KPRLOAD = 34;
2041 pub const USRSTACKBASE = 35;
2042 pub const USRSTACKLIM = 36;
2043 pub const COUNT = 37;
2044};1614};
20451615
2046pub const addrinfo = extern struct {1616pub const addrinfo = extern struct {
...@@ -2373,468 +1943,7 @@ pub const NAME_MAX = 255;...@@ -2373,468 +1943,7 @@ pub const NAME_MAX = 255;
2373pub const MFD = struct {1943pub const MFD = struct {
2374 pub const CLOEXEC = 0x0001;1944 pub const CLOEXEC = 0x0001;
2375 pub const ALLOW_SEALING = 0x0002;1945 pub const ALLOW_SEALING = 0x0002;
2376 pub const HUGETLB = 0x00000004;
2377 pub const HUGE_MASK = 0xFC000000;
2378 pub const HUGE_SHIFT = 26;
2379 pub const HUGE_64KB = 16 << HUGE_SHIFT;
2380 pub const HUGE_512KB = 19 << HUGE_SHIFT;
2381 pub const HUGE_1MB = 20 << HUGE_SHIFT;
2382 pub const HUGE_2MB = 21 << HUGE_SHIFT;
2383 pub const HUGE_8MB = 23 << HUGE_SHIFT;
2384 pub const HUGE_16MB = 24 << HUGE_SHIFT;
2385 pub const HUGE_32MB = 25 << HUGE_SHIFT;
2386 pub const HUGE_256MB = 28 << HUGE_SHIFT;
2387 pub const HUGE_512MB = 29 << HUGE_SHIFT;
2388 pub const HUGE_1GB = 30 << HUGE_SHIFT;
2389 pub const HUGE_2GB = 31 << HUGE_SHIFT;
2390 pub const HUGE_16GB = 34 << HUGE_SHIFT;
2391};1946};
23921947
2393pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;1948pub extern "c" fn memfd_create(name: [*:0]const u8, flags: c_uint) c_int;
2394pub 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;1949pub 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;
2395
2396pub const idtype_t = enum(c_int) {
2397 P_PID = 0,
2398 P_PPID = 1,
2399 P_PGID = 2,
2400 P_SID = 3,
2401 P_CID = 4,
2402 P_UID = 5,
2403 P_GID = 6,
2404 P_ALL = 7,
2405 P_LWPID = 8,
2406 P_TASKID = 9,
2407 P_PROJID = 10,
2408 P_POOLID = 11,
2409 P_JAILID = 12,
2410 P_CTID = 13,
2411 P_CPUID = 14,
2412 P_PSETID = 15,
2413};
2414
2415pub const PROC = struct {
2416 // constants for the id_t argument
2417 pub const SPROTECT: id_t = 1;
2418 pub const REAP_ACQUIRE: id_t = 2;
2419 pub const REAP_RELEASE: id_t = 3;
2420 pub const REAP_STATUS: id_t = 4;
2421 pub const REAP_GETPIDS: id_t = 5;
2422 pub const REAP_KILL: id_t = 6;
2423 pub const TRACE_CTL: id_t = 7;
2424 pub const TRACE_STATUS: id_t = 8;
2425 pub const TRACECAP_CTL = 9;
2426 pub const TRACECAP_STATUS: id_t = 10;
2427 pub const PDEATHSIG_CTL: id_t = 11;
2428 pub const PDEATHSIG_STATUS: id_t = 12;
2429 pub const ASLR_CTL: id_t = 13;
2430 pub const ASLR_STATUS: id_t = 14;
2431 pub const PROTMAX_CTL: id_t = 15;
2432 pub const PROTMAX_STATUS: id_t = 16;
2433 pub const STACKGAP_CTL: id_t = 17;
2434 pub const STACKGAP_STATUS: id_t = 18;
2435 pub const NO_NEW_PRIVS_CTL: id_t = 19;
2436 pub const NO_NEW_PRIVS_STATUS: id_t = 20;
2437 pub const WXMAP_CTL: id_t = 21;
2438 pub const WXMAP_STATUS: id_t = 22;
2439
2440 // constants for the operations
2441 pub const TRACE_CTL_ENABLE = 1;
2442 pub const TRACE_CTL_DISABLE = 2;
2443 pub const TRACE_CTL_DISABLE_EXEC = 3;
2444 pub const TRAPCAP_CTL_ENABLE = 1;
2445 pub const TRAPCAP_CTL_DISABLE = 2;
2446 pub const ASLR_FORCE_ENABLE = 1;
2447 pub const ASLR_FORCE_DISABLE = 2;
2448 pub const ASLR_FORCE_NOFORCE = 3;
2449 pub const ASLR_FORCE_ACTIVE = 0x80000000;
2450 pub const PROTMAX_FORCE_ENABLE = 1;
2451 pub const PROTMAX_FORCE_DISABLE = 2;
2452 pub const PROTMAX_FORCE_NOFORCE = 3;
2453 pub const PROTMAX_FORCE_ACTIVE = 0x80000000;
2454 pub const STACKGAP_ENABLE = 0x0001;
2455 pub const STACKGAP_DISABLE = 0x0002;
2456 pub const STACKGAP_ENABLE_EXEC = 0x0004;
2457 pub const STACKGAP_DISABLE_EXEC = 0x0008;
2458 pub const NO_NEW_PRIVS_ENABLE = 1;
2459 pub const NO_NEW_PRIVS_DISABLE = 2;
2460 pub const WX_MAPPINGS_PERMIT = 0x0001;
2461 pub const WX_MAPPINGS_DISALLOW_EXEC = 0x0002;
2462 pub const WX_MAPPINGS_ENFORCE = 0x80000000;
2463 pub const PROCCTL_MD_MIN = 0x10000000;
2464 // x86_64-only constants
2465 pub const KPTI = switch (builtin.cpu.arch) {
2466 .x86_64 => struct {
2467 pub const CTL = PROC.PROCCTL_MD_MIN;
2468 pub const STATUS = PROC.PROCCTL_MD_MIN + 1;
2469 pub const CTL_ENABLE_ON_EXEC = 1;
2470 pub const CTL_DISABLE_ON_EXEC = 2;
2471 pub const STATUS_ACTIVE = 0x80000000;
2472 },
2473 else => void,
2474 };
2475 pub const LA = switch (builtin.cpu.arch) {
2476 .x86_64 => struct {
2477 pub const CTL = PROC.PROCCTL_MD_MIN + 2;
2478 pub const STATUS = PROC.PROCCTL_MD_MIN + 3;
2479 pub const CTL_LA48_ON_EXEC = 1;
2480 pub const CTL_LA57_ON_EXEC = 2;
2481 pub const CTL_DEFAULT_ON_EXEC = 3;
2482 pub const STATUS_LA48 = 0x01000000;
2483 pub const STATUS_LA57 = 0x02000000;
2484 },
2485 else => void,
2486 };
2487};
2488
2489pub const PPROT = struct {
2490 pub fn OP(x: i32) i32 {
2491 return x & 0xf;
2492 }
2493 pub const SET = 1;
2494 pub const CLEAR = 2;
2495 pub fn FLAGS(x: i32) i32 {
2496 return x & !0xf;
2497 }
2498 pub const DESCEND = 0x10;
2499 pub const INHERIT = 0x20;
2500};
2501
2502pub const REAPER = struct {
2503 pub const STATUS_OWNED = 0x00000001;
2504 pub const STATUS_REALINIT = 0x00000002;
2505 pub const PIDINFO_VALID = 0x00000001;
2506 pub const PIDINFO_CHILD = 0x00000002;
2507 pub const PIDINFO_REAPER = 0x00000004;
2508 pub const KILL_CHILDREN = 0x00000001;
2509 pub const KILL_SUBTREE = 0x00000002;
2510};
2511
2512pub const procctl_reaper_status = extern struct {
2513 rs_flags: u32,
2514 rs_children: u32,
2515 rs_descendants: u32,
2516 rs_reaper: pid_t,
2517 rs_pid: pid_t,
2518 rs_pad0: [15]u32,
2519};
2520
2521pub const procctl_reaper_pidinfo = extern struct {
2522 pi_pid: pid_t,
2523 pi_subtree: pid_t,
2524 pi_flags: u32,
2525 pi_pad0: [15]u32,
2526};
2527
2528pub const procctl_reaper_pids = extern struct {
2529 rp_count: u32,
2530 rp_pad0: [15]u32,
2531 rp_pids: [*]procctl_reaper_pidinfo,
2532};
2533
2534pub const procctl_reaper_kill = extern struct {
2535 rk_sig: c_int,
2536 rk_flags: u32,
2537 rk_subtree: pid_t,
2538 rk_killed: u32,
2539 rk_fpid: pid_t,
2540 rk_pad0: [15]u32,
2541};
2542
2543pub extern "c" fn procctl(idtype: idtype_t, id: id_t, cmd: c_int, data: ?*anyopaque) c_int;
2544
2545pub const SHM = struct {
2546 pub const ALLOW_SEALING = 0x00000001;
2547 pub const GROW_ON_WRWITE = 0x00000002;
2548 pub const LARGEPAGE = 0x00000004;
2549 pub const LARGEPAGE_ALLOC_DEFAULT = 0;
2550 pub const LARGEPAGE_ALLOC_NOWAIT = 1;
2551 pub const LARGEPAGE_ALLOC_HARD = 2;
2552};
2553
2554pub const shm_largeconf = extern struct {
2555 psind: c_int,
2556 alloc_policy: c_int,
2557 pad: [10]c_int,
2558};
2559
2560pub 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;
2561
2562pub extern "c" fn elf_aux_info(aux: c_int, buf: ?*anyopaque, buflen: c_int) c_int;
2563
2564pub const lwpid = i32;
2565
2566pub const SIGEV = struct {
2567 pub const NONE = 0;
2568 pub const SIGNAL = 1;
2569 pub const THREAD = 2;
2570 pub const KEVENT = 3;
2571 pub const THREAD_ID = 4;
2572};
2573
2574pub const sigevent = extern struct {
2575 sigev_notify: c_int,
2576 sigev_signo: c_int,
2577 sigev_value: sigval,
2578 _sigev_un: extern union {
2579 _threadid: lwpid,
2580 _sigev_thread: extern struct {
2581 _function: ?*const fn (sigval) callconv(.C) void,
2582 _attribute: ?**pthread_attr_t,
2583 },
2584 _kevent_flags: c_ushort,
2585 __spare__: [8]c_long,
2586 },
2587};
2588
2589pub const timer_t = *opaque {};
2590
2591pub const MIN = struct {
2592 pub const INCORE = 0x1;
2593 pub const REFERENCED = 0x2;
2594 pub const MODIFIED = 0x4;
2595 pub const REFERENCED_OTHER = 0x8;
2596 pub const MODIFIED_OTHER = 0x10;
2597 pub const SUPER = 0x60;
2598 pub fn PSIND(i: u32) u32 {
2599 return (i << 5) & SUPER;
2600 }
2601};
2602
2603pub extern "c" fn mincore(
2604 addr: *align(std.mem.page_size) const anyopaque,
2605 length: usize,
2606 vec: [*]u8,
2607) c_int;
2608
2609pub const MAXMEMDOM = 8;
2610pub const domainid_t = u8;
2611
2612pub const LIST_ENTRY = opaque {};
2613
2614pub const DOMAINSET = struct {
2615 pub const POLICY_INVALID = 0;
2616 pub const POLICY_ROUNDROBIN = 1;
2617 pub const POLICY_FIRSTOUCH = 2;
2618 pub const POLICY_PREFER = 3;
2619 pub const POLICY_INTERLEAVE = 4;
2620 pub const POLICY_MAX = DOMAINSET.POLICY_INTERLEAVE;
2621};
2622
2623pub const DOMAINSET_SIZE = 256;
2624pub const domainset_t = extern struct {
2625 __bits: [(DOMAINSET_SIZE + (@sizeOf(domainset) - 1)) / @bitSizeOf(domainset)]domainset,
2626};
2627
2628pub fn DOMAINSET_COUNT(set: domainset_t) c_int {
2629 return @as(c_int, @intCast(__BIT_COUNT(set.__bits[0..])));
2630}
2631
2632pub const domainset = extern struct {
2633 link: LIST_ENTRY,
2634 mask: domainset_t,
2635 policy: u16,
2636 prefer: domainid_t,
2637 cnt: domainid_t,
2638 order: [MAXMEMDOM]domainid_t,
2639};
2640
2641pub extern "c" fn cpuset_getdomain(level: cpulevel_t, which: cpuwhich_t, id: id_t, len: usize, domain: *domainset_t, r: *c_int) c_int;
2642pub 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;
2643
2644const ioctl_cmd = enum(u32) {
2645 VOID = 0x20000000,
2646 OUT = 0x40000000,
2647 IN = 0x80000000,
2648 INOUT = ioctl_cmd.IN | ioctl_cmd.OUT,
2649 DIRMASK = ioctl_cmd.VOID | ioctl_cmd.IN | ioctl_cmd.OUT,
2650};
2651
2652fn ioImpl(cmd: ioctl_cmd, op: u8, nr: u8, comptime IT: type) u32 {
2653 return @as(u32, @bitCast(@intFromEnum(cmd) | @as(u32, @intCast(@as(u8, @truncate(@sizeOf(IT))))) << 16 | @as(u32, @intCast(op)) << 8 | nr));
2654}
2655
2656pub fn IO(op: u8, nr: u8) u32 {
2657 return ioImpl(ioctl_cmd.VOID, op, nr, 0);
2658}
2659
2660pub fn IOR(op: u8, nr: u8, comptime IT: type) u32 {
2661 return ioImpl(ioctl_cmd.OUT, op, nr, @sizeOf(IT));
2662}
2663
2664pub fn IOW(op: u8, nr: u8, comptime IT: type) u32 {
2665 return ioImpl(ioctl_cmd.IN, op, nr, @sizeOf(IT));
2666}
2667
2668pub fn IOWR(op: u8, nr: u8, comptime IT: type) u32 {
2669 return ioImpl(ioctl_cmd.INOUT, op, nr, @sizeOf(IT));
2670}
2671
2672pub const RF = struct {
2673 pub const NAMEG = 1 << 0;
2674 pub const ENVG = 1 << 1;
2675 /// copy file descriptors table
2676 pub const FDG = 1 << 2;
2677 pub const NOTEG = 1 << 3;
2678 /// creates a new process
2679 pub const PROC = 1 << 4;
2680 /// shares address space
2681 pub const MEM = 1 << 5;
2682 /// detaches the child
2683 pub const NOWAIT = 1 << 6;
2684 pub const CNAMEG = 1 << 10;
2685 pub const CENVG = 1 << 11;
2686 /// distinct file descriptor table
2687 pub const CFDG = 1 << 12;
2688 /// thread support
2689 pub const THREAD = 1 << 13;
2690 /// shares signal handlers
2691 pub const SIGSHARE = 1 << 14;
2692 /// emits SIGUSR1 on exit
2693 pub const LINUXTHPN = 1 << 16;
2694 /// child in stopped state
2695 pub const STOPPED = 1 << 17;
2696 /// use high pid id
2697 pub const HIGHPID = 1 << 18;
2698 /// selects signal flag for parent notification
2699 pub const SIGSZMB = 1 << 19;
2700 pub fn SIGNUM(f: u32) u32 {
2701 return f >> 20;
2702 }
2703 pub fn SIGFLAGS(f: u32) u32 {
2704 return f << 20;
2705 }
2706};
2707
2708pub extern "c" fn rfork(flags: c_int) c_int;
2709
2710pub const PTRACE = struct {
2711 pub const EXC = 0x0001;
2712 pub const SCE = 0x0002;
2713 pub const SCX = 0x0004;
2714 pub const SYSCALL = (PTRACE.SCE | PTRACE.SCX);
2715 pub const FORK = 0x0008;
2716 pub const LWP = 0x0010;
2717 pub const VFORK = 0x0020;
2718 pub const DEFAULT = PTRACE.EXEC;
2719};
2720
2721pub const PT = struct {
2722 pub const TRACE_ME = 0;
2723 pub const READ_I = 1;
2724 pub const READ_D = 2;
2725 pub const WRITE_I = 4;
2726 pub const WRITE_D = 5;
2727 pub const CONTINUE = 7;
2728 pub const KILL = 8;
2729 pub const STEP = 9;
2730 pub const ATTACH = 10;
2731 pub const DETACH = 11;
2732 pub const IO = 12;
2733 pub const LWPINFO = 13;
2734 pub const GETNUMLWPS = 14;
2735 pub const GETLWPLIST = 15;
2736 pub const CLEARSTEP = 16;
2737 pub const SETSTEP = 17;
2738 pub const SUSPEND = 18;
2739 pub const RESUME = 19;
2740 pub const TO_SCE = 20;
2741 pub const TO_SCX = 21;
2742 pub const SYSCALL = 22;
2743 pub const FOLLOW_FORK = 23;
2744 pub const LWP_EVENTS = 24;
2745 pub const GET_EVENT_MASK = 25;
2746 pub const SET_EVENT_MASK = 26;
2747 pub const GET_SC_ARGS = 27;
2748 pub const GET_SC_RET = 28;
2749 pub const COREDUMP = 29;
2750 pub const GETREGS = 33;
2751 pub const SETREGS = 34;
2752 pub const GETFPREGS = 35;
2753 pub const SETFPREGS = 36;
2754 pub const GETDBREGS = 37;
2755 pub const SETDBREGS = 38;
2756 pub const VM_TIMESTAMP = 40;
2757 pub const VM_ENTRY = 41;
2758 pub const GETREGSET = 42;
2759 pub const SETREGSET = 43;
2760 pub const SC_REMOTE = 44;
2761 pub const FIRSTMACH = 64;
2762};
2763
2764pub const ptrace_io_desc = extern struct {
2765 op: c_int,
2766 offs: ?*anyopaque,
2767 addr: ?*anyopaque,
2768 len: usize,
2769};
2770
2771pub const PIOD = struct {
2772 pub const READ_D = 1;
2773 pub const WRITE_D = 2;
2774 pub const READ_I = 3;
2775 pub const WRITE_I = 4;
2776};
2777
2778pub const ptrace_lwpinfo = extern struct {
2779 lwpid: lwpid_t,
2780 event: c_int,
2781 flags: c_int,
2782 sigmask: sigset_t,
2783 siglist: sigset_t,
2784 siginfo: siginfo_t,
2785 tdname: [MAXCOMLEN + 1]u8,
2786 child_pid: pid_t,
2787 syscall_code: c_uint,
2788 syscall_narg: c_uint,
2789};
2790
2791pub const ptrace_sc_ret = extern struct {
2792 retval: [2]isize,
2793 err: c_int,
2794};
2795
2796pub const ptrace_vm_entry = extern struct {
2797 entry: c_int,
2798 timestamp: c_int,
2799 start: c_ulong,
2800 end: c_ulong,
2801 offset: c_ulong,
2802 prot: c_uint,
2803 pathlen: c_uint,
2804 fileid: c_long,
2805 fsid: u32,
2806 pve_path: ?[*:0]u8,
2807};
2808
2809pub const ptrace_coredump = extern struct {
2810 fd: c_int,
2811 flags: u32,
2812 limit: isize,
2813};
2814
2815pub const ptrace_cs_remote = extern struct {
2816 ret: ptrace_sc_ret,
2817 syscall: c_uint,
2818 nargs: c_uint,
2819 args: *isize,
2820};
2821
2822pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: [*:0]u8, data: c_int) c_int;
2823
2824/// TODO refines if necessary
2825pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
2826 .x86, .powerpc => 4 * 512,
2827 else => 4 * 1024,
2828};
2829
2830pub const SYS_NMLN = 256;
2831
2832pub const utsname = extern struct {
2833 sysname: [255:0]u8,
2834 nodename: [255:0]u8,
2835 release: [255:0]u8,
2836 version: [255:0]u8,
2837 machine: [255:0]u8,
2838};
2839
2840pub extern "c" fn uname(u: *utsname) c_int;
lib/std/c/haiku.zig+8-43
...@@ -5,15 +5,11 @@ const maxInt = std.math.maxInt;...@@ -5,15 +5,11 @@ const maxInt = std.math.maxInt;
5const iovec = std.os.iovec;5const iovec = std.os.iovec;
6const iovec_const = std.os.iovec_const;6const iovec_const = std.os.iovec_const;
77
8const status_t = i32;
9
10extern "c" fn _errnop() *c_int;8extern "c" fn _errnop() *c_int;
119
12pub const _errno = _errnop;10pub const _errno = _errnop;
1311
14pub extern "c" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) status_t;12pub extern "c" fn find_directory(which: c_int, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
15
16pub extern "c" fn find_path(codePointer: ?*const u8, baseDirectory: path_base_directory, subPath: ?[*:0]const u8, pathBuffer: [*:0]u8, bufferSize: usize) status_t;
1713
18pub extern "c" fn find_thread(thread_name: ?*anyopaque) i32;14pub extern "c" fn find_thread(thread_name: ?*anyopaque) i32;
1915
...@@ -173,25 +169,25 @@ pub const Flock = extern struct {...@@ -173,25 +169,25 @@ pub const Flock = extern struct {
173169
174pub const msghdr = extern struct {170pub const msghdr = extern struct {
175 /// optional address171 /// optional address
176 name: ?*sockaddr,172 msg_name: ?*sockaddr,
177173
178 /// size of address174 /// size of address
179 namelen: socklen_t,175 msg_namelen: socklen_t,
180176
181 /// scatter/gather array177 /// scatter/gather array
182 iov: [*]iovec,178 msg_iov: [*]iovec,
183179
184 /// # elements in msg_iov180 /// # elements in msg_iov
185 iovlen: i32,181 msg_iovlen: i32,
186182
187 /// ancillary data183 /// ancillary data
188 control: ?*anyopaque,184 msg_control: ?*anyopaque,
189185
190 /// ancillary data buffer len186 /// ancillary data buffer len
191 controllen: socklen_t,187 msg_controllen: socklen_t,
192188
193 /// flags on received message189 /// flags on received message
194 flags: i32,190 msg_flags: i32,
195};191};
196192
197pub const off_t = i64;193pub const off_t = i64;
...@@ -1024,13 +1020,6 @@ pub const directory_which = enum(c_int) {...@@ -1024,13 +1020,6 @@ pub const directory_which = enum(c_int) {
1024 _,1020 _,
1025};1021};
10261022
1027// TODO fill out if needed
1028pub const path_base_directory = enum(c_int) {
1029 B_FIND_PATH_IMAGE_PATH = 1000,
1030};
1031
1032pub const B_APP_IMAGE_SYMBOL = null;
1033
1034pub const cc_t = u8;1023pub const cc_t = u8;
1035pub const speed_t = u8;1024pub const speed_t = u8;
1036pub const tcflag_t = u32;1025pub const tcflag_t = u32;
...@@ -1049,27 +1038,3 @@ pub const termios = extern struct {...@@ -1049,27 +1038,3 @@ pub const termios = extern struct {
1049};1038};
10501039
1051pub const MSG_NOSIGNAL = 0x0800;1040pub const MSG_NOSIGNAL = 0x0800;
1052
1053pub const SIGEV = struct {
1054 pub const NONE = 0;
1055 pub const SIGNAL = 1;
1056 pub const THREAD = 2;
1057};
1058
1059pub const sigval = extern union {
1060 int: c_int,
1061 ptr: ?*anyopaque,
1062};
1063
1064pub const sigevent = extern struct {
1065 sigev_notify: c_int,
1066 sigev_signo: c_int,
1067 sigev_value: sigval,
1068 sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
1069 sigev_notify_attributes: ?*pthread_attr_t,
1070};
1071
1072/// TODO refines if necessary
1073pub const PTHREAD_STACK_MIN = 2 * 4096;
1074
1075pub extern "c" fn malloc_usable_size(?*anyopaque) usize;
lib/std/c/linux.zig-34
...@@ -13,10 +13,6 @@ pub const ARCH = linux.ARCH;...@@ -13,10 +13,6 @@ pub const ARCH = linux.ARCH;
13pub const AT = linux.AT;13pub const AT = linux.AT;
14pub const CLOCK = linux.CLOCK;14pub const CLOCK = linux.CLOCK;
15pub const CPU_COUNT = linux.CPU_COUNT;15pub const CPU_COUNT = linux.CPU_COUNT;
16pub const CPU_SET = linux.CPU_SET;
17pub const CPU_ISSET = linux.CPU_ISSET;
18pub const CPU_CLR = linux.CPU_CLR;
19pub const CPU_ZERO = linux.CPU_ZERO;
20pub const E = linux.E;16pub const E = linux.E;
21pub const Elf_Symndx = linux.Elf_Symndx;17pub const Elf_Symndx = linux.Elf_Symndx;
22pub const F = linux.F;18pub const F = linux.F;
...@@ -100,7 +96,6 @@ pub const stack_t = linux.stack_t;...@@ -100,7 +96,6 @@ pub const stack_t = linux.stack_t;
100pub const tcflag_t = linux.tcflag_t;96pub const tcflag_t = linux.tcflag_t;
101pub const termios = linux.termios;97pub const termios = linux.termios;
102pub const time_t = linux.time_t;98pub const time_t = linux.time_t;
103pub const timer_t = linux.timer_t;
104pub const timespec = linux.timespec;99pub const timespec = linux.timespec;
105pub const timeval = linux.timeval;100pub const timeval = linux.timeval;
106pub const timezone = linux.timezone;101pub const timezone = linux.timezone;
...@@ -250,7 +245,6 @@ pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_...@@ -250,7 +245,6 @@ pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_
250245
251pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;246pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
252pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;247pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
253pub extern "c" fn sched_setaffinity(pid: c_int, size: usize, set: *const cpu_set_t) c_int;
254pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;248pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
255pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;249pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
256pub extern "c" fn epoll_create1(flags: c_uint) c_int;250pub extern "c" fn epoll_create1(flags: c_uint) c_int;
...@@ -351,18 +345,6 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (native_abi) {...@@ -351,18 +345,6 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (native_abi) {
351};345};
352const __SIZEOF_SEM_T = 4 * @sizeOf(usize);346const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
353347
354/// TODO refines if necessary
355pub const PTHREAD_STACK_MIN = switch (native_abi) {
356 .musl, .musleabi, .musleabihf => 2048,
357 .gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (native_arch) {
358 .aarch64, .arm, .armeb, .powerpc, .powerpc64, .powerpc64le, .loongarch32, .loongarch64 => 131072,
359 .sparc64 => 24576,
360 else => 16 * 1024,
361 },
362 .android => if (@sizeOf(usize) == 8) 16 * 1024 else 8 * 1024,
363 else => 16 * 1024,
364};
365
366pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;348pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
367pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;349pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
368350
...@@ -389,19 +371,3 @@ pub const dirent64 = struct {...@@ -389,19 +371,3 @@ pub const dirent64 = struct {
389 d_type: u8,371 d_type: u8,
390 d_name: [256]u8,372 d_name: [256]u8,
391};373};
392
393pub const MPOL = struct {
394 pub const F_NODE = 1 << 0;
395 pub const F_ADDR = 1 << 1;
396 pub const F_MEMS_ALLOWED = 1 << 2;
397 /// flags for SYS_mbind
398 pub const MF_STRICT = 1 << 0;
399 pub const MF_MOVE = 1 << 1;
400 pub const MF_MOVE_ALL = 1 << 2;
401 pub const MF_LAZY = 1 << 3;
402 pub const MF_INTERNAL = 1 << 4;
403 pub const MF_VALID = MPOL.MF_STRICT | MPOL.MF_MOVE | MPOL.MOVE_ALL;
404};
405
406pub extern "c" fn getcpu(cpu: *c_uint, node: *c_uint) c_int;
407pub extern "c" fn sched_getcpu() c_int;
lib/std/c/minix.zig-2
...@@ -16,5 +16,3 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (builtin.abi) {...@@ -16,5 +16,3 @@ const __SIZEOF_PTHREAD_MUTEX_T = switch (builtin.abi) {
16 },16 },
17 else => unreachable,17 else => unreachable,
18};18};
19
20pub const PTHREAD_STACK_MIN = 16 * 1024;
lib/std/c/netbsd.zig+14-134
...@@ -121,21 +121,9 @@ pub const pthread_attr_t = extern struct {...@@ -121,21 +121,9 @@ pub const pthread_attr_t = extern struct {
121};121};
122122
123pub const sem_t = ?*opaque {};123pub const sem_t = ?*opaque {};
124pub const cpuset_t = opaque {};
125pub const cpuid_t = c_ulong;
126124
127pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;125pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;
128pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;126pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
129pub extern "c" fn pthread_setaffinity_np(thread: std.c.pthread_t, size: usize, set: ?*cpuset_t) c_int;
130pub extern "c" fn pthread_getaffinity_np(thread: std.c.pthread_t, size: usize, set: ?*cpuset_t) c_int;
131
132pub extern "c" fn cpuset_create() ?*cpuset_t;
133pub extern "c" fn cpuset_destroy(set: ?*cpuset_t) void;
134pub extern "c" fn cpuset_zero(set: ?*cpuset_t) void;
135pub extern "c" fn cpuset_set(cpu: cpuid_t, set: ?*cpuset_t) c_int;
136pub extern "c" fn cpuset_clr(cpu: cpuid_t, set: ?*cpuset_t) c_int;
137pub extern "c" fn cpuset_isset(cpu: cpuid_t, set: ?*const cpuset_t) c_int;
138pub extern "c" fn cpuset_size(set: ?*cpuset_t) usize;
139127
140pub const blkcnt_t = i64;128pub const blkcnt_t = i64;
141pub const blksize_t = i32;129pub const blksize_t = i32;
...@@ -253,48 +241,48 @@ pub const EAI_MAX = 15;...@@ -253,48 +241,48 @@ pub const EAI_MAX = 15;
253241
254pub const msghdr = extern struct {242pub const msghdr = extern struct {
255 /// optional address243 /// optional address
256 name: ?*sockaddr,244 msg_name: ?*sockaddr,
257245
258 /// size of address246 /// size of address
259 namelen: socklen_t,247 msg_namelen: socklen_t,
260248
261 /// scatter/gather array249 /// scatter/gather array
262 iov: [*]iovec,250 msg_iov: [*]iovec,
263251
264 /// # elements in msg_iov252 /// # elements in msg_iov
265 iovlen: i32,253 msg_iovlen: i32,
266254
267 /// ancillary data255 /// ancillary data
268 control: ?*anyopaque,256 msg_control: ?*anyopaque,
269257
270 /// ancillary data buffer len258 /// ancillary data buffer len
271 controllen: socklen_t,259 msg_controllen: socklen_t,
272260
273 /// flags on received message261 /// flags on received message
274 flags: i32,262 msg_flags: i32,
275};263};
276264
277pub const msghdr_const = extern struct {265pub const msghdr_const = extern struct {
278 /// optional address266 /// optional address
279 name: ?*const sockaddr,267 msg_name: ?*const sockaddr,
280268
281 /// size of address269 /// size of address
282 namelen: socklen_t,270 msg_namelen: socklen_t,
283271
284 /// scatter/gather array272 /// scatter/gather array
285 iov: [*]const iovec_const,273 msg_iov: [*]const iovec_const,
286274
287 /// # elements in msg_iov275 /// # elements in msg_iov
288 iovlen: i32,276 msg_iovlen: i32,
289277
290 /// ancillary data278 /// ancillary data
291 control: ?*const anyopaque,279 msg_control: ?*const anyopaque,
292280
293 /// ancillary data buffer len281 /// ancillary data buffer len
294 controllen: socklen_t,282 msg_controllen: socklen_t,
295283
296 /// flags on received message284 /// flags on received message
297 flags: i32,285 msg_flags: i32,
298};286};
299287
300/// The stat structure used by libc.288/// The stat structure used by libc.
...@@ -485,11 +473,6 @@ pub const AF = struct {...@@ -485,11 +473,6 @@ pub const AF = struct {
485 pub const MAX = 37;473 pub const MAX = 37;
486};474};
487475
488pub const accept_filter_arg = extern struct {
489 af_name: [16]u8,
490 af_args: [240]u8,
491};
492
493pub const in_port_t = u16;476pub const in_port_t = u16;
494pub const sa_family_t = u8;477pub const sa_family_t = u8;
495478
...@@ -579,12 +562,6 @@ pub const PROT = struct {...@@ -579,12 +562,6 @@ pub const PROT = struct {
579 pub const READ = 1;562 pub const READ = 1;
580 pub const WRITE = 2;563 pub const WRITE = 2;
581 pub const EXEC = 4;564 pub const EXEC = 4;
582 pub fn MPROTECT(flag: u32) u32 {
583 return flag << 3;
584 }
585 pub fn MPROTECT_EXTRACT(flag: u32) u32 {
586 return (flag >> 3) & 0x7;
587 }
588};565};
589566
590pub const CLOCK = struct {567pub const CLOCK = struct {
...@@ -614,27 +591,6 @@ pub const MAP = struct {...@@ -614,27 +591,6 @@ pub const MAP = struct {
614 pub const ANON = 0x1000;591 pub const ANON = 0x1000;
615 pub const ANONYMOUS = ANON;592 pub const ANONYMOUS = ANON;
616 pub const STACK = 0x2000;593 pub const STACK = 0x2000;
617
618 pub const ALIGNMENT_SHIFT = 24;
619 pub fn ALIGNED(n: u32) u32 {
620 return n << ALIGNMENT_SHIFT;
621 }
622 pub const ALIGNMENT_64KB = MAP.ALIGNED(0xff);
623 pub const ALIGNMENT_16MB = MAP.ALIGNED(16);
624 pub const ALIGNMENT_4GB = MAP.ALIGNED(32);
625 pub const ALIGNMENT_1TB = MAP.ALIGNED(40);
626 pub const ALIGNMENT_256TB = MAP.ALIGNED(48);
627 pub const ALIGNMENT_64PB = MAP.ALIGNED(56);
628};
629
630pub const MADV = struct {
631 pub const NORMAL = 0;
632 pub const RANDOM = 1;
633 pub const SEQUENTIAL = 2;
634 pub const WILLNEED = 3;
635 pub const DONTNEED = 4;
636 pub const SPACEAVAIL = 5;
637 pub const FREE = 6;
638};594};
639595
640pub const MSF = struct {596pub const MSF = struct {
...@@ -1665,79 +1621,3 @@ pub const POLL = struct {...@@ -1665,79 +1621,3 @@ pub const POLL = struct {
1665 pub const HUP = 0x0010;1621 pub const HUP = 0x0010;
1666 pub const NVAL = 0x0020;1622 pub const NVAL = 0x0020;
1667};1623};
1668
1669pub const SIGEV = struct {
1670 pub const NONE = 0;
1671 pub const SIGNAL = 1;
1672 pub const THREAD = 2;
1673};
1674
1675pub const sigval = extern union {
1676 int: c_int,
1677 ptr: ?*anyopaque,
1678};
1679
1680pub const sigevent = extern struct {
1681 sigev_notify: c_int,
1682 sigev_signo: c_int,
1683 sigev_value: sigval,
1684 sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
1685 sigev_notify_attributes: ?*pthread_attr_t,
1686};
1687
1688pub const PTRACE = struct {
1689 pub const FORK = 0x0001;
1690 pub const VFORK = 0x0002;
1691 pub const VFORK_DONE = 0x0004;
1692 pub const LWP_CREATE = 0x0008;
1693 pub const LWP_EXIT = 0x0010;
1694 pub const POSIX_SPAWN = 0x0020;
1695};
1696
1697pub const PT = struct {
1698 pub const TRACE_ME = 0;
1699 pub const READ_I = 1;
1700 pub const READ_D = 2;
1701 pub const WRITE_I = 4;
1702 pub const WRITE_D = 5;
1703 pub const CONTINUE = 7;
1704 pub const KILL = 8;
1705 pub const ATTACH = 9;
1706 pub const DETACH = 10;
1707 pub const IO = 11;
1708 pub const DUMPCORE = 11;
1709 pub const LWPINFO = 12;
1710};
1711
1712pub const ptrace_event = extern struct {
1713 set_event: c_int,
1714};
1715
1716pub const ptrace_state = extern struct {
1717 report_event: c_int,
1718 _option: extern union {
1719 other_pid: pid_t,
1720 lwp: lwpid_t,
1721 },
1722};
1723
1724pub const ptrace_io_desc = extern struct {
1725 op: c_int,
1726 offs: ?*anyopaque,
1727 addr: ?*anyopaque,
1728 len: usize,
1729};
1730
1731pub const PIOD = struct {
1732 pub const READ_D = 1;
1733 pub const WRITE_D = 2;
1734 pub const READ_I = 3;
1735 pub const WRITE_I = 4;
1736};
1737
1738pub extern "c" fn ptrace(request: c_int, pid: pid_t, addr: ?*anyopaque, data: c_int) c_int;
1739
1740/// TODO refines if necessary
1741pub const PTHREAD_STACK_MIN = 16 * 1024;
1742
1743pub const timer_t = *opaque {};
lib/std/c/openbsd.zig+49-71
...@@ -252,22 +252,16 @@ pub const EAI_MAX = 15;...@@ -252,22 +252,16 @@ pub const EAI_MAX = 15;
252pub const msghdr = extern struct {252pub const msghdr = extern struct {
253 /// optional address253 /// optional address
254 name: ?*sockaddr,254 name: ?*sockaddr,
255
256 /// size of address255 /// size of address
257 namelen: socklen_t,256 namelen: socklen_t,
258
259 /// scatter/gather array257 /// scatter/gather array
260 iov: [*]iovec,258 iov: [*]iovec,
261259 /// # elements in iov
262 /// # elements in msg_iov
263 iovlen: c_uint,260 iovlen: c_uint,
264
265 /// ancillary data261 /// ancillary data
266 control: ?*anyopaque,262 control: ?*anyopaque,
267
268 /// ancillary data buffer len263 /// ancillary data buffer len
269 controllen: socklen_t,264 controllen: socklen_t,
270
271 /// flags on received message265 /// flags on received message
272 flags: c_int,266 flags: c_int,
273};267};
...@@ -275,22 +269,16 @@ pub const msghdr = extern struct {...@@ -275,22 +269,16 @@ pub const msghdr = extern struct {
275pub const msghdr_const = extern struct {269pub const msghdr_const = extern struct {
276 /// optional address270 /// optional address
277 name: ?*const sockaddr,271 name: ?*const sockaddr,
278
279 /// size of address272 /// size of address
280 namelen: socklen_t,273 namelen: socklen_t,
281
282 /// scatter/gather array274 /// scatter/gather array
283 iov: [*]const iovec_const,275 iov: [*]const iovec_const,
284276 /// # elements in iov
285 /// # elements in msg_iov
286 iovlen: c_uint,277 iovlen: c_uint,
287
288 /// ancillary data278 /// ancillary data
289 control: ?*const anyopaque,279 control: ?*const anyopaque,
290
291 /// ancillary data buffer len280 /// ancillary data buffer len
292 controllen: socklen_t,281 controllen: socklen_t,
293
294 /// flags on received message282 /// flags on received message
295 flags: c_int,283 flags: c_int,
296};284};
...@@ -466,16 +454,6 @@ pub const MAP = struct {...@@ -466,16 +454,6 @@ pub const MAP = struct {
466 pub const CONCEAL = 0x8000;454 pub const CONCEAL = 0x8000;
467};455};
468456
469pub const MADV = struct {
470 pub const NORMAL = 0;
471 pub const RANDOM = 1;
472 pub const SEQUENTIAL = 2;
473 pub const WILLNEED = 3;
474 pub const DONTNEED = 4;
475 pub const SPACEAVAIL = 5;
476 pub const FREE = 6;
477};
478
479pub const MSF = struct {457pub const MSF = struct {
480 pub const ASYNC = 1;458 pub const ASYNC = 1;
481 pub const INVALIDATE = 2;459 pub const INVALIDATE = 2;
...@@ -1102,54 +1080,55 @@ comptime {...@@ -1102,54 +1080,55 @@ comptime {
1102}1080}
11031081
1104pub usingnamespace switch (builtin.cpu.arch) {1082pub usingnamespace switch (builtin.cpu.arch) {
1105 .x86_64 => struct {1083 .x86_64 => struct {},
1106 pub const ucontext_t = extern struct {1084 else => struct {},
1107 sc_rdi: c_long,1085};
1108 sc_rsi: c_long,1086
1109 sc_rdx: c_long,1087pub const ucontext_t = switch (builtin.cpu.arch) {
1110 sc_rcx: c_long,1088 .x86_64 => extern struct {
1111 sc_r8: c_long,1089 sc_rdi: c_long,
1112 sc_r9: c_long,1090 sc_rsi: c_long,
1113 sc_r10: c_long,1091 sc_rdx: c_long,
1114 sc_r11: c_long,1092 sc_rcx: c_long,
1115 sc_r12: c_long,1093 sc_r8: c_long,
1116 sc_r13: c_long,1094 sc_r9: c_long,
1117 sc_r14: c_long,1095 sc_r10: c_long,
1118 sc_r15: c_long,1096 sc_r11: c_long,
1119 sc_rbp: c_long,1097 sc_r12: c_long,
1120 sc_rbx: c_long,1098 sc_r13: c_long,
1121 sc_rax: c_long,1099 sc_r14: c_long,
1122 sc_gs: c_long,1100 sc_r15: c_long,
1123 sc_fs: c_long,1101 sc_rbp: c_long,
1124 sc_es: c_long,1102 sc_rbx: c_long,
1125 sc_ds: c_long,1103 sc_rax: c_long,
1126 sc_trapno: c_long,1104 sc_gs: c_long,
1127 sc_err: c_long,1105 sc_fs: c_long,
1128 sc_rip: c_long,1106 sc_es: c_long,
1129 sc_cs: c_long,1107 sc_ds: c_long,
1130 sc_rflags: c_long,1108 sc_trapno: c_long,
1131 sc_rsp: c_long,1109 sc_err: c_long,
1132 sc_ss: c_long,1110 sc_rip: c_long,
11331111 sc_cs: c_long,
1134 sc_fpstate: *anyopaque, // struct fxsave64 *1112 sc_rflags: c_long,
1135 __sc_unused: c_int,1113 sc_rsp: c_long,
1136 sc_mask: c_int,1114 sc_ss: c_long,
1137 sc_cookie: c_long,1115
1138 };1116 sc_fpstate: *anyopaque, // struct fxsave64 *
1117 __sc_unused: c_int,
1118 sc_mask: c_int,
1119 sc_cookie: c_long,
1139 },1120 },
1140 .aarch64 => struct {1121 .aarch64 => extern struct {
1141 pub const ucontext_t = extern struct {1122 __sc_unused: c_int,
1142 __sc_unused: c_int,1123 sc_mask: c_int,
1143 sc_mask: c_int,1124 sc_sp: c_ulong,
1144 sc_sp: c_ulong,1125 sc_lr: c_ulong,
1145 sc_lr: c_ulong,1126 sc_elr: c_ulong,
1146 sc_elr: c_ulong,1127 sc_spsr: c_ulong,
1147 sc_spsr: c_ulong,1128 sc_x: [30]c_ulong,
1148 sc_x: [30]c_ulong,1129 sc_cookie: c_long,
1149 sc_cookie: c_long,
1150 };
1151 },1130 },
1152 else => struct {},1131 else => @compileError("missing ucontext_t type definition"),
1153};1132};
11541133
1155pub const sigset_t = c_uint;1134pub const sigset_t = c_uint;
...@@ -1645,7 +1624,6 @@ pub const HW = struct {...@@ -1645,7 +1624,6 @@ pub const HW = struct {
1645 pub const POWER = 26;1624 pub const POWER = 26;
1646};1625};
16471626
1648/// TODO refines if necessary
1649pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {1627pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
1650 .sparc64 => 1 << 13,1628 .sparc64 => 1 << 13,
1651 .mips64 => 1 << 14,1629 .mips64 => 1 << 14,
lib/std/c/solaris.zig+14-38
...@@ -16,7 +16,6 @@ pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;...@@ -16,7 +16,6 @@ pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
16pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;16pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
17pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;17pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
18pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;18pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
19pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
20pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;19pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
21pub extern "c" fn sysconf(sc: c_int) i64;20pub extern "c" fn sysconf(sc: c_int) i64;
22pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) c_int;21pub extern "c" fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) c_int;
...@@ -183,36 +182,36 @@ pub const EAI_MAX = 14;...@@ -183,36 +182,36 @@ pub const EAI_MAX = 14;
183182
184pub const msghdr = extern struct {183pub const msghdr = extern struct {
185 /// optional address184 /// optional address
186 name: ?*sockaddr,185 msg_name: ?*sockaddr,
187 /// size of address186 /// size of address
188 namelen: socklen_t,187 msg_namelen: socklen_t,
189 /// scatter/gather array188 /// scatter/gather array
190 iov: [*]iovec,189 msg_iov: [*]iovec,
191 /// # elements in msg_iov190 /// # elements in msg_iov
192 iovlen: i32,191 msg_iovlen: i32,
193 /// ancillary data192 /// ancillary data
194 control: ?*anyopaque,193 msg_control: ?*anyopaque,
195 /// ancillary data buffer len194 /// ancillary data buffer len
196 controllen: socklen_t,195 msg_controllen: socklen_t,
197 /// flags on received message196 /// flags on received message
198 flags: i32,197 msg_flags: i32,
199};198};
200199
201pub const msghdr_const = extern struct {200pub const msghdr_const = extern struct {
202 /// optional address201 /// optional address
203 name: ?*const sockaddr,202 msg_name: ?*const sockaddr,
204 /// size of address203 /// size of address
205 namelen: socklen_t,204 msg_namelen: socklen_t,
206 /// scatter/gather array205 /// scatter/gather array
207 iov: [*]const iovec_const,206 msg_iov: [*]const iovec_const,
208 /// # elements in msg_iov207 /// # elements in msg_iov
209 iovlen: i32,208 msg_iovlen: i32,
210 /// ancillary data209 /// ancillary data
211 control: ?*const anyopaque,210 msg_control: ?*const anyopaque,
212 /// ancillary data buffer len211 /// ancillary data buffer len
213 controllen: socklen_t,212 msg_controllen: socklen_t,
214 /// flags on received message213 /// flags on received message
215 flags: i32,214 msg_flags: i32,
216};215};
217216
218pub const cmsghdr = extern struct {217pub const cmsghdr = extern struct {
...@@ -1927,26 +1926,3 @@ pub fn IOW(io_type: u8, nr: u8, comptime IOT: type) i32 {...@@ -1927,26 +1926,3 @@ pub fn IOW(io_type: u8, nr: u8, comptime IOT: type) i32 {
1927pub fn IOWR(io_type: u8, nr: u8, comptime IOT: type) i32 {1926pub fn IOWR(io_type: u8, nr: u8, comptime IOT: type) i32 {
1928 return ioImpl(.read_write, io_type, nr, IOT);1927 return ioImpl(.read_write, io_type, nr, IOT);
1929}1928}
1930
1931pub const SIGEV = struct {
1932 pub const NONE = 0;
1933 pub const SIGNAL = 1;
1934 pub const THREAD = 2;
1935};
1936
1937pub const sigval = extern union {
1938 int: c_int,
1939 ptr: ?*anyopaque,
1940};
1941
1942pub const sigevent = extern struct {
1943 sigev_notify: c_int,
1944 sigev_signo: c_int,
1945 sigev_value: sigval,
1946 sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
1947 sigev_notify_attributes: ?*pthread_attr_t,
1948};
1949
1950pub const PTHREAD_STACK_MIN = if (@sizeOf(usize) == 8) 8 * 1024 else 4 * 1024;
1951
1952pub const timer_t = *opaque {};
lib/std/c/wasi.zig-2
...@@ -119,5 +119,3 @@ pub const POLL = struct {...@@ -119,5 +119,3 @@ pub const POLL = struct {
119 pub const HUP = 0x2000;119 pub const HUP = 0x2000;
120 pub const NVAL = 0x4000;120 pub const NVAL = 0x4000;
121};121};
122
123pub const PTHREAD_STACK_MIN = 16 * 1024;
lib/std/fs.zig+2-10
...@@ -2934,7 +2934,6 @@ pub const OpenSelfExeError = error{...@@ -2934,7 +2934,6 @@ pub const OpenSelfExeError = error{
2934 /// On Windows, file paths cannot contain these characters:2934 /// On Windows, file paths cannot contain these characters:
2935 /// '/', '*', '?', '"', '<', '>', '|'2935 /// '/', '*', '?', '"', '<', '>', '|'
2936 BadPathName,2936 BadPathName,
2937 Overflow,
2938 Unexpected,2937 Unexpected,
2939} || os.OpenError || SelfExePathError || os.FlockError;2938} || os.OpenError || SelfExePathError || os.FlockError;
29402939
...@@ -3014,14 +3013,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -3014,14 +3013,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
3014 // TODO could this slice from 0 to out_len instead?3013 // TODO could this slice from 0 to out_len instead?
3015 return mem.sliceTo(out_buffer, 0);3014 return mem.sliceTo(out_buffer, 0);
3016 },3015 },
3017 .haiku => {3016 .openbsd, .haiku => {
3018 // The only possible issue when looking for the self image path is
3019 // when the buffer is too short.
3020 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)
3021 return error.Overflow;
3022 return mem.sliceTo(out_buffer, 0);
3023 },
3024 .openbsd => {
3025 // OpenBSD doesn't support getting the path of a running process, so try to guess it3017 // OpenBSD doesn't support getting the path of a running process, so try to guess it
3026 if (os.argv.len == 0)3018 if (os.argv.len == 0)
3027 return error.FileNotFound;3019 return error.FileNotFound;
...@@ -3120,7 +3112,7 @@ const CopyFileRawError = error{SystemResources} || os.CopyFileRangeError || os.S...@@ -3120,7 +3112,7 @@ const CopyFileRawError = error{SystemResources} || os.CopyFileRangeError || os.S
3120// No metadata is transferred over.3112// No metadata is transferred over.
3121fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t, maybe_size: ?u64) CopyFileRawError!void {3113fn copy_file(fd_in: os.fd_t, fd_out: os.fd_t, maybe_size: ?u64) CopyFileRawError!void {
3122 if (comptime builtin.target.isDarwin()) {3114 if (comptime builtin.target.isDarwin()) {
3123 const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE.DATA);3115 const rc = os.system.fcopyfile(fd_in, fd_out, null, os.system.COPYFILE_DATA);
3124 switch (os.errno(rc)) {3116 switch (os.errno(rc)) {
3125 .SUCCESS => return,3117 .SUCCESS => return,
3126 .INVAL => unreachable,3118 .INVAL => unreachable,
lib/std/os.zig+21-79
...@@ -146,12 +146,7 @@ pub const addrinfo = system.addrinfo;...@@ -146,12 +146,7 @@ pub const addrinfo = system.addrinfo;
146pub const blkcnt_t = system.blkcnt_t;146pub const blkcnt_t = system.blkcnt_t;
147pub const blksize_t = system.blksize_t;147pub const blksize_t = system.blksize_t;
148pub const clock_t = system.clock_t;148pub const clock_t = system.clock_t;
149pub const cpu_set_t = if (builtin.os.tag == .linux)149pub const cpu_set_t = system.cpu_set_t;
150 system.cpu_set_t
151else if (builtin.os.tag == .freebsd)
152 freebsd.cpuset_t
153else
154 u32;
155pub const dev_t = system.dev_t;150pub const dev_t = system.dev_t;
156pub const dl_phdr_info = system.dl_phdr_info;151pub const dl_phdr_info = system.dl_phdr_info;
157pub const empty_sigset = system.empty_sigset;152pub const empty_sigset = system.empty_sigset;
...@@ -517,18 +512,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {...@@ -517,18 +512,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
517 return;512 return;
518 }513 }
519 switch (builtin.os.tag) {514 switch (builtin.os.tag) {
520 .macos, .ios => {515 .netbsd, .openbsd, .macos, .ios, .tvos, .watchos => {
521 const rc = darwin.CCRandomGenerateBytes(buffer.ptr, buffer.len);
522 if (rc != darwin.CCRNGStatus.kCCSuccess) {
523 if (rc == darwin.CCRNGStatus.kCCParamError or rc == darwin.CCRNGStatus.kCCBufferTooSmall) {
524 return error.InvalidHandle;
525 } else {
526 return error.SystemResources;
527 }
528 }
529 return;
530 },
531 .netbsd, .openbsd, .tvos, .watchos => {
532 system.arc4random_buf(buffer.ptr, buffer.len);516 system.arc4random_buf(buffer.ptr, buffer.len);
533 return;517 return;
534 },518 },
...@@ -1001,7 +985,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {...@@ -1001,7 +985,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
1001 if (have_pread_but_not_preadv) {985 if (have_pread_but_not_preadv) {
1002 // We could loop here; but proper usage of `preadv` must handle partial reads anyway.986 // We could loop here; but proper usage of `preadv` must handle partial reads anyway.
1003 // So we simply read into the first vector only.987 // So we simply read into the first vector only.
1004 if (iov.len == 0) return @as(usize, @intCast(0));988 if (iov.len == 0) return 0;
1005 const first = iov[0];989 const first = iov[0];
1006 return pread(fd, first.iov_base[0..first.iov_len], offset);990 return pread(fd, first.iov_base[0..first.iov_len], offset);
1007 }991 }
...@@ -4707,8 +4691,11 @@ pub fn sysctl(...@@ -4707,8 +4691,11 @@ pub fn sysctl(
4707 newp: ?*anyopaque,4691 newp: ?*anyopaque,
4708 newlen: usize,4692 newlen: usize,
4709) SysCtlError!void {4693) SysCtlError!void {
4710 if (builtin.os.tag == .wasi or builtin.os.tag == .haiku) {4694 if (builtin.os.tag == .wasi) {
4711 @compileError("unsupported OS");4695 @panic("unsupported"); // TODO should be compile error, not panic
4696 }
4697 if (builtin.os.tag == .haiku) {
4698 @panic("unsupported"); // TODO should be compile error, not panic
4712 }4699 }
47134700
4714 const name_len = math.cast(c_uint, name.len) orelse return error.NameTooLong;4701 const name_len = math.cast(c_uint, name.len) orelse return error.NameTooLong;
...@@ -4729,8 +4716,11 @@ pub fn sysctlbynameZ(...@@ -4729,8 +4716,11 @@ pub fn sysctlbynameZ(
4729 newp: ?*anyopaque,4716 newp: ?*anyopaque,
4730 newlen: usize,4717 newlen: usize,
4731) SysCtlError!void {4718) SysCtlError!void {
4732 if (builtin.os.tag == .wasi or builtin.os.tag == .haiku) {4719 if (builtin.os.tag == .wasi) {
4733 @compileError("unsupported OS");4720 @panic("unsupported"); // TODO should be compile error, not panic
4721 }
4722 if (builtin.os.tag == .haiku) {
4723 @panic("unsupported"); // TODO should be compile error, not panic
4734 }4724 }
47354725
4736 switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) {4726 switch (errno(system.sysctlbyname(name, oldp, oldlenp, newp, newlen))) {
...@@ -5494,64 +5484,16 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {...@@ -5494,64 +5484,16 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
5494}5484}
54955485
5496pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;5486pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
5497pub const SchedSetAffinityError = error{ InvalidCpu, PermissionDenied } || UnexpectedError;
54985487
5499pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {5488pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
5500 var set: cpu_set_t = undefined;5489 var set: cpu_set_t = undefined;
5501 if (builtin.os.tag == .linux) {5490 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
5502 switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {5491 .SUCCESS => return set,
5503 .SUCCESS => return set,5492 .FAULT => unreachable,
5504 .FAULT => unreachable,5493 .INVAL => unreachable,
5505 .INVAL => unreachable,5494 .SRCH => unreachable,
5506 .SRCH => unreachable,5495 .PERM => return error.PermissionDenied,
5507 .PERM => return error.PermissionDenied,5496 else => |err| return unexpectedErrno(err),
5508 else => |err| return unexpectedErrno(err),
5509 }
5510 } else if (builtin.os.tag == .freebsd) {
5511 switch (errno(freebsd.cpuset_getaffinity(freebsd.CPU_LEVEL_WHICH, freebsd.CPU_WHICH_PID, pid, @sizeOf(cpu_set_t), &set))) {
5512 .SUCCESS => return set,
5513 .FAULT => unreachable,
5514 .INVAL => unreachable,
5515 .SRCH => unreachable,
5516 .EDEADLK => unreachable,
5517 .PERM => return error.PermissionDenied,
5518 else => |err| return unexpectedErrno(err),
5519 }
5520 } else {
5521 @compileError("unsupported platform");
5522 }
5523}
5524
5525pub fn sched_setaffinity(pid: pid_t, cpus: []usize) SchedSetAffinityError!cpu_set_t {
5526 var set: cpu_set_t = undefined;
5527 if (builtin.os.tag == .linux) {
5528 system.CPU_ZERO(&set);
5529 for (cpus) |cpu| {
5530 system.CPU_SET(cpu, &set);
5531 }
5532 switch (errno(system.sched_setaffinity(pid, @sizeOf(cpu_set_t), &set))) {
5533 .SUCCESS => return set,
5534 .FAULT => unreachable,
5535 .SRCH => unreachable,
5536 .INVAL => return error.InvalidCpu,
5537 .PERM => return error.PermissionDenied,
5538 else => |err| return unexpectedErrno(err),
5539 }
5540 } else if (builtin.os.tag == .freebsd) {
5541 freebsd.CPU_ZERO(&set);
5542 for (cpus) |cpu| {
5543 freebsd.CPU_SET(cpu, &set);
5544 }
5545 switch (errno(freebsd.cpuset_setaffinity(freebsd.CPU_LEVEL_WHICH, freebsd.CPU_WHICH_PID, pid, @sizeOf(cpu_set_t), &set))) {
5546 .SUCCESS => return set,
5547 .FAULT => unreachable,
5548 .SRCH => unreachable,
5549 .INVAL => return error.InvalidCpu,
5550 .PERM => return error.PermissionDenied,
5551 else => |err| return unexpectedErrno(err),
5552 }
5553 } else {
5554 @compileError("unsupported platform");
5555 }5497 }
5556}5498}
55575499
...@@ -5695,7 +5637,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {...@@ -5695,7 +5637,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
5695 else => |err| return unexpectedErrno(err),5637 else => |err| return unexpectedErrno(err),
5696 }5638 }
5697 }5639 }
5698 if (builtin.os.tag == .linux or builtin.os.tag == .macos or builtin.os.tag == .freebsd) {5640 if (builtin.os.tag == .linux) {
5699 const uts = uname();5641 const uts = uname();
5700 const hostname = mem.sliceTo(&uts.nodename, 0);5642 const hostname = mem.sliceTo(&uts.nodename, 0);
5701 const result = name_buffer[0..hostname.len];5643 const result = name_buffer[0..hostname.len];
lib/std/os/linux.zig-90
...@@ -1520,28 +1520,6 @@ pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize {...@@ -1520,28 +1520,6 @@ pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize {
1520 return 0;1520 return 0;
1521}1521}
15221522
1523pub fn getcpu(cpu: *u32, node: *u32) usize {
1524 return syscall3(.getcpu, @intFromPtr(cpu), @intFromPtr(node), 0);
1525}
1526
1527pub fn sched_getcpu() usize {
1528 var cpu: u32 = undefined;
1529 const rc = syscall3(.getcpu, @intFromPtr(&cpu), 0, 0);
1530 if (@as(isize, @bitCast(rc)) < 0) return rc;
1531 return @as(usize, @intCast(cpu));
1532}
1533
1534/// libc has no wrapper for this syscall
1535pub fn mbind(addr: ?*anyopaque, len: u32, mode: i32, nodemask: *const u32, maxnode: u32, flags: u32) usize {
1536 return syscall6(.mbind, @intFromPtr(addr), len, @as(usize, @bitCast(@as(isize, mode))), @intFromPtr(nodemask), maxnode, flags);
1537}
1538
1539pub fn sched_setaffinity(pid: pid_t, size: usize, set: *const cpu_set_t) usize {
1540 const rc = syscall3(.sched_setaffinity, @as(usize, @bitCast(@as(isize, pid))), size, @intFromPtr(set));
1541 if (@as(isize, @bitCast(rc)) < 0) return rc;
1542 return 0;
1543}
1544
1545pub fn epoll_create() usize {1523pub fn epoll_create() usize {
1546 return epoll_create1(0);1524 return epoll_create1(0);
1547}1525}
...@@ -1591,43 +1569,6 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_va...@@ -1591,43 +1569,6 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_va
1591 return syscall4(.timerfd_settime, @as(usize, @bitCast(@as(isize, fd))), flags, @intFromPtr(new_value), @intFromPtr(old_value));1569 return syscall4(.timerfd_settime, @as(usize, @bitCast(@as(isize, fd))), flags, @intFromPtr(new_value), @intFromPtr(old_value));
1592}1570}
15931571
1594pub const sigevent = extern struct {
1595 value: sigval,
1596 signo: i32,
1597 inotify: i32,
1598 libc_priv_impl: opaque {},
1599};
1600
1601// Flags for sigevent sigev_inotify's field
1602pub const SIGEV = enum(i32) {
1603 NONE = 0,
1604 SIGNAL = 1,
1605 THREAD = 2,
1606 THREAD_ID = 4,
1607};
1608
1609pub const timer_t = ?*anyopaque;
1610
1611pub fn timer_create(clockid: i32, sevp: *sigevent, timerid: *timer_t) usize {
1612 var t: timer_t = undefined;
1613 const rc = syscall3(.timer_create, @as(usize, @bitCast(@as(isize, clockid))), @intFromPtr(sevp), @intFromPtr(&t));
1614 if (@as(isize, @bitCast(rc)) < 0) return rc;
1615 timerid.* = t;
1616 return rc;
1617}
1618
1619pub fn timer_delete(timerid: timer_t) usize {
1620 return syscall1(.timer_delete, timerid);
1621}
1622
1623pub fn timer_gettime(timerid: timer_t, curr_value: *itimerspec) usize {
1624 return syscall2(.timer_gettime, @intFromPtr(timerid), @intFromPtr(curr_value));
1625}
1626
1627pub fn timer_settime(timerid: timer_t, flags: i32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1628 return syscall4(.timer_settime, @intFromPtr(timerid), @as(usize, @bitCast(@as(isize, flags))), @intFromPtr(new_value), @intFromPtr(old_value));
1629}
1630
1631// Flags for the 'setitimer' system call1572// Flags for the 'setitimer' system call
1632pub const ITIMER = enum(i32) {1573pub const ITIMER = enum(i32) {
1633 REAL = 0,1574 REAL = 0,
...@@ -3597,11 +3538,6 @@ pub const CPU_SETSIZE = 128;...@@ -3597,11 +3538,6 @@ pub const CPU_SETSIZE = 128;
3597pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;3538pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
3598pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));3539pub const cpu_count_t = std.meta.Int(.unsigned, std.math.log2(CPU_SETSIZE * 8));
35993540
3600fn cpu_mask(s: usize) cpu_count_t {
3601 var x = s & (CPU_SETSIZE * 8);
3602 return @as(cpu_count_t, @intCast(1)) << @as(u4, @intCast(x));
3603}
3604
3605pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {3541pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
3606 var sum: cpu_count_t = 0;3542 var sum: cpu_count_t = 0;
3607 for (set) |x| {3543 for (set) |x| {
...@@ -3610,32 +3546,6 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {...@@ -3610,32 +3546,6 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
3610 return sum;3546 return sum;
3611}3547}
36123548
3613pub fn CPU_ZERO(set: *cpu_set_t) void {
3614 @memset(set, 0);
3615}
3616
3617pub fn CPU_SET(cpu: usize, set: *cpu_set_t) void {
3618 const x = cpu / @sizeOf(usize);
3619 if (x < @sizeOf(cpu_set_t)) {
3620 (set.*)[x] |= cpu_mask(x);
3621 }
3622}
3623
3624pub fn CPU_ISSET(cpu: usize, set: cpu_set_t) bool {
3625 const x = cpu / @sizeOf(usize);
3626 if (x < @sizeOf(cpu_set_t)) {
3627 return set[x] & cpu_mask(x) != 0;
3628 }
3629 return false;
3630}
3631
3632pub fn CPU_CLR(cpu: usize, set: *cpu_set_t) void {
3633 const x = cpu / @sizeOf(usize);
3634 if (x < @sizeOf(cpu_set_t)) {
3635 (set.*)[x] &= !cpu_mask(x);
3636 }
3637}
3638
3639pub const MINSIGSTKSZ = switch (native_arch) {3549pub const MINSIGSTKSZ = switch (native_arch) {
3640 .x86, .x86_64, .arm, .mipsel => 2048,3550 .x86, .x86_64, .arm, .mipsel => 2048,
3641 .aarch64 => 5120,3551 .aarch64 => 5120,
lib/std/process.zig+3-8
...@@ -1163,17 +1163,12 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {...@@ -1163,17 +1163,12 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
1163 .linux => {1163 .linux => {
1164 return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory;1164 return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory;
1165 },1165 },
1166 .freebsd, .netbsd, .dragonfly, .macos => {1166 .freebsd => {
1167 var physmem: c_ulong = undefined;1167 var physmem: c_ulong = undefined;
1168 var len: usize = @sizeOf(c_ulong);1168 var len: usize = @sizeOf(c_ulong);
1169 const name = switch (builtin.os.tag) {1169 os.sysctlbynameZ("hw.physmem", &physmem, &len, null, 0) catch |err| switch (err) {
1170 .macos => "hw.memsize",
1171 .netbsd => "hw.physmem64",
1172 else => "hw.physmem",
1173 };
1174 os.sysctlbynameZ(name, &physmem, &len, null, 0) catch |err| switch (err) {
1175 error.NameTooLong, error.UnknownName => unreachable,1170 error.NameTooLong, error.UnknownName => unreachable,
1176 else => return error.UnknownTotalSystemMemory,1171 else => |e| return e,
1177 };1172 };
1178 return @as(usize, @intCast(physmem));1173 return @as(usize, @intCast(physmem));
1179 },1174 },