[project @ 2002-06-09 19:27:16 by panne]
[ghc-hetmet.git] / ghc / rts / LinkerBasic.c
1 /* -----------------------------------------------------------------------------
2  * $Id: LinkerBasic.c,v 1.4 2001/09/04 16:33:04 sewardj Exp $
3  *
4  * (c) The GHC Team, 2000
5  *
6  * RTS Object Linker
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #include "PosixSource.h"
11 #include "Rts.h"
12 #include "Hash.h"
13 #include "StoragePriv.h"
14 #include "LinkerInternals.h"
15
16 /* List of currently loaded objects */
17 ObjectCode *objects = NULL;     /* initially empty */
18
19 /* -----------------------------------------------------------------------------
20  * Look up an address to discover whether it is in text or data space.
21  *
22  * Used by the garbage collector when walking the stack.
23  * -------------------------------------------------------------------------- */
24
25 static __inline__ SectionKind
26 lookupSection ( void* addr )
27 {
28    Section*    se;
29    ObjectCode* oc;
30    
31    for (oc=objects; oc; oc=oc->next) {
32        for (se=oc->sections; se; se=se->next) {
33            if (se->start <= addr && addr <= se->end)
34                return se->kind;
35        }
36    }
37    return SECTIONKIND_OTHER;
38 }
39
40 int
41 is_dynamically_loaded_code_or_rodata_ptr ( void* p )
42 {
43    SectionKind sk = lookupSection(p);
44    ASSERT (sk != SECTIONKIND_NOINFOAVAIL);
45    return (sk == SECTIONKIND_CODE_OR_RODATA);
46 }
47
48
49 int
50 is_dynamically_loaded_rwdata_ptr ( void* p )
51 {
52    SectionKind sk = lookupSection(p);
53    ASSERT (sk != SECTIONKIND_NOINFOAVAIL);
54    return (sk == SECTIONKIND_RWDATA);
55 }
56
57
58 int
59 is_not_dynamically_loaded_ptr ( void* p )
60 {
61    SectionKind sk = lookupSection(p);
62    ASSERT (sk != SECTIONKIND_NOINFOAVAIL);
63    return (sk == SECTIONKIND_OTHER);
64 }