Commit of the code which was suggested by Georg as a fix for:
[cake.git] / rom / exec / typeofmem.c
blobce5f0edf4fe74556df461a97bb81bbf47ebc7ddc
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Examine memory
6 Lang: english
7 */
8 #include <exec/memory.h>
9 #include <exec/execbase.h>
10 #include <aros/libcall.h>
11 #include <proto/exec.h>
13 /*****************************************************************************
15 NAME */
17 AROS_LH1(ULONG, TypeOfMem,
19 /* SYNOPSIS */
20 AROS_LHA(APTR, address, A1),
22 /* LOCATION */
23 struct ExecBase *, SysBase, 89, Exec)
25 /* FUNCTION
26 Return type of memory at a given address or 0 if there is no memory
27 there.
29 INPUTS
30 address - Address to test
32 RESULT
33 The memory flags you would give to AllocMem().
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
43 INTERNALS
45 ******************************************************************************/
47 AROS_LIBFUNC_INIT
49 ULONG ret=0;
50 struct MemHeader *mh;
52 /* Nobody should change the memory list now. */
53 Forbid();
55 /* Follow the list of MemHeaders */
56 mh=(struct MemHeader *)SysBase->MemList.lh_Head;
57 while(mh->mh_Node.ln_Succ!=NULL)
59 /* Check if this MemHeader fits */
60 if(address>=mh->mh_Lower&&address<mh->mh_Upper)
62 /* Yes. Prepare returncode */
63 ret=mh->mh_Attributes;
64 break;
66 /* Go to next MemHeader */
67 mh=(struct MemHeader *)mh->mh_Node.ln_Succ;
69 /* Allow Taskswitches and return */
70 Permit();
71 return ret;
72 AROS_LIBFUNC_EXIT
73 } /* TypeOfMem */