authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-19 11:35:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-19 11:35:22-07:00
log01337e209366bf7eed9a8aca0b80be0e8c9c04f5
tree82d84ded03cf82eca3662acc1b16b100964937b4
parent7157189143e83dedb29d25553d2841ff2576dc5c

fix regression of flock being called on wasi targets

* common symbols are now public from std.c even if they live in std.posix * LOCK is now one of the common symbols since it is the same on 100% of operating systems. * flock is now void value on wasi and windows * std.fs.Dir now uses flock being void as feature detection, avoiding trying to call it on wasi and windows

14 files changed, 27 insertions(+), 88 deletions(-)

lib/std/c.zig+17-14
...@@ -4,9 +4,6 @@ const c = @This();...@@ -4,9 +4,6 @@ const c = @This();
4const maxInt = std.math.maxInt;4const maxInt = std.math.maxInt;
5const assert = std.debug.assert;5const assert = std.debug.assert;
6const page_size = std.mem.page_size;6const page_size = std.mem.page_size;
7const iovec = std.posix.iovec;
8const iovec_const = std.posix.iovec_const;
9const winsize = std.posix.winsize;
10const native_abi = builtin.abi;7const native_abi = builtin.abi;
11const native_arch = builtin.cpu.arch;8const native_arch = builtin.cpu.arch;
12const native_os = builtin.os.tag;9const native_os = builtin.os.tag;
...@@ -23,6 +20,14 @@ const dragonfly = @import("c/dragonfly.zig");...@@ -23,6 +20,14 @@ const dragonfly = @import("c/dragonfly.zig");
23const haiku = @import("c/haiku.zig");20const haiku = @import("c/haiku.zig");
24const openbsd = @import("c/openbsd.zig");21const openbsd = @import("c/openbsd.zig");
2522
23// These constants are shared among all operating systems even when not linking
24// libc.
25
26pub const iovec = std.posix.iovec;
27pub const iovec_const = std.posix.iovec_const;
28pub const LOCK = std.posix.LOCK;
29pub const winsize = std.posix.winsize;
30
26/// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address31/// The value of the link editor defined symbol _MH_EXECUTE_SYM is the address
27/// of the mach header in a Mach-O executable file type. It does not appear in32/// of the mach header in a Mach-O executable file type. It does not appear in
28/// any file type other than a MH_EXECUTE file type. The type of the symbol is33/// any file type other than a MH_EXECUTE file type. The type of the symbol is
...@@ -1330,16 +1335,6 @@ pub const KERN = switch (native_os) {...@@ -1330,16 +1335,6 @@ pub const KERN = switch (native_os) {
1330 },1335 },
1331 else => void,1336 else => void,
1332};1337};
1333pub const LOCK = switch (native_os) {
1334 .linux => linux.LOCK,
1335 .emscripten => emscripten.LOCK,
1336 else => struct {
1337 pub const SH = 1;
1338 pub const EX = 2;
1339 pub const NB = 4;
1340 pub const UN = 8;
1341 },
1342};
1343pub const MADV = switch (native_os) {1338pub const MADV = switch (native_os) {
1344 .linux => linux.MADV,1339 .linux => linux.MADV,
1345 .emscripten => emscripten.MADV,1340 .emscripten => emscripten.MADV,
...@@ -9032,6 +9027,11 @@ pub const sf_hdtr = switch (native_os) {...@@ -9032,6 +9027,11 @@ pub const sf_hdtr = switch (native_os) {
9032 else => void,9027 else => void,
9033};9028};
90349029
9030pub const flock = switch (native_os) {
9031 .windows, .wasi => {},
9032 else => private.flock,
9033};
9034
9035pub extern "c" var environ: [*:null]?[*:0]u8;9035pub extern "c" var environ: [*:null]?[*:0]u8;
90369036
9037pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;9037pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
...@@ -9116,7 +9116,6 @@ pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*u...@@ -9116,7 +9116,6 @@ pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*u
9116pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int;9116pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int;
9117pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int;9117pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int;
9118pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int;9118pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int;
9119pub extern "c" fn flock(fd: fd_t, operation: c_int) c_int;
9120pub extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int;9119pub extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int;
9121pub extern "c" fn uname(buf: *utsname) c_int;9120pub extern "c" fn uname(buf: *utsname) c_int;
91229121
...@@ -9396,6 +9395,9 @@ pub extern "c" fn pthread_getthreadid_np() c_int;...@@ -9396,6 +9395,9 @@ pub extern "c" fn pthread_getthreadid_np() c_int;
9396pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void;9395pub extern "c" fn pthread_set_name_np(thread: pthread_t, name: [*:0]const u8) void;
9397pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usize) void;9396pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usize) void;
93989397
9398// OS-specific bits. These are protected from being used on the wrong OS by
9399// comptime assertions inside each OS-specific file.
9400
9399pub const AF_SUN = solaris.AF_SUN;9401pub const AF_SUN = solaris.AF_SUN;
9400pub const AT_SUN = solaris.AT_SUN;9402pub const AT_SUN = solaris.AT_SUN;
9401pub const FILE_EVENT = solaris.FILE_EVENT;9403pub const FILE_EVENT = solaris.FILE_EVENT;
...@@ -9675,6 +9677,7 @@ const private = struct {...@@ -9675,6 +9677,7 @@ const private = struct {
9675 extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int;9677 extern "c" fn clock_getres(clk_id: clockid_t, tp: *timespec) c_int;
9676 extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int;9678 extern "c" fn clock_gettime(clk_id: clockid_t, tp: *timespec) c_int;
9677 extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize;9679 extern "c" fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: c_uint) isize;
9680 extern "c" fn flock(fd: fd_t, operation: c_int) c_int;
9678 extern "c" fn fork() c_int;9681 extern "c" fn fork() c_int;
9679 extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;9682 extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
9680 extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;9683 extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, buf: *Stat, flag: u32) c_int;
lib/std/fs/Dir.zig+3-2
...@@ -881,7 +881,7 @@ pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File...@@ -881,7 +881,7 @@ pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File
881 const fd = try posix.openatZ(self.fd, sub_path, os_flags, 0);881 const fd = try posix.openatZ(self.fd, sub_path, os_flags, 0);
882 errdefer posix.close(fd);882 errdefer posix.close(fd);
883883
884 if (!has_flock_open_flags and flags.lock != .none) {884 if (have_flock and !has_flock_open_flags and flags.lock != .none) {
885 // TODO: integrate async I/O885 // TODO: integrate async I/O
886 const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0;886 const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0;
887 try posix.flock(fd, switch (flags.lock) {887 try posix.flock(fd, switch (flags.lock) {
...@@ -1029,7 +1029,7 @@ pub fn createFileZ(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags...@@ -1029,7 +1029,7 @@ pub fn createFileZ(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags
1029 const fd = try posix.openatZ(self.fd, sub_path_c, os_flags, flags.mode);1029 const fd = try posix.openatZ(self.fd, sub_path_c, os_flags, flags.mode);
1030 errdefer posix.close(fd);1030 errdefer posix.close(fd);
10311031
1032 if (!has_flock_open_flags and flags.lock != .none) {1032 if (have_flock and !has_flock_open_flags and flags.lock != .none) {
1033 // TODO: integrate async I/O1033 // TODO: integrate async I/O
1034 const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0;1034 const lock_nonblocking: i32 = if (flags.lock_nonblocking) posix.LOCK.NB else 0;
1035 try posix.flock(fd, switch (flags.lock) {1035 try posix.flock(fd, switch (flags.lock) {
...@@ -2702,3 +2702,4 @@ const Allocator = std.mem.Allocator;...@@ -2702,3 +2702,4 @@ const Allocator = std.mem.Allocator;
2702const assert = std.debug.assert;2702const assert = std.debug.assert;
2703const windows = std.os.windows;2703const windows = std.os.windows;
2704const native_os = builtin.os.tag;2704const native_os = builtin.os.tag;
2705const have_flock = @TypeOf(posix.system.flock) != void;
lib/std/os/linux.zig-1
...@@ -69,7 +69,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx;...@@ -69,7 +69,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx;
69pub const F = arch_bits.F;69pub const F = arch_bits.F;
70pub const Flock = arch_bits.Flock;70pub const Flock = arch_bits.Flock;
71pub const HWCAP = arch_bits.HWCAP;71pub const HWCAP = arch_bits.HWCAP;
72pub const LOCK = arch_bits.LOCK;
73pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT;72pub const MMAP2_UNIT = arch_bits.MMAP2_UNIT;
74pub const REG = arch_bits.REG;73pub const REG = arch_bits.REG;
75pub const SC = arch_bits.SC;74pub const SC = arch_bits.SC;
lib/std/os/linux/arm-eabi.zig-7
...@@ -167,13 +167,6 @@ pub const F = struct {...@@ -167,13 +167,6 @@ pub const F = struct {
167 pub const GETOWNER_UIDS = 17;167 pub const GETOWNER_UIDS = 17;
168};168};
169169
170pub const LOCK = struct {
171 pub const SH = 1;
172 pub const EX = 2;
173 pub const UN = 8;
174 pub const NB = 4;
175};
176
177pub const VDSO = struct {170pub const VDSO = struct {
178 pub const CGT_SYM = "__vdso_clock_gettime";171 pub const CGT_SYM = "__vdso_clock_gettime";
179 pub const CGT_VER = "LINUX_2.6";172 pub const CGT_VER = "LINUX_2.6";
lib/std/os/linux/arm64.zig-7
...@@ -149,13 +149,6 @@ pub const F = struct {...@@ -149,13 +149,6 @@ pub const F = struct {
149 pub const GETOWNER_UIDS = 17;149 pub const GETOWNER_UIDS = 17;
150};150};
151151
152pub const LOCK = struct {
153 pub const SH = 1;
154 pub const EX = 2;
155 pub const UN = 8;
156 pub const NB = 4;
157};
158
159pub const VDSO = struct {152pub const VDSO = struct {
160 pub const CGT_SYM = "__kernel_clock_gettime";153 pub const CGT_SYM = "__kernel_clock_gettime";
161 pub const CGT_VER = "LINUX_2.6.39";154 pub const CGT_VER = "LINUX_2.6.39";
lib/std/os/linux/mips.zig-7
...@@ -239,13 +239,6 @@ pub const F = struct {...@@ -239,13 +239,6 @@ pub const F = struct {
239 pub const GETOWNER_UIDS = 17;239 pub const GETOWNER_UIDS = 17;
240};240};
241241
242pub const LOCK = struct {
243 pub const SH = 1;
244 pub const EX = 2;
245 pub const UN = 8;
246 pub const NB = 4;
247};
248
249pub const MMAP2_UNIT = 4096;242pub const MMAP2_UNIT = 4096;
250243
251pub const VDSO = struct {244pub const VDSO = struct {
lib/std/os/linux/mips64.zig-7
...@@ -224,13 +224,6 @@ pub const F = struct {...@@ -224,13 +224,6 @@ pub const F = struct {
224 pub const GETOWNER_UIDS = 17;224 pub const GETOWNER_UIDS = 17;
225};225};
226226
227pub const LOCK = struct {
228 pub const SH = 1;
229 pub const EX = 2;
230 pub const UN = 8;
231 pub const NB = 4;
232};
233
234pub const MMAP2_UNIT = 4096;227pub const MMAP2_UNIT = 4096;
235228
236pub const VDSO = struct {229pub const VDSO = struct {
lib/std/os/linux/powerpc.zig-7
...@@ -168,13 +168,6 @@ pub const F = struct {...@@ -168,13 +168,6 @@ pub const F = struct {
168 pub const UNLCK = 2;168 pub const UNLCK = 2;
169};169};
170170
171pub const LOCK = struct {
172 pub const SH = 1;
173 pub const EX = 2;
174 pub const UN = 8;
175 pub const NB = 4;
176};
177
178pub const VDSO = struct {171pub const VDSO = struct {
179 pub const CGT_SYM = "__kernel_clock_gettime";172 pub const CGT_SYM = "__kernel_clock_gettime";
180 pub const CGT_VER = "LINUX_2.6.15";173 pub const CGT_VER = "LINUX_2.6.15";
lib/std/os/linux/powerpc64.zig-7
...@@ -168,13 +168,6 @@ pub const F = struct {...@@ -168,13 +168,6 @@ pub const F = struct {
168 pub const GETOWNER_UIDS = 17;168 pub const GETOWNER_UIDS = 17;
169};169};
170170
171pub const LOCK = struct {
172 pub const SH = 1;
173 pub const EX = 2;
174 pub const UN = 8;
175 pub const NB = 4;
176};
177
178pub const VDSO = struct {171pub const VDSO = struct {
179 pub const CGT_SYM = "__kernel_clock_gettime";172 pub const CGT_SYM = "__kernel_clock_gettime";
180 pub const CGT_VER = "LINUX_2.6.15";173 pub const CGT_VER = "LINUX_2.6.15";
lib/std/os/linux/riscv64.zig-7
...@@ -134,13 +134,6 @@ pub const F = struct {...@@ -134,13 +134,6 @@ pub const F = struct {
134 pub const GETOWNER_UIDS = 17;134 pub const GETOWNER_UIDS = 17;
135};135};
136136
137pub const LOCK = struct {
138 pub const SH = 1;
139 pub const EX = 2;
140 pub const UN = 8;
141 pub const NB = 4;
142};
143
144pub const blksize_t = i32;137pub const blksize_t = i32;
145pub const nlink_t = u32;138pub const nlink_t = u32;
146pub const time_t = isize;139pub const time_t = isize;
lib/std/os/linux/sparc64.zig-7
...@@ -218,13 +218,6 @@ pub const F = struct {...@@ -218,13 +218,6 @@ pub const F = struct {
218 pub const GETOWNER_UIDS = 17;218 pub const GETOWNER_UIDS = 17;
219};219};
220220
221pub const LOCK = struct {
222 pub const SH = 1;
223 pub const EX = 2;
224 pub const NB = 4;
225 pub const UN = 8;
226};
227
228pub const VDSO = struct {221pub const VDSO = struct {
229 pub const CGT_SYM = "__vdso_clock_gettime";222 pub const CGT_SYM = "__vdso_clock_gettime";
230 pub const CGT_VER = "LINUX_2.6";223 pub const CGT_VER = "LINUX_2.6";
lib/std/os/linux/x86.zig-7
...@@ -181,13 +181,6 @@ pub const F = struct {...@@ -181,13 +181,6 @@ pub const F = struct {
181 pub const UNLCK = 2;181 pub const UNLCK = 2;
182};182};
183183
184pub const LOCK = struct {
185 pub const SH = 1;
186 pub const EX = 2;
187 pub const NB = 4;
188 pub const UN = 8;
189};
190
191pub const MMAP2_UNIT = 4096;184pub const MMAP2_UNIT = 4096;
192185
193pub const VDSO = struct {186pub const VDSO = struct {
lib/std/os/linux/x86_64.zig-7
...@@ -195,13 +195,6 @@ pub const REG = struct {...@@ -195,13 +195,6 @@ pub const REG = struct {
195 pub const CR2 = 22;195 pub const CR2 = 22;
196};196};
197197
198pub const LOCK = struct {
199 pub const SH = 1;
200 pub const EX = 2;
201 pub const NB = 4;
202 pub const UN = 8;
203};
204
205pub const Flock = extern struct {198pub const Flock = extern struct {
206 type: i16,199 type: i16,
207 whence: i16,200 whence: i16,
lib/std/posix.zig+7-1
...@@ -70,7 +70,6 @@ pub const IOV_MAX = system.IOV_MAX;...@@ -70,7 +70,6 @@ pub const IOV_MAX = system.IOV_MAX;
70pub const IPPROTO = system.IPPROTO;70pub const IPPROTO = system.IPPROTO;
71pub const KERN = system.KERN;71pub const KERN = system.KERN;
72pub const Kevent = system.Kevent;72pub const Kevent = system.Kevent;
73pub const LOCK = system.LOCK;
74pub const MADV = system.MADV;73pub const MADV = system.MADV;
75pub const MAP = system.MAP;74pub const MAP = system.MAP;
76pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;75pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
...@@ -202,6 +201,13 @@ pub const winsize = extern struct {...@@ -202,6 +201,13 @@ pub const winsize = extern struct {
202 ypixel: u16,201 ypixel: u16,
203};202};
204203
204pub const LOCK = struct {
205 pub const SH = 1;
206 pub const EX = 2;
207 pub const NB = 4;
208 pub const UN = 8;
209};
210
205pub const LOG = struct {211pub const LOG = struct {
206 /// system is unusable212 /// system is unusable
207 pub const EMERG = 0;213 pub const EMERG = 0;