• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This is a hack to access CFI interface that Android has in libdl.so on
2 // device, but not in the NDK.
3 #include <dlfcn.h>
4 #include <stdint.h>
5 #include <stdlib.h>
6 
7 typedef void (*cfi_slowpath_ty)(uint64_t, void *);
8 typedef void (*cfi_slowpath_diag_ty)(uint64_t, void *, void *);
9 
10 static cfi_slowpath_ty cfi_slowpath;
11 static cfi_slowpath_diag_ty cfi_slowpath_diag;
12 
init()13 __attribute__((constructor(0), no_sanitize("cfi"))) static void init() {
14   cfi_slowpath = (cfi_slowpath_ty)dlsym(RTLD_NEXT, "__cfi_slowpath");
15   cfi_slowpath_diag =
16       (cfi_slowpath_diag_ty)dlsym(RTLD_NEXT, "__cfi_slowpath_diag");
17   if (!cfi_slowpath || !cfi_slowpath_diag) abort();
18 }
19 
20 extern "C" {
__cfi_slowpath(uint64_t Type,void * Addr)21 __attribute__((visibility("hidden"), no_sanitize("cfi"))) void __cfi_slowpath(
22     uint64_t Type, void *Addr) {
23   cfi_slowpath(Type, Addr);
24 }
25 
26 __attribute__((visibility("hidden"), no_sanitize("cfi"))) void
__cfi_slowpath_diag(uint64_t Type,void * Addr,void * Diag)27 __cfi_slowpath_diag(uint64_t Type, void *Addr, void *Diag) {
28   cfi_slowpath_diag(Type, Addr, Diag);
29 }
30 }
31