Do not try to get stack pointer from invalid ESP field, which coincidentally
[AROS.git] / rom / exec / availmem.c
blobfb8aadaa1c5cddc32400adff98e3d84e23bce3a3
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Tell how much memory is available.
6 Lang: english
7 */
9 #include <exec/alerts.h>
10 #include <exec/execbase.h>
11 #include <aros/libcall.h>
12 #include <aros/macros.h>
13 #include <exec/memory.h>
14 #include <exec/memheaderext.h>
15 #include <proto/exec.h>
17 #include "exec_intern.h"
18 #include "memory.h"
19 #include "mungwall.h"
21 /*****************************************************************************
23 NAME */
25 AROS_LH1(ULONG, AvailMem,
27 /* SYNOPSIS */
28 AROS_LHA(ULONG, attributes, D1),
30 /* LOCATION */
31 struct ExecBase *, SysBase, 36, Exec)
33 /* FUNCTION
34 Return either the total available memory or the largest available
35 chunk of a given type of memory.
37 INPUTS
38 attributes - The same attributes you would give to AllocMem().
40 RESULT
41 Either the total of the available memory or the largest chunk if
42 MEMF_LARGEST is set in the attributes.
44 NOTES
45 Due to the nature of multitasking the returned value may already
46 be obsolete when this function returns.
48 EXAMPLE
49 Print the total available memory.
51 printf("Free memory: %lu bytes\n", AvailMem(0));
53 Print the size of the largest chunk of chip memory.
55 printf("Largest chipmem chunk: %lu bytes\n",
56 AvailMem(MEMF_CHIP|MEMF_LARGEST));
58 BUGS
60 SEE ALSO
62 INTERNALS
64 ******************************************************************************/
66 AROS_LIBFUNC_INIT
68 ULONG ret;
70 ret = nommu_AvailMem(attributes, SysBase);
72 if (attributes & MEMF_CLEAR)
73 MungWall_Scan(NULL, SysBase);
75 return ret;
76 AROS_LIBFUNC_EXIT
77 } /* AvailMem */