Add a naked pointers dynamic checker, continued#9956
Add a naked pointers dynamic checker, continued#9956xavierleroy merged 16 commits intoocaml:trunkfrom
Conversation
- It must run in naked pointers mode, otherwise other parts of the runtime system will crash on naked pointers before they can be detected - It cannot run in bytecode because catching SIGSEGV is done only in native code
np1 and np2 are valid uses of out-of-heap pointers even in no-naked-pointers mode. np2 will generate an alarm in checking mode, though. np3 and np4 are OK only in naked-pointers mode. They will generate alarms in checking mode.
runtime/major_gc.c
Outdated
| /* For the pointer to be considered safe, either the given pointer is in heap | ||
| * or the (out of heap) pointer has a black header and its size is < 2 ** 40 | ||
| * words (128 GB). If not, we report a warning. */ | ||
| if (Is_in_heap (v) || |
There was a problem hiding this comment.
IIUC check_pointer_safe is only invoked when !Is_in_heap(v) && !Is_young(v). check_pointer_safe should not be called on a pointer in the minor heap since OCaml does not define what the colour of minor objects is.
Would it be useful to rename this function to caml_is_naked_pointer_safe, with an assertion CAMLassert (!Is_in_heap(v) && !Is_young(v)) to make these assumptions explicit?
There was a problem hiding this comment.
Yes, you're absolutely right! I renamed to is_naked_pointer_safe (it's a static function, so no need for caml_), added the assertion, and removed the Is_in_heap test within.
|
I've reviewed the changes and it looks good to me. In particular, having the test in naked pointers mode makes sense to me. |
|
@kayceesrk Just to make sure I understand, in this comment it is written that |
|
I should have clarified that |
|
Thanks for the explanation, I understand now. |
- Rename `check_pointer_safe` -> `is_naked_pointer_safe` - Make it clear that it is called only on out-of-heap pointers (neither Is_young nor Is_in_heap), as checked by the caller.
|
Lgtm! |
This is a variant of #9947 where the check for "naked pointers" (dangerous out-of-heap pointers) is performed in a runtime system that supports naked pointers and will not crash early when it encounters one.
Also, the check is disabled in bytecode, as we don't catch SEGV signals in this case.
Tests were added to the test suite that exercise the three modes: naked pointers / naked pointers + dynamic checker / no naked pointers.