Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 1 | /* |
| 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 Hodson | d1ccdfa | 2020-07-27 14:12:46 +0100 | [diff] [blame] | 17 | // An implementation of the native-bridge interface for testing. |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 18 | |
| 19 | #include "nativebridge/native_bridge.h" |
| 20 | |
| 21 | #include <signal.h> |
| 22 | |
| 23 | // NativeBridgeCallbacks implementations |
| 24 | extern "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 | |
| 30 | extern "C" void* native_bridge2_loadLibrary(const char* /* libpath */, int /* flag */) { |
| 31 | return nullptr; |
| 32 | } |
| 33 | |
| 34 | extern "C" void* native_bridge2_getTrampoline(void* /* handle */, const char* /* name */, |
| 35 | const char* /* shorty */, uint32_t /* len */) { |
| 36 | return nullptr; |
| 37 | } |
| 38 | |
| 39 | extern "C" bool native_bridge2_isSupported(const char* /* libpath */) { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | extern "C" const struct android::NativeBridgeRuntimeValues* native_bridge2_getAppEnv( |
| 44 | const char* /* abi */) { |
| 45 | return nullptr; |
| 46 | } |
| 47 | |
| 48 | extern "C" bool native_bridge2_is_compatible_compatible_with(uint32_t version) { |
Martin Stjernholm | d90291b | 2021-05-27 20:54:22 +0100 | [diff] [blame] | 49 | // For testing, allow 1-3, but disallow later. |
| 50 | return version <= 3; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Orion Hodson | d1ccdfa | 2020-07-27 14:12:46 +0100 | [diff] [blame] | 53 | static bool native_bridge2_test_case_signal_handler(int, siginfo_t*, void*) { |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 54 | // 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 | |
| 59 | extern "C" android::NativeBridgeSignalHandlerFn native_bridge2_get_signal_handler(int signal) { |
| 60 | if (signal == SIGSEGV) { |
Orion Hodson | d1ccdfa | 2020-07-27 14:12:46 +0100 | [diff] [blame] | 61 | return &native_bridge2_test_case_signal_handler; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 62 | } |
| 63 | return nullptr; |
| 64 | } |
| 65 | |
| 66 | android::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 | }; |