2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
11 static MemHash
* Purify_CurrentStackNode
;
13 void Purify_InitStack (char * stackBase
, long stackSize
)
22 +4 /* return address for main() */
23 +8 /* two arguments for main() */
27 printf ("Stack goes from %p to %p\n", stackBase
- stackSize
, stackBase
);
30 node
= Purify_AddMemory (stackBase
- stackSize
32 , PURIFY_MemFlag_Empty
33 , PURIFY_MemType_Stack
38 Purify_CurrentStackNode
= node
;
41 argv
= ((char ***)stackBase
)[-1];
42 argc
= ((int *)stackBase
)[-2];
45 printf ("&argc=%p\n", &((int *)stackBase
)[-2]);
46 printf ("argc=%d argv=%p\n", argc
, argv
);
49 offset
= (long)(&((int *)stackBase
)[-2]) - (long)(node
->mem
);
51 Purify_SetMemoryFlags (node
, offset
, 8,
52 PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
55 node
= Purify_AddMemory (argv
56 , (argc
+1) * sizeof (char *)
57 , PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
58 , PURIFY_MemType_Stack
61 node
->data
= "argv[] array";
63 for (t
=0; t
<argc
; t
++)
65 node
= Purify_AddMemory (argv
[t
]
66 , strlen (argv
[t
]) + 1
67 , PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
68 , PURIFY_MemType_Stack
71 node
->data
= "argument string";
75 Purify_PrintMemory ();
79 void Purify_Push (char * stackBase
, long pushSize
)
83 passert (Purify_CurrentStackNode
);
84 passert (Purify_CurrentStackNode
->mem
);
87 printf ("Push(): sp=%p, size=%ld fp=%p stackBase=%p\n",
88 stackBase
, pushSize
, (&offset
)-1, Purify_CurrentStackNode
->mem
);
92 stackBase
-= pushSize
;
94 offset
= (long)stackBase
- (long)(Purify_CurrentStackNode
->mem
);
97 printf ("offset=%d\n", offset
);
100 passert (offset
>= 0);
102 Purify_SetMemoryFlags (Purify_CurrentStackNode
, offset
, pushSize
,
103 PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
107 void Purify_Pop (char * stackBase
, long popSize
)
111 passert (Purify_CurrentStackNode
);
112 passert (Purify_CurrentStackNode
->mem
);
116 offset
= (long)stackBase
- (long)(Purify_CurrentStackNode
->mem
);
118 passert (offset
>= 0);
120 Purify_SetMemoryFlags (Purify_CurrentStackNode
, offset
, popSize
,
125 void Purify_Alloca (char * stackBase
, long allocSize
)
129 passert (Purify_CurrentStackNode
);
130 passert (Purify_CurrentStackNode
->mem
);
133 printf ("alloca(): sp=%p, size=%ld fp=%p stackBase=%p\n",
134 stackBase
, allocSize
, (&offset
)-1, Purify_CurrentStackNode
->mem
);
138 stackBase
-= allocSize
;
140 offset
= (long)stackBase
- (long)(Purify_CurrentStackNode
->mem
);
143 printf ("offset=%ld\n", offset
);
146 passert (offset
>= 0);
148 Purify_SetMemoryFlags (Purify_CurrentStackNode
, offset
, allocSize
,
149 PURIFY_MemFlag_Empty
|PURIFY_MemFlag_Writable
153 void Purify_MoveSP (char * SP
, char * newSP
)
157 dist
= (long)newSP
- (long)SP
;
160 Purify_Pop (SP
, dist
);
162 Purify_Alloca (SP
, -dist
);