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.
This commit is contained in:
Alex Rønne Petersen 2025-10-17 00:36:16 +02:00
parent cfdc0f0e34
commit dc1bc52dd6
No known key found for this signature in database
16 changed files with 68 additions and 498 deletions

View File

@ -88,8 +88,6 @@ pub fn clone(
}
pub const ARCH = arch_bits.ARCH;
pub const F = arch_bits.F;
pub const Flock = arch_bits.Flock;
pub const HWCAP = arch_bits.HWCAP;
pub const SC = arch_bits.SC;
pub const Stat = arch_bits.Stat;
@ -110,7 +108,7 @@ pub const IOCTL = @import("linux/ioctl.zig");
pub const SECCOMP = @import("linux/seccomp.zig");
pub const syscalls = @import("linux/syscalls.zig");
pub const SYS = switch (@import("builtin").cpu.arch) {
pub const SYS = switch (native_arch) {
.arc => syscalls.Arc,
.arm, .armeb, .thumb, .thumbeb => syscalls.Arm,
.aarch64, .aarch64_be => syscalls.Arm64,
@ -1596,6 +1594,70 @@ pub fn waitid(id_type: P, id: i32, infop: *siginfo_t, flags: u32) usize {
return syscall5(.waitid, @intFromEnum(id_type), @as(usize, @bitCast(@as(isize, id))), @intFromPtr(infop), flags, 0);
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const GETLK = GET_SET_LK.GETLK;
pub const SETLK = GET_SET_LK.SETLK;
pub const SETLKW = GET_SET_LK.SETLKW;
const GET_SET_LK = if (@sizeOf(usize) == 64) extern struct {
pub const GETLK = if (is_mips) 14 else if (is_sparc) 7 else 5;
pub const SETLK = if (is_mips) 6 else if (is_sparc) 8 else 6;
pub const SETLKW = if (is_mips) 7 else if (is_sparc) 9 else 7;
} else extern struct {
// Ensure that 32-bit code uses the large-file variants (GETLK64, etc).
pub const GETLK = if (is_mips) 33 else 12;
pub const SETLK = if (is_mips) 34 else 13;
pub const SETLKW = if (is_mips) 35 else 14;
};
pub const SETOWN = if (is_mips) 24 else if (is_sparc) 6 else 8;
pub const GETOWN = if (is_mips) 23 else if (is_sparc) 5 else 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
pub const OFD_GETLK = 36;
pub const OFD_SETLK = 37;
pub const OFD_SETLKW = 38;
pub const RDLCK = if (is_sparc) 1 else 0;
pub const WRLCK = if (is_sparc) 2 else 1;
pub const UNLCK = if (is_sparc) 3 else 2;
};
pub const F_OWNER = enum(i32) {
TID = 0,
PID = 1,
PGRP = 2,
_,
};
pub const f_owner_ex = extern struct {
type: F_OWNER,
pid: pid_t,
};
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
_unused: if (is_sparc) i16 else void,
};
pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize {
if (@hasField(SYS, "fcntl64")) {
return syscall3(.fcntl64, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, cmd))), arg);

View File

@ -150,46 +150,11 @@ pub fn restore_rt() callconv(.naked) noreturn {
}
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const GETLK = 5;
pub const SETLK = 6;
pub const SETLKW = 7;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const VDSO = struct {
pub const CGT_SYM = "__kernel_clock_gettime";
pub const CGT_VER = "LINUX_2.6.39";
};
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
__unused: [4]u8,
};
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = i64;

View File

@ -159,32 +159,6 @@ pub fn restore_rt() callconv(.naked) noreturn {
}
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const GETLK = 12;
pub const SETLK = 13;
pub const SETLKW = 14;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const VDSO = struct {
pub const CGT_SYM = "__vdso_clock_gettime";
pub const CGT_VER = "LINUX_2.6";
@ -216,16 +190,6 @@ pub const HWCAP = struct {
pub const EVTSTRM = 1 << 21;
};
pub const Flock = extern struct {
type: i16,
whence: i16,
__pad0: [4]u8,
start: off_t,
len: off_t,
pid: pid_t,
__unused: [4]u8,
};
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = i32;

View File

@ -130,39 +130,6 @@ pub fn clone() callconv(.naked) u32 {
);
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const GETLK = 5;
pub const SETLK = 6;
pub const SETLKW = 7;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
__unused: [4]u8,
};
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = i32;

View File

@ -176,30 +176,6 @@ pub const Stat = extern struct {
}
};
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const GETLK = 5;
pub const SETLK = 6;
pub const SETLKW = 7;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const VDSO = struct {
pub const CGT_SYM = "__vdso_clock_gettime";
pub const CGT_VER = "LINUX_5.10";

View File

@ -151,32 +151,6 @@ pub fn restore_rt() callconv(.naked) noreturn {
);
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const GETLK = 12;
pub const SETLK = 13;
pub const SETLKW = 14;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
};
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = i32;
@ -186,14 +160,6 @@ pub const ino_t = u64;
pub const dev_t = u64;
pub const blkcnt_t = i64;
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
};
pub const Stat = extern struct {
dev: dev_t,
__pad: i16,

View File

@ -243,47 +243,11 @@ pub fn clone() callconv(.naked) u32 {
);
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 24;
pub const GETOWN = 23;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const GETLK = 33;
pub const SETLK = 34;
pub const SETLKW = 35;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const VDSO = struct {
pub const CGT_SYM = "__vdso_clock_gettime";
pub const CGT_VER = "LINUX_2.6";
};
pub const Flock = extern struct {
type: i16,
whence: i16,
__pad0: [4]u8,
start: off_t,
len: off_t,
pid: pid_t,
__unused: [4]u8,
};
pub const blksize_t = u32;
pub const nlink_t = u32;
pub const time_t = i32;

View File

@ -222,47 +222,11 @@ pub fn clone() callconv(.naked) u64 {
);
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 24;
pub const GETOWN = 23;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const GETLK = 33;
pub const SETLK = 34;
pub const SETLKW = 35;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const VDSO = struct {
pub const CGT_SYM = "__vdso_clock_gettime";
pub const CGT_VER = "LINUX_2.6";
};
pub const Flock = extern struct {
type: i16,
whence: i16,
__pad0: [4]u8,
start: off_t,
len: off_t,
pid: pid_t,
__unused: [4]u8,
};
pub const blksize_t = u32;
pub const nlink_t = u32;
pub const time_t = i32;

View File

@ -262,45 +262,11 @@ pub fn restore_rt() callconv(.naked) noreturn {
}
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const GETLK = 12;
pub const SETLK = 13;
pub const SETLKW = 14;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
};
pub const VDSO = struct {
pub const CGT_SYM = "__kernel_clock_gettime";
pub const CGT_VER = "LINUX_2.6.15";
};
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
};
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = i32;

View File

@ -247,46 +247,11 @@ pub fn restore_rt() callconv(.naked) noreturn {
}
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const GETLK = 5;
pub const SETLK = 6;
pub const SETLKW = 7;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const VDSO = struct {
pub const CGT_SYM = "__kernel_clock_gettime";
pub const CGT_VER = "LINUX_2.6.15";
};
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
__unused: [4]u8,
};
pub const blksize_t = i64;
pub const nlink_t = u64;
pub const time_t = i64;

View File

@ -135,30 +135,6 @@ pub fn clone() callconv(.naked) u32 {
);
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const GETLK = 5;
pub const SETLK = 6;
pub const SETLKW = 7;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = i64;
@ -168,15 +144,6 @@ pub const ino_t = u64;
pub const dev_t = u64;
pub const blkcnt_t = i64;
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
__unused: [4]u8,
};
// The `stat` definition used by the Linux kernel.
pub const Stat = extern struct {
dev: dev_t,

View File

@ -135,30 +135,6 @@ pub fn clone() callconv(.naked) u64 {
);
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const GETLK = 5;
pub const SETLK = 6;
pub const SETLKW = 7;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = i64;
@ -168,15 +144,6 @@ pub const ino_t = u64;
pub const dev_t = u64;
pub const blkcnt_t = i64;
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
__unused: [4]u8,
};
// The `stat` definition used by the Linux kernel.
pub const Stat = extern struct {
dev: dev_t,

View File

@ -157,26 +157,6 @@ pub fn restore_rt() callconv(.naked) noreturn {
);
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const GETLK = 5;
pub const SETLK = 6;
pub const SETLKW = 7;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const blksize_t = i64;
pub const nlink_t = u64;
pub const time_t = i64;
@ -186,14 +166,6 @@ pub const ino_t = u64;
pub const dev_t = u64;
pub const blkcnt_t = i64;
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
};
// The `stat` definition used by the Linux kernel.
pub const Stat = extern struct {
dev: dev_t,

View File

@ -236,42 +236,11 @@ pub fn restore_rt() callconv(.c) void {
: .{ .memory = true, .icc = true, .o0 = true, .o1 = true, .o2 = true, .o3 = true, .o4 = true, .o5 = true, .o7 = true });
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 5;
pub const GETOWN = 6;
pub const GETLK = 7;
pub const SETLK = 8;
pub const SETLKW = 9;
pub const RDLCK = 1;
pub const WRLCK = 2;
pub const UNLCK = 3;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
};
pub const VDSO = struct {
pub const CGT_SYM = "__vdso_clock_gettime";
pub const CGT_VER = "LINUX_2.6";
};
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
};
pub const off_t = i64;
pub const ino_t = u64;
pub const time_t = i64;

View File

@ -200,43 +200,11 @@ pub fn restore_rt() callconv(.naked) noreturn {
}
}
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const GETLK = 12;
pub const SETLK = 13;
pub const SETLKW = 14;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
};
pub const VDSO = struct {
pub const CGT_SYM = "__vdso_clock_gettime";
pub const CGT_VER = "LINUX_2.6";
};
pub const ARCH = struct {};
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
};
pub const blksize_t = i32;
pub const nlink_t = u32;
pub const time_t = i32;

View File

@ -151,29 +151,9 @@ pub const time_t = i64;
pub const nlink_t = u64;
pub const blksize_t = i64;
pub const blkcnt_t = i64;
pub const F = struct {
pub const DUPFD = 0;
pub const GETFD = 1;
pub const SETFD = 2;
pub const GETFL = 3;
pub const SETFL = 4;
pub const GETLK = 5;
pub const SETLK = 6;
pub const SETLKW = 7;
pub const SETOWN = 8;
pub const GETOWN = 9;
pub const SETSIG = 10;
pub const GETSIG = 11;
pub const SETOWN_EX = 15;
pub const GETOWN_EX = 16;
pub const GETOWNER_UIDS = 17;
pub const RDLCK = 0;
pub const WRLCK = 1;
pub const UNLCK = 2;
};
pub const off_t = i64;
pub const ino_t = u64;
pub const dev_t = u64;
pub const VDSO = struct {
pub const CGT_SYM = "__vdso_clock_gettime";
@ -190,18 +170,6 @@ pub const ARCH = struct {
pub const GET_GS = 0x1004;
};
pub const Flock = extern struct {
type: i16,
whence: i16,
start: off_t,
len: off_t,
pid: pid_t,
};
pub const off_t = i64;
pub const ino_t = u64;
pub const dev_t = u64;
// The `stat` definition used by the Linux kernel.
pub const Stat = extern struct {
dev: dev_t,