Skip to content

Commit 5ad8384

Browse files
authored
linux_raw: inline __NR_getrandom into ARM assembly (#688)
`asm_const` was stabilized only in Rust 1.82, so inlining the constant relaxes MSRV for the `linux_raw` backend on ARM targets.
1 parent cdf3a46 commit 5ad8384

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [0.3.4] - UNRELEASED
88

9+
### Changed
10+
- Relax MSRV for the `linux_raw` opt-in backend on ARM targets [#688]
11+
912
### Added
1013
- `unsupported` opt-in backend [#667]
1114

1215
[#667]: https://github.com/rust-random/getrandom/pull/667
16+
[#688]: https://github.com/rust-random/getrandom/pull/688
1317

1418
## [0.3.3] - 2025-05-09
1519

src/backends/linux_raw.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ unsafe fn getrandom_syscall(buf: *mut u8, buflen: usize, flags: u32) -> isize {
1313
// Based on `rustix` and `linux-raw-sys` code.
1414
cfg_if! {
1515
if #[cfg(target_arch = "arm")] {
16-
const __NR_getrandom: u32 = 384;
1716
// In thumb-mode, r7 is the frame pointer and is not permitted to be used in
1817
// an inline asm operand, so we have to use a different register and copy it
1918
// into r7 inside the inline asm.
@@ -22,10 +21,10 @@ unsafe fn getrandom_syscall(buf: *mut u8, buflen: usize, flags: u32) -> isize {
2221
// bother with it.
2322
core::arch::asm!(
2423
"mov {tmp}, r7",
25-
"mov r7, {nr}",
24+
// TODO(MSRV-1.82): replace with `nr = const __NR_getrandom,`
25+
"mov r7, #384",
2626
"svc 0",
2727
"mov r7, {tmp}",
28-
nr = const __NR_getrandom,
2928
tmp = out(reg) _,
3029
inlateout("r0") buf => r0,
3130
in("r1") buflen,

0 commit comments

Comments
 (0)