-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadjstack.c
More file actions
47 lines (44 loc) · 1.15 KB
/
Copy pathadjstack.c
File metadata and controls
47 lines (44 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
/*adjstack takes a stack which is bounded by addresses lim0 and lim1
*and adjusts the saved frame pointers (ebp) by adj bytes.
*It is intended to be used in conjunction with sched_fork to fix
*the child's stack, and should be called from the parent task, after
*having allocated the child's stack and copying into it the contents of
*the entire parent's stack. There are some debugging fprintfs that
*could be commented out if needed.
*/
void adjstack(void *lim0,void *lim1,unsigned long adj)
{
void **p;
void *prev,*new;
#ifdef _LP64
__asm__(
"movq %%rbp,%0"
:"=m" (p));
#else
__asm__(
"movl %%ebp,%0"
:"=m" (p));
#endif
/* Now current bp (for adjstack fn) is in p */
/* Unwind stack to get to saved ebp addr of caller */
/* then begin adjustment process */
fprintf(stderr,"Asked to adjust child stack by %#lX bytes bet %p and %p\n",adj,lim0,lim1);
prev=*p;
p= prev + adj;
for(;;)
{
prev=*p;
new=prev+adj;
if (new<lim0 || new>lim1)
{
fprintf(stderr,"Enough already, saved BP @%p is %p\n",
p,prev);
break;
}
*p=new;
fprintf(stderr,"Adjusted saved bp @%p to %p\n",
p,*p);
p=new;
}
}