f2688eee4817b1b3db45aac045b9089edaa1aac0
[AROS.git] / arch / all-unix / exec / freemem.c
blobf2688eee4817b1b3db45aac045b9089edaa1aac0
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Free memory allocated by AllocMem()
6 Lang: english
7 */
8 #include <exec/alerts.h>
9 #include <exec/execbase.h>
10 #include <aros/libcall.h>
11 #include <aros/config.h>
12 #include <aros/macros.h>
13 #include <aros/rt.h>
14 #include <exec/memory.h>
15 #include <exec/memheaderext.h>
16 #include <proto/exec.h>
18 #include "exec_debug.h"
20 #ifndef DEBUG_FreeMem
21 # define DEBUG_FreeMem 0
22 #endif
23 #undef DEBUG
24 #if DEBUG_FreeMem
25 # define DEBUG 1
26 #endif
27 #define MDEBUG 1
29 #include <aros/debug.h>
31 #include <stdlib.h>
33 #include "exec_intern.h"
34 #include "memory.h"
36 #undef FreeMem /* If we're debugging, AROS Clib will try to remap this */
38 /*****************************************************************************
40 NAME */
42 AROS_LH2(void, FreeMem,
44 /* SYNOPSIS */
45 AROS_LHA(APTR, memoryBlock, A1),
46 AROS_LHA(IPTR, byteSize, D0),
48 /* LOCATION */
49 struct ExecBase *, SysBase, 35, Exec)
51 /* FUNCTION
52 Give a block of memory back to the system pool.
54 INPUTS
55 memoryBlock - Pointer to the memory to be freed
56 byteSize - Size of the block
58 RESULT
60 NOTES
62 EXAMPLE
64 BUGS
66 SEE ALSO
67 AllocMem()
69 INTERNALS
71 ******************************************************************************/
73 AROS_LIBFUNC_INIT
75 ULONG origsize = byteSize;
77 D(bug("Call FreeMem (%08lx, %ld)\n", memoryBlock, byteSize));
79 /* If there is no memory free nothing */
80 if(!byteSize || !memoryBlock)
81 ReturnVoid ("FreeMem");
83 #if ENABLE_RT
84 RT_Free(RTT_MEMORY, memoryBlock, byteSize);
85 #endif
87 /* In early boot mode we can't free any memory */
88 if (!PrivExecBase(SysBase)->defaultPool)
89 return;
91 FreePooled(PrivExecBase(SysBase)->defaultPool, memoryBlock, byteSize);
93 ReturnVoid ("FreeMem");
95 AROS_LIBFUNC_EXIT
96 } /* FreeMem */