Skip to content

Commit cced7fb

Browse files
authored
Merge pull request #686 from folkertdev/use-naked-asm
use `naked_asm!` in `#[naked]` functions
2 parents b411563 + a863636 commit cced7fb

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

Diff for: src/aarch64.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ intrinsics! {
66
#[naked]
77
#[cfg(all(target_os = "uefi", not(feature = "no-asm")))]
88
pub unsafe extern "C" fn __chkstk() {
9-
core::arch::asm!(
9+
core::arch::naked_asm!(
1010
".p2align 2",
1111
"lsl x16, x15, #4",
1212
"mov x17, sp",
@@ -16,7 +16,6 @@ intrinsics! {
1616
"ldr xzr, [x17]",
1717
"b.gt 1b",
1818
"ret",
19-
options(noreturn)
2019
);
2120
}
2221
}

Diff for: src/aarch64_linux.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ macro_rules! compare_and_swap {
136136
expected: int_ty!($bytes), desired: int_ty!($bytes), ptr: *mut int_ty!($bytes)
137137
) -> int_ty!($bytes) {
138138
// We can't use `AtomicI8::compare_and_swap`; we *are* compare_and_swap.
139-
unsafe { core::arch::asm! {
139+
unsafe { core::arch::naked_asm! {
140140
// UXT s(tmp0), s(0)
141141
concat!(uxt!($bytes), " ", reg!($bytes, 16), ", ", reg!($bytes, 0)),
142142
"0:",
@@ -150,7 +150,6 @@ macro_rules! compare_and_swap {
150150
"cbnz w17, 0b",
151151
"1:",
152152
"ret",
153-
options(noreturn)
154153
} }
155154
}
156155
}
@@ -166,7 +165,7 @@ macro_rules! compare_and_swap_i128 {
166165
pub unsafe extern "C" fn $name (
167166
expected: i128, desired: i128, ptr: *mut i128
168167
) -> i128 {
169-
unsafe { core::arch::asm! {
168+
unsafe { core::arch::naked_asm! {
170169
"mov x16, x0",
171170
"mov x17, x1",
172171
"0:",
@@ -180,7 +179,6 @@ macro_rules! compare_and_swap_i128 {
180179
"cbnz w15, 0b",
181180
"1:",
182181
"ret",
183-
options(noreturn)
184182
} }
185183
}
186184
}
@@ -196,7 +194,7 @@ macro_rules! swap {
196194
pub unsafe extern "C" fn $name (
197195
left: int_ty!($bytes), right_ptr: *mut int_ty!($bytes)
198196
) -> int_ty!($bytes) {
199-
unsafe { core::arch::asm! {
197+
unsafe { core::arch::naked_asm! {
200198
// mov s(tmp0), s(0)
201199
concat!("mov ", reg!($bytes, 16), ", ", reg!($bytes, 0)),
202200
"0:",
@@ -206,7 +204,6 @@ macro_rules! swap {
206204
concat!(stxr!($ordering, $bytes), " w17, ", reg!($bytes, 16), ", [x1]"),
207205
"cbnz w17, 0b",
208206
"ret",
209-
options(noreturn)
210207
} }
211208
}
212209
}
@@ -222,7 +219,7 @@ macro_rules! fetch_op {
222219
pub unsafe extern "C" fn $name (
223220
val: int_ty!($bytes), ptr: *mut int_ty!($bytes)
224221
) -> int_ty!($bytes) {
225-
unsafe { core::arch::asm! {
222+
unsafe { core::arch::naked_asm! {
226223
// mov s(tmp0), s(0)
227224
concat!("mov ", reg!($bytes, 16), ", ", reg!($bytes, 0)),
228225
"0:",
@@ -234,7 +231,6 @@ macro_rules! fetch_op {
234231
concat!(stxr!($ordering, $bytes), " w15, ", reg!($bytes, 17), ", [x1]"),
235232
"cbnz w15, 0b",
236233
"ret",
237-
options(noreturn)
238234
} }
239235
}
240236
}

Diff for: src/arm.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@ intrinsics! {
2323
#[naked]
2424
#[cfg(not(target_env = "msvc"))]
2525
pub unsafe extern "C" fn __aeabi_uidivmod() {
26-
core::arch::asm!(
26+
core::arch::naked_asm!(
2727
"push {{lr}}",
2828
"sub sp, sp, #4",
2929
"mov r2, sp",
3030
bl!("__udivmodsi4"),
3131
"ldr r1, [sp]",
3232
"add sp, sp, #4",
3333
"pop {{pc}}",
34-
options(noreturn)
3534
);
3635
}
3736

3837
#[naked]
3938
pub unsafe extern "C" fn __aeabi_uldivmod() {
40-
core::arch::asm!(
39+
core::arch::naked_asm!(
4140
"push {{r4, lr}}",
4241
"sub sp, sp, #16",
4342
"add r4, sp, #8",
@@ -47,26 +46,24 @@ intrinsics! {
4746
"ldr r3, [sp, #12]",
4847
"add sp, sp, #16",
4948
"pop {{r4, pc}}",
50-
options(noreturn)
5149
);
5250
}
5351

5452
#[naked]
5553
pub unsafe extern "C" fn __aeabi_idivmod() {
56-
core::arch::asm!(
54+
core::arch::naked_asm!(
5755
"push {{r0, r1, r4, lr}}",
5856
bl!("__aeabi_idiv"),
5957
"pop {{r1, r2}}",
6058
"muls r2, r2, r0",
6159
"subs r1, r1, r2",
6260
"pop {{r4, pc}}",
63-
options(noreturn)
6461
);
6562
}
6663

6764
#[naked]
6865
pub unsafe extern "C" fn __aeabi_ldivmod() {
69-
core::arch::asm!(
66+
core::arch::naked_asm!(
7067
"push {{r4, lr}}",
7168
"sub sp, sp, #16",
7269
"add r4, sp, #8",
@@ -76,7 +73,6 @@ intrinsics! {
7673
"ldr r3, [sp, #12]",
7774
"add sp, sp, #16",
7875
"pop {{r4, pc}}",
79-
options(noreturn)
8076
);
8177
}
8278

Diff for: src/x86.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ intrinsics! {
1414
not(feature = "no-asm")
1515
))]
1616
pub unsafe extern "C" fn __chkstk() {
17-
core::arch::asm!(
17+
core::arch::naked_asm!(
1818
"jmp __alloca", // Jump to __alloca since fallthrough may be unreliable"
19-
options(noreturn, att_syntax)
19+
options(att_syntax)
2020
);
2121
}
2222

@@ -27,7 +27,7 @@ intrinsics! {
2727
))]
2828
pub unsafe extern "C" fn _alloca() {
2929
// __chkstk and _alloca are the same function
30-
core::arch::asm!(
30+
core::arch::naked_asm!(
3131
"push %ecx",
3232
"cmp $0x1000,%eax",
3333
"lea 8(%esp),%ecx", // esp before calling this routine -> ecx
@@ -47,7 +47,7 @@ intrinsics! {
4747
"push (%eax)", // push return address onto the stack
4848
"sub %esp,%eax", // restore the original value in eax
4949
"ret",
50-
options(noreturn, att_syntax)
50+
options(att_syntax)
5151
);
5252
}
5353
}

Diff for: src/x86_64.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ intrinsics! {
1414
not(feature = "no-asm")
1515
))]
1616
pub unsafe extern "C" fn ___chkstk_ms() {
17-
core::arch::asm!(
17+
core::arch::naked_asm!(
1818
"push %rcx",
1919
"push %rax",
2020
"cmp $0x1000,%rax",
@@ -32,7 +32,7 @@ intrinsics! {
3232
"pop %rax",
3333
"pop %rcx",
3434
"ret",
35-
options(noreturn, att_syntax)
35+
options(att_syntax)
3636
);
3737
}
3838
}

0 commit comments

Comments
 (0)