2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Desc: Allocate memory at address
9 #include <aros/debug.h>
10 #include <exec/alerts.h>
11 #include <exec/execbase.h>
12 #include <exec/memory.h>
13 #include <exec/memheaderext.h>
14 #include <proto/exec.h>
16 #include "exec_intern.h"
17 #include "exec_util.h"
21 /*****************************************************************************
25 AROS_LH2(APTR
, AllocAbs
,
28 AROS_LHA(IPTR
, byteSize
, D0
),
29 AROS_LHA(APTR
, location
, A1
),
32 struct ExecBase
*, SysBase
, 34, Exec
)
35 Allocate some memory from the system memory pool at a given address.
38 byteSize - Number of bytes you want to get
39 location - Where you want to get the memory
42 A pointer to some memory including the requested bytes or NULL if
43 the memory couldn't be allocated
55 This function may trash memory right after the allocation if it builds
56 a new MemChunk there. Additionally it will trash additional area before
57 and after the allocated space if mungwall is turned on. The additional
58 space will be used for mungwall service data.
60 We can't just disable mungwalling for this function because in this case
61 FreeMem() on AllocAbs()ed region will crash (FreeMem() will expect mungwall
62 header attached to the chunk and there's no way to tell which function was
65 ******************************************************************************/
69 IPTR origSize
= byteSize
;
71 struct TraceLocation tp
= CURRENT_LOCATION("AllocAbs");
73 /* Zero bytes requested? May return everything ;-). */
77 /* Make room for mungwall if needed */
78 if (PrivExecBase(SysBase
)->IntFlags
& EXECF_MungWall
)
80 location
-= MUNGWALL_BLOCK_SHIFT
;
81 byteSize
+= MUNGWALL_TOTAL_SIZE
;
84 ret
= InternalAllocAbs(location
, byteSize
, SysBase
);
86 D(bug("[AllocAbs] Location: requested 0x%p, actual 0x%p\n", location
, ret
));
87 D(bug("[AllocAbs] Length: requested %u, actual %u\n", origSize
, origSize
+ location
- ret
));
89 * Starting address may have been adjusted, in this case 'ret' will
90 * differ from 'location', and allocation length was in fact increased
92 * We also specify MEMF_CLEAR because we do not want to destroy original
95 return MungWall_Build(ret
, NULL
, origSize
+ location
- ret
, MEMF_CLEAR
, &tp
, SysBase
);