blob: 5164dec7be3bd76553f26d3ad00c2d4faa74eb46 [file] [log] [blame]
Orion Hodson9b16e342019-10-09 13:29:16 +01001/*
2 * Copyright (C) 2014 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
Orion Hodsond1ccdfa2020-07-27 14:12:46 +010017// An implementation of the native-bridge interface for testing.
Orion Hodson9b16e342019-10-09 13:29:16 +010018
19#include "nativebridge/native_bridge.h"
20
21#include <signal.h>
22
23// NativeBridgeCallbacks implementations
24extern "C" bool native_bridge2_initialize(const android::NativeBridgeRuntimeCallbacks* /* art_cbs */,
25 const char* /* app_code_cache_dir */,
26 const char* /* isa */) {
27 return true;
28}
29
30extern "C" void* native_bridge2_loadLibrary(const char* /* libpath */, int /* flag */) {
31 return nullptr;
32}
33
34extern "C" void* native_bridge2_getTrampoline(void* /* handle */, const char* /* name */,
35 const char* /* shorty */, uint32_t /* len */) {
36 return nullptr;
37}
38
39extern "C" bool native_bridge2_isSupported(const char* /* libpath */) {
40 return false;
41}
42
43extern "C" const struct android::NativeBridgeRuntimeValues* native_bridge2_getAppEnv(
44 const char* /* abi */) {
45 return nullptr;
46}
47
48extern "C" bool native_bridge2_is_compatible_compatible_with(uint32_t version) {
Martin Stjernholmd90291b2021-05-27 20:54:22 +010049 // For testing, allow 1-3, but disallow later.
50 return version <= 3;
Orion Hodson9b16e342019-10-09 13:29:16 +010051}
52
Orion Hodsond1ccdfa2020-07-27 14:12:46 +010053static bool native_bridge2_test_case_signal_handler(int, siginfo_t*, void*) {
Orion Hodson9b16e342019-10-09 13:29:16 +010054 // TODO: Implement something here. We'd either have to have a death test with a log here, or
55 // we'd have to be able to resume after the faulting instruction...
56 return true;
57}
58
59extern "C" android::NativeBridgeSignalHandlerFn native_bridge2_get_signal_handler(int signal) {
60 if (signal == SIGSEGV) {
Orion Hodsond1ccdfa2020-07-27 14:12:46 +010061 return &native_bridge2_test_case_signal_handler;
Orion Hodson9b16e342019-10-09 13:29:16 +010062 }
63 return nullptr;
64}
65
66android::NativeBridgeCallbacks NativeBridgeItf {
67 .version = 2,
68 .initialize = &native_bridge2_initialize,
69 .loadLibrary = &native_bridge2_loadLibrary,
70 .getTrampoline = &native_bridge2_getTrampoline,
71 .isSupported = &native_bridge2_isSupported,
72 .getAppEnv = &native_bridge2_getAppEnv,
73 .isCompatibleWith = &native_bridge2_is_compatible_compatible_with,
74 .getSignalHandler = &native_bridge2_get_signal_handler
75};