2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: Allocate some memory
8 #include <exec/alerts.h>
9 #include <exec/execbase.h>
10 #include <aros/libcall.h>
11 #include <aros/asmcall.h>
13 #include <aros/macros.h>
14 #include <aros/config.h>
15 #include <aros/arossupportbase.h>
16 #include <exec/memory.h>
17 #include <exec/memheaderext.h>
18 #include <exec/nodes.h>
20 #include <dos/dosextens.h>
21 #include <proto/exec.h>
25 #include "exec_debug.h"
27 #ifndef DEBUG_AllocMem
28 # define DEBUG_AllocMem 0
35 # include <aros/debug.h>
37 #include "exec_intern.h"
39 /* See rom/exec/allocmem.c for documentation */
41 AROS_LH2(APTR
, AllocMem
,
42 AROS_LHA(IPTR
, byteSize
, D0
),
43 AROS_LHA(ULONG
, requirements
, D1
),
44 struct ExecBase
*, SysBase
, 33, Exec
)
50 D(if (SysBase
->DebugAROSBase
))
51 D(bug("Call AllocMem (%d, %08x)\n", byteSize
, requirements
));
53 /* Zero bytes requested? May return everything ;-). */
57 byteSize
+= sizeof(APTR
);
60 if (!PrivExecBase(SysBase
)->defaultPool
)
61 /* If we don't have defaultPool, it's early boot mode */
62 res
= allocBootMem((struct MemHeader
*)SysBase
->MemList
.lh_Head
, byteSize
);
67 /* TODO: in future we will have separate pool for MEMF_EXECUTABLE memory */
68 pool
= PrivExecBase(SysBase
)->defaultPool
;
70 res
= AllocPooled(pool
, byteSize
);
75 if (requirements
& MEMF_CLEAR
)
76 memset(res
, 0, byteSize
);
78 RT_Add(RTT_MEMORY
, res
, byteSize
);
83 /* Set DOS error if called from a process */
84 struct Process
*process
= (struct Process
*)FindTask(NULL
);
86 if (process
->pr_Task
.tc_Node
.ln_Type
== NT_PROCESS
)
87 process
->pr_Result2
= ERROR_NO_FREE_STORE
;
91 if (SysBase
->DebugAROSBase
)
92 bug("AllocMem result: 0x%p\n", res
);