Debian Codegraph @

third_party/rust/crash-context/src/linux/getcontext/arm.rs

raw
1 std::arch::global_asm! {
2 ".text",
3 ".global crash_context_getcontext",
4 ".hidden crash_context_getcontext",
5 ".type crash_context_getcontext, #function",
6 ".align 0",
7 ".fnstart",
8 "crash_context_getcontext:",
9
10 // First, save r4-r11
11 "add r1, r0, #(32 + 4 * 4)",
12 "stm r1, {{r4-r11}}",
13
14 // r12 is a scratch register, don't save it
15
16 // Save sp and lr explicitly.
17 // - sp can't be stored with stmia in Thumb-2
18 // - STM instructions that store sp and pc are deprecated in ARM
19 "str sp, [r0, #(32 + 13 * 4)]",
20 "str lr, [r0, #(32 + 14 * 4)]",
21
22 // Save the caller's address in 'pc'
23 "str lr, [r0, #(32 + 15 * 4)]",
24
25 // Save ucontext_t* pointer across next call
26 "mov r4, r0",
27
28 // Call sigprocmask(SIG_BLOCK, NULL, &(ucontext->uc_sigmask))
29 "mov r0, #0", // SIG_BLOCK
30 "mov r1, #0", // NULL
31 "add r2, r4, #104", // UCONTEXT_SIGMASK_OFFSET
32 "bl sigprocmask(PLT)",
33
34 /* Intentionally do not save the FPU state here. This is because on
35 * Linux/ARM, one should instead use ptrace(PTRACE_GETFPREGS) or
36 * ptrace(PTRACE_GETVFPREGS) to get it.
37 *
38 * Note that a real implementation of getcontext() would need to save
39 * this here to allow setcontext()/swapcontext() to work correctly.
40 */
41
42 // Restore the values of r4 and lr
43 "mov r0, r4",
44 "ldr lr, [r0, #(32 + 14 * 4)]",
45 "ldr r4, [r0, #(32 + 4 * 4)]",
46
47 // Return 0
48 "mov r0, #0",
49 "bx lr",
50
51 ".fnend",
52 ".size crash_context_getcontext, . - crash_context_getcontext",
53 }