exec.library: tabs -> spaces
[AROS.git] / rom / exec / allocabs.c
blobfbe62ff8dbae4fa60ad6262547f86aa3f9b68c35
1 /*
2 Copyright © 1995-2012, 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.
37 INPUTS
38 byteSize - Number of bytes you want to get
39 location - Where you want to get the memory
41 RESULT
42 A pointer to some memory including the requested bytes or NULL if
43 the memory couldn't be allocated
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 FreeMem()
54 INTERNALS
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
63 used to allocate it.
65 ******************************************************************************/
67 AROS_LIBFUNC_INIT
69 IPTR origSize = byteSize;
70 APTR ret = NULL;
71 struct TraceLocation tp = CURRENT_LOCATION("AllocAbs");
73 /* Zero bytes requested? May return everything ;-). */
74 if(!byteSize)
75 return NULL;
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
91 * by this difference.
92 * We also specify MEMF_CLEAR because we do not want to destroy original
93 * memory contents.
95 return MungWall_Build(ret, NULL, origSize + location - ret, MEMF_CLEAR, &tp, SysBase);
97 AROS_LIBFUNC_EXIT
98 } /* AllocAbs */