Hi All,
Q群里问问题不过瘾,还是来这边了
是一个有关v8架构下函数栈的问题,先帖代码:
/*
* AArch64 PCS assigns the frame pointer to x29.
*
* A simple function prologue looks like this:
* subsp, sp, #0x10
* stpx29, x30, [sp]
*movx29, sp
*
* A simple function epilogue looks like this:
*movsp, x29
*ldpx29, x30, [sp]
*addsp, sp, #0x10
*/
int notrace unwind_frame(struct stackframe *frame)
{
unsigned long high, low;
unsigned long fp = frame->fp;
low = frame->sp;
high = ALIGN(low, THREAD_SIZE);
if (fp < low || fp > high || fp & 0xf)
return -EINVAL;
frame->sp = fp + 0x10;
frame->fp = *(unsigned long *)(fp);
/*
* -4 here because we care about the PC at time of bl,
* not where the return will go.
*/
frame->pc = *(unsigned long *)(fp + 8) - 4;
return 0;
}
Q: 注释部分:
* A simple function prologue looks like this:
* subsp, sp, #0x10
* stpx29, x30, [sp]
*movx29, sp
大概做了以下几件事:
1. sp指针自减0x10
2. 将0x29(即FP)入栈,将0x30(即LR)入栈,地址为SP
3. 将FP寄存器的值赋给SP
那么是不是意味着,对于单个函数,函数栈的大小只能是0x10?如果函数中临时变量较多超出0x10怎么办?
之前我在x86架构下,确定一个函数的栈范围需要ESP和EBP两个指针,似乎ARM下是用FP和SP,并且FP的相邻地址就保存了LR
按照以上的说法,如果出现了系统崩溃的bug,似乎只需要知道FP指针,就可以推导函数调用的整个流程(因为相当于同时知道了LR)
最近编辑记录 showstopper (2016-05-31 22:21:01)