;;
esac
+AC_CACHE_CHECK([whether compiler supports pointer authentication],
+ libffi_cv_as_ptrauth, [
+ libffi_cv_as_ptrauth=unknown
+ AC_TRY_COMPILE(,[
+#ifdef __clang__
+# if __has_feature(ptrauth_calls)
+# define HAVE_PTRAUTH 1
+# endif
+#endif
+
+#ifndef HAVE_PTRAUTH
+# error Pointer authentication not supported
+#endif
+ ],
+ [libffi_cv_as_ptrauth=yes],
+ [libffi_cv_as_ptrauth=no])
+])
+if test "x$libffi_cv_as_ptrauth" = xyes; then
+ AC_DEFINE(HAVE_PTRAUTH, 1,
+ [Define if your compiler supports pointer authentication.])
+fi
+
# On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
AC_ARG_ENABLE(pax_emutramp,
[ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
#if FFI_EXEC_TRAMPOLINE_TABLE
#ifdef __MACH__
+#ifdef HAVE_PTRAUTH
+#include <ptrauth.h>
+#endif
#include <mach/vm_param.h>
#endif
#if FFI_EXEC_TRAMPOLINE_TABLE
#ifdef __MACH__
+#ifdef HAVE_PTRAUTH
+ codeloc = ptrauth_strip (codeloc, ptrauth_key_asia);
+#endif
void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
config[0] = closure;
config[1] = start;
#define PTR_SIZE 4
#else
#define PTR_SIZE 8
+#endif
+
+#if FFI_EXEC_TRAMPOLINE_TABLE && defined(__MACH__) && defined(HAVE_PTRAUTH)
+# define BR(r) braaz r
+# define BLR(r) blraaz r
+#else
+# define BR(r) br r
+# define BLR(r) blr r
#endif
.text
/* Deallocate the context, leaving the stacked arguments. */
add sp, sp, #CALL_CONTEXT_SIZE
- blr x9 /* call fn */
+ BLR(x9) /* call fn */
ldp x3, x4, [x29, #16] /* reload rvalue and flags */
bl CNAME(ffi_closure_SYSV_inner)
/* Load the return value as directed. */
+#if FFI_EXEC_TRAMPOLINE_TABLE && defined(__MACH__) && defined(HAVE_PTRAUTH)
+ autiza x1
+#endif
adr x1, 0f
and w0, w0, #AARCH64_RET_MASK
add x1, x1, x0, lsl #3
.rept PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE
adr x16, -PAGE_MAX_SIZE
ldp x17, x16, [x16]
- br x16
+ BR(x16)
nop /* each entry in the trampoline config page is 2*sizeof(void*) so the trampoline itself cannot be smaller that 16 bytes */
.endr
#include <mach/mach.h>
#include <pthread.h>
+#ifdef HAVE_PTRAUTH
+#include <ptrauth.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
/* Initialize the return values */
*code = entry->trampoline;
+#ifdef HAVE_PTRAUTH
+ *code = ptrauth_sign_unauthenticated (*code, ptrauth_key_asia, 0);
+#endif
closure->trampoline_table = table;
closure->trampoline_table_entry = entry;