Skip to content

Commit 8416bb1

Browse files
committed
naked functions now require unsafe attributes
1 parent 181889d commit 8416bb1

File tree

5 files changed

+148
-162
lines changed

5 files changed

+148
-162
lines changed

src/unwinder/arch/aarch64.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,12 @@ macro_rules! save {
113113
(maybesavefp()) => { "" };
114114
}
115115

116-
#[naked]
116+
#[unsafe(naked)]
117117
pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), ptr: *mut ()) {
118-
unsafe {
119-
#[cfg(target_feature = "neon")]
120-
save!(gp, fp);
121-
#[cfg(not(target_feature = "neon"))]
122-
save!(gp);
123-
}
118+
#[cfg(target_feature = "neon")]
119+
save!(gp, fp);
120+
#[cfg(not(target_feature = "neon"))]
121+
save!(gp);
124122
}
125123

126124
macro_rules! restore {

src/unwinder/arch/riscv32.rs

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -173,60 +173,56 @@ macro_rules! code {
173173
};
174174
}
175175

176-
#[naked]
176+
#[unsafe(naked)]
177177
pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), ptr: *mut ()) {
178178
// No need to save caller-saved registers here.
179179
#[cfg(target_feature = "d")]
180-
unsafe {
181-
core::arch::naked_asm!(
182-
maybe_cfi!(".cfi_startproc"),
183-
"
184-
mv t0, sp
185-
add sp, sp, -0x190
186-
",
187-
maybe_cfi!(".cfi_def_cfa_offset 0x190"),
188-
"sw ra, 0x180(sp)",
189-
maybe_cfi!(".cfi_offset ra, -16"),
190-
code!(save_gp),
191-
code!(save_fp),
192-
"
193-
mv t0, a0
194-
mv a0, sp
195-
jalr t0
196-
lw ra, 0x180(sp)
197-
add sp, sp, 0x190
198-
",
199-
maybe_cfi!(".cfi_def_cfa_offset 0"),
200-
maybe_cfi!(".cfi_restore ra"),
201-
"ret",
202-
maybe_cfi!(".cfi_endproc"),
203-
);
204-
}
180+
core::arch::naked_asm!(
181+
maybe_cfi!(".cfi_startproc"),
182+
"
183+
mv t0, sp
184+
add sp, sp, -0x190
185+
",
186+
maybe_cfi!(".cfi_def_cfa_offset 0x190"),
187+
"sw ra, 0x180(sp)",
188+
maybe_cfi!(".cfi_offset ra, -16"),
189+
code!(save_gp),
190+
code!(save_fp),
191+
"
192+
mv t0, a0
193+
mv a0, sp
194+
jalr t0
195+
lw ra, 0x180(sp)
196+
add sp, sp, 0x190
197+
",
198+
maybe_cfi!(".cfi_def_cfa_offset 0"),
199+
maybe_cfi!(".cfi_restore ra"),
200+
"ret",
201+
maybe_cfi!(".cfi_endproc"),
202+
);
205203
#[cfg(not(target_feature = "d"))]
206-
unsafe {
207-
core::arch::naked_asm!(
208-
maybe_cfi!(".cfi_startproc"),
209-
"
210-
mv t0, sp
211-
add sp, sp, -0x90
212-
",
213-
maybe_cfi!(".cfi_def_cfa_offset 0x90"),
214-
"sw ra, 0x80(sp)",
215-
maybe_cfi!(".cfi_offset ra, -16"),
216-
code!(save_gp),
217-
"
218-
mv t0, a0
219-
mv a0, sp
220-
jalr t0
221-
lw ra, 0x80(sp)
222-
add sp, sp, 0x90
223-
",
224-
maybe_cfi!(".cfi_def_cfa_offset 0"),
225-
maybe_cfi!(".cfi_restore ra"),
226-
"ret",
227-
maybe_cfi!(".cfi_endproc")
228-
);
229-
}
204+
core::arch::naked_asm!(
205+
maybe_cfi!(".cfi_startproc"),
206+
"
207+
mv t0, sp
208+
add sp, sp, -0x90
209+
",
210+
maybe_cfi!(".cfi_def_cfa_offset 0x90"),
211+
"sw ra, 0x80(sp)",
212+
maybe_cfi!(".cfi_offset ra, -16"),
213+
code!(save_gp),
214+
"
215+
mv t0, a0
216+
mv a0, sp
217+
jalr t0
218+
lw ra, 0x80(sp)
219+
add sp, sp, 0x90
220+
",
221+
maybe_cfi!(".cfi_def_cfa_offset 0"),
222+
maybe_cfi!(".cfi_restore ra"),
223+
"ret",
224+
maybe_cfi!(".cfi_endproc")
225+
);
230226
}
231227

