2 Copyright © 1995-2010, 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 /*****************************************************************************
43 AROS_LH2(APTR
, AllocMem
,
46 AROS_LHA(ULONG
, byteSize
, D0
),
47 AROS_LHA(ULONG
, requirements
, D1
),
50 struct ExecBase
*, SysBase
, 33, Exec
)
53 Allocate some memory from the sytem memory pool with the given
57 byteSize - Number of bytes you want to get
58 requirements - Type of memory
61 A pointer to the number of bytes you wanted or NULL if the memory
65 The memory is aligned to sizeof(struct MemChunk). All requests
66 are rounded up to a multiple of that size.
69 mytask=(struct Task *)AllocMem(sizeof(struct Task),MEMF_PUBLIC|MEMF_CLEAR);
78 ******************************************************************************/
84 D(if (SysBase
->DebugAROSBase
))
85 D(bug("Call AllocMem (%d, %08x)\n", byteSize
, requirements
));
87 /* Zero bytes requested? May return everything ;-). */
91 byteSize
+= sizeof(APTR
);
94 if (!PrivExecBase(SysBase
)->defaultPool
)
95 /* If we don't have defaultPool, it's early boot mode */
96 res
= allocBootMem((struct MemHeader
*)SysBase
->MemList
.lh_Head
, byteSize
);
101 /* TODO: in future we will have separate pool for MEMF_EXECUTABLE memory */
102 pool
= PrivExecBase(SysBase
)->defaultPool
;
104 res
= AllocPooled(pool
, byteSize
);
109 if (requirements
& MEMF_CLEAR
)
110 memset(res
, 0, byteSize
);
112 RT_Add(RTT_MEMORY
, res
, byteSize
);
117 /* Set DOS error if called from a process */
118 struct Process
*process
= (struct Process
*)FindTask(NULL
);
120 if (process
->pr_Task
.tc_Node
.ln_Type
== NT_PROCESS
)
121 process
->pr_Result2
= ERROR_NO_FREE_STORE
;
125 if (SysBase
->DebugAROSBase
)
126 bug("AllocMem result: 0x%p\n", res
);