Removed autodocs of arch specific variants of ROM modules.
[AROS.git] / arch / all-unix / exec / allocmem.c
blob601d401dd65c9573046b6a74afcb490ec09d5b62
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Allocate some memory
6 Lang: english
7 */
8 #include <exec/alerts.h>
9 #include <exec/execbase.h>
10 #include <aros/libcall.h>
11 #include <aros/asmcall.h>
12 #include <aros/rt.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>
19 #include <dos/dos.h>
20 #include <dos/dosextens.h>
21 #include <proto/exec.h>
23 #include <string.h>
25 #include "exec_debug.h"
27 #ifndef DEBUG_AllocMem
28 # define DEBUG_AllocMem 0
29 #endif
30 #undef DEBUG
31 #if DEBUG_AllocMem
32 # define DEBUG 1
33 #endif
34 #define MDEBUG 1
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)
46 AROS_LIBFUNC_INIT
48 APTR res;
50 D(if (SysBase->DebugAROSBase))
51 D(bug("Call AllocMem (%d, %08x)\n", byteSize, requirements));
53 /* Zero bytes requested? May return everything ;-). */
54 if(!byteSize)
55 return NULL;
57 byteSize += sizeof(APTR);
59 if (!pool)
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);
63 else
65 APTR pool;
67 /* TODO: in future we will have separate pool for MEMF_EXECUTABLE memory */
68 pool = PrivExecBase(SysBase)->defaultPool;
70 res = AllocPooled(pool, byteSize);
73 if (res)
75 if (requirements & MEMF_CLEAR)
76 memset(res, 0, byteSize);
77 #if ENABLE_RT
78 RT_Add(RTT_MEMORY, res, byteSize);
79 #endif
81 else
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;
90 #if DEBUG
91 if (SysBase->DebugAROSBase)
92 bug("AllocMem result: 0x%p\n", res);
93 #endif
94 return res;
96 AROS_LIBFUNC_EXIT
97 } /* AllocMem */