1 /*
2  * Copyright (C) 2023 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 #include <android_runtime/AndroidRuntime.h>
18 
19 #include "berberis/guest_abi/function_wrappers.h"
20 #include "berberis/guest_abi/guest_params.h"
21 #include "berberis/jni/jni_trampolines.h"
22 #include "berberis/proxy_loader/proxy_library_builder.h"
23 
24 namespace berberis {
25 
26 namespace {
27 
28 // At the moment this function simply calls jniRegisterNativeMethods.
29 // However, this can change in the future, at least this function might start
30 // doing some additional stuff - so merging these 2 symbols seems wrong.
DoCustomTrampoline__ZN7android14AndroidRuntime21registerNativeMethodsEP7_JNIEnvPKcPK15JNINativeMethodi(HostCode,ProcessState * state)31 void DoCustomTrampoline__ZN7android14AndroidRuntime21registerNativeMethodsEP7_JNIEnvPKcPK15JNINativeMethodi(  // NOLINT(whitespace/line_length)
32     HostCode /* callee */,
33     ProcessState* state) {
34   using PFN_callee = decltype(&android::AndroidRuntime::registerNativeMethods);
35   auto [arg_env, arg_class_name, arg_methods, arg_n] = GuestParamsValues<PFN_callee>(state);
36 
37   auto&& [ret] = GuestReturnReference<PFN_callee>(state);
38 
39   ret = android::AndroidRuntime::registerNativeMethods(arg_env, arg_class_name,
40                                                        arg_methods, arg_n);
41 }
42 
43 // TODO(b/278625630): This is not a standard library and will be deprecated.
44 
45 #if defined(NATIVE_BRIDGE_GUEST_ARCH_ARM) && defined(__i386__)
46 
47 #include "trampolines_arm_to_x86-inl.h"  // generated file NOLINT [build/include]
48 
49 #elif defined(NATIVE_BRIDGE_GUEST_ARCH_ARM64) && defined(__x86_64__)
50 
51 #include "trampolines_arm64_to_x86_64-inl.h"  // generated file NOLINT [build/include]
52 
53 #elif defined(NATIVE_BRIDGE_GUEST_ARCH_RISCV64) && defined(__x86_64__)
54 
55 #include "trampolines_riscv64_to_x86_64-inl.h"  // generated file NOLINT [build/include]
56 
57 #else
58 
59 #error "Unknown guest/host arch combination"
60 
61 #endif
62 
63 DEFINE_INIT_PROXY_LIBRARY("libandroid_runtime.so")
64 
65 }  // namespace
66 
67 }  // namespace berberis
68