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 {
5454};
5555
5656pub const pthread_attr_t = extern struct {
57 __size: [56]u8,
58 __align: c_long,
57 inner: ?*anyopaque = null,
5958};
6059
6160pub const sem_t = extern struct {
......@@ -181,6 +180,7 @@ pub const AI = struct {
181180pub const blksize_t = i32;
182181pub const blkcnt_t = i64;
183182pub const clockid_t = i32;
183pub const fflags_t = u32;
184184pub const fsblkcnt_t = u64;
185185pub const fsfilcnt_t = u64;
186186pub const nlink_t = u64;
......@@ -201,13 +201,20 @@ pub const suseconds_t = c_long;
201201
202202/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
203203pub const Kevent = extern struct {
204 /// Identifier for this event.
204205 ident: usize,
206 /// Filter for event.
205207 filter: i16,
208 /// Action flags for kqueue.
206209 flags: u16,
210 /// Filter flag value.
207211 fflags: u32,
212 /// Filter data value.
208213 data: i64,
214 /// Opaque user data identifier.
209215 udata: usize,
210 // TODO ext
216 /// Future extensions.
217 _ext: [4]u64 = [_]u64{0} ** 4,
211218};
212219
213220// Modes and flags for dlopen()
......@@ -230,90 +237,108 @@ pub const RTLD = struct {
230237 /// Do not load if not already loaded.
231238 pub const NOLOAD = 0x02000;
232239};
240
233241pub 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.
235245 dlpi_name: ?[*:0]const u8,
246 /// Pointer to module's phdr.
236247 dlpi_phdr: [*]std.elf.Phdr,
248 /// Number of entries in phdr.
237249 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,
238256};
239257
240258pub const Flock = extern struct {
259 /// Starting offset.
241260 start: off_t,
261 /// Number of consecutive bytes to be locked.
262 /// A value of 0 means to the end of the file.
242263 len: off_t,
264 /// Lock owner.
243265 pid: pid_t,
244 type: i16,
266 /// Lock type.
267 @"type": i16,
268 /// Type of the start member.
245269 whence: i16,
270 /// Remote system id or zero for local.
246271 sysid: i32,
247 __unused: [4]u8,
248272};
249273
250274pub const msghdr = extern struct {
251 /// optional address
275 /// Optional address.
252276 msg_name: ?*sockaddr,
253
254 /// size of address
277 /// Size of address.
255278 msg_namelen: socklen_t,
256
257 /// scatter/gather array
279 /// Scatter/gather array.
258280 msg_iov: [*]iovec,
259
260 /// # elements in msg_iov
281 /// Number of elements in msg_iov.
261282 msg_iovlen: i32,
262
263 /// ancillary data
283 /// Ancillary data.
264284 msg_control: ?*anyopaque,
265
266 /// ancillary data buffer len
285 /// Ancillary data buffer length.
267286 msg_controllen: socklen_t,
268
269 /// flags on received message
287 /// Flags on received message.
270288 msg_flags: i32,
271289};
272290
273291pub const msghdr_const = extern struct {
274 /// optional address
292 /// Optional address.
275293 msg_name: ?*const sockaddr,
276
277 /// size of address
294 /// Size of address.
278295 msg_namelen: socklen_t,
279
280 /// scatter/gather array
296 /// Scatter/gather array.
281297 msg_iov: [*]iovec_const,
282
283 /// # elements in msg_iov
298 /// Number of elements in msg_iov.
284299 msg_iovlen: i32,
285
286 /// ancillary data
300 /// Ancillary data.
287301 msg_control: ?*anyopaque,
288
289 /// ancillary data buffer len
302 /// Ancillary data buffer length.
290303 msg_controllen: socklen_t,
291
292 /// flags on received message
304 /// Flags on received message.
293305 msg_flags: i32,
294306};
295307
296308pub const Stat = extern struct {
309 /// The inode's device.
297310 dev: dev_t,
311 /// The inode's number.
298312 ino: ino_t,
313 /// Number of hard links.
299314 nlink: nlink_t,
300
315 /// Inode protection mode.
301316 mode: mode_t,
302 __pad0: u16,
317 __pad0: i16,
318 /// User ID of the file's owner.
303319 uid: uid_t,
320 /// Group ID of the file's group.
304321 gid: gid_t,
305 __pad1: u32,
322 __pad1: i32,
323 /// Device type.
306324 rdev: dev_t,
307
325 /// Time of last access.
308326 atim: timespec,
327 /// Time of last data modification.
309328 mtim: timespec,
329 /// Time of last file status change.
310330 ctim: timespec,
331 /// Time of file creation.
311332 birthtim: timespec,
312
333 /// File size, in bytes.
313334 size: off_t,
314 blocks: i64,
315 blksize: isize,
316 flags: u32,
335 /// Blocks allocated for file.
336 blocks: blkcnt_t,
337 /// Optimal blocksize for I/O.
338 blksize: blksize_t,
339 /// User defined flags for file.
340 flags: fflags_t,
341 /// File generation number.
317342 gen: u64,
318343 __spare: [10]u64,
319344
......@@ -347,14 +372,20 @@ pub const timeval = extern struct {
347372};
348373
349374pub const dirent = extern struct {
350 d_fileno: usize,
351 d_off: i64,
375 /// File number of entry.
376 d_fileno: ino_t,
377 /// Directory offset of entry.
378 d_off: off_t,
379 /// Length of this record.
352380 d_reclen: u16,
381 /// File type, one of DT_.
353382 d_type: u8,
354 d_pad0: u8,
383 _d_pad0: u8,
384 /// Length of the d_name member.
355385 d_namlen: u16,
356 d_pad1: u16,
357 d_name: [256]u8,
386 _d_pad1: u16,
387 /// Name of entry.
388 d_name: [255:0]u8,
358389
359390 pub fn reclen(self: dirent) u16 {
360391 return self.d_reclen;
......@@ -1192,16 +1223,30 @@ pub const Sigaction = extern struct {
11921223};
11931224
11941225pub const siginfo_t = extern struct {
1226 // Signal number.
11951227 signo: c_int,
1228 // Errno association.
11961229 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.
11971236 code: c_int,
1237 /// Sending process.
11981238 pid: pid_t,
1239 /// Sender's ruid.
11991240 uid: uid_t,
1241 /// Exit value.
12001242 status: c_int,
1243 /// Faulting instruction.
12011244 addr: ?*anyopaque,
1245 /// Signal value.
12021246 value: sigval,
12031247 reason: extern union {
12041248 fault: extern struct {
1249 /// Machine specific trap code.
12051250 trapno: c_int,
12061251 },
12071252 timer: extern struct {
......@@ -1212,6 +1257,7 @@ pub const siginfo_t = extern struct {
12121257 mqd: c_int,
12131258 },
12141259 poll: extern struct {
1260 /// Band event for SIGPOLL. UNUSED.
12151261 band: c_long,
12161262 },
12171263 spare: extern struct {
......@@ -1263,6 +1309,15 @@ pub usingnamespace switch (builtin.cpu.arch) {
12631309 rflags: u64,
12641310 rsp: u64,
12651311 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,
12661321 };
12671322 },
12681323 else => struct {},
......@@ -1408,8 +1463,11 @@ pub const SS_ONSTACK = 1;
14081463pub const SS_DISABLE = 4;
14091464
14101465pub const stack_t = extern struct {
1411 sp: [*]u8,
1412 size: isize,
1466 /// Signal stack base.
1467 sp: *anyopaque,
1468 /// Signal stack length.
1469 size: usize,
1470 /// SS_DISABLE and/or SS_ONSTACK.
14131471 flags: i32,
14141472};
14151473