232228
pub unsafe fn restore_context(ctx: &Context) -> ! {

src/unwinder/arch/riscv64.rs

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -173,60 +173,56 @@ macro_rules! code {
173173
};
174174
}
175175

176-
#[naked]
176+
#[unsafe(naked)]
177177
pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), ptr: *mut ()) {
178178
// No need to save caller-saved registers here.
179179
#[cfg(target_feature = "d")]
180-
unsafe {
181-
core::arch::naked_asm!(
182-
maybe_cfi!(".cfi_startproc"),
183-
"
184-
mv t0, sp
185-
add sp, sp, -0x210
186-
",
187-
maybe_cfi!(".cfi_def_cfa_offset 0x210"),
188-
"sd ra, 0x200(sp)",
189-
maybe_cfi!(".cfi_offset ra, -16"),
190-
code!(save_gp),
191-
code!(save_fp),
192-
"
193-
mv t0, a0
194-
mv a0, sp
195-
jalr t0
196-
ld ra, 0x200(sp)
197-
add sp, sp, 0x210
198-
",
199-
maybe_cfi!(".cfi_def_cfa_offset 0"),
200-
maybe_cfi!(".cfi_restore ra"),
201-
"ret",
202-
maybe_cfi!(".cfi_endproc"),
203-
);
204-
}
180+
core::arch::naked_asm!(
181+
maybe_cfi!(".cfi_startproc"),
182+
"
183+
mv t0, sp
184+
add sp, sp, -0x210
185+
",
186+
maybe_cfi!(".cfi_def_cfa_offset 0x210"),
187+
"sd ra, 0x200(sp)",
188+
maybe_cfi!(".cfi_offset ra, -16"),
189+
code!(save_gp),
190+
code!(save_fp),
191+
"
192+
mv t0, a0
193+
mv a0, sp
194+
jalr t0
195+
ld ra, 0x200(sp)
196+
add sp, sp, 0x210
197+
",
198+
maybe_cfi!(".cfi_def_cfa_offset 0"),
199+
maybe_cfi!(".cfi_restore ra"),
200+
"ret",
201+
maybe_cfi!(".cfi_endproc"),
202+
);
205203
#[cfg(not(target_feature = "d"))]
206-
unsafe {
207-
core::arch::naked_asm!(
208-
maybe_cfi!(".cfi_startproc"),
209-
"
210-
mv t0, sp
211-
add sp, sp, -0x110
212-
",
213-
maybe_cfi!(".cfi_def_cfa_offset 0x110"),
214-
"sd ra, 0x100(sp)",
215-
maybe_cfi!(".cfi_offset ra, -16"),
216-
code!(save_gp),
217-
"
218-
mv t0, a0
219-
mv a0, sp
220-
jalr t0
221-
ld ra, 0x100(sp)
222-
add sp, sp, 0x110
223-
",
224-
maybe_cfi!(".cfi_def_cfa_offset 0"),
225-
maybe_cfi!(".cfi_restore ra"),
226-
"ret",
227-
maybe_cfi!(".cfi_endproc"),
228-
);
229-
}
204+
core::arch::naked_asm!(
205+
maybe_cfi!(".cfi_startproc"),
206+
"
207+
mv t0, sp
208+
add sp, sp, -0x110
209+
",
210+
maybe_cfi!(".cfi_def_cfa_offset 0x110"),
211+
"sd ra, 0x100(sp)",
212+
maybe_cfi!(".cfi_offset ra, -16"),
213+
code!(save_gp),
214+
"
215+
mv t0, a0
216+
mv a0, sp
217+
jalr t0
218+
ld ra, 0x100(sp)
219+
add sp, sp, 0x110
220+
",
221+
maybe_cfi!(".cfi_def_cfa_offset 0"),
222+
maybe_cfi!(".cfi_restore ra"),
223+
"ret",
224+
maybe_cfi!(".cfi_endproc"),
225+
);
230226
}
231227

232228
pub unsafe fn restore_context(ctx: &Context) -> ! {

src/unwinder/arch/x86.rs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,51 +56,49 @@ impl ops::IndexMut<gimli::Register> for Context {
5656
}
5757
}
5858

59-
#[naked]
59+
#[unsafe(naked)]
6060
pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), ptr: *mut ()) {
6161
// No need to save caller-saved registers here.
62-
unsafe {
63-
core::arch::naked_asm!(
64-
maybe_cfi!(".cfi_startproc"),
65-
"sub esp, 52",
66-
maybe_cfi!(".cfi_def_cfa_offset 56"),
67-
"
68-
mov [esp + 4], ecx
69-
mov [esp + 8], edx
70-
mov [esp + 12], ebx
71-
72-
/* Adjust the stack to account for the return address */
73-
lea eax, [esp + 56]
74-
mov [esp + 16], eax
75-
76-
mov [esp + 20], ebp
77-
mov [esp + 24], esi
78-
mov [esp + 28], edi
79-
80-
/* Return address */
81-
mov eax, [esp + 52]
82-
mov [esp + 32], eax
83-
84-
stmxcsr [esp + 36]
85-
fnstcw [esp + 40]
86-
87-
mov eax, [esp + 60]
88-
mov ecx, esp
89-
push eax
90-
",
91-
maybe_cfi!(".cfi_adjust_cfa_offset 4"),
92-
"push ecx",
93-
maybe_cfi!(".cfi_adjust_cfa_offset 4"),
94-
"
95-
call [esp + 64]
96-
97-
add esp, 60
98-
",
99-
maybe_cfi!(".cfi_def_cfa_offset 4"),
100-
"ret",
101-
maybe_cfi!(".cfi_endproc"),
102-
);
103-
}
62+
core::arch::naked_asm!(
63+
maybe_cfi!(".cfi_startproc"),
64+
"sub esp, 52",
65+
maybe_cfi!(".cfi_def_cfa_offset 56"),
66+
"
67+
mov [esp + 4], ecx
68+
mov [esp + 8], edx
69+
mov [esp + 12], ebx
70+
71+
/* Adjust the stack to account for the return address */
72+
lea eax, [esp + 56]
73+
mov [esp + 16], eax
74+
75+
mov [esp + 20], ebp
76+
mov [esp + 24], esi
77+
mov [esp + 28], edi
78+
79+
/* Return address */
80+
mov eax, [esp + 52]
81+
mov [esp + 32], eax
82+
83+
stmxcsr [esp + 36]
84+
fnstcw [esp + 40]
85+
86+
mov eax, [esp + 60]
87+
mov ecx, esp
88+
push eax
89+
",
90+
maybe_cfi!(".cfi_adjust_cfa_offset 4"),
91+
"push ecx",
92+
maybe_cfi!(".cfi_adjust_cfa_offset 4"),
93+
"
94+
call [esp + 64]
95+
96+
add esp, 60
97+
",
98+
maybe_cfi!(".cfi_def_cfa_offset 4"),
99+
"ret",
100+
maybe_cfi!(".cfi_endproc"),
101+
);
104102
}
105103

106104
pub unsafe fn restore_context(ctx: &Context) -> ! {

src/unwinder/arch/x86_64.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,14 @@ impl ops::IndexMut<gimli::Register> for Context {
5858
}
5959
}
6060

61-
#[naked]
61+
#[unsafe(naked)]
6262
pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), ptr: *mut ()) {
6363
// No need to save caller-saved registers here.
64-
unsafe {
65-
core::arch::naked_asm!(
66-
maybe_cfi!(".cfi_startproc"),
67-
"sub rsp, 0x98",
68-
maybe_cfi!(".cfi_def_cfa_offset 0xA0"),
69-
"
64+
core::arch::naked_asm!(
65+
maybe_cfi!(".cfi_startproc"),
66+
"sub rsp, 0x98",
67+
maybe_cfi!(".cfi_def_cfa_offset 0xA0"),
68+
"
7069
mov [rsp + 0x18], rbx
7170
mov [rsp + 0x30], rbp
7271
@@ -91,11 +90,10 @@ pub extern "C-unwind" fn save_context(f: extern "C" fn(&mut Context, *mut ()), p
9190
call rax
9291
add rsp, 0x98
9392
",
94-
maybe_cfi!(".cfi_def_cfa_offset 8"),
95-
"ret",
96-
maybe_cfi!(".cfi_endproc"),
97-
);
98-
}
93+
maybe_cfi!(".cfi_def_cfa_offset 8"),
94+
"ret",
95+
maybe_cfi!(".cfi_endproc"),
96+
);
9997
}
10098

10199
pub unsafe fn restore_context(ctx: &Context) -> ! {

0 commit comments

Comments
 (0)