• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2017 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef NATIVE_BRIDGE_SUPPORT_VDSO_INTERCEPTABLE_FUNCTIONS_H_
18 #define NATIVE_BRIDGE_SUPPORT_VDSO_INTERCEPTABLE_FUNCTIONS_H_
19 
20 #include <assert.h>
21 #include <stdint.h>
22 
23 #include "native_bridge_support/vdso/vdso.h"
24 
25 #if defined(__arm__)
26 #define INTERCEPTABLE_STUB_ASM_FUNCTION(name)                  \
27   extern "C" void __attribute((target("arm"), naked)) name() { \
28     __asm__ __volatile__(                                      \
29         "ldr r3, =0\n"                                         \
30         "bx r3");                                              \
31   }
32 #elif defined(__aarch64__)
33 #define INTERCEPTABLE_STUB_ASM_FUNCTION(name)   \
34   extern "C" void __attribute((naked)) name() { \
35     __asm__ __volatile__(                       \
36         "ldr x3, =0\n"                          \
37         "blr x3");                              \
38   }
39 #else
40 #error Unknown architecture, only arm and aarch64 are supported.
41 #endif
42 
43 #define DEFINE_INTERCEPTABLE_STUB_VARIABLE(name) uintptr_t name;
44 
45 #define INIT_INTERCEPTABLE_STUB_VARIABLE(library_name, name) \
46   native_bridge_intercept_symbol(&name, library_name, #name)
47 
48 #define DEFINE_INTERCEPTABLE_STUB_FUNCTION(name) \
49   extern "C" void name();                        \
50   INTERCEPTABLE_STUB_ASM_FUNCTION(name)
51 
52 #define INIT_INTERCEPTABLE_STUB_FUNCTION(library_name, name) \
53   native_bridge_intercept_symbol(reinterpret_cast<void*>(name), library_name, #name)
54 
55 #endif  // NATIVE_BRIDGE_SUPPORT_VDSO_INTERCEPTABLE_FUNCTIONS_H_
56