summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2020-04-24 15:43:48 +0100
committerNicolas Geoffray <ngeoffray@google.com>2020-04-27 09:34:03 +0000
commit7ca8b67c21513d3cd236f47332afdd1be1cb1569 (patch)
tree4e226c25734451053b85d24e5176abcc299e3986
parent5c25e537f59c2f87a57097ad3eb2f70d8c54de23 (diff)
Use ART_TARGET_ANDROID instead of __ANDROID__
On golem, we build for ART_TARGET_LINUX, which doesn't have support for linkerconfig. Therefore, guard all linker namespace code on ART_TARGET_ANDROID instead of __ANDROID__ (which is unfortunately not under ART's control). Test: build for golem and run Bug: 154074847 Change-Id: I7a2b81918177704b42d8aafbd6d7e9d06d34e5f4
-rw-r--r--libnativeloader/library_namespaces.cpp5
-rw-r--r--libnativeloader/library_namespaces.h4
-rw-r--r--libnativeloader/native_loader.cpp16
-rw-r--r--libnativeloader/native_loader_namespace.cpp4
-rw-r--r--libnativeloader/native_loader_namespace.h4
-rw-r--r--libnativeloader/native_loader_test.cpp4
-rw-r--r--libnativeloader/public_libraries.cpp6
7 files changed, 28 insertions, 15 deletions
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp
index 6092c004ef..d42a4b55ed 100644
--- a/libnativeloader/library_namespaces.cpp
+++ b/libnativeloader/library_namespaces.cpp
@@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#if defined(ART_TARGET_ANDROID)
+
#include "library_namespaces.h"
#include <dirent.h>
@@ -392,3 +395,5 @@ base::Result<std::string> FindApexNamespaceName(const std::string& location) {
}
} // namespace android::nativeloader
+
+#endif // defined(ART_TARGET_ANDROID)
diff --git a/libnativeloader/library_namespaces.h b/libnativeloader/library_namespaces.h
index e6d1a87cbb..c41f2e461f 100644
--- a/libnativeloader/library_namespaces.h
+++ b/libnativeloader/library_namespaces.h
@@ -17,8 +17,8 @@
#ifndef ART_LIBNATIVELOADER_LIBRARY_NAMESPACES_H_
#define ART_LIBNATIVELOADER_LIBRARY_NAMESPACES_H_
-#if !defined(__ANDROID__)
-#error "Not available for host"
+#if !defined(ART_TARGET_ANDROID)
+#error "Not available for host or linux target"
#endif
#define LOG_TAG "nativeloader"
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 2a28a05c01..b187474c5b 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -33,7 +33,7 @@
#include <nativebridge/native_bridge.h>
#include <nativehelper/scoped_utf_chars.h>
-#ifdef __ANDROID__
+#ifdef ART_TARGET_ANDROID
#include <log/log.h>
#include "library_namespaces.h"
#include "nativeloader/dlext_namespaces.h"
@@ -42,7 +42,7 @@
namespace android {
namespace {
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
using android::nativeloader::LibraryNamespaces;
std::mutex g_namespaces_mutex;
@@ -58,18 +58,18 @@ android_namespace_t* FindExportedNamespace(const char* caller_location) {
}
return nullptr;
}
-#endif // #if defined(__ANDROID__)
+#endif // #if defined(ART_TARGET_ANDROID)
} // namespace
void InitializeNativeLoader() {
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
std::lock_guard<std::mutex> guard(g_namespaces_mutex);
g_namespaces->Initialize();
#endif
}
void ResetNativeLoader() {
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
std::lock_guard<std::mutex> guard(g_namespaces_mutex);
g_namespaces->Reset();
#endif
@@ -78,7 +78,7 @@ void ResetNativeLoader() {
jstring CreateClassLoaderNamespace(JNIEnv* env, int32_t target_sdk_version, jobject class_loader,
bool is_shared, jstring dex_path, jstring library_path,
jstring permitted_path) {
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
std::lock_guard<std::mutex> guard(g_namespaces_mutex);
auto ns = g_namespaces->Create(env, target_sdk_version, class_loader, is_shared, dex_path,
library_path, permitted_path);
@@ -94,7 +94,7 @@ jstring CreateClassLoaderNamespace(JNIEnv* env, int32_t target_sdk_version, jobj
void* OpenNativeLibrary(JNIEnv* env, int32_t target_sdk_version, const char* path,
jobject class_loader, const char* caller_location, jstring library_path,
bool* needs_native_bridge, char** error_msg) {
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
UNUSED(target_sdk_version);
if (class_loader == nullptr) {
*needs_native_bridge = false;
@@ -208,7 +208,7 @@ void NativeLoaderFreeErrorMessage(char* msg) {
free(msg);
}
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
void* OpenNativeLibraryInNamespace(NativeLoaderNamespace* ns, const char* path,
bool* needs_native_bridge, char** error_msg) {
auto handle = ns->Load(path);
diff --git a/libnativeloader/native_loader_namespace.cpp b/libnativeloader/native_loader_namespace.cpp
index 49f3035dd5..79a9791dd0 100644
--- a/libnativeloader/native_loader_namespace.cpp
+++ b/libnativeloader/native_loader_namespace.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#if defined(ART_TARGET_ANDROID)
+
#define LOG_TAG "nativeloader"
#include "native_loader_namespace.h"
@@ -175,3 +177,5 @@ Result<void*> NativeLoaderNamespace::Load(const char* lib_name) const {
}
} // namespace android
+
+#endif // defined(ART_TARGET_ANDROID)
diff --git a/libnativeloader/native_loader_namespace.h b/libnativeloader/native_loader_namespace.h
index ee84f61cd8..a295d18f6a 100644
--- a/libnativeloader/native_loader_namespace.h
+++ b/libnativeloader/native_loader_namespace.h
@@ -17,7 +17,7 @@
#ifndef ART_LIBNATIVELOADER_NATIVE_LOADER_NAMESPACE_H_
#define ART_LIBNATIVELOADER_NATIVE_LOADER_NAMESPACE_H_
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
#include <string>
#include <variant>
@@ -73,6 +73,6 @@ struct NativeLoaderNamespace {
};
} // namespace android
-#endif // #if defined(__ANDROID__)
+#endif // #if defined(ART_TARGET_ANDROID)
#endif // ART_LIBNATIVELOADER_NATIVE_LOADER_NAMESPACE_H_
diff --git a/libnativeloader/native_loader_test.cpp b/libnativeloader/native_loader_test.cpp
index 3f2505c2de..66d7531b35 100644
--- a/libnativeloader/native_loader_test.cpp
+++ b/libnativeloader/native_loader_test.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#if defined(ART_TARGET_ANDROID)
+
#include <dlfcn.h>
#include <memory>
#include <unordered_map>
@@ -700,3 +702,5 @@ TEST(NativeLoaderJniConfigParser, RejectMalformed) {
} // namespace nativeloader
} // namespace android
+
+#endif // defined(ART_TARGET_ANDROID)
diff --git a/libnativeloader/public_libraries.cpp b/libnativeloader/public_libraries.cpp
index 258dbf69f0..4b56dc2a16 100644
--- a/libnativeloader/public_libraries.cpp
+++ b/libnativeloader/public_libraries.cpp
@@ -31,7 +31,7 @@
#include <android-base/strings.h>
#include <log/log.h>
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
#include <android/sysprop/VndkProperties.sysprop.h>
#endif
@@ -394,7 +394,7 @@ const std::string& apex_jni_libraries(const std::string& apex_ns_name) {
}
bool is_product_vndk_version_defined() {
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
return android::sysprop::VndkProperties::product_vndk_version().has_value();
#else
return false;
@@ -402,7 +402,7 @@ bool is_product_vndk_version_defined() {
}
std::string get_vndk_version(bool is_product_vndk) {
-#if defined(__ANDROID__)
+#if defined(ART_TARGET_ANDROID)
if (is_product_vndk) {
return android::sysprop::VndkProperties::product_vndk_version().value_or("");
}