2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
7 #include <proto/exec.h>
13 * Re-define output to bug in order to get exact measurements.
14 * Console's history consumes memory, so this may look like a
19 static BOOL trash
= FALSE
;
20 static BOOL leak
= FALSE
;
22 static inline void AccessTest(ULONG
*ptr
)
27 ptr
[-1] = 0x40302010; /* This should NOT cause mungwall warning */
28 ptr
[0] = 0x01020304; /* This SHOULD produce mungwall warning */
31 int main(int argc
, char **argv
)
34 APTR block0
, start
, block1
;
37 * Do some memory trashing if started with "trash" argument.
38 * It's not adviced to do this without mungwall enabled.
39 * The actual purpose of this is to test mungwall functionality.
41 for (i
= 1; i
< argc
; i
++)
43 if (!strcmp(argv
[i
], "trash"))
45 else if (!strcmp(argv
[i
], "leak"))
49 /* We Forbid() in order to see how our allocations influence free memory size */
52 output("Available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
54 output("Allocating 256 KB...\n");
55 block0
= AllocMem(256 * 1024, MEMF_ANY
);
56 output("Allocated at 0x%p, available memory: %lu bytes\n", block0
, (unsigned long)AvailMem(MEMF_ANY
));
58 AccessTest(block0
+ 256 * 1024);
62 output("Freeing the block...\n");
63 FreeMem(block0
, 256 * 1024);
64 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
67 start
= block0
+ 1027; /* Add some none-round displacement to make the life harder */
68 output("Now trying AllocAbs() 4 KB at 0x%p\n", start
);
69 block1
= AllocAbs(4096, start
);
70 output("Allocated at 0x%p, available memory: %lu bytes\n", block1
, (unsigned long)AvailMem(MEMF_ANY
));
72 AccessTest(start
+ 4096);
76 output("Freeing the block...\n");
77 FreeMem(block1
, 4096 + start
- block1
);
78 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
81 output("Now repeat this AllocAbs(), but free using our requested start address...\n");
82 block1
= AllocAbs(4096, start
);
83 output("Allocated at 0x%p, available memory: %lu bytes\n", block1
, (unsigned long)AvailMem(MEMF_ANY
));
87 AccessTest(start
+ 4096);
91 output("Freeing the block...\n");
93 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));
97 output("And now trying MEMF_REVERSE...\n");
98 block0
= AllocMem(4096, MEMF_REVERSE
);
99 output("Allocated at 0x%p, available memory: %lu bytes\n", block0
, (unsigned long)AvailMem(MEMF_ANY
));
101 /* This test actually proves that we don't hit for example MMIO region */
102 *((volatile ULONG
*)block0
) = 0xC0DEBAD;
103 if (*((volatile ULONG
*)block0
) != 0xC0DEBAD)
104 output("It's not a memory!!!\n");
106 AccessTest(block0
+ 4096);
110 output("Freeing the block...\n");
111 FreeMem(block0
, 4096);
112 output("Done, available memory: %lu bytes\n", (unsigned long)AvailMem(MEMF_ANY
));