Skip to content

Commit

Permalink
Support naked pointer checker on ARM64 (Linux and macOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierleroy committed Aug 2, 2021
1 parent 5988c66 commit 7aa4118
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,8 @@ AS_IF([test x"$enable_naked_pointers_checker" = "xyes" ],
AS_CASE(["$arch","$system"],
[amd64,linux|amd64,macosx \
|amd64,openbsd|amd64,win64 \
|amd64,freebsd|amd64,solaris],
|amd64,freebsd|amd64,solaris \
|arm64,linux|arm64,macosx],
[naked_pointers_checker=true
AC_DEFINE([NAKED_POINTERS_CHECKER])],
[*],
Expand Down
30 changes: 28 additions & 2 deletions runtime/major_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ void caml_finalise_heap (void)

#if defined(NAKED_POINTERS_CHECKER) && defined(NATIVE_CODE)

#ifdef _WIN32
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

Expand All @@ -1146,7 +1146,7 @@ Caml_inline int safe_load(volatile header_t * p, header_t * result)
return 1;
}

#else
#elif defined(TARGET_amd64)

Caml_inline int safe_load (header_t * addr, /*out*/ header_t * contents)
{
Expand All @@ -1170,6 +1170,32 @@ Caml_inline int safe_load (header_t * addr, /*out*/ header_t * contents)
return ok;
}

#elif defined(TARGET_arm64)

Caml_inline int safe_load (header_t * addr, /*out*/ header_t * contents)
{
int ok;
header_t h;
intnat tmp;

asm volatile(
"adr %[tmp], 1f \n\t"
"str %[tmp], [%[handler]] \n\t"
"mov %w[ok], #0 \n\t"
"ldr %[h], [%[addr]] \n\t"
"mov %w[ok], #1 \n\t"
"1: \n\t"
"mov %[tmp], #0 \n\t"
"str %[tmp], [%[handler]]"
: [tmp] "=&r" (tmp), [ok] "=&r" (ok), [h] "=&r" (h)
: [addr] "r" (addr),
[handler] "r" (&(Caml_state->checking_pointer_pc)));
*contents = h;
return ok;
}

#else
#error "NAKED_POINTERS_CHECKER not supported on this platform"
#endif

static void is_naked_pointer_safe (value v, value *p)
Expand Down

0 comments on commit 7aa4118

Please sign in to comment.