1 #include <aros/debug.h>
2 #include <proto/exec.h>
8 * Re-define output to bug in order to get exact measurements.
9 * Console's history consumes memory, so this may look like a
14 static BOOL trash
= FALSE
;
15 static BOOL leak
= FALSE
;
17 static inline void AccessTest(ULONG
*ptr
)
22 ptr
[-1] = 0x40302010; /* This should NOT cause mungwall warning */
23 ptr
[0] = 0x01020304; /* This SHOULD produce mungwall warning */
26 int main(int argc
, char **argv
)
29 APTR block0
, start
, block1
;
32 * Do some memory trashing if started with "trash" argument.
33 * It's not adviced to do this without mungwall enabled.
34 * The actual purpose of this is to test mungwall functionality.
36 for (i
= 1; i
< argc
; i
++)
38 if (!strcmp(argv
[i
], "trash"))
40 else if (!strcmp(argv
[i
], "leak"))
44 /* We Forbid() in order to see how our allocations influence free memory size */
47 output("Available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
49 output("Allocating 256 KB...\n");
50 block0
= AllocMem(256 * 1024, MEMF_ANY
);
51 output("Allocated at 0x%p, available memory: %lu bytes\n", block0
, (unsigned long)AvailMem(MEMF_ANY
));
53 AccessTest(block0
+ 256 * 1024);
57 output("Freeing the block...\n");
58 FreeMem(block0
, 256 * 1024);
59 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
62 start
= block0
+ 1027; /* Add some none-round displacement to make the life harder */
63 output("Now trying AllocAbs() 4 KB at 0x%p\n", start
);
64 block1
= AllocAbs(4096, start
);
65 output("Allocated at 0x%p, available memory: %lu bytes\n", block1
, (unsigned long)AvailMem(MEMF_ANY
));
67 AccessTest(start
+ 4096);
71 output("Freeing the block...\n");
72 FreeMem(block1
, 4096 + start
- block1
);
73 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
76 output("Now repeat this AllocAbs(), but free using our requested start address...\n");
77 block1
= AllocAbs(4096, start
);
78 output("Allocated at 0x%p, available memory: %lu bytes\n", block1
, (unsigned long)AvailMem(MEMF_ANY
));
82 AccessTest(start
+ 4096);
86 output("Freeing the block...\n");
88 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
92 output("And now trying MEMF_REVERSE...\n");
93 block0
= AllocMem(4096, MEMF_REVERSE
);
94 output("Allocated at 0x%p, available memory: %lu bytes\n", block0
, (unsigned long)AvailMem(MEMF_ANY
));
96 /* This test actually proves that we don't hit for example MMIO region */
97 *((volatile ULONG
*)block0
) = 0xC0DEBAD;
98 if (*((volatile ULONG
*)block0
) != 0xC0DEBAD)
99 output("It's not a memory!!!\n");
101 AccessTest(block0
+ 4096);
105 output("Freeing the block...\n");
106 FreeMem(block0
, 4096);
107 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));