2 Copyright © 1995-2015, 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.
36 The memory must be freed with FreeMem().
39 byteSize - Number of bytes you want to get
40 location - Where you want to get the memory
43 A pointer to some memory including the requested bytes or NULL if
44 the memory couldn't be allocated.
56 This function may trash memory right after the allocation if it builds
57 a new MemChunk there. Additionally it will trash additional area before
58 and after the allocated space if mungwall is turned on. The additional
59 space will be used for mungwall service data.
61 We can't just disable mungwalling for this function because in this case
62 FreeMem() on AllocAbs()ed region will crash (FreeMem() will expect mungwall
63 header attached to the chunk and there's no way to tell which function was
66 ******************************************************************************/
70 IPTR origSize
= byteSize
;
72 struct TraceLocation tp
= CURRENT_LOCATION("AllocAbs");
74 /* Zero bytes requested? May return everything ;-). */
78 /* Make room for mungwall if needed */
79 if (PrivExecBase(SysBase
)->IntFlags
& EXECF_MungWall
)
81 location
-= MUNGWALL_BLOCK_SHIFT
;
82 byteSize
+= MUNGWALL_TOTAL_SIZE
;
85 ret
= InternalAllocAbs(location
, byteSize
, SysBase
);
87 D(bug("[AllocAbs] Location: requested 0x%p, actual 0x%p\n", location
, ret
));
88 D(bug("[AllocAbs] Length: requested %u, actual %u\n", origSize
, origSize
+ location
- ret
));
90 * Starting address may have been adjusted, in this case 'ret' will
91 * differ from 'location', and allocation length was in fact increased
93 * We also specify MEMF_CLEAR because we do not want to destroy original
96 return MungWall_Build(ret
, NULL
, origSize
+ location
- ret
, MEMF_CLEAR
, &tp
, SysBase
);