revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / allocabs.c
blob2349fd9e9bb88176e0518b0de665d58f2ecf5b6d
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Allocate memory at address
6 Lang: english
7 */
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"
18 #include "memory.h"
19 #include "mungwall.h"
21 /*****************************************************************************
23 NAME */
25 AROS_LH2(APTR, AllocAbs,
27 /* SYNOPSIS */
28 AROS_LHA(IPTR, byteSize, D0),
29 AROS_LHA(APTR, location, A1),
31 /* LOCATION */
32 struct ExecBase *, SysBase, 34, Exec)
34 /* FUNCTION
35 Allocate some memory from the system memory pool at a given address.
36 The memory must be freed with FreeMem().
38 INPUTS
39 byteSize - Number of bytes you want to get
40 location - Where you want to get the memory
42 RESULT
43 A pointer to some memory including the requested bytes or NULL if
44 the memory couldn't be allocated.
46 NOTES
48 EXAMPLE
50 BUGS
52 SEE ALSO
53 FreeMem()
55 INTERNALS
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
64 used to allocate it.
66 ******************************************************************************/
68 AROS_LIBFUNC_INIT
70 IPTR origSize = byteSize;
71 APTR ret = NULL;
72 struct TraceLocation tp = CURRENT_LOCATION("AllocAbs");
74 /* Zero bytes requested? May return everything ;-). */
75 if(!byteSize)
76 return NULL;
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
92 * by this difference.
93 * We also specify MEMF_CLEAR because we do not want to destroy original
94 * memory contents.
96 return MungWall_Build(ret, NULL, origSize + location - ret, MEMF_CLEAR, &tp, SysBase);
98 AROS_LIBFUNC_EXIT
99 } /* AllocAbs */