| Jiyong Park | 6291da2 | 2019-04-26 18:55:48 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #pragma once |
| 17 | #if defined(__ANDROID__) |
| 18 | |
| 19 | #include <dlfcn.h> |
| 20 | |
| 21 | #include "android-base/logging.h" |
| 22 | #include "android/dlext.h" |
| 23 | #include "log/log.h" |
| 24 | #include "nativebridge/native_bridge.h" |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | // NativeLoaderNamespace abstracts a linker namespace for the native |
| 29 | // architecture (ex: arm on arm) or the translated architecture (ex: arm on |
| 30 | // x86). Instances of this class are managed by LibraryNamespaces object. |
| 31 | struct NativeLoaderNamespace { |
| 32 | public: |
| 33 | NativeLoaderNamespace() : android_ns_(nullptr), native_bridge_ns_(nullptr) {} |
| 34 | |
| 35 | explicit NativeLoaderNamespace(android_namespace_t* ns) |
| 36 | : android_ns_(ns), native_bridge_ns_(nullptr) {} |
| 37 | |
| 38 | explicit NativeLoaderNamespace(native_bridge_namespace_t* ns) |
| 39 | : android_ns_(nullptr), native_bridge_ns_(ns) {} |
| 40 | |
| 41 | NativeLoaderNamespace(NativeLoaderNamespace&&) = default; |
| 42 | NativeLoaderNamespace(const NativeLoaderNamespace&) = default; |
| 43 | NativeLoaderNamespace& operator=(const NativeLoaderNamespace&) = default; |
| 44 | |
| 45 | android_namespace_t* get_android_ns() const { |
| 46 | CHECK(native_bridge_ns_ == nullptr); |
| 47 | return android_ns_; |
| 48 | } |
| 49 | |
| 50 | native_bridge_namespace_t* get_native_bridge_ns() const { |
| 51 | CHECK(android_ns_ == nullptr); |
| 52 | return native_bridge_ns_; |
| 53 | } |
| 54 | |
| 55 | bool is_android_namespace() const { return native_bridge_ns_ == nullptr; } |
| 56 | |
| 57 | private: |
| 58 | // Only one of them can be not null |
| 59 | android_namespace_t* android_ns_; |
| 60 | native_bridge_namespace_t* native_bridge_ns_; |
| 61 | }; |
| 62 | |
| 63 | } // namespace android |
| 64 | #endif // #if defined(__ANDROID__) |