diff options
2 files changed, 51 insertions, 83 deletions
diff --git a/meta/recipes-devtools/rust/cargo-c/0001-getrandom-Use-libc-SYS_futex_time64-on-riscv32.patch b/meta/recipes-devtools/rust/cargo-c/0001-getrandom-Use-libc-SYS_futex_time64-on-riscv32.patch index dc7130fb57..638832c467 100644 --- a/meta/recipes-devtools/rust/cargo-c/0001-getrandom-Use-libc-SYS_futex_time64-on-riscv32.patch +++ b/meta/recipes-devtools/rust/cargo-c/0001-getrandom-Use-libc-SYS_futex_time64-on-riscv32.patch | |||
@@ -1,53 +1,36 @@ | |||
1 | From 71c356a07fbbf1530cfc87960e975f93bc9007e8 Mon Sep 17 00:00:00 2001 | 1 | From 71c356a07fbbf1530cfc87960e975f93bc9007e8 Mon Sep 17 00:00:00 2001 |
2 | From: Khem Raj <raj.khem@gmail.com> | 2 | From: Khem Raj <raj.khem@gmail.com> |
3 | Date: Tue, 22 Jul 2025 09:46:03 -0700 | 3 | Date: Tue, 22 Jul 2025 09:46:03 -0700 |
4 | Subject: [PATCH] Use libc::SYS_futex_time64 on riscv32 | 4 | Subject: [PATCH] Use getrandom syscall on riscv32/riscv64 linux |
5 | 5 | ||
6 | On RISC-V 32-bit (riscv32), the SYS_futex system call is | 6 | Minimum kernel needed on RISCV is fairly new (4.15+) so we are sure |
7 | often handled indirectly due to the use of a 64-bit time_t | 7 | to have getrandom syscall, on glibc there is mimimal ABI kernel to denote |
8 | type. Specifically, while SYS_futex is not directly defined, | 8 | it but musl does not have any other way to indicate it, so add it |
9 | a related syscall like SYS_futex_time64 can be used, | 9 | as a condition here to choose getrandom backend for rv32/rv64 on linux |
10 | when using musl. | ||
10 | 11 | ||
11 | Upstream-Status: Submitted [https://github.com/rust-random/getrandom/pull/698] | 12 | Upstream-Status: Backport [https://github.com/rust-random/getrandom/pull/699] |
12 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | 13 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
13 | --- | 14 | --- |
14 | src/backends/use_file.rs | 17 +++++++++++++++++ | 15 | src/backends/use_file.rs | 17 +++++++++++++++++ |
15 | 1 file changed, 17 insertions(+) | 16 | 1 file changed, 17 insertions(+) |
16 | 17 | ||
17 | diff --git a/src/backends/use_file.rs b/src/backends/use_file.rs | 18 | --- a/src/backends.rs |
18 | index 7b48d43..baa0c66 100644 | 19 | +++ b/src/backends.rs |
19 | --- a/src/backends/use_file.rs | 20 | @@ -93,7 +93,15 @@ cfg_if! { |
20 | +++ b/src/backends/use_file.rs | 21 | // Minimum supported Linux kernel version for MUSL targets |
21 | @@ -158,7 +158,18 @@ mod sync { | 22 | // is not specified explicitly (as of Rust 1.77) and they |
22 | pub(super) fn wait() { | 23 | // are used in practice to target pre-3.17 kernels. |
23 | let op = libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG; | 24 | - target_env = "musl", |
24 | let timeout_ptr = core::ptr::null::<libc::timespec>(); | 25 | + all( |
25 | + #[cfg(not(target_arch = "riscv32"))] | 26 | + target_env = "musl", |
26 | let ret = unsafe { libc::syscall(libc::SYS_futex, &FD, op, FD_ONGOING_INIT, timeout_ptr) }; | 27 | + not( |
27 | + #[cfg(target_arch = "riscv32")] | 28 | + any( |
28 | + let ret = unsafe { | 29 | + target_arch = "riscv64", |
29 | + libc::syscall( | 30 | + target_arch = "riscv32", |
30 | + libc::SYS_futex_time64, | 31 | + ), |
31 | + &FD, | 32 | + ), |
32 | + op, | 33 | + ), |
33 | + FD_ONGOING_INIT, | 34 | ), |
34 | + timeout_ptr, | 35 | ) |
35 | + ) | 36 | ))] { |
36 | + }; | ||
37 | // FUTEX_WAIT should return either 0 or EAGAIN error | ||
38 | debug_assert!({ | ||
39 | match ret { | ||
40 | @@ -172,7 +183,13 @@ mod sync { | ||
41 | /// Wake up all threads which wait for value of atomic `FD` to change. | ||
42 | pub(super) fn wake() { | ||
43 | let op = libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG; | ||
44 | + | ||
45 | + #[cfg(not(target_arch = "riscv32"))] | ||
46 | let ret = unsafe { libc::syscall(libc::SYS_futex, &FD, op, libc::INT_MAX) }; | ||
47 | + | ||
48 | + #[cfg(target_arch = "riscv32")] | ||
49 | + let ret = unsafe { libc::syscall(libc::SYS_futex_time64, &FD, op, libc::INT_MAX) }; | ||
50 | + | ||
51 | debug_assert!(ret >= 0); | ||
52 | } | ||
53 | |||
diff --git a/meta/recipes-devtools/rust/cargo-c/0001-parking-lot-Use-libc-SYS_futex_time64-on-riscv32.patch b/meta/recipes-devtools/rust/cargo-c/0001-parking-lot-Use-libc-SYS_futex_time64-on-riscv32.patch index 37f21af3d1..9e84ca3ec7 100644 --- a/meta/recipes-devtools/rust/cargo-c/0001-parking-lot-Use-libc-SYS_futex_time64-on-riscv32.patch +++ b/meta/recipes-devtools/rust/cargo-c/0001-parking-lot-Use-libc-SYS_futex_time64-on-riscv32.patch | |||
@@ -1,66 +1,51 @@ | |||
1 | From 78d4c37e9c5b60ea2368627c2fc297dfc46bec2a Mon Sep 17 00:00:00 2001 | 1 | From 7ebddca7070742bbb9cce471a93d699ad70ee371 Mon Sep 17 00:00:00 2001 |
2 | From: Khem Raj <raj.khem@gmail.com> | 2 | From: Khem Raj <raj.khem@gmail.com> |
3 | Date: Tue, 22 Jul 2025 10:15:06 -0700 | 3 | Date: Tue, 22 Jul 2025 10:15:06 -0700 |
4 | Subject: [PATCH] Use libc::SYS_futex_time64 on riscv32 | 4 | Subject: [PATCH] Use libc::SYS_futex_time64 on riscv32/musl |
5 | 5 | ||
6 | On RISC-V 32-bit (riscv32), the SYS_futex system call is | 6 | On RISC-V 32-bit (riscv32), the SYS_futex system call is |
7 | often handled indirectly due to the use of a 64-bit time_t | 7 | often handled indirectly due to the use of a 64-bit time_t |
8 | type. Specifically, while SYS_futex is not directly defined, | 8 | type. Specifically, while SYS_futex is not directly defined, |
9 | a related syscall like SYS_futex_time64 can be used, | 9 | a related syscall like SYS_futex_time64 can be used on target |
10 | e.g. riscv32 | ||
10 | 11 | ||
11 | Upstream-Status: Submitted [https://github.com/Amanieu/parking_lot/pull/485] | 12 | Upstream-Status: Submitted [https://github.com/Amanieu/parking_lot/pull/485] |
12 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | 13 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
13 | --- | 14 | --- |
14 | src/thread_parker/linux.rs | 19 +++++++++++++++++++ | 15 | src/thread_parker/linux.rs | 13 +++++++++++-- |
15 | 1 file changed, 19 insertions(+) | 16 | 1 file changed, 11 insertions(+), 2 deletions(-) |
16 | 17 | ||
17 | diff --git a/src/thread_parker/linux.rs b/src/thread_parker/linux.rs | 18 | diff --git a/src/thread_parker/linux.rs b/src/thread_parker/linux.rs |
18 | index 92601f6..3695624 100644 | 19 | index 92601f6..0952db4 100644 |
19 | --- a/src/thread_parker/linux.rs | 20 | --- a/src/thread_parker/linux.rs |
20 | +++ b/src/thread_parker/linux.rs | 21 | +++ b/src/thread_parker/linux.rs |
21 | @@ -108,6 +108,7 @@ impl ThreadParker { | 22 | @@ -108,9 +108,13 @@ impl ThreadParker { |
22 | .as_ref() | 23 | .as_ref() |
23 | .map(|ts_ref| ts_ref as *const _) | 24 | .map(|ts_ref| ts_ref as *const _) |
24 | .unwrap_or(ptr::null()); | 25 | .unwrap_or(ptr::null()); |
25 | + #[cfg(not(target_arch = "riscv32"))] | 26 | + #[cfg(not(all(target_arch = "riscv32", target_env = "musl")))] |
27 | + let futex_num = libc::SYS_futex; | ||
28 | + #[cfg(all(target_arch = "riscv32", target_env = "musl",))] | ||
29 | + let futex_num = libc::SYS_futex_time64; | ||
26 | let r = unsafe { | 30 | let r = unsafe { |
27 | libc::syscall( | 31 | libc::syscall( |
28 | libc::SYS_futex, | 32 | - libc::SYS_futex, |
29 | @@ -117,6 +118,16 @@ impl ThreadParker { | 33 | + futex_num, |
30 | ts_ptr, | 34 | &self.futex, |
31 | ) | 35 | libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG, |
32 | }; | 36 | 1, |
33 | + #[cfg(target_arch = "riscv32")] | 37 | @@ -137,8 +141,13 @@ impl super::UnparkHandleT for UnparkHandle { |
34 | + let r = unsafe { | ||
35 | + libc::syscall( | ||
36 | + libc::SYS_futex_time64, | ||
37 | + &self.futex, | ||
38 | + libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG, | ||
39 | + 1, | ||
40 | + ts_ptr, | ||
41 | + ) | ||
42 | + }; | ||
43 | debug_assert!(r == 0 || r == -1); | ||
44 | if r == -1 { | ||
45 | debug_assert!( | ||
46 | @@ -137,12 +148,20 @@ impl super::UnparkHandleT for UnparkHandle { | ||
47 | unsafe fn unpark(self) { | 38 | unsafe fn unpark(self) { |
48 | // The thread data may have been freed at this point, but it doesn't | 39 | // The thread data may have been freed at this point, but it doesn't |
49 | // matter since the syscall will just return EFAULT in that case. | 40 | // matter since the syscall will just return EFAULT in that case. |
50 | + #[cfg(not(target_arch = "riscv32"))] | 41 | + #[cfg(not(all(target_arch = "riscv32", target_env = "musl",)))] |
42 | + let futex_num = libc::SYS_futex; | ||
43 | + #[cfg(all(target_arch = "riscv32", target_env = "musl",))] | ||
44 | + let futex_num = libc::SYS_futex_time64; | ||
45 | + | ||
51 | let r = libc::syscall( | 46 | let r = libc::syscall( |
52 | libc::SYS_futex, | 47 | - libc::SYS_futex, |
48 | + futex_num, | ||
53 | self.futex, | 49 | self.futex, |
54 | libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG, | 50 | libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG, |
55 | 1, | 51 | 1, |
56 | ); | ||
57 | + #[cfg(target_arch = "riscv32")] | ||
58 | + let r = libc::syscall( | ||
59 | + libc::SYS_futex_time64, | ||
60 | + self.futex, | ||
61 | + libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG, | ||
62 | + 1, | ||
63 | + ); | ||
64 | debug_assert!(r == 0 || r == 1 || r == -1); | ||
65 | if r == -1 { | ||
66 | debug_assert_eq!(errno(), libc::EFAULT); | ||