Debian Codegraph @

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

raw
1 // Unfortunately, the asm! macro has a few really annoying limitations at the
2 // moment
3 //
4 // 1. const operands are unstable
5 // 2. cfg attributes can't be used inside the asm macro at all
6 //
7 // and the worst part is we need it for literally only 1 thing, using a different
8 // offset to the fpstate in ucontext depending on whether we are targeting android
9 // or not :(
10 macro_rules! asm_func {
11 ($offset:expr) => {
12 std::arch::global_asm! {
13 ".text",
14 ".global crash_context_getcontext",
15 ".hidden crash_context_getcontext",
16 ".align 4",
17 ".type crash_context_getcontext, @function",
18 "crash_context_getcontext:",
19 "movl 4(%esp), %eax", // eax = uc
20
21 // Save register values
22 "movl %ecx, 0x3c(%eax)",
23 "movl %edx, 0x38(%eax)",
24 "movl %ebx, 0x34(%eax)",
25 "movl %edi, 0x24(%eax)",
26 "movl %esi, 0x28(%eax)",
27 "movl %ebp, 0x2c(%eax)",
28
29 "movl (%esp), %edx", /* return address */
30 "lea 4(%esp), %ecx", /* exclude return address from stack */
31 "mov %edx, 0x4c(%eax)",
32 "mov %ecx, 0x30(%eax)",
33
34 "xorl %ecx, %ecx",
35 "movw %fs, %cx",
36 "mov %ecx, 0x18(%eax)",
37
38 "movl $0, 0x40(%eax)",
39
40 // Save floating point state to fpregstate, then update
41 // the fpregs pointer to point to it
42 stringify!(leal $offset(%eax),%ecx),
43 "fnstenv (%ecx)",
44 "fldenv (%ecx)",
45 "mov %ecx, 0x60(%eax)",
46
47 // Save signal mask: sigprocmask(SIGBLOCK, NULL, &uc->uc_sigmask)
48 "leal 0x6c(%eax), %edx",
49 "xorl %ecx, %ecx",
50 "push %edx", /* &uc->uc_sigmask */
51 "push %ecx", /* NULL */
52 "push %ecx", /* SIGBLOCK == 0 on i386 */
53 "call sigprocmask@PLT",
54 "addl $12, %esp",
55
56 "movl $0, %eax",
57 "ret",
58
59 ".size crash_context_getcontext, . - crash_context_getcontext",
60 options(att_syntax)
61 }
62 };
63 }
64
65 #[cfg(target_os = "linux")]
66 asm_func!(0xec);
67 #[cfg(target_os = "android")]
68 asm_func!(0x74);