Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report status of the naked pointers checker in the process exit code #10171

Merged
merged 1 commit into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Working version
- #10136: Minor clean-ups in runtime/io.c and runtime/caml/io.h
(Xavier Leroy, review by David Allsopp and Guillaume Munch-Maccagnoni)

- #10171: Tweak the naked pointers checker so that processes which trigger the
alarm always exit with non-zero status (i.e. exit(0) becomes exit(70)).
(David Allsopp, review by Xavier Leroy)

- #10188, #10213: Switch the default allocation policy to best-fit and adjust
the default overhead parameter accordingly.
(Damien Doligez, review by Josh Berdine and Xavier Leroy)
Expand Down
4 changes: 4 additions & 0 deletions runtime/caml/major_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ void caml_set_major_window (int);
*/
void caml_finalise_heap (void);

#ifdef NAKED_POINTERS_CHECKER
extern int caml_naked_pointers_detected;
#endif

#endif /* CAML_INTERNALiS */

#endif /* CAML_MAJOR_GC_H */
6 changes: 6 additions & 0 deletions runtime/major_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ double caml_gc_clock = 0.0;
static unsigned long major_gc_counter = 0;
#endif

#ifdef NAKED_POINTERS_CHECKER
int caml_naked_pointers_detected = 0;
#endif

void (*caml_major_gc_hook)(void) = NULL;

/* This function prunes the mark stack if it's about to overflow. It does so
Expand Down Expand Up @@ -1163,6 +1167,7 @@ static void is_naked_pointer_safe (value v, value *p)
if (Is_black_hd(h) && Wosize_hd(h) < (INT64_LITERAL(1) << 40))
return;

caml_naked_pointers_detected = 1;
if (!Is_black_hd(h)) {
fprintf (stderr, "Out-of-heap pointer at %p of value %p has "
"non-black head (tag=%d)\n", p, (void*)v, t);
Expand All @@ -1175,6 +1180,7 @@ static void is_naked_pointer_safe (value v, value *p)
return;

on_segfault:
caml_naked_pointers_detected = 1;
fprintf (stderr, "Out-of-heap pointer at %p of value %p. "
"Cannot read head.\n", p, (void*)v);
}
Expand Down
8 changes: 8 additions & 0 deletions runtime/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "caml/debugger.h"
#include "caml/fail.h"
#include "caml/gc_ctrl.h"
#include "caml/major_gc.h"
#include "caml/io.h"
#include "caml/misc.h"
#include "caml/mlvalues.h"
Expand Down Expand Up @@ -159,6 +160,13 @@ CAMLprim value caml_sys_exit(value retcode_v)
caml_shutdown();
#ifdef _WIN32
caml_restore_win32_terminal();
#endif
#ifdef NAKED_POINTERS_CHECKER
if (retcode == 0 && caml_naked_pointers_detected) {
fprintf (stderr, "\nOut-of-heap pointers were detected by the runtime.\n"
"The process would otherwise have terminated normally.\n");
retcode = 70; /* EX_SOFTWARE; see sysexits.h */
}
#endif
exit(retcode);
}
Expand Down