Skip to content

Commit dc1bc52

Browse files
committed
std.os.linux: retranslate F_* constants and Flock struct, and move out of arch bits
Flock is now equivalent to struct flock64, and the related F.* constants map to the 64-bit variants on 32-bit systems.
1 parent cfdc0f0 commit dc1bc52

File tree

16 files changed

+68
-498
lines changed

16 files changed

+68
-498
lines changed

lib/std/os/linux.zig

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ pub fn clone(
8888
}
8989

9090
pub const ARCH = arch_bits.ARCH;
91-
pub const F = arch_bits.F;
92-
pub const Flock = arch_bits.Flock;
9391
pub const HWCAP = arch_bits.HWCAP;
9492
pub const SC = arch_bits.SC;
9593
pub const Stat = arch_bits.Stat;
@@ -110,7 +108,7 @@ pub const IOCTL = @import("linux/ioctl.zig");
110108
pub const SECCOMP = @import("linux/seccomp.zig");
111109

112110
pub const syscalls = @import("linux/syscalls.zig");
113-
pub const SYS = switch (@import("builtin").cpu.arch) {
111+
pub const SYS = switch (native_arch) {
114112
.arc => syscalls.Arc,
115113
.arm, .armeb, .thumb, .thumbeb => syscalls.Arm,
116114
.aarch64, .aarch64_be => syscalls.Arm64,
@@ -1596,6 +1594,70 @@ pub fn waitid(id_type: P, id: i32, infop: *siginfo_t, flags: u32) usize {
15961594
return syscall5(.waitid, @intFromEnum(id_type), @as(usize, @bitCast(@as(isize, id))), @intFromPtr(infop), flags, 0);
15971595
}
15981596

1597+
pub const F = struct {
1598+
pub const DUPFD = 0;
1599+
pub const GETFD = 1;
1600+
pub const SETFD = 2;
1601+
pub const GETFL = 3;
1602+
pub const SETFL = 4;
1603+
1604+
pub const GETLK = GET_SET_LK.GETLK;
1605+
pub const SETLK = GET_SET_LK.SETLK;
1606+
pub const SETLKW = GET_SET_LK.SETLKW;
1607+
1608+
const GET_SET_LK = if (@sizeOf(usize) == 64) extern struct {
1609+
pub const GETLK = if (is_mips) 14 else if (is_sparc) 7 else 5;
1610+
pub const SETLK = if (is_mips) 6 else if (is_sparc) 8 else 6;
1611+
pub const SETLKW = if (is_mips) 7 else if (is_sparc) 9 else 7;
1612+
} else extern struct {
1613+
// Ensure that 32-bit code uses the large-file variants (GETLK64, etc).
1614+
1615+
pub const GETLK = if (is_mips) 33 else 12;
1616+
pub const SETLK = if (is_mips) 34 else 13;
1617+
pub const SETLKW = if (is_mips) 35 else 14;
1618+
};
1619+
1620+
pub const SETOWN = if (is_mips) 24 else if (is_sparc) 6 else 8;
1621+
pub const GETOWN = if (is_mips) 23 else if (is_sparc) 5 else 9;
1622+
1623+
pub const SETSIG = 10;
1624+
pub const GETSIG = 11;
1625+
1626+
pub const SETOWN_EX = 15;
1627+
pub const GETOWN_EX = 16;
1628+
1629+
pub const GETOWNER_UIDS = 17;
1630+
1631+
pub const OFD_GETLK = 36;
1632+
pub const OFD_SETLK = 37;
1633+
pub const OFD_SETLKW = 38;
1634+
1635+
pub const RDLCK = if (is_sparc) 1 else 0;
1636+
pub const WRLCK = if (is_sparc) 2 else 1;
1637+
pub const UNLCK = if (is_sparc) 3 else 2;
1638+
};
1639+
1640+
pub const F_OWNER = enum(i32) {
1641+
TID = 0,
1642+
PID = 1,
1643+
PGRP = 2,
1644+
_,
1645+
};
1646+
1647+
pub const f_owner_ex = extern struct {
1648+
type: F_OWNER,
1649+
pid: pid_t,
1650+
};
1651+
1652+
pub const Flock = extern struct {
1653+
type: i16,
1654+
whence: i16,
1655+
start: off_t,
1656+
len: off_t,
1657+
pid: pid_t,
1658+
_unused: if (is_sparc) i16 else void,
1659+
};
1660+
15991661
pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize {
16001662
if (@hasField(SYS, "fcntl64")) {
16011663
return syscall3(.fcntl64, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, cmd))), arg);

lib/std/os/linux/aarch64.zig

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -150,46 +150,11 @@ pub fn restore_rt() callconv(.naked) noreturn {
150150
}
151151
}
152152

153-
pub const F = struct {
154-
pub const DUPFD = 0;
155-
pub const GETFD = 1;
156-
pub const SETFD = 2;
157-
pub const GETFL = 3;
158-
pub const SETFL = 4;
159-
160-
pub const SETOWN = 8;
161-
pub const GETOWN = 9;
162-
pub const SETSIG = 10;
163-
pub const GETSIG = 11;
164-
165-
pub const GETLK = 5;
166-
pub const SETLK = 6;
167-
pub const SETLKW = 7;
168-
169-
pub const RDLCK = 0;
170-
pub const WRLCK = 1;
171-
pub const UNLCK = 2;
172-
173-
pub const SETOWN_EX = 15;
174-
pub const GETOWN_EX = 16;
175-
176-
pub const GETOWNER_UIDS = 17;
177-
};
178-
179153
pub const VDSO = struct {
180154
pub const CGT_SYM = "__kernel_clock_gettime";
181155
pub const CGT_VER = "LINUX_2.6.39";
182156
};
183157

184-
pub const Flock = extern struct {
185-
type: i16,
186-
whence: i16,
187-
start: off_t,
188-
len: off_t,
189-
pid: pid_t,
190-
__unused: [4]u8,
191-
};
192-
193158
pub const blksize_t = i32;
194159
pub const nlink_t = u32;
195160
pub const time_t = i64;

lib/std/os/linux/arm.zig

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -159,32 +159,6 @@ pub fn restore_rt() callconv(.naked) noreturn {
159159
}
160160
}
161161

162-
pub const F = struct {
163-
pub const DUPFD = 0;
164-
pub const GETFD = 1;
165-
pub const SETFD = 2;
166-
pub const GETFL = 3;
167-
pub const SETFL = 4;
168-
169-
pub const SETOWN = 8;
170-
pub const GETOWN = 9;
171-
pub const SETSIG = 10;
172-
pub const GETSIG = 11;
173-
174-
pub const GETLK = 12;
175-
pub const SETLK = 13;
176-
pub const SETLKW = 14;
177-
178-
pub const RDLCK = 0;
179-
pub const WRLCK = 1;
180-
pub const UNLCK = 2;
181-
182-
pub const SETOWN_EX = 15;
183-
pub const GETOWN_EX = 16;
184-
185-
pub const GETOWNER_UIDS = 17;
186-
};
187-
188162
pub const VDSO = struct {
189163
pub const CGT_SYM = "__vdso_clock_gettime";
190164
pub const CGT_VER = "LINUX_2.6";
@@ -216,16 +190,6 @@ pub const HWCAP = struct {
216190
pub const EVTSTRM = 1 << 21;
217191
};
218192

219-
pub const Flock = extern struct {
220-
type: i16,
221-
whence: i16,
222-
__pad0: [4]u8,
223-
start: off_t,
224-
len: off_t,
225-
pid: pid_t,
226-
__unused: [4]u8,
227-
};
228-
229193
pub const blksize_t = i32;
230194
pub const nlink_t = u32;
231195
pub const time_t = i32;

lib/std/os/linux/hexagon.zig

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -130,39 +130,6 @@ pub fn clone() callconv(.naked) u32 {
130130
);
131131
}
132132

133-
pub const F = struct {
134-
pub const DUPFD = 0;
135-
pub const GETFD = 1;
136-
pub const SETFD = 2;
137-
pub const GETFL = 3;
138-
pub const SETFL = 4;
139-
pub const GETLK = 5;
140-
pub const SETLK = 6;
141-
pub const SETLKW = 7;
142-
pub const SETOWN = 8;
143-
pub const GETOWN = 9;
144-
pub const SETSIG = 10;
145-
pub const GETSIG = 11;
146-
147-
pub const RDLCK = 0;
148-
pub const WRLCK = 1;
149-
pub const UNLCK = 2;
150-
151-
pub const SETOWN_EX = 15;
152-
pub const GETOWN_EX = 16;
153-
154-
pub const GETOWNER_UIDS = 17;
155-
};
156-
157-
pub const Flock = extern struct {
158-
type: i16,
159-
whence: i16,
160-
start: off_t,
161-
len: off_t,
162-
pid: pid_t,
163-
__unused: [4]u8,
164-
};
165-
166133
pub const blksize_t = i32;
167134
pub const nlink_t = u32;
168135
pub const time_t = i32;

lib/std/os/linux/loongarch64.zig

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,30 +176,6 @@ pub const Stat = extern struct {
176176
}
177177
};
178178

179-
pub const F = struct {
180-
pub const DUPFD = 0;
181-
pub const GETFD = 1;
182-
pub const SETFD = 2;
183-
pub const GETFL = 3;
184-
pub const SETFL = 4;
185-
pub const GETLK = 5;
186-
pub const SETLK = 6;
187-
pub const SETLKW = 7;
188-
pub const SETOWN = 8;
189-
pub const GETOWN = 9;
190-
pub const SETSIG = 10;
191-
pub const GETSIG = 11;
192-
193-
pub const RDLCK = 0;
194-
pub const WRLCK = 1;
195-
pub const UNLCK = 2;
196-
197-
pub const SETOWN_EX = 15;
198-
pub const GETOWN_EX = 16;
199-
200-
pub const GETOWNER_UIDS = 17;
201-
};
202-
203179
pub const VDSO = struct {
204180
pub const CGT_SYM = "__vdso_clock_gettime";
205181
pub const CGT_VER = "LINUX_5.10";

lib/std/os/linux/m68k.zig

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -151,32 +151,6 @@ pub fn restore_rt() callconv(.naked) noreturn {
151151
);
152152
}
153153

154-
pub const F = struct {
155-
pub const DUPFD = 0;
156-
pub const GETFD = 1;
157-
pub const SETFD = 2;
158-
pub const GETFL = 3;
159-
pub const SETFL = 4;
160-
161-
pub const SETOWN = 8;
162-
pub const GETOWN = 9;
163-
pub const SETSIG = 10;
164-
pub const GETSIG = 11;
165-
166-
pub const GETLK = 12;
167-
pub const SETLK = 13;
168-
pub const SETLKW = 14;
169-
170-
pub const SETOWN_EX = 15;
171-
pub const GETOWN_EX = 16;
172-
173-
pub const GETOWNER_UIDS = 17;
174-
175-
pub const RDLCK = 0;
176-
pub const WRLCK = 1;
177-
pub const UNLCK = 2;
178-
};
179-
180154
pub const blksize_t = i32;
181155
pub const nlink_t = u32;
182156
pub const time_t = i32;
@@ -186,14 +160,6 @@ pub const ino_t = u64;
186160
pub const dev_t = u64;
187161
pub const blkcnt_t = i64;
188162

189-
pub const Flock = extern struct {
190-
type: i16,
191-
whence: i16,
192-
start: off_t,
193-
len: off_t,
194-
pid: pid_t,
195-
};
196-
197163
pub const Stat = extern struct {
198164
dev: dev_t,
199165
__pad: i16,

lib/std/os/linux/mips.zig

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -243,47 +243,11 @@ pub fn clone() callconv(.naked) u32 {
243243
);
244244
}
245245

246-
pub const F = struct {
247-
pub const DUPFD = 0;
248-
pub const GETFD = 1;
249-
pub const SETFD = 2;
250-
pub const GETFL = 3;
251-
pub const SETFL = 4;
252-
253-
pub const SETOWN = 24;
254-
pub const GETOWN = 23;
255-
pub const SETSIG = 10;
256-
pub const GETSIG = 11;
257-
258-
pub const GETLK = 33;
259-
pub const SETLK = 34;
260-
pub const SETLKW = 35;
261-
262-
pub const RDLCK = 0;
263-
pub const WRLCK = 1;
264-
pub const UNLCK = 2;
265-
266-
pub const SETOWN_EX = 15;
267-
pub const GETOWN_EX = 16;
268-
269-
pub const GETOWNER_UIDS = 17;
270-
};
271-
272246
pub const VDSO = struct {
273247
pub const CGT_SYM = "__vdso_clock_gettime";
274248
pub const CGT_VER = "LINUX_2.6";
275249
};
276250

277-
pub const Flock = extern struct {
278-
type: i16,
279-
whence: i16,
280-
__pad0: [4]u8,
281-
start: off_t,
282-
len: off_t,
283-
pid: pid_t,
284-
__unused: [4]u8,
285-
};
286-
287251
pub const blksize_t = u32;
288252
pub const nlink_t = u32;
289253
pub const time_t = i32;

0 commit comments

Comments
 (0)