Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_bridge3_initialize( |
| 25 | const android::NativeBridgeRuntimeCallbacks* /* art_cbs */, |
| 26 | const char* /* app_code_cache_dir */, |
| 27 | const char* /* isa */) { |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | extern "C" void* native_bridge3_loadLibrary(const char* /* libpath */, int /* flag */) { |
| 32 | return nullptr; |
| 33 | } |
| 34 | |
| 35 | extern "C" void* native_bridge3_getTrampoline(void* /* handle */, const char* /* name */, |
| 36 | const char* /* shorty */, uint32_t /* len */) { |
| 37 | return nullptr; |
| 38 | } |
| 39 | |
| 40 | extern "C" bool native_bridge3_isSupported(const char* /* libpath */) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | extern "C" const struct android::NativeBridgeRuntimeValues* native_bridge3_getAppEnv( |
| 45 | const char* /* abi */) { |
| 46 | return nullptr; |
| 47 | } |
| 48 | |
| 49 | extern "C" bool native_bridge3_isCompatibleWith(uint32_t version) { |
| 50 | // For testing, allow 1-3, but disallow 4+. |
| 51 | return version <= 3; |
| 52 | } |
| 53 | |
Orion Hodson | d1ccdfa | 2020-07-27 14:12:46 +0100 | [diff] [blame] | 54 | static bool native_bridge3_test_case_signal_handler(int, siginfo_t*, void*) { |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 55 | // TODO: Implement something here. We'd either have to have a death test with a log here, or |
| 56 | // we'd have to be able to resume after the faulting instruction... |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | extern "C" android::NativeBridgeSignalHandlerFn native_bridge3_getSignalHandler(int signal) { |
| 61 | if (signal == SIGSEGV) { |
Orion Hodson | d1ccdfa | 2020-07-27 14:12:46 +0100 | [diff] [blame] | 62 | return &native_bridge3_test_case_signal_handler; |
Orion Hodson | 9b16e34 | 2019-10-09 13:29:16 +0100 | [diff] [blame] | 63 | } |
| 64 | return nullptr; |
| 65 | } |
| 66 | |
| 67 | extern "C" int native_bridge3_unloadLibrary(void* /* handle */) { |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | extern "C" const char* native_bridge3_getError() { |
| 72 | return nullptr; |
| 73 | } |
| 74 | |
| 75 | extern "C" bool native_bridge3_isPathSupported(const char* /* path */) { |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | extern "C" bool native_bridge3_initAnonymousNamespace(const char* /* public_ns_sonames */, |
| 80 | const char* /* anon_ns_library_path */) { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | extern "C" android::native_bridge_namespace_t* |
| 85 | native_bridge3_createNamespace(const char* /* name */, |
| 86 | const char* /* ld_library_path */, |
| 87 | const char* /* default_library_path */, |
| 88 | uint64_t /* type */, |
| 89 | const char* /* permitted_when_isolated_path */, |
| 90 | android::native_bridge_namespace_t* /* parent_ns */) { |
| 91 | return nullptr; |
| 92 | } |
| 93 | |
| 94 | extern "C" bool native_bridge3_linkNamespaces(android::native_bridge_namespace_t* /* from */, |
| 95 | android::native_bridge_namespace_t* /* to */, |
| 96 | const char* /* shared_libs_soname */) { |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | extern "C" void* native_bridge3_loadLibraryExt(const char* /* libpath */, |
| 101 | int /* flag */, |
| 102 | android::native_bridge_namespace_t* /* ns */) { |
| 103 | return nullptr; |
| 104 | } |
| 105 | |
| 106 | android::NativeBridgeCallbacks NativeBridgeItf{ |
| 107 | // v1 |
| 108 | .version = 3, |
| 109 | .initialize = &native_bridge3_initialize, |
| 110 | .loadLibrary = &native_bridge3_loadLibrary, |
| 111 | .getTrampoline = &native_bridge3_getTrampoline, |
| 112 | .isSupported = &native_bridge3_isSupported, |
| 113 | .getAppEnv = &native_bridge3_getAppEnv, |
| 114 | // v2 |
| 115 | .isCompatibleWith = &native_bridge3_isCompatibleWith, |
| 116 | .getSignalHandler = &native_bridge3_getSignalHandler, |
| 117 | // v3 |
| 118 | .unloadLibrary = &native_bridge3_unloadLibrary, |
| 119 | .getError = &native_bridge3_getError, |
| 120 | .isPathSupported = &native_bridge3_isPathSupported, |
| 121 | .initAnonymousNamespace = &native_bridge3_initAnonymousNamespace, |
| 122 | .createNamespace = &native_bridge3_createNamespace, |
| 123 | .linkNamespaces = &native_bridge3_linkNamespaces, |
| 124 | .loadLibraryExt = &native_bridge3_loadLibraryExt}; |