Fix IO memory access .. SB128 driver makes noises in VMWare - CMI is untested (Curren...
[AROS.git] / rom / exec / allocabs.c
blob2b0563d56bd7ad0d62bcc0181f59bd15498da1cd
1 /*
2 Copyright © 1995-2011, 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 "memory.h"
18 #include "mungwall.h"
20 /*****************************************************************************
22 NAME */
24 AROS_LH2(APTR, AllocAbs,
26 /* SYNOPSIS */
27 AROS_LHA(ULONG, byteSize, D0),
28 AROS_LHA(APTR, location, A1),
30 /* LOCATION */
31 struct ExecBase *, SysBase, 34, Exec)
33 /* FUNCTION
34 Allocate some memory from the system memory pool at a given address.
36 INPUTS
37 byteSize - Number of bytes you want to get
38 location - Where you want to get the memory
40 RESULT
41 A pointer to some memory including the requested bytes or NULL if
42 the memory couldn't be allocated
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 FreeMem()
53 INTERNALS
54 This function may trash memory right after the allocation if it builds
55 a new MemChunk there. Additionally it will trash additional area before
56 and after the allocated space if mungwall is turned on. The additional
57 space will be used for mungwall service data.
59 We can't just disable mungwalling for this function because in this case
60 FreeMem() on AllocAbs()ed region will crash (FreeMem() will expect mungwall
61 header attached to the chunk and there's no way to tell which function was
62 used to allocate it.
64 ******************************************************************************/
66 AROS_LIBFUNC_INIT
68 IPTR origSize = byteSize;
69 APTR ret = NULL;
71 /* Zero bytes requested? May return everything ;-). */
72 if(!byteSize)
73 return NULL;
75 /* Make room for mungwall if needed */
76 if (PrivExecBase(SysBase)->IntFlags & EXECF_MungWall)
78 location -= MUNGWALL_BLOCK_SHIFT;
79 byteSize += MUNGWALL_TOTAL_SIZE;
82 ret = InternalAllocAbs(location, byteSize, SysBase);
84 D(bug("[AllocAbs] Location: requested 0x%p, actual 0x%p\n", location, ret));
85 D(bug("[AllocAbs] Length: requested %u, actual %u\n", origSize, origSize + location - ret));
87 * Starting address may have been adjusted, in this case 'ret' will
88 * differ from 'location', and allocation length was in fact increased
89 * by this difference.
90 * We also specify MEMF_CLEAR because we do not want to destroy original
91 * memory contents.
93 return MungWall_Build(ret, NULL, origSize + location - ret, MEMF_CLEAR, "AllocAbs", __builtin_return_address(0), SysBase);
95 AROS_LIBFUNC_EXIT
96 } /* AllocAbs */