From f313c884283e69298f6dc375259eb522fcf58487 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 4 Nov 2020 15:54:38 +0100 Subject: [PATCH 1/4] std: Fix pipe syscall stub for sparc64 --- lib/std/os/linux/sparc64.zig | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index c3c95424a005f9617ae3b0e8242f68614e91b701..a5aa6c543a4ea2cc56c52afdac2db2b3c845b321 100644 --- a/lib/std/os/linux/sparc64.zig +++ b/lib/std/os/linux/sparc64.zig @@ -2,20 +2,21 @@ usingnamespace @import("../bits.zig"); pub fn syscall_pipe(fd: *[2]i32) usize { return asm volatile ( - \\ mov %%o0, %%o2 + \\ mov %[arg], %%g3 \\ t 0x6d \\ bcc,pt %%xcc, 1f \\ nop + \\ # Return the error code \\ ba 2f \\ neg %%o0 - \\ 1: - \\ st %%o0, [%%o2] - \\ st %%o1, [%%o2 + 4] - \\ clr %%o0 - \\ 2: + \\1: + \\ st %%o0, [%%g3+0] + \\ st %%o1, [%%g3+4] + \\2: : [ret] "={o0}" (-> usize) - : [number] "{$2}" (@enumToInt(SYS.pipe)) - : "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7" + : [number] "{g1}" (@enumToInt(SYS.pipe)), + [arg] "r" (fd) + : "memory", "g3" ); } @@ -107,7 +108,7 @@ pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, [arg2] "{o1}" (arg2), [arg3] "{o2}" (arg3), [arg4] "{o3}" (arg4), - [arg5] "{o4}" (arg5), + [arg5] "{o4}" (arg5) : "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7" ); } @@ -134,7 +135,7 @@ pub fn syscall6( [arg3] "{o2}" (arg3), [arg4] "{o3}" (arg4), [arg5] "{o4}" (arg5), - [arg6] "{o5}" (arg6), + [arg6] "{o5}" (arg6) : "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7" ); } -- 2.54.0 From 346a686b9d6a086d0e5f3b25bd686681eea7052b Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 4 Nov 2020 15:55:06 +0100 Subject: [PATCH 2/4] std: Correct stack_t definition for mips --- lib/std/os/bits/linux.zig | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index ce9b4a90d1531d7b3be9216929fcf0c4efb1187f..a81c0783248cd3faf87df04d2fbacfa0f28db0dd 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -1131,11 +1131,19 @@ pub const SS_ONSTACK = 1; pub const SS_DISABLE = 2; pub const SS_AUTODISARM = 1 << 31; -pub const stack_t = extern struct { - ss_sp: [*]u8, - ss_flags: i32, - ss_size: isize, -}; +pub const stack_t = if (is_mips) + // IRIX compatible stack_t + extern struct { + ss_sp: [*]u8, + ss_size: usize, + ss_flags: i32, + } +else + extern struct { + ss_sp: [*]u8, + ss_flags: i32, + ss_size: usize, + }; pub const sigval = extern union { int: i32, @@ -1301,7 +1309,7 @@ pub const io_uring_sqe = extern struct { buf_index: u16, personality: u16, splice_fd_in: i32, - __pad2: [2]u64 + __pad2: [2]u64, }; pub const IOSQE_BIT = extern enum(u8) { @@ -1311,7 +1319,7 @@ pub const IOSQE_BIT = extern enum(u8) { IO_HARDLINK, ASYNC, BUFFER_SELECT, - + _, }; -- 2.54.0 From 0e95fa455c1012fc5d2247600b89e2d60f146ef3 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 4 Nov 2020 15:55:36 +0100 Subject: [PATCH 3/4] std: Split kernel&libc definitions of stat struct There's no guarantee for the kernel definition to be ABI compatible with the libc one (and vice versa). There's also no guarantee of ABI compatibility between musl/glibc. Fun, isn't it? --- lib/std/c.zig | 12 +++---- lib/std/c/darwin.zig | 8 ++--- lib/std/os.zig | 5 +++ lib/std/os/bits/darwin.zig | 14 +++----- lib/std/os/bits/dragonfly.zig | 8 ++--- lib/std/os/bits/freebsd.zig | 14 +++----- lib/std/os/bits/linux/arm-eabi.zig | 18 +++++----- lib/std/os/bits/linux/arm64.zig | 18 +++++----- lib/std/os/bits/linux/i386.zig | 18 +++++----- lib/std/os/bits/linux/mips.zig | 51 ++++++++++++++++++++++++----- lib/std/os/bits/linux/powerpc64.zig | 18 +++++----- lib/std/os/bits/linux/riscv64.zig | 18 +++++----- lib/std/os/bits/linux/sparc64.zig | 51 ++++++++++++----------------- lib/std/os/bits/linux/x86_64.zig | 18 +++++----- lib/std/os/bits/netbsd.zig | 14 +++----- lib/std/os/bits/openbsd.zig | 14 +++----- lib/std/os/bits/wasi.zig | 2 +- lib/std/os/linux.zig | 8 ++--- lib/std/os/linux/sparc64.zig | 1 + lib/std/os/linux/test.zig | 2 +- 20 files changed, 153 insertions(+), 159 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 7d2d200e7e42bdda7874ad37289800783ba60a1a..54155a7e1a62987f289eb40e2c3e8b29b85ce33b 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -128,7 +128,7 @@ pub usingnamespace switch (builtin.os.tag) { }, else => struct { pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; - pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int; + pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int; }, }; @@ -202,26 +202,26 @@ pub usingnamespace switch (builtin.os.tag) { pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; - pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int; + pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int; }, .windows => struct { // TODO: copied the else case and removed the socket function (because its in ws2_32) // need to verify which of these is actually supported on windows pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int; pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int; - pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; + pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int; pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int; pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; pub extern "c" fn sched_yield() c_int; pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; - pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int; + pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int; }, else => struct { pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int; pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int; - pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; + pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int; pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int; pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; @@ -229,7 +229,7 @@ pub usingnamespace switch (builtin.os.tag) { pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; - pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int; + pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int; }, }; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index e0acd6c746752aecc1a907e14d404d7a2d255872..6074a0960dbcdbea8c16be59af2afb7fcd10e79d 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -30,16 +30,16 @@ pub extern "c" fn @"realpath$DARWIN_EXTSN"(noalias file_name: [*:0]const u8, noa pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize; -extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; +extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int; /// On x86_64 Darwin, fstat has to be manully linked with $INODE64 suffix to force 64bit version. /// Note that this is fixed on aarch64 and no longer necessary. -extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *Stat) c_int; +extern "c" fn @"fstat$INODE64"(fd: fd_t, buf: *libc_stat) c_int; pub const _fstat = if (builtin.arch == .aarch64) fstat else @"fstat$INODE64"; -extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int; +extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int; /// On x86_64 Darwin, fstatat has to be manully linked with $INODE64 suffix to force 64bit version. /// Note that this is fixed on aarch64 and no longer necessary. -extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path_name: [*:0]const u8, buf: *Stat, flags: u32) c_int; +extern "c" fn @"fstatat$INODE64"(dirfd: fd_t, path_name: [*:0]const u8, buf: *libc_stat, flags: u32) c_int; pub const _fstatat = if (builtin.arch == .aarch64) fstatat else @"fstatat$INODE64"; pub extern "c" fn mach_absolute_time() u64; diff --git a/lib/std/os.zig b/lib/std/os.zig index d593f816c98290768f352b6c930631bcee9d0495..bda41ae165ff967d8271fba9831ef81d5ea13f12 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3267,6 +3267,11 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult { } } +pub const Stat = if (builtin.link_libc) + system.libc_stat +else + system.kernel_stat; + pub const FStatError = error{ SystemResources, diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig index 3e4149decd08b438b4d2ccf285d7a0ad9dc0b4a3..92849db4f6d103007bbba2dadc536da5dfdd59f9 100644 --- a/lib/std/os/bits/darwin.zig +++ b/lib/std/os/bits/darwin.zig @@ -72,13 +72,7 @@ pub const Flock = extern struct { l_whence: i16, }; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +pub const libc_stat = extern struct { dev: i32, mode: u16, nlink: u16, @@ -102,21 +96,21 @@ pub const Stat = extern struct { lspare: i32, qspare: [2]i64, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return timespec{ .tv_sec = self.atimesec, .tv_nsec = self.atimensec, }; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return timespec{ .tv_sec = self.mtimesec, .tv_nsec = self.mtimensec, }; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return timespec{ .tv_sec = self.ctimesec, .tv_nsec = self.ctimensec, diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index c79da00729102011045155ac09fa7def77f5aa23..2fd9e39c7b5aed4a3d4ef946d52d6d18578eb67a 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -152,7 +152,7 @@ pub const PATH_MAX = 1024; pub const ino_t = c_ulong; -pub const Stat = extern struct { +pub const libc_stat = extern struct { ino: ino_t, nlink: c_uint, dev: c_uint, @@ -172,15 +172,15 @@ pub const Stat = extern struct { lspare: i32, qspare1: i64, qspare2: i64, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index fecd1be118172d2efd0ff6f3789836a716e0849d..30de9f4d59587725a0d07560adc476e4a536e343 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -119,13 +119,7 @@ pub const msghdr_const = extern struct { pub const off_t = i64; pub const ino_t = u64; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +pub const libc_stat = extern struct { dev: u64, ino: ino_t, nlink: usize, @@ -149,15 +143,15 @@ pub const Stat = extern struct { gen: u64, __spare: [10]u64, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; diff --git a/lib/std/os/bits/linux/arm-eabi.zig b/lib/std/os/bits/linux/arm-eabi.zig index 36f1f4f44225bd1f6c5b1366d1923dfbb967848e..5539199c73a207e7f99afcf487ef0413dd7e775a 100644 --- a/lib/std/os/bits/linux/arm-eabi.zig +++ b/lib/std/os/bits/linux/arm-eabi.zig @@ -553,13 +553,8 @@ pub const ino_t = u64; pub const dev_t = u64; pub const blkcnt_t = i64; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +// The `stat` definition used by the Linux kernel. +pub const kernel_stat = extern struct { dev: dev_t, __dev_padding: u32, __ino_truncated: u32, @@ -577,19 +572,22 @@ pub const Stat = extern struct { ctim: timespec, ino: ino_t, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; +// The `stat64` definition used by the libc. +pub const libc_stat = kernel_stat; + pub const timespec = extern struct { tv_sec: i32, tv_nsec: i32, diff --git a/lib/std/os/bits/linux/arm64.zig b/lib/std/os/bits/linux/arm64.zig index 6ecbcc9ae1d83b3e265d25be5a026ea586a00a3e..2f677ca537f4e7bae07d3dc50be7c3791988f0f2 100644 --- a/lib/std/os/bits/linux/arm64.zig +++ b/lib/std/os/bits/linux/arm64.zig @@ -424,13 +424,8 @@ pub const ino_t = usize; pub const dev_t = usize; pub const blkcnt_t = isize; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +// The `stat` definition used by the Linux kernel. +pub const kernel_stat = extern struct { dev: dev_t, ino: ino_t, mode: mode_t, @@ -448,19 +443,22 @@ pub const Stat = extern struct { ctim: timespec, __unused: [2]u32, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; +// The `stat64` definition used by the libc. +pub const libc_stat = kernel_stat; + pub const timespec = extern struct { tv_sec: time_t, tv_nsec: isize, diff --git a/lib/std/os/bits/linux/i386.zig b/lib/std/os/bits/linux/i386.zig index a560c146133014556daacda62a5cc0f5f0c8e59f..b8c7221e9efd38d6024af04114d9129b94fcfdc4 100644 --- a/lib/std/os/bits/linux/i386.zig +++ b/lib/std/os/bits/linux/i386.zig @@ -546,13 +546,8 @@ pub const ino_t = u64; pub const dev_t = u64; pub const blkcnt_t = i64; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +// The `stat` definition used by the Linux kernel. +pub const kernel_stat = extern struct { dev: dev_t, __dev_padding: u32, __ino_truncated: u32, @@ -570,19 +565,22 @@ pub const Stat = extern struct { ctim: timespec, ino: ino_t, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; +// The `stat64` definition used by the libc. +pub const libc_stat = kernel_stat; + pub const timespec = extern struct { tv_sec: i32, tv_nsec: i32, diff --git a/lib/std/os/bits/linux/mips.zig b/lib/std/os/bits/linux/mips.zig index b5f77c9061a62f04ebb15e3eb088ea033013eb5b..cfd9c7adce84d13a8442aef3b8ce0dbfce8e6bc4 100644 --- a/lib/std/os/bits/linux/mips.zig +++ b/lib/std/os/bits/linux/mips.zig @@ -536,41 +536,74 @@ pub const Flock = extern struct { pub const blksize_t = i32; pub const nlink_t = u32; -pub const time_t = isize; +pub const time_t = i32; pub const mode_t = u32; pub const off_t = i64; pub const ino_t = u64; -pub const dev_t = usize; +pub const dev_t = u64; pub const blkcnt_t = i64; -pub const Stat = extern struct { +// The `stat` definition used by the Linux kernel. +pub const kernel_stat = extern struct { dev: u32, - __pad0: [3]u32, + __pad0: [3]u32, // Reserved for st_dev expansion ino: ino_t, mode: mode_t, nlink: nlink_t, uid: uid_t, gid: gid_t, - rdev: dev_t, + rdev: u32, __pad1: [3]u32, size: off_t, atim: timespec, mtim: timespec, ctim: timespec, blksize: blksize_t, - __pad3: [1]u32, + __pad3: u32, blocks: blkcnt_t, __pad4: [14]usize, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { + return self.ctim; + } +}; + +pub const libc_stat = extern struct { + dev: dev_t, + __pad0: [2]u32, + ino: ino_t, + mode: mode_t, + nlink: nlink_t, + uid: uid_t, + gid: gid_t, + rdev: dev_t, + __pad1: [2]u32, + size: off_t, + atim: timespec, + mtim: timespec, + ctim: timespec, + blksize: blksize_t, + __pad3: u32, + blocks: blkcnt_t, + __pad4: [14]u32, + + pub fn atime(self: @This()) timespec { + return self.atim; + } + + pub fn mtime(self: @This()) timespec { + return self.mtim; + } + + pub fn ctime(self: @This()) timespec { return self.ctim; } }; diff --git a/lib/std/os/bits/linux/powerpc64.zig b/lib/std/os/bits/linux/powerpc64.zig index 769b7e614d4f777eb0bae2820d73d237f3325413..89619ebe16158155354326a3f7b8c684e97700d2 100644 --- a/lib/std/os/bits/linux/powerpc64.zig +++ b/lib/std/os/bits/linux/powerpc64.zig @@ -516,13 +516,8 @@ pub const ino_t = u64; pub const dev_t = u64; pub const blkcnt_t = i64; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +// The `stat` definition used by the Linux kernel. +pub const kernel_stat = extern struct { dev: dev_t, ino: ino_t, nlink: nlink_t, @@ -538,19 +533,22 @@ pub const Stat = extern struct { ctim: timespec, __unused: [3]u64, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; +// The `stat64` definition used by the libc. +pub const libc_stat = kernel_stat; + pub const timespec = extern struct { tv_sec: time_t, tv_nsec: isize, diff --git a/lib/std/os/bits/linux/riscv64.zig b/lib/std/os/bits/linux/riscv64.zig index c4b0f044f28c12c8388d772cdc4cf52fdf5d9788..bd4b45f95f28ffef599ae6922b7f93e59a6bcdf2 100644 --- a/lib/std/os/bits/linux/riscv64.zig +++ b/lib/std/os/bits/linux/riscv64.zig @@ -381,13 +381,8 @@ pub const Flock = extern struct { __unused: [4]u8, }; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +// The `stat` definition used by the Linux kernel. +pub const kernel_stat = extern struct { dev: dev_t, ino: ino_t, mode: mode_t, @@ -405,17 +400,20 @@ pub const Stat = extern struct { ctim: timespec, __unused: [2]u32, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; +// The `stat64` definition used by the libc. +pub const libc_stat = kernel_stat; + pub const Elf_Symndx = u32; diff --git a/lib/std/os/bits/linux/sparc64.zig b/lib/std/os/bits/linux/sparc64.zig index 0f2e5b503565a8bc9c353858d08b25d374f018a1..1ce17b3a017fc595d1f3703c4ae366b3fac510d5 100644 --- a/lib/std/os/bits/linux/sparc64.zig +++ b/lib/std/os/bits/linux/sparc64.zig @@ -484,11 +484,7 @@ pub const off_t = i64; pub const ino_t = u64; pub const mode_t = u32; -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. +// The `stat64` definition used by the libc. pub const libc_stat = extern struct { dev: u64, ino: ino_t, @@ -522,45 +518,40 @@ pub const libc_stat = extern struct { } }; +// The `stat64` definition used by the kernel. pub const kernel_stat = extern struct { - dev: u32, - ino: ino_t, - mode: mode_t, - nlink: i16, + dev: u64, + ino: u64, + nlink: u64, + mode: u32, uid: u32, gid: u32, - rdev: u32, + __pad0: u32, - size: off_t, - atim: isize, - mtim: isize, - ctim: isize, + rdev: u64, + size: i64, + blksize: i64, + blocks: i64, - blksize: off_t, - blocks: off_t, + atim: timespec, + mtim: timespec, + ctim: timespec, + __unused: [3]u64, - __unused4: [2]isize, - - // Hack to make the stdlib not complain about atime - // and friends not being a method. - // TODO what should tv_nsec be filled with? - pub fn atime(self: kernel_stat) timespec { - return timespec{.tv_sec=self.atim, .tv_nsec=0}; + pub fn atime(self: @This()) timespec { + return self.atim; } - pub fn mtime(self: kernel_stat) timespec { - return timespec{.tv_sec=self.mtim, .tv_nsec=0}; + pub fn mtime(self: @This()) timespec { + return self.mtim; } - pub fn ctime(self: kernel_stat) timespec { - return timespec{.tv_sec=self.ctim, .tv_nsec=0}; + pub fn ctime(self: @This()) timespec { + return self.ctim; } }; -/// Renamed to Stat to not conflict with the stat function. -pub const Stat = if (std.builtin.link_libc) libc_stat else kernel_stat; - pub const timespec = extern struct { tv_sec: isize, tv_nsec: isize, diff --git a/lib/std/os/bits/linux/x86_64.zig b/lib/std/os/bits/linux/x86_64.zig index 0f01c40813914a3b0444518ec680edcdac4e9f3c..936c03bd345ecf326ed54c18a24097bfaf831833 100644 --- a/lib/std/os/bits/linux/x86_64.zig +++ b/lib/std/os/bits/linux/x86_64.zig @@ -512,13 +512,8 @@ pub const msghdr_const = extern struct { pub const off_t = i64; pub const ino_t = u64; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +// The `stat` definition used by the Linux kernel. +pub const kernel_stat = extern struct { dev: u64, ino: ino_t, nlink: usize, @@ -537,19 +532,22 @@ pub const Stat = extern struct { ctim: timespec, __unused: [3]isize, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; +// The `stat64` definition used by the libc. +pub const libc_stat = kernel_stat; + pub const timespec = extern struct { tv_sec: isize, tv_nsec: isize, diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index 623510faab0193902bdd7dbb5e53228bdf36785f..d5c4ebe653d63344b4e509a7cd853a232da49056 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -153,13 +153,7 @@ pub const msghdr_const = extern struct { msg_flags: i32, }; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +pub const libc_stat = extern struct { dev: dev_t, mode: mode_t, ino: ino_t, @@ -178,15 +172,15 @@ pub const Stat = extern struct { gen: u32, __spare: [2]u32, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; diff --git a/lib/std/os/bits/openbsd.zig b/lib/std/os/bits/openbsd.zig index 8f0fae04b38375dd65a1294f443e2c55c4f401bb..d265c68b427ce4bfd7cbb6b8b1042b09da462341 100644 --- a/lib/std/os/bits/openbsd.zig +++ b/lib/std/os/bits/openbsd.zig @@ -152,13 +152,7 @@ pub const msghdr_const = extern struct { msg_flags: i32, }; -/// Renamed to Stat to not conflict with the stat function. -/// atime, mtime, and ctime have functions to return `timespec`, -/// because although this is a POSIX API, the layout and names of -/// the structs are inconsistent across operating systems, and -/// in C, macros are used to hide the differences. Here we use -/// methods to accomplish this. -pub const Stat = extern struct { +pub const libc_stat = extern struct { mode: mode_t, dev: dev_t, ino: ino_t, @@ -176,15 +170,15 @@ pub const Stat = extern struct { gen: u32, birthtim: timespec, - pub fn atime(self: Stat) timespec { + pub fn atime(self: @This()) timespec { return self.atim; } - pub fn mtime(self: Stat) timespec { + pub fn mtime(self: @This()) timespec { return self.mtim; } - pub fn ctime(self: Stat) timespec { + pub fn ctime(self: @This()) timespec { return self.ctim; } }; diff --git a/lib/std/os/bits/wasi.zig b/lib/std/os/bits/wasi.zig index f768b5522ba007b8cfd386da6c2866783114be68..033f8cc8774058ad137705491282a3682f7d1250 100644 --- a/lib/std/os/bits/wasi.zig +++ b/lib/std/os/bits/wasi.zig @@ -31,7 +31,7 @@ pub const timespec = struct { } }; -pub const Stat = struct { +pub const libc_stat = struct { dev: device_t, ino: inode_t, mode: mode_t, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index c5fbd0bcfe7cb72099f81ce63be9e93f3ca48d9c..9c6f7d3374b8bb7fb49561585eb85bdb16cd3474 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1047,7 +1047,7 @@ pub fn accept4(fd: i32, noalias addr: ?*sockaddr, noalias len: ?*socklen_t, flag return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags); } -pub fn fstat(fd: i32, stat_buf: *Stat) usize { +pub fn fstat(fd: i32, stat_buf: *kernel_stat) usize { if (@hasField(SYS, "fstat64")) { return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); } else { @@ -1055,7 +1055,7 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize { } } -pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize { +pub fn stat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize { if (@hasField(SYS, "stat64")) { return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf)); } else { @@ -1063,7 +1063,7 @@ pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize { } } -pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize { +pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize { if (@hasField(SYS, "lstat64")) { return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf)); } else { @@ -1071,7 +1071,7 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize { } } -pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize { +pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *kernel_stat, flags: u32) usize { if (@hasField(SYS, "fstatat64")) { return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); } else { diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index a5aa6c543a4ea2cc56c52afdac2db2b3c845b321..eefa4d60fd77a7c19217f6423d041ef96b5c021a 100644 --- a/lib/std/os/linux/sparc64.zig +++ b/lib/std/os/linux/sparc64.zig @@ -12,6 +12,7 @@ pub fn syscall_pipe(fd: *[2]i32) usize { \\1: \\ st %%o0, [%%g3+0] \\ st %%o1, [%%g3+4] + \\ clr %%o0 \\2: : [ret] "={o0}" (-> usize) : [number] "{g1}" (@enumToInt(SYS.pipe)), diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index 7599cfc39508fdb8f5b7f413c0dcb1c2f35f3188..4fb6ea8d9efe2a66c51ebb5f9dd9d0539c6c10cc 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -67,7 +67,7 @@ test "statx" { else => unreachable, } - var stat_buf: linux.Stat = undefined; + var stat_buf: linux.kernel_stat = undefined; switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) { 0 => {}, else => unreachable, -- 2.54.0 From cca6b1113825e5d9723568a398d270ceac6da92c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 5 Nov 2020 12:44:43 +0100 Subject: [PATCH 4/4] Label WASI stat as kernel_stat We're using WASI syscalls, it makes sense to put the kernel_ prefix. --- lib/std/os/bits/wasi.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os/bits/wasi.zig b/lib/std/os/bits/wasi.zig index 033f8cc8774058ad137705491282a3682f7d1250..07275fc229308270d14024dc7f835036942cfc68 100644 --- a/lib/std/os/bits/wasi.zig +++ b/lib/std/os/bits/wasi.zig @@ -31,7 +31,7 @@ pub const timespec = struct { } }; -pub const libc_stat = struct { +pub const kernel_stat = struct { dev: device_t, ino: inode_t, mode: mode_t, -- 2.54.0