Skip to content

Commit 07cf3b4

Browse files
committed
require naked functions to be unsafe again
they dereference raw pointers, so the caller needs to make sure the pointer is valid. note that this requires changing `maybe_use_optimized_c_shim` to support unsafe functions.
1 parent 31ee454 commit 07cf3b4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/aarch64.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ macro_rules! compare_and_swap {
131131
intrinsics! {
132132
#[maybe_use_optimized_c_shim]
133133
#[naked]
134-
pub extern "C" fn $name (
134+
pub unsafe extern "C" fn $name (
135135
expected: int_ty!($bytes), desired: int_ty!($bytes), ptr: *mut int_ty!($bytes)
136136
) -> int_ty!($bytes) {
137137
// We can't use `AtomicI8::compare_and_swap`; we *are* compare_and_swap.
@@ -162,7 +162,7 @@ macro_rules! compare_and_swap_i128 {
162162
intrinsics! {
163163
#[maybe_use_optimized_c_shim]
164164
#[naked]
165-
pub extern "C" fn $name (
165+
pub unsafe extern "C" fn $name (
166166
expected: i128, desired: i128, ptr: *mut i128
167167
) -> i128 {
168168
unsafe { core::arch::asm! {
@@ -192,7 +192,7 @@ macro_rules! swap {
192192
intrinsics! {
193193
#[maybe_use_optimized_c_shim]
194194
#[naked]
195-
pub extern "C" fn $name (
195+
pub unsafe extern "C" fn $name (
196196
left: int_ty!($bytes), right_ptr: *mut int_ty!($bytes)
197197
) -> int_ty!($bytes) {
198198
unsafe { core::arch::asm! {
@@ -218,7 +218,7 @@ macro_rules! fetch_op {
218218
intrinsics! {
219219
#[maybe_use_optimized_c_shim]
220220
#[naked]
221-
pub extern "C" fn $name (
221+
pub unsafe extern "C" fn $name (
222222
val: int_ty!($bytes), ptr: *mut int_ty!($bytes)
223223
) -> int_ty!($bytes) {
224224
unsafe { core::arch::asm! {

src/macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ macro_rules! intrinsics {
204204
(
205205
#[maybe_use_optimized_c_shim]
206206
$(#[$($attr:tt)*])*
207-
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
207+
pub $(unsafe $(@ $empty:tt)? )? extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
208208
$($body:tt)*
209209
}
210210

211211
$($rest:tt)*
212212
) => (
213213
#[cfg($name = "optimized-c")]
214214
#[cfg_attr(feature = "weak-intrinsics", linkage = "weak")]
215-
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
215+
pub $(unsafe $($empty)? )? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
216216
extern $abi {
217217
fn $name($($argname: $ty),*) $(-> $ret)?;
218218
}
@@ -224,7 +224,7 @@ macro_rules! intrinsics {
224224
#[cfg(not($name = "optimized-c"))]
225225
intrinsics! {
226226
$(#[$($attr)*])*
227-
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
227+
pub $(unsafe $($empty)? )? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
228228
$($body)*
229229
}
230230
}
@@ -419,7 +419,7 @@ macro_rules! intrinsics {
419419
(
420420
#[naked]
421421
$(#[$($attr:tt)*])*
422-
pub $(unsafe)? extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
422+
pub unsafe extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
423423
$($body:tt)*
424424
}
425425

0 commit comments

Comments
 (0)