diff options
| author | Maxime Dénès | 2018-05-16 15:25:34 +0200 |
|---|---|---|
| committer | Maxime Dénès | 2018-05-16 15:25:34 +0200 |
| commit | d74d72419f5e9b68fe8ec9e8c046faecacf9f2f4 (patch) | |
| tree | 045e6940c2d292f296c577e28ef1fb2d9835e17e /kernel/byterun/coq_memory.c | |
| parent | 19e24bf1f5eefee37ee2648c04844b5ea3ca2ab2 (diff) | |
| parent | 5c0b2171844cee7a5344c535c2793e362d925e0c (diff) | |
Merge PR #7079: Remove naked pointers from the VM
Diffstat (limited to 'kernel/byterun/coq_memory.c')
| -rw-r--r-- | kernel/byterun/coq_memory.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/kernel/byterun/coq_memory.c b/kernel/byterun/coq_memory.c index b2917a55ee..542a05fd25 100644 --- a/kernel/byterun/coq_memory.c +++ b/kernel/byterun/coq_memory.c @@ -10,6 +10,8 @@ #include <stdio.h> #include <string.h> +#include <caml/alloc.h> +#include <caml/address_class.h> #include "coq_gc.h" #include "coq_instruct.h" #include "coq_fix_code.h" @@ -46,7 +48,11 @@ value coq_static_alloc(value size) /* ML */ value accumulate_code(value unit) /* ML */ { - return (value) accumulate; + CAMLparam1(unit); + CAMLlocal1(res); + res = caml_alloc_small(1, Abstract_tag); + Code_val(res) = accumulate; + CAMLreturn(res); } static void (*coq_prev_scan_roots_hook) (scanning_action); @@ -56,6 +62,10 @@ static void coq_scan_roots(scanning_action action) register value * i; /* Scan the stack */ for (i = coq_sp; i < coq_stack_high; i++) { +#ifdef NO_NAKED_POINTERS + /* The VM stack may contain C-allocated bytecode */ + if (Is_block(*i) && !Is_in_heap_or_young(*i)) continue; +#endif (*action) (*i, i); }; /* Hook */ @@ -94,8 +104,12 @@ value init_coq_vm(value unit) /* ML */ /* Initialing the interpreter */ init_coq_interpreter(); - /* Some predefined pointer code */ - accumulate = (code_t) coq_stat_alloc(sizeof(opcode_t)); + /* Some predefined pointer code. + * It is typically contained in accumlator blocks whose tag is 0 and thus + * scanned by the GC, so make it look like an OCaml block. */ + value accu_block = (value) coq_stat_alloc(2 * sizeof(value)); + Hd_hp (accu_block) = Make_header (1, Abstract_tag, Caml_black); \ + accumulate = (code_t) Val_hp(accu_block); *accumulate = VALINSTR(ACCUMULATE); /* Initialize GC */ |
