1 /**************************************************************************/ 2 /* */ 3 /* OCaml */ 4 /* */ 5 /* Damien Doligez, projet Para, INRIA Rocquencourt */ 6 /* */ 7 /* Copyright 1996 Institut National de Recherche en Informatique et */ 8 /* en Automatique. */ 9 /* */ 10 /* All rights reserved. This file is distributed under the terms of */ 11 /* the GNU Lesser General Public License version 2.1, with the */ 12 /* special exception on linking described in the file LICENSE. */ 13 /* */ 14 /**************************************************************************/ 15 16 /* Classification of addresses for GC and runtime purposes. */ 17 18 #ifndef CAML_ADDRESS_CLASS_H 19 #define CAML_ADDRESS_CLASS_H 20 21 #include "config.h" 22 #include "misc.h" 23 #include "mlvalues.h" 24 25 /* Use the following macros to test an address for the different classes 26 it might belong to. */ 27 28 #define Is_young(val) \ 29 (Assert (Is_block (val)), \ 30 (addr)(val) < (addr)caml_young_end && (addr)(val) > (addr)caml_young_start) 31 32 #define Is_in_heap(a) (Classify_addr(a) & In_heap) 33 34 #define Is_in_heap_or_young(a) (Classify_addr(a) & (In_heap | In_young)) 35 36 #define Is_in_value_area(a) \ 37 (Classify_addr(a) & (In_heap | In_young | In_static_data)) 38 39 #define Is_in_code_area(pc) \ 40 ( ((char *)(pc) >= caml_code_area_start && \ 41 (char *)(pc) <= caml_code_area_end) \ 42 || (Classify_addr(pc) & In_code_area) ) 43 44 #define Is_in_static_data(a) (Classify_addr(a) & In_static_data) 45 46 /***********************************************************************/ 47 /* The rest of this file is private and may change without notice. */ 48 49 extern value *caml_young_start, *caml_young_end; 50 extern char * caml_code_area_start, * caml_code_area_end; 51 52 #define Not_in_heap 0 53 #define In_heap 1 54 #define In_young 2 55 #define In_static_data 4 56 #define In_code_area 8 57 58 #ifdef ARCH_SIXTYFOUR 59 60 /* 64 bits: Represent page table as a sparse hash table */ 61 int caml_page_table_lookup(void * addr); 62 #define Classify_addr(a) (caml_page_table_lookup((void *)(a))) 63 64 #else 65 66 /* 32 bits: Represent page table as a 2-level array */ 67 #define Pagetable2_log 11 68 #define Pagetable2_size (1 << Pagetable2_log) 69 #define Pagetable1_log (Page_log + Pagetable2_log) 70 #define Pagetable1_size (1 << (32 - Pagetable1_log)) 71 CAMLextern unsigned char * caml_page_table[Pagetable1_size]; 72 73 #define Pagetable_index1(a) (((uintnat)(a)) >> Pagetable1_log) 74 #define Pagetable_index2(a) \ 75 ((((uintnat)(a)) >> Page_log) & (Pagetable2_size - 1)) 76 #define Classify_addr(a) \ 77 caml_page_table[Pagetable_index1(a)][Pagetable_index2(a)] 78 79 #endif 80 81 int caml_page_table_add(int kind, void * start, void * end); 82 int caml_page_table_remove(int kind, void * start, void * end); 83 int caml_page_table_initialize(mlsize_t bytesize); 84 85 #endif /* CAML_ADDRESS_CLASS_H */ 86