bd079ef3eba2ab5291c0dcc65a4dbf3fc309f89f
[ghc-hetmet.git] / ghc / rts / LinkerBasic.c
1 /* -----------------------------------------------------------------------------
2  * $Id: LinkerBasic.c,v 1.3 2001/08/14 13:40:09 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    int          i;
29    ObjectCode*  oc;
30    
31    for ( oc = objects; oc; oc = oc->next ) {
32        for (i = 0; i < oc->n_sections; i++) {
33            if (oc->sections[i].start <= addr 
34                && addr <= oc->sections[i].end)
35                return oc->sections[i].kind;
36        }
37    }
38    return SECTIONKIND_OTHER;
39 }
40
41 int
42 is_dynamically_loaded_code_or_rodata_ptr ( void* p )
43 {
44    SectionKind sk = lookupSection(p);
45    ASSERT (sk != SECTIONKIND_NOINFOAVAIL);
46    return (sk == SECTIONKIND_CODE_OR_RODATA);
47 }
48
49
50 int
51 is_dynamically_loaded_rwdata_ptr ( void* p )
52 {
53    SectionKind sk = lookupSection(p);
54    ASSERT (sk != SECTIONKIND_NOINFOAVAIL);
55    return (sk == SECTIONKIND_RWDATA);
56 }
57
58
59 int
60 is_not_dynamically_loaded_ptr ( void* p )
61 {
62    SectionKind sk = lookupSection(p);
63    ASSERT (sk != SECTIONKIND_NOINFOAVAIL);
64    return (sk == SECTIONKIND_OTHER);
65 }