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.
This commit is contained in:
Joshua Nelson 2023-06-26 16:27:16 +00:00
parent 6242fd629e
commit e7c4a45348
2 changed files with 8 additions and 8 deletions

View file

@ -131,7 +131,7 @@ macro_rules! compare_and_swap {
intrinsics! {
#[maybe_use_optimized_c_shim]
#[naked]
pub extern "C" fn $name (
pub unsafe extern "C" fn $name (
expected: int_ty!($bytes), desired: int_ty!($bytes), ptr: *mut int_ty!($bytes)
) -> int_ty!($bytes) {
// We can't use `AtomicI8::compare_and_swap`; we *are* compare_and_swap.
@ -162,7 +162,7 @@ macro_rules! compare_and_swap_i128 {
intrinsics! {
#[maybe_use_optimized_c_shim]
#[naked]
pub extern "C" fn $name (
pub unsafe extern "C" fn $name (
expected: i128, desired: i128, ptr: *mut i128
) -> i128 {
unsafe { core::arch::asm! {
@ -192,7 +192,7 @@ macro_rules! swap {
intrinsics! {
#[maybe_use_optimized_c_shim]
#[naked]
pub extern "C" fn $name (
pub unsafe extern "C" fn $name (
left: int_ty!($bytes), right_ptr: *mut int_ty!($bytes)
) -> int_ty!($bytes) {
unsafe { core::arch::asm! {
@ -218,7 +218,7 @@ macro_rules! fetch_op {
intrinsics! {
#[maybe_use_optimized_c_shim]
#[naked]
pub extern "C" fn $name (
pub unsafe extern "C" fn $name (
val: int_ty!($bytes), ptr: *mut int_ty!($bytes)
) -> int_ty!($bytes) {
unsafe { core::arch::asm! {

View file

@ -204,7 +204,7 @@ macro_rules! intrinsics {
(
#[maybe_use_optimized_c_shim]
$(#[$($attr:tt)*])*
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
pub $(unsafe $(@ $empty:tt)? )? extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
$($body:tt)*
}
@ -212,7 +212,7 @@ macro_rules! intrinsics {
) => (
#[cfg($name = "optimized-c")]
#[cfg_attr(feature = "weak-intrinsics", linkage = "weak")]
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
pub $(unsafe $($empty)? )? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
extern $abi {
fn $name($($argname: $ty),*) $(-> $ret)?;
}
@ -224,7 +224,7 @@ macro_rules! intrinsics {
#[cfg(not($name = "optimized-c"))]
intrinsics! {
$(#[$($attr)*])*
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
pub $(unsafe $($empty)? )? extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
$($body)*
}
}
@ -419,7 +419,7 @@ macro_rules! intrinsics {
(
#[naked]
$(#[$($attr:tt)*])*
pub $(unsafe)? extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
pub unsafe extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
$($body:tt)*
}