authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-15 23:04:02-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-15 23:04:02-08:00
log88ee323cd79612999f1e7c645df3391849c6d7f4
treeedba3afdd3b051d5ac43609f66fb6d224a15ab80
parentd1ce8b8837ef5ede6ccc5fb9118f2c583cfcfa6e
parent3200fae9c51a57d6b9e15e04130aa317fea1251b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #18570 from gh-fork-dump/linux-6.7

Linux: Update syscall bits for 6.7

2 files changed, 196 insertions(+), 0 deletions(-)

lib/std/os/linux.zig+157
...@@ -323,6 +323,113 @@ pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize {...@@ -323,6 +323,113 @@ pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize {
323 return syscall3(.futex, @intFromPtr(uaddr), futex_op, @as(u32, @bitCast(val)));323 return syscall3(.futex, @intFromPtr(uaddr), futex_op, @as(u32, @bitCast(val)));
324}324}
325325
326/// Given an array of `futex_waitv`, wait on each uaddr.
327/// The thread wakes if a futex_wake() is performed at any uaddr.
328/// The syscall returns immediately if any waiter has *uaddr != val.
329/// timeout is an optional timeout value for the operation.
330/// Each waiter has individual flags.
331/// The `flags` argument for the syscall should be used solely for specifying
332/// the timeout as realtime, if needed.
333/// Flags for private futexes, sizes, etc. should be used on the
334/// individual flags of each waiter.
335///
336/// Returns the array index of one of the woken futexes.
337/// No further information is provided: any number of other futexes may also
338/// have been woken by the same event, and if more than one futex was woken,
339/// the retrned index may refer to any one of them.
340/// (It is not necessaryily the futex with the smallest index, nor the one
341/// most recently woken, nor...)
342pub fn futex2_waitv(
343 /// List of futexes to wait on.
344 waiters: [*]futex_waitv,
345 /// Length of `waiters`.
346 nr_futexes: u32,
347 /// Flag for timeout (monotonic/realtime).
348 flags: u32,
349 /// Optional absolute timeout.
350 timeout: ?*const timespec,
351 /// Clock to be used for the timeout, realtime or monotonic.
352 clockid: i32,
353) usize {
354 return syscall6(
355 .futex_waitv,
356 @intFromPtr(waiters),
357 nr_futexes,
358 flags,
359 @intFromPtr(timeout),
360 @bitCast(@as(isize, clockid)),
361 );
362}
363
364/// Wait on a futex.
365/// Identical to `FUTEX.WAIT`, except it is part of the futex2 family of calls.
366pub fn futex2_wait(
367 /// Address of the futex to wait on.
368 uaddr: *const anyopaque,
369 /// Value of `uaddr`.
370 val: usize,
371 /// Bitmask.
372 mask: usize,
373 /// `FUTEX2` flags.
374 flags: u32,
375 /// Optional absolute timeout.
376 timeout: *const timespec,
377 /// Clock to be used for the timeout, realtime or monotonic.
378 clockid: i32,
379) usize {
380 return syscall6(
381 .futex_wait,
382 @intFromPtr(uaddr),
383 val,
384 mask,
385 flags,
386 @intFromPtr(timeout),
387 @bitCast(@as(isize, clockid)),
388 );
389}
390
391/// Wake a number of futexes.
392/// Identical to `FUTEX.WAKE`, except it is part of the futex2 family of calls.
393pub fn futex2_wake(
394 /// Address of the futex(es) to wake.
395 uaddr: [*]const anyopaque,
396 /// Bitmask
397 mask: usize,
398 /// Number of the futexes to wake.
399 nr: i32,
400 /// `FUTEX2` flags.
401 flags: u32,
402) usize {
403 return syscall4(
404 .futex_wake,
405 @intFromPtr(uaddr),
406 mask,
407 @bitCast(@as(isize, nr)),
408 flags,
409 );
410}
411
412/// Requeue a waiter from one futex to another.
413/// Identical to `FUTEX.CMP_REQUEUE`, except it is part of the futex2 family of calls.
414pub fn futex2_requeue(
415 /// Array describing the source and destination futex.
416 waiters: [*]futex_waitv,
417 /// Unsed.
418 flags: u32,
419 /// Number of futexes to wake.
420 nr_wake: i32,
421 /// Number of futexes to requeue.
422 nr_requeue: i32,
423) usize {
424 return syscall4(
425 .futex_requeue,
426 @intFromPtr(waiters),
427 flags,
428 @bitCast(@as(isize, nr_wake)),
429 @bitCast(@as(isize, nr_requeue)),
430 );
431}
432
326pub fn getcwd(buf: [*]u8, size: usize) usize {433pub fn getcwd(buf: [*]u8, size: usize) usize {
327 return syscall2(.getcwd, @intFromPtr(buf), size);434 return syscall2(.getcwd, @intFromPtr(buf), size);
328}435}
...@@ -1901,10 +2008,17 @@ pub fn ptrace(...@@ -1901,10 +2008,17 @@ pub fn ptrace(
1901 );2008 );
1902}2009}
19032010
2011/// Query the page cache statistics of a file.
1904pub fn cachestat(2012pub fn cachestat(
2013 /// The open file descriptor to retrieve statistics from.
1905 fd: fd_t,2014 fd: fd_t,
2015 /// The byte range in `fd` to query.
2016 /// When `len > 0`, the range is `[off..off + len]`.
2017 /// When `len` == 0, the range is from `off` to the end of `fd`.
1906 cstat_range: *const cache_stat_range,2018 cstat_range: *const cache_stat_range,
2019 /// The structure where page cache statistics are stored.
1907 cstat: *cache_stat,2020 cstat: *cache_stat,
2021 /// Currently unused, and must be set to `0`.
1908 flags: u32,2022 flags: u32,
1909) usize {2023) usize {
1910 return syscall4(2024 return syscall4(
...@@ -1916,6 +2030,10 @@ pub fn cachestat(...@@ -1916,6 +2030,10 @@ pub fn cachestat(
1916 );2030 );
1917}2031}
19182032
2033pub fn map_shadow_stack(addr: u64, size: u64, flags: u32) usize {
2034 return syscall3(.map_shadow_stack, addr, size, flags);
2035}
2036
1919pub const E = switch (native_arch) {2037pub const E = switch (native_arch) {
1920 .mips, .mipsel => @import("linux/errno/mips.zig").E,2038 .mips, .mipsel => @import("linux/errno/mips.zig").E,
1921 .sparc, .sparcel, .sparc64 => @import("linux/errno/sparc.zig").E,2039 .sparc, .sparcel, .sparc64 => @import("linux/errno/sparc.zig").E,
...@@ -2016,6 +2134,19 @@ pub const FUTEX = struct {...@@ -2016,6 +2134,19 @@ pub const FUTEX = struct {
2016 pub const PRIVATE_FLAG = 128;2134 pub const PRIVATE_FLAG = 128;
20172135
2018 pub const CLOCK_REALTIME = 256;2136 pub const CLOCK_REALTIME = 256;
2137
2138 /// Max numbers of elements in a `futex_waitv` array.
2139 pub const WAITV_MAX = 128;
2140};
2141
2142pub const FUTEX2 = struct {
2143 pub const SIZE_U8 = 0x00;
2144 pub const SIZE_U16 = 0x01;
2145 pub const SIZE_U32 = 0x02;
2146 pub const SIZE_U64 = 0x03;
2147 pub const NUMA = 0x04;
2148
2149 pub const PRIVATE = FUTEX.PRIVATE_FLAG;
2019};2150};
20202151
2021pub const PROT = struct {2152pub const PROT = struct {
...@@ -6100,15 +6231,41 @@ pub const PTRACE = struct {...@@ -6100,15 +6231,41 @@ pub const PTRACE = struct {
6100 pub const GET_SYSCALL_INFO = 0x420e;6231 pub const GET_SYSCALL_INFO = 0x420e;
6101};6232};
61026233
6234/// A waiter for vectorized wait.
6235pub const futex_waitv = extern struct {
6236 // Expected value at uaddr
6237 val: u64,
6238 /// User address to wait on.
6239 uaddr: u64,
6240 /// Flags for this waiter.
6241 flags: u32,
6242 /// Reserved memeber to preserve alignment.
6243 /// Should be 0.
6244 __reserved: u32,
6245};
6246
6103pub const cache_stat_range = extern struct {6247pub const cache_stat_range = extern struct {
6104 off: u64,6248 off: u64,
6105 len: u64,6249 len: u64,
6106};6250};
61076251
6108pub const cache_stat = extern struct {6252pub const cache_stat = extern struct {
6253 /// Number of cached pages.
6109 cache: u64,6254 cache: u64,
6255 /// Number of dirty pages.
6110 dirty: u64,6256 dirty: u64,
6257 /// Number of pages marked for writeback.
6111 writeback: u64,6258 writeback: u64,
6259 /// Number of pages evicted from the cache.
6112 evicted: u64,6260 evicted: u64,
6261 /// Number of recently evicted pages.
6262 /// A page is recently evicted if its last eviction was recent enough that its
6263 /// reentry to the cache would indicate that it is actively being used by the
6264 /// system, and that there is memory pressure on the system.
6113 recently_evicted: u64,6265 recently_evicted: u64,
6114};6266};
6267
6268pub const SHADOW_STACK = struct {
6269 /// Set up a restore token in the shadow stack.
6270 pub const SET_TOKEN: u64 = 1 << 0;
6271};
lib/std/os/linux/syscalls.zig+39
...@@ -444,6 +444,10 @@ pub const X86 = enum(usize) {...@@ -444,6 +444,10 @@ pub const X86 = enum(usize) {
444 set_mempolicy_home_node = 450,444 set_mempolicy_home_node = 450,
445 cachestat = 451,445 cachestat = 451,
446 fchmodat2 = 452,446 fchmodat2 = 452,
447 map_shadow_stack = 453,
448 futex_wake = 454,
449 futex_wait = 455,
450 futex_requeue = 456,
447};451};
448452
449pub const X64 = enum(usize) {453pub const X64 = enum(usize) {
...@@ -812,6 +816,9 @@ pub const X64 = enum(usize) {...@@ -812,6 +816,9 @@ pub const X64 = enum(usize) {
812 cachestat = 451,816 cachestat = 451,
813 fchmodat2 = 452,817 fchmodat2 = 452,
814 map_shadow_stack = 453,818 map_shadow_stack = 453,
819 futex_wake = 454,
820 futex_wait = 455,
821 futex_requeue = 456,
815};822};
816823
817pub const Arm = enum(usize) {824pub const Arm = enum(usize) {
...@@ -1222,6 +1229,10 @@ pub const Arm = enum(usize) {...@@ -1222,6 +1229,10 @@ pub const Arm = enum(usize) {
1222 set_mempolicy_home_node = 450,1229 set_mempolicy_home_node = 450,
1223 cachestat = 451,1230 cachestat = 451,
1224 fchmodat2 = 452,1231 fchmodat2 = 452,
1232 map_shadow_stack = 453,
1233 futex_wake = 454,
1234 futex_wait = 455,
1235 futex_requeue = 456,
12251236
1226 breakpoint = arm_base + 1,1237 breakpoint = arm_base + 1,
1227 cacheflush = arm_base + 2,1238 cacheflush = arm_base + 2,
...@@ -1616,6 +1627,10 @@ pub const Sparc64 = enum(usize) {...@@ -1616,6 +1627,10 @@ pub const Sparc64 = enum(usize) {
1616 set_mempolicy_home_node = 450,1627 set_mempolicy_home_node = 450,
1617 cachestat = 451,1628 cachestat = 451,
1618 fchmodat2 = 452,1629 fchmodat2 = 452,
1630 map_shadow_stack = 453,
1631 futex_wake = 454,
1632 futex_wait = 455,
1633 futex_requeue = 456,
1619};1634};
16201635
1621pub const Mips = enum(usize) {1636pub const Mips = enum(usize) {
...@@ -2041,6 +2056,10 @@ pub const Mips = enum(usize) {...@@ -2041,6 +2056,10 @@ pub const Mips = enum(usize) {
2041 set_mempolicy_home_node = Linux + 450,2056 set_mempolicy_home_node = Linux + 450,
2042 cachestat = Linux + 451,2057 cachestat = Linux + 451,
2043 fchmodat2 = Linux + 452,2058 fchmodat2 = Linux + 452,
2059 map_shadow_stack = Linux + 453,
2060 futex_wake = Linux + 454,
2061 futex_wait = Linux + 455,
2062 futex_requeue = Linux + 456,
2044};2063};
20452064
2046pub const Mips64 = enum(usize) {2065pub const Mips64 = enum(usize) {
...@@ -2402,6 +2421,10 @@ pub const Mips64 = enum(usize) {...@@ -2402,6 +2421,10 @@ pub const Mips64 = enum(usize) {
2402 set_mempolicy_home_node = Linux + 450,2421 set_mempolicy_home_node = Linux + 450,
2403 cachestat = Linux + 451,2422 cachestat = Linux + 451,
2404 fchmodat2 = Linux + 452,2423 fchmodat2 = Linux + 452,
2424 map_shadow_stack = Linux + 453,
2425 futex_wake = Linux + 454,
2426 futex_wait = Linux + 455,
2427 futex_requeue = Linux + 456,
2405};2428};
24062429
2407pub const PowerPC = enum(usize) {2430pub const PowerPC = enum(usize) {
...@@ -2838,6 +2861,10 @@ pub const PowerPC = enum(usize) {...@@ -2838,6 +2861,10 @@ pub const PowerPC = enum(usize) {
2838 set_mempolicy_home_node = 450,2861 set_mempolicy_home_node = 450,
2839 cachestat = 451,2862 cachestat = 451,
2840 fchmodat2 = 452,2863 fchmodat2 = 452,
2864 map_shadow_stack = 453,
2865 futex_wake = 454,
2866 futex_wait = 455,
2867 futex_requeue = 456,
2841};2868};
28422869
2843pub const PowerPC64 = enum(usize) {2870pub const PowerPC64 = enum(usize) {
...@@ -3246,6 +3273,10 @@ pub const PowerPC64 = enum(usize) {...@@ -3246,6 +3273,10 @@ pub const PowerPC64 = enum(usize) {
3246 set_mempolicy_home_node = 450,3273 set_mempolicy_home_node = 450,
3247 cachestat = 451,3274 cachestat = 451,
3248 fchmodat2 = 452,3275 fchmodat2 = 452,
3276 map_shadow_stack = 453,
3277 futex_wake = 454,
3278 futex_wait = 455,
3279 futex_requeue = 456,
3249};3280};
32503281
3251pub const Arm64 = enum(usize) {3282pub const Arm64 = enum(usize) {
...@@ -3557,6 +3588,10 @@ pub const Arm64 = enum(usize) {...@@ -3557,6 +3588,10 @@ pub const Arm64 = enum(usize) {
3557 set_mempolicy_home_node = 450,3588 set_mempolicy_home_node = 450,
3558 cachestat = 451,3589 cachestat = 451,
3559 fchmodat2 = 452,3590 fchmodat2 = 452,
3591 map_shadow_stack = 453,
3592 futex_wake = 454,
3593 futex_wait = 455,
3594 futex_requeue = 456,
3560};3595};
35613596
3562pub const RiscV64 = enum(usize) {3597pub const RiscV64 = enum(usize) {
...@@ -3869,6 +3904,10 @@ pub const RiscV64 = enum(usize) {...@@ -3869,6 +3904,10 @@ pub const RiscV64 = enum(usize) {
3869 set_mempolicy_home_node = 450,3904 set_mempolicy_home_node = 450,
3870 cachestat = 451,3905 cachestat = 451,
3871 fchmodat2 = 452,3906 fchmodat2 = 452,
3907 map_shadow_stack = 453,
3908 futex_wake = 454,
3909 futex_wait = 455,
3910 futex_requeue = 456,
38723911
3873 riscv_flush_icache = arch_specific_syscall + 15,3912 riscv_flush_icache = arch_specific_syscall + 15,
3874};3913};