6 static MemHash
* Purify_CurrentStackNode
;
8 void Purify_InitStack (char * stackBase
, long stackSize
)
17 +4 /* return address for main() */
18 +8 /* two arguments for main() */
22 printf ("Stack goes from %p to %p\n", stackBase
- stackSize
, stackBase
);
25 node
= Purify_AddMemory (stackBase
- stackSize
27 , PURIFY_MemFlag_Empty
28 , PURIFY_MemType_Stack
33 Purify_CurrentStackNode
= node
;
36 argv
= ((char ***)stackBase
)[-1];
37 argc
= ((int *)stackBase
)[-2];
40 printf ("&argc=%p\n", &((int *)stackBase
)[-2]);
41 printf ("argc=%d argv=%p\n", argc
, argv
);
44 offset
= (long)(&((int *)stackBase
)[-2]) - (long)(node
->mem
);
46 Purify_SetMemoryFlags (node
, offset
, 8,
47 PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
50 node
= Purify_AddMemory (argv
51 , (argc
+1) * sizeof (char *)
52 , PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
53 , PURIFY_MemType_Stack
56 node
->data
= "argv[] array";
58 for (t
=0; t
<argc
; t
++)
60 node
= Purify_AddMemory (argv
[t
]
61 , strlen (argv
[t
]) + 1
62 , PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
63 , PURIFY_MemType_Stack
66 node
->data
= "argument string";
70 Purify_PrintMemory ();
74 void Purify_Push (char * stackBase
, long pushSize
)
78 passert (Purify_CurrentStackNode
);
79 passert (Purify_CurrentStackNode
->mem
);
82 printf ("Push(): sp=%p, size=%ld fp=%p stackBase=%p\n",
83 stackBase
, pushSize
, (&offset
)-1, Purify_CurrentStackNode
->mem
);
87 stackBase
-= pushSize
;
89 offset
= (long)stackBase
- (long)(Purify_CurrentStackNode
->mem
);
92 printf ("offset=%d\n", offset
);
95 passert (offset
>= 0);
97 Purify_SetMemoryFlags (Purify_CurrentStackNode
, offset
, pushSize
,
98 PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
102 void Purify_Pop (char * stackBase
, long popSize
)
106 passert (Purify_CurrentStackNode
);
107 passert (Purify_CurrentStackNode
->mem
);
111 offset
= (long)stackBase
- (long)(Purify_CurrentStackNode
->mem
);
113 passert (offset
>= 0);
115 Purify_SetMemoryFlags (Purify_CurrentStackNode
, offset
, popSize
,
120 void Purify_Alloca (char * stackBase
, long allocSize
)
124 passert (Purify_CurrentStackNode
);
125 passert (Purify_CurrentStackNode
->mem
);
128 printf ("alloca(): sp=%p, size=%ld fp=%p stackBase=%p\n",
129 stackBase
, allocSize
, (&offset
)-1, Purify_CurrentStackNode
->mem
);
133 stackBase
-= allocSize
;
135 offset
= (long)stackBase
- (long)(Purify_CurrentStackNode
->mem
);
138 printf ("offset=%ld\n", offset
);
141 passert (offset
>= 0);
143 Purify_SetMemoryFlags (Purify_CurrentStackNode
, offset
, allocSize
,
144 PURIFY_MemFlag_Empty
|PURIFY_MemFlag_Writable
148 void Purify_MoveSP (char * SP
, char * newSP
)
152 dist
= (long)newSP
- (long)SP
;
155 Purify_Pop (SP
, dist
);
157 Purify_Alloca (SP
, -dist
);