MCPcopy Create free account
hub / github.com/F-Stack/f-stack / stack_capture

Function stack_capture

freebsd/mips/mips/stack_machdep.c:46–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44#define VALID_PC(addr) ((addr) >= (uintptr_t)btext && (addr) % 4 == 0)
45
46static void
47stack_capture(struct stack *st, struct thread *td, uintptr_t pc, uintptr_t sp)
48{
49 u_register_t ra;
50 uintptr_t i, ra_addr;
51 int ra_stack_pos, stacksize;
52 InstFmt insn;
53
54 stack_zero(st);
55
56 for (;;) {
57 if (!VALID_PC(pc))
58 break;
59
60 /*
61 * Walk backward from the PC looking for the function
62 * start. Assume a subtraction from SP is the start
63 * of a function. Hope that we find the store of RA
64 * into the stack frame along the way and save the
65 * offset of the saved RA relative to SP.
66 */
67 ra_stack_pos = -1;
68 stacksize = 0;
69 for (i = pc; VALID_PC(i); i -= sizeof(insn)) {
70 bcopy((void *)i, &insn, sizeof(insn));
71 switch (insn.IType.op) {
72 case OP_ADDI:
73 case OP_ADDIU:
74 case OP_DADDI:
75 case OP_DADDIU:
76 if (insn.IType.rs != SP || insn.IType.rt != SP)
77 break;
78
79 /*
80 * Ignore stack fixups in "early"
81 * returns in a function, or if the
82 * call was from an unlikely branch
83 * moved after the end of the normal
84 * return.
85 */
86 if ((short)insn.IType.imm > 0)
87 break;
88
89 stacksize = -(short)insn.IType.imm;
90 break;
91
92 case OP_SW:
93 case OP_SD:
94 if (insn.IType.rs != SP || insn.IType.rt != RA)
95 break;
96 ra_stack_pos = (short)insn.IType.imm;
97 break;
98 default:
99 break;
100 }
101
102 if (stacksize != 0)
103 break;

Callers 2

stack_save_tdFunction · 0.70
stack_saveFunction · 0.70

Calls 3

stack_zeroFunction · 0.85
stack_putFunction · 0.85
kstack_containsFunction · 0.85

Tested by

no test coverage detected