prism2.device: Compiler delint
[AROS.git] / arch / all-unix / exec / allocmem.c
blob158b4db776aec2ce21d83b45ddb53365e46dfdb4
1 /*
2 Copyright © 1995-2010, 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 /*****************************************************************************
41 NAME */
43 AROS_LH2(APTR, AllocMem,
45 /* SYNOPSIS */
46 AROS_LHA(ULONG, byteSize, D0),
47 AROS_LHA(ULONG, requirements, D1),
49 /* LOCATION */
50 struct ExecBase *, SysBase, 33, Exec)
52 /* FUNCTION
53 Allocate some memory from the sytem memory pool with the given
54 requirements.
56 INPUTS
57 byteSize - Number of bytes you want to get
58 requirements - Type of memory
60 RESULT
61 A pointer to the number of bytes you wanted or NULL if the memory
62 couldn't be allocated
64 NOTES
65 The memory is aligned to sizeof(struct MemChunk). All requests
66 are rounded up to a multiple of that size.
68 EXAMPLE
69 mytask=(struct Task *)AllocMem(sizeof(struct Task),MEMF_PUBLIC|MEMF_CLEAR);
71 BUGS
73 SEE ALSO
74 FreeMem()
76 INTERNALS
78 ******************************************************************************/
80 AROS_LIBFUNC_INIT
82 APTR res;
84 D(if (SysBase->DebugAROSBase))
85 D(bug("Call AllocMem (%d, %08x)\n", byteSize, requirements));
87 /* Zero bytes requested? May return everything ;-). */
88 if(!byteSize)
89 return NULL;
91 byteSize += sizeof(APTR);
93 if (!pool)
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);
97 else
99 APTR pool;
101 /* TODO: in future we will have separate pool for MEMF_EXECUTABLE memory */
102 pool = PrivExecBase(SysBase)->defaultPool;
104 res = AllocPooled(pool, byteSize);
107 if (res)
109 if (requirements & MEMF_CLEAR)
110 memset(res, 0, byteSize);
111 #if ENABLE_RT
112 RT_Add(RTT_MEMORY, res, byteSize);
113 #endif
115 else
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;
124 #if DEBUG
125 if (SysBase->DebugAROSBase)
126 bug("AllocMem result: 0x%p\n", res);
127 #endif
128 return res;
130 AROS_LIBFUNC_EXIT
131 } /* AllocMem */