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