Skip to content

Commit f888219

Browse files
authored
Updates for Rust 1.82 (#2449)
Rust 1.82 adds `&raw` expressions, and marks some attributes as unsafe.
1 parent 2bba470 commit f888219

File tree

24 files changed

+100
-72
lines changed

24 files changed

+100
-72
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ jobs:
5555
- name: Setup Rust cache
5656
uses: ./.github/workflows/setup-rust-cache
5757

58+
- name: Update Rust
59+
run: rustup update
60+
5861
- name: Build Rust code
5962
run: cargo build
6063

@@ -89,7 +92,9 @@ jobs:
8992
sudo apt install gcc-aarch64-linux-gnu
9093
9194
- name: Install toolchain
92-
run: rustup target add ${{ matrix.target }}
95+
run: |
96+
rustup update
97+
rustup target add ${{ matrix.target }}
9398
9499
- name: Build Rust code
95100
working-directory: ${{ matrix.directory }}
@@ -140,6 +145,9 @@ jobs:
140145
sudo apt update
141146
sudo apt install gettext
142147
148+
- name: Update Rust
149+
run: rustup update
150+
143151
- name: Install mdbook
144152
uses: ./.github/workflows/install-mdbook
145153

src/android/interoperability/java/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use jni::sys::jstring;
2020
use jni::JNIEnv;
2121

2222
/// HelloWorld::hello method implementation.
23-
#[no_mangle]
23+
// SAFETY: There is no other global function of this name.
24+
#[unsafe(no_mangle)]
2425
pub extern "system" fn Java_HelloWorld_hello(
2526
mut env: JNIEnv,
2627
_class: JClass,

src/android/interoperability/with-c.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ Similarly, you can export Rust functions and call them from C.
66
You can do it by hand if you want:
77

88
```rust
9-
extern "C" {
10-
fn abs(x: i32) -> i32;
9+
unsafe extern "C" {
10+
safe fn abs(x: i32) -> i32;
1111
}
1212

1313
fn main() {
1414
let x = -42;
15-
// SAFETY: `abs` doesn't have any safety requirements.
16-
let abs_x = unsafe { abs(x) };
15+
let abs_x = abs(x);
1716
println!("{x}, {abs_x}");
1817
}
1918
```

src/android/interoperability/with-c/hand-written.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
We can declare external functions by hand:
44

55
```rust
6-
extern "C" {
7-
fn abs(x: i32) -> i32;
6+
unsafe extern "C" {
7+
safe fn abs(x: i32) -> i32;
88
}
99

1010
fn main() {
1111
let x = -42;
12-
// SAFETY: `abs` doesn't have any safety requirements.
13-
let abs_x = unsafe { abs(x) };
12+
let abs_x = abs(x);
1413
println!("{x}, {abs_x}");
1514
}
1615
```

src/android/interoperability/with-c/rust.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Build, push, and run the binary on your device:
4242

4343
<details>
4444

45-
`#[no_mangle]` disables Rust's usual name mangling, so the exported symbol will
46-
just be the name of the function. You can also use
47-
`#[export_name = "some_name"]` to specify whatever name you want.
45+
`#[unsafe(no_mangle)]` disables Rust's usual name mangling, so the exported
46+
symbol will just be the name of the function. You can also use
47+
`#[unsafe(export_name = "some_name")]` to specify whatever name you want.
4848

4949
</details>

src/android/interoperability/with-c/rust/libanalyze/analyze.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
use std::os::raw::c_int;
2020

2121
/// Analyze the numbers.
22-
#[no_mangle]
22+
// SAFETY: There is no other global function of this name.
23+
#[unsafe(no_mangle)]
2324
pub extern "C" fn analyze_numbers(x: c_int, y: c_int) {
2425
if x < y {
2526
println!("x ({x}) is smallest!");

src/bare-metal/aps/better-uart/driver.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Now let's use the new `Registers` struct in our driver.
88

99
<details>
1010

11-
- Note the use of `addr_of!` / `addr_of_mut!` to get pointers to individual
12-
fields without creating an intermediate reference, which would be unsound.
11+
- Note the use of `&raw const` / `&raw mut` to get pointers to individual fields
12+
without creating an intermediate reference, which would be unsound.
1313

1414
</details>

src/bare-metal/aps/examples/src/exceptions.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,57 @@ use log::error;
1717
use smccc::psci::system_off;
1818
use smccc::Hvc;
1919

20-
#[no_mangle]
20+
// SAFETY: There is no other global function of this name.
21+
#[unsafe(no_mangle)]
2122
extern "C" fn sync_exception_current(_elr: u64, _spsr: u64) {
2223
error!("sync_exception_current");
2324
system_off::<Hvc>().unwrap();
2425
}
2526

26-
#[no_mangle]
27+
// SAFETY: There is no other global function of this name.
28+
#[unsafe(no_mangle)]
2729
extern "C" fn irq_current(_elr: u64, _spsr: u64) {
2830
error!("irq_current");
2931
system_off::<Hvc>().unwrap();
3032
}
3133

32-
#[no_mangle]
34+
// SAFETY: There is no other global function of this name.
35+
#[unsafe(no_mangle)]
3336
extern "C" fn fiq_current(_elr: u64, _spsr: u64) {
3437
error!("fiq_current");
3538
system_off::<Hvc>().unwrap();
3639
}
3740

38-
#[no_mangle]
41+
// SAFETY: There is no other global function of this name.
42+
#[unsafe(no_mangle)]
3943
extern "C" fn serr_current(_elr: u64, _spsr: u64) {
4044
error!("serr_current");
4145
system_off::<Hvc>().unwrap();
4246
}
4347

44-
#[no_mangle]
48+
// SAFETY: There is no other global function of this name.
49+
#[unsafe(no_mangle)]
4550
extern "C" fn sync_lower(_elr: u64, _spsr: u64) {
4651
error!("sync_lower");
4752
system_off::<Hvc>().unwrap();
4853
}
4954

50-
#[no_mangle]
55+
// SAFETY: There is no other global function of this name.
56+
#[unsafe(no_mangle)]
5157
extern "C" fn irq_lower(_elr: u64, _spsr: u64) {
5258
error!("irq_lower");
5359
system_off::<Hvc>().unwrap();
5460
}
5561

56-
#[no_mangle]
62+
// SAFETY: There is no other global function of this name.
63+
#[unsafe(no_mangle)]
5764
extern "C" fn fiq_lower(_elr: u64, _spsr: u64) {
5865
error!("fiq_lower");
5966
system_off::<Hvc>().unwrap();
6067
}
6168

62-
#[no_mangle]
69+
// SAFETY: There is no other global function of this name.
70+
#[unsafe(no_mangle)]
6371
extern "C" fn serr_lower(_elr: u64, _spsr: u64) {
6472
error!("serr_lower");
6573
system_off::<Hvc>().unwrap();

src/bare-metal/aps/examples/src/main_improved.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use smccc::Hvc;
2929
/// Base address of the primary PL011 UART.
3030
const PL011_BASE_ADDRESS: *mut u32 = 0x900_0000 as _;
3131

32-
#[no_mangle]
32+
// SAFETY: There is no other global function of this name.
33+
#[unsafe(no_mangle)]
3334
extern "C" fn main(x0: u64, x1: u64, x2: u64, x3: u64) {
3435
// SAFETY: `PL011_BASE_ADDRESS` is the base address of a PL011 device, and
3536
// nothing else accesses that address range.

src/bare-metal/aps/examples/src/main_logger.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use smccc::Hvc;
2929
/// Base address of the primary PL011 UART.
3030
const PL011_BASE_ADDRESS: *mut u32 = 0x900_0000 as _;
3131

32-
#[no_mangle]
32+
// SAFETY: There is no other global function of this name.
33+
#[unsafe(no_mangle)]
3334
extern "C" fn main(x0: u64, x1: u64, x2: u64, x3: u64) {
3435
// SAFETY: `PL011_BASE_ADDRESS` is the base address of a PL011 device, and
3536
// nothing else accesses that address range.

0 commit comments

Comments
 (0)