Merge pull request #23478 from alexrp/bsd-versions

`std.Target`: Bump some minimum OS versions for BSDs
This commit is contained in:
Alex Rønne Petersen 2025-04-08 18:27:39 +02:00 committed by GitHub
commit 9bbac42886
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 58 deletions

View File

@ -500,25 +500,25 @@ pub const Os = struct {
.dragonfly => .{
.semver = .{
.min = .{ .major = 5, .minor = 8, .patch = 0 },
.min = .{ .major = 6, .minor = 0, .patch = 0 },
.max = .{ .major = 6, .minor = 4, .patch = 0 },
},
},
.freebsd => .{
.semver = .{
.min = .{ .major = 12, .minor = 0, .patch = 0 },
.min = .{ .major = 13, .minor = 4, .patch = 0 },
.max = .{ .major = 14, .minor = 2, .patch = 0 },
},
},
.netbsd => .{
.semver = .{
.min = .{ .major = 8, .minor = 0, .patch = 0 },
.min = .{ .major = 9, .minor = 4, .patch = 0 },
.max = .{ .major = 10, .minor = 1, .patch = 0 },
},
},
.openbsd => .{
.semver = .{
.min = .{ .major = 7, .minor = 3, .patch = 0 },
.min = .{ .major = 7, .minor = 5, .patch = 0 },
.max = .{ .major = 7, .minor = 6, .patch = 0 },
},
},

View File

@ -158,57 +158,18 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
return target;
},
.freebsd => {
if (builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) {
var kfile: std.c.kinfo_file = undefined;
kfile.structsize = std.c.KINFO_FILE_SIZE;
switch (posix.errno(std.c.fcntl(fd, std.c.F.KINFO, @intFromPtr(&kfile)))) {
.SUCCESS => {},
.BADF => return error.FileNotFound,
else => |err| return posix.unexpectedErrno(err),
}
const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse max_path_bytes;
if (len == 0) return error.NameTooLong;
const result = out_buffer[0..len];
@memcpy(result, kfile.path[0..len]);
return result;
} else {
// This fallback implementation reimplements libutil's `kinfo_getfile()`.
// The motivation is to avoid linking -lutil when building zig or general
// user executables.
var mib = [4]c_int{ posix.CTL.KERN, posix.KERN.PROC, posix.KERN.PROC_FILEDESC, std.c.getpid() };
var len: usize = undefined;
posix.sysctl(&mib, null, &len, null, 0) catch |err| switch (err) {
error.PermissionDenied => unreachable,
error.SystemResources => return error.SystemResources,
error.NameTooLong => unreachable,
error.UnknownName => unreachable,
else => return error.Unexpected,
};
len = len * 4 / 3;
const buf = std.heap.c_allocator.alloc(u8, len) catch return error.SystemResources;
defer std.heap.c_allocator.free(buf);
len = buf.len;
posix.sysctl(&mib, &buf[0], &len, null, 0) catch |err| switch (err) {
error.PermissionDenied => unreachable,
error.SystemResources => return error.SystemResources,
error.NameTooLong => unreachable,
error.UnknownName => unreachable,
else => return error.Unexpected,
};
var i: usize = 0;
while (i < len) {
const kf: *align(1) std.c.kinfo_file = @ptrCast(&buf[i]);
if (kf.fd == fd) {
len = mem.indexOfScalar(u8, &kf.path, 0) orelse max_path_bytes;
if (len == 0) return error.NameTooLong;
const result = out_buffer[0..len];
@memcpy(result, kf.path[0..len]);
return result;
}
i += @intCast(kf.structsize);
}
return error.FileNotFound;
var kfile: std.c.kinfo_file = undefined;
kfile.structsize = std.c.KINFO_FILE_SIZE;
switch (posix.errno(std.c.fcntl(fd, std.c.F.KINFO, @intFromPtr(&kfile)))) {
.SUCCESS => {},
.BADF => return error.FileNotFound,
else => |err| return posix.unexpectedErrno(err),
}
const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse max_path_bytes;
if (len == 0) return error.NameTooLong;
const result = out_buffer[0..len];
@memcpy(result, kfile.path[0..len]);
return result;
},
.dragonfly => {
@memset(out_buffer[0..max_path_bytes], 0);

View File

@ -6590,7 +6590,7 @@ pub const CopyFileRangeError = error{
///
/// Maximum offsets on Linux and FreeBSD are `maxInt(i64)`.
pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize {
if ((comptime builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) or
if (builtin.os.tag == .freebsd or
(comptime builtin.os.tag == .linux and std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 })))
{
var off_in_copy: i64 = @bitCast(off_in);

View File

@ -71,8 +71,6 @@ const targets = [_]std.Target.Query{
// .{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .eabi },
// .{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .eabihf },
.{ .cpu_arch = .armeb, .os_tag = .freebsd, .abi = .eabi },
.{ .cpu_arch = .armeb, .os_tag = .freebsd, .abi = .eabihf },
.{ .cpu_arch = .armeb, .os_tag = .freestanding, .abi = .eabi },
.{ .cpu_arch = .armeb, .os_tag = .freestanding, .abi = .eabihf },
.{ .cpu_arch = .armeb, .os_tag = .linux, .abi = .eabi },
@ -257,7 +255,6 @@ const targets = [_]std.Target.Query{
// .{ .cpu_arch = .sparc, .os_tag = .rtems, .abi = .none },
// .{ .cpu_arch = .sparc, .os_tag = .solaris, .abi = .none },
.{ .cpu_arch = .sparc64, .os_tag = .freebsd, .abi = .none },
.{ .cpu_arch = .sparc64, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .sparc64, .os_tag = .haiku, .abi = .none },
.{ .cpu_arch = .sparc64, .os_tag = .illumos, .abi = .none },