Andreas Gampe | a6ac9ce | 2015-04-30 20:39:12 -0700 | [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 | |
| 17 | // A dummy implementation of the native-bridge interface. |
| 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) { |
| 49 | // For testing, allow 1 and 2, but disallow 3+. |
| 50 | return version <= 2; |
| 51 | } |
| 52 | |
| 53 | static bool native_bridge2_dummy_signal_handler(int, siginfo_t*, void*) { |
| 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) { |
| 61 | return &native_bridge2_dummy_signal_handler; |
| 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 | }; |
| 76 | |