[project @ 2001-03-23 16:36:20 by simonmar]
[ghc-hetmet.git] / ghc / rts / LinkerBasic.c
1 /* -----------------------------------------------------------------------------
2  * $Id: LinkerBasic.c,v 1.2 2001/02/12 13:03:17 sewardj Exp $
3  *
4  * (c) The GHC Team, 2000
5  *
6  * RTS Object Linker
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #include "Rts.h"
11 #include "Hash.h"
12 #include "StoragePriv.h"
13 #include "LinkerInternals.h"
14
15 /* List of currently loaded objects */
16 ObjectCode *objects = NULL;     /* initially empty */
17
18 /* -----------------------------------------------------------------------------
19  * Look up an address to discover whether it is in text or data space.
20  *
21  * Used by the garbage collector when walking the stack.
22  * -------------------------------------------------------------------------- */
23
24 static __inline__ SectionKind
25 lookupSection ( void* addr )
26 {
27    int          i;
28    ObjectCode*  oc;
29    
30    for ( oc = objects; oc; oc = oc->next ) {
31        for (i = 0; i < oc->n_sections; i++) {
32            if (oc->sections[i].start <= addr 
33                && addr <= oc->sections[i].end)
34                return oc->sections[i].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 }