authorgravatar for dev@sgregoratto.meStephen Gregoratto <dev@sgregoratto.me> 2022-08-08 15:06:47+10:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-09-14 20:05:54-04:00
log7ccb94fac87ada47af32ae187e68f294873d2694
tree7d286547e483c7628a94d5c646769c323f9ef2a8
parent8c9f468fddbba41e49c932e015d49725ca62338e

Audit FreeBSD structs to match header files/ABI

The big outliers were `Stat` and `mcontext_t`. Also adds doc-comments from the headers where possible.

1 files changed, 105 insertions(+), 47 deletions(-)

lib/std/c/freebsd.zig+105-47
...@@ -54,8 +54,7 @@ pub const pthread_rwlock_t = extern struct {...@@ -54,8 +54,7 @@ pub const pthread_rwlock_t = extern struct {
54};54};
5555
56pub const pthread_attr_t = extern struct {56pub const pthread_attr_t = extern struct {
57 __size: [56]u8,57 inner: ?*anyopaque = null,
58 __align: c_long,
59};58};
6059
61pub const sem_t = extern struct {60pub const sem_t = extern struct {
...@@ -181,6 +180,7 @@ pub const AI = struct {...@@ -181,6 +180,7 @@ pub const AI = struct {
181pub const blksize_t = i32;180pub const blksize_t = i32;
182pub const blkcnt_t = i64;181pub const blkcnt_t = i64;
183pub const clockid_t = i32;182pub const clockid_t = i32;
183pub const fflags_t = u32;
184pub const fsblkcnt_t = u64;184pub const fsblkcnt_t = u64;
185pub const fsfilcnt_t = u64;185pub const fsfilcnt_t = u64;
186pub const nlink_t = u64;186pub const nlink_t = u64;
...@@ -201,13 +201,20 @@ pub const suseconds_t = c_long;...@@ -201,13 +201,20 @@ pub const suseconds_t = c_long;
201201
202/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.202/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
203pub const Kevent = extern struct {203pub const Kevent = extern struct {
204 /// Identifier for this event.
204 ident: usize,205 ident: usize,
206 /// Filter for event.
205 filter: i16,207 filter: i16,
208 /// Action flags for kqueue.
206 flags: u16,209 flags: u16,
210 /// Filter flag value.
207 fflags: u32,211 fflags: u32,
212 /// Filter data value.
208 data: i64,213 data: i64,
214 /// Opaque user data identifier.
209 udata: usize,215 udata: usize,
210 // TODO ext216 /// Future extensions.
217 _ext: [4]u64 = [_]u64{0} ** 4,
211};218};
212219
213// Modes and flags for dlopen()220// Modes and flags for dlopen()
...@@ -230,90 +237,108 @@ pub const RTLD = struct {...@@ -230,90 +237,108 @@ pub const RTLD = struct {
230 /// Do not load if not already loaded.237 /// Do not load if not already loaded.
231 pub const NOLOAD = 0x02000;238 pub const NOLOAD = 0x02000;
232};239};
240
233pub const dl_phdr_info = extern struct {241pub const dl_phdr_info = extern struct {
234 dlpi_addr: usize,242 /// Module relocation base.
243 dlpi_addr: if (builtin.cpu.arch.ptrBitWidth() == 32) std.elf.Elf32_Addr else std.elf.Elf64_Addr,
244 /// Module name.
235 dlpi_name: ?[*:0]const u8,245 dlpi_name: ?[*:0]const u8,
246 /// Pointer to module's phdr.
236 dlpi_phdr: [*]std.elf.Phdr,247 dlpi_phdr: [*]std.elf.Phdr,
248 /// Number of entries in phdr.
237 dlpi_phnum: u16,249 dlpi_phnum: u16,
250 /// Total number of loads.
251 dlpi_adds: u64,
252 /// Total number of unloads.
253 dlpi_subs: u64,
254 dlpi_tls_modid: usize,
255 dlpi_tls_data: ?*anyopaque,
238};256};
239257
240pub const Flock = extern struct {258pub const Flock = extern struct {
259 /// Starting offset.
241 start: off_t,260 start: off_t,
261 /// Number of consecutive bytes to be locked.
262 /// A value of 0 means to the end of the file.
242 len: off_t,263 len: off_t,
264 /// Lock owner.
243 pid: pid_t,265 pid: pid_t,
244 type: i16,266 /// Lock type.
267 @"type": i16,
268 /// Type of the start member.
245 whence: i16,269 whence: i16,
270 /// Remote system id or zero for local.
246 sysid: i32,271 sysid: i32,
247 __unused: [4]u8,
248};272};
249273
250pub const msghdr = extern struct {274pub const msghdr = extern struct {
251 /// optional address275 /// Optional address.
252 msg_name: ?*sockaddr,276 msg_name: ?*sockaddr,
253277 /// Size of address.
254 /// size of address
255 msg_namelen: socklen_t,278 msg_namelen: socklen_t,
256279 /// Scatter/gather array.
257 /// scatter/gather array
258 msg_iov: [*]iovec,280 msg_iov: [*]iovec,
259281 /// Number of elements in msg_iov.
260 /// # elements in msg_iov
261 msg_iovlen: i32,282 msg_iovlen: i32,
262283 /// Ancillary data.
263 /// ancillary data
264 msg_control: ?*anyopaque,284 msg_control: ?*anyopaque,
265285 /// Ancillary data buffer length.
266 /// ancillary data buffer len
267 msg_controllen: socklen_t,286 msg_controllen: socklen_t,
268287 /// Flags on received message.
269 /// flags on received message
270 msg_flags: i32,288 msg_flags: i32,
271};289};
272290
273pub const msghdr_const = extern struct {291pub const msghdr_const = extern struct {
274 /// optional address292 /// Optional address.
275 msg_name: ?*const sockaddr,293 msg_name: ?*const sockaddr,
276294 /// Size of address.
277 /// size of address
278 msg_namelen: socklen_t,295 msg_namelen: socklen_t,
279296 /// Scatter/gather array.
280 /// scatter/gather array
281 msg_iov: [*]iovec_const,297 msg_iov: [*]iovec_const,
282298 /// Number of elements in msg_iov.
283 /// # elements in msg_iov
284 msg_iovlen: i32,299 msg_iovlen: i32,
285300 /// Ancillary data.
286 /// ancillary data
287 msg_control: ?*anyopaque,301 msg_control: ?*anyopaque,
288302 /// Ancillary data buffer length.
289 /// ancillary data buffer len
290 msg_controllen: socklen_t,303 msg_controllen: socklen_t,
291304 /// Flags on received message.
292 /// flags on received message
293 msg_flags: i32,305 msg_flags: i32,
294};306};
295307
296pub const Stat = extern struct {308pub const Stat = extern struct {
309 /// The inode's device.
297 dev: dev_t,310 dev: dev_t,
311 /// The inode's number.
298 ino: ino_t,312 ino: ino_t,
313 /// Number of hard links.
299 nlink: nlink_t,314 nlink: nlink_t,
300315 /// Inode protection mode.
301 mode: mode_t,316 mode: mode_t,
302 __pad0: u16,317 __pad0: i16,
318 /// User ID of the file's owner.
303 uid: uid_t,319 uid: uid_t,
320 /// Group ID of the file's group.
304 gid: gid_t,321 gid: gid_t,
305 __pad1: u32,322 __pad1: i32,
323 /// Device type.
306 rdev: dev_t,324 rdev: dev_t,
307325 /// Time of last access.
308 atim: timespec,326 atim: timespec,
327 /// Time of last data modification.
309 mtim: timespec,328 mtim: timespec,
329 /// Time of last file status change.
310 ctim: timespec,330 ctim: timespec,
331 /// Time of file creation.
311 birthtim: timespec,332 birthtim: timespec,
312333 /// File size, in bytes.
313 size: off_t,334 size: off_t,
314 blocks: i64,335 /// Blocks allocated for file.
315 blksize: isize,336 blocks: blkcnt_t,
316 flags: u32,337 /// Optimal blocksize for I/O.
338 blksize: blksize_t,
339 /// User defined flags for file.
340 flags: fflags_t,
341 /// File generation number.
317 gen: u64,342 gen: u64,
318 __spare: [10]u64,343 __spare: [10]u64,
319344
...@@ -347,14 +372,20 @@ pub const timeval = extern struct {...@@ -347,14 +372,20 @@ pub const timeval = extern struct {
347};372};
348373
349pub const dirent = extern struct {374pub const dirent = extern struct {
350 d_fileno: usize,375 /// File number of entry.
351 d_off: i64,376 d_fileno: ino_t,
377 /// Directory offset of entry.
378 d_off: off_t,
379 /// Length of this record.
352 d_reclen: u16,380 d_reclen: u16,
381 /// File type, one of DT_.
353 d_type: u8,382 d_type: u8,
354 d_pad0: u8,383 _d_pad0: u8,
384 /// Length of the d_name member.
355 d_namlen: u16,385 d_namlen: u16,
356 d_pad1: u16,386 _d_pad1: u16,
357 d_name: [256]u8,387 /// Name of entry.
388 d_name: [255:0]u8,
358389
359 pub fn reclen(self: dirent) u16 {390 pub fn reclen(self: dirent) u16 {
360 return self.d_reclen;391 return self.d_reclen;
...@@ -1192,16 +1223,30 @@ pub const Sigaction = extern struct {...@@ -1192,16 +1223,30 @@ pub const Sigaction = extern struct {
1192};1223};
11931224
1194pub const siginfo_t = extern struct {1225pub const siginfo_t = extern struct {
1226 // Signal number.
1195 signo: c_int,1227 signo: c_int,
1228 // Errno association.
1196 errno: c_int,1229 errno: c_int,
1230 /// Signal code.
1231 ///
1232 /// Cause of signal, one of the SI_ macros or signal-specific values, i.e.
1233 /// one of the FPE_... values for SIGFPE.
1234 /// This value is equivalent to the second argument to an old-style FreeBSD
1235 /// signal handler.
1197 code: c_int,1236 code: c_int,
1237 /// Sending process.
1198 pid: pid_t,1238 pid: pid_t,
1239 /// Sender's ruid.
1199 uid: uid_t,1240 uid: uid_t,
1241 /// Exit value.
1200 status: c_int,1242 status: c_int,
1243 /// Faulting instruction.
1201 addr: ?*anyopaque,1244 addr: ?*anyopaque,
1245 /// Signal value.
1202 value: sigval,1246 value: sigval,
1203 reason: extern union {1247 reason: extern union {
1204 fault: extern struct {1248 fault: extern struct {
1249 /// Machine specific trap code.
1205 trapno: c_int,1250 trapno: c_int,
1206 },1251 },
1207 timer: extern struct {1252 timer: extern struct {
...@@ -1212,6 +1257,7 @@ pub const siginfo_t = extern struct {...@@ -1212,6 +1257,7 @@ pub const siginfo_t = extern struct {
1212 mqd: c_int,1257 mqd: c_int,
1213 },1258 },
1214 poll: extern struct {1259 poll: extern struct {
1260 /// Band event for SIGPOLL. UNUSED.
1215 band: c_long,1261 band: c_long,
1216 },1262 },
1217 spare: extern struct {1263 spare: extern struct {
...@@ -1263,6 +1309,15 @@ pub usingnamespace switch (builtin.cpu.arch) {...@@ -1263,6 +1309,15 @@ pub usingnamespace switch (builtin.cpu.arch) {
1263 rflags: u64,1309 rflags: u64,
1264 rsp: u64,1310 rsp: u64,
1265 ss: u64,1311 ss: u64,
1312 len: u64,
1313 fpformat: u64,
1314 ownedfp: u64,
1315 fpstate: [64]u64 align(16),
1316 fsbase: u64,
1317 gsbase: u64,
1318 xfpustate: u64,
1319 xfpustate_len: u64,
1320 spare: [4]u64,
1266 };1321 };
1267 },1322 },
1268 else => struct {},1323 else => struct {},
...@@ -1408,8 +1463,11 @@ pub const SS_ONSTACK = 1;...@@ -1408,8 +1463,11 @@ pub const SS_ONSTACK = 1;
1408pub const SS_DISABLE = 4;1463pub const SS_DISABLE = 4;
14091464
1410pub const stack_t = extern struct {1465pub const stack_t = extern struct {
1411 sp: [*]u8,1466 /// Signal stack base.
1412 size: isize,1467 sp: *anyopaque,
1468 /// Signal stack length.
1469 size: usize,
1470 /// SS_DISABLE and/or SS_ONSTACK.
1413 flags: i32,1471 flags: i32,
1414};1472};
14151473