summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Steven Moreland <smoreland@google.com> 2019-04-01 18:52:30 -0700
committer Steven Moreland <smoreland@google.com> 2019-09-09 22:58:26 +0000
commit28723ae444e4ef1678160314bd03cbd8212d7414 (patch)
tree153768ec1e3b80bcb7f78b373562e2287ffae252
parent8f82e1240fde062a2b30b018015b06c7a757d4bd (diff)
libbinder: on host
The usecase is unit testing things which implement binder interfaces. Bug: 124524556 Test: TH runs all relevant unit tests Change-Id: I8caba1290da6d0354a7736a26d1dad7b6ab852e6
-rw-r--r--libs/binder/Android.bp67
-rw-r--r--libs/binder/IServiceManager.cpp18
-rw-r--r--libs/binder/Parcel.cpp2
-rw-r--r--libs/binder/ProcessState.cpp3
-rw-r--r--libs/binder/Static.cpp4
-rw-r--r--libs/binder/include/binder/IBinder.h5
-rw-r--r--libs/binder/include/binder/Parcel.h4
-rw-r--r--libs/binder/include/private/binder/binder_module.h10
-rw-r--r--libs/binderthreadstate/Android.bp2
9 files changed, 72 insertions, 43 deletions
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index 86f19c5873..8af2872152 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -16,6 +16,8 @@ cc_library_headers {
name: "libbinder_headers",
export_include_dirs: ["include"],
vendor_available: true,
+ host_supported: true,
+
header_libs: [
"libbase_headers",
"libcutils_headers",
@@ -28,6 +30,27 @@ cc_library_headers {
],
}
+// These interfaces are android-specific implementation unrelated to binder
+// transport itself and should be moved to AIDL or in domain-specific libs.
+//
+// Currently, these are only on system android (not vendor, not host)
+libbinder_device_interface_sources = [
+ "ActivityManager.cpp",
+ "AppOpsManager.cpp",
+ "IActivityManager.cpp",
+ "IAppOpsCallback.cpp",
+ "IAppOpsService.cpp",
+ "IBatteryStats.cpp",
+ "IMediaResourceMonitor.cpp",
+ "IPermissionController.cpp",
+ "IProcessInfoService.cpp",
+ "IUidObserver.cpp",
+ "PermissionCache.cpp",
+ "PermissionController.cpp",
+ "ProcessInfoService.cpp",
+ "IpPrefix.cpp",
+]
+
cc_library_shared {
name: "libbinder",
@@ -37,6 +60,13 @@ cc_library_shared {
enabled: true,
},
double_loadable: true,
+ host_supported: true,
+
+ // TODO(b/31559095): get headers from bionic on host
+ include_dirs: [
+ "bionic/libc/kernel/android/uapi/",
+ "bionic/libc/kernel/uapi/",
+ ],
// libbinder does not offer a stable wire protocol.
// if a second copy of it is installed, then it may break after security
@@ -44,62 +74,39 @@ cc_library_shared {
no_apex: true,
srcs: [
- "ActivityManager.cpp",
- "AppOpsManager.cpp",
"Binder.cpp",
"BpBinder.cpp",
"BufferedTextOutput.cpp",
"Debug.cpp",
- "IActivityManager.cpp",
- "IAppOpsCallback.cpp",
- "IAppOpsService.cpp",
- "IBatteryStats.cpp",
"IInterface.cpp",
- "IMediaResourceMonitor.cpp",
"IMemory.cpp",
"IPCThreadState.cpp",
- "IPermissionController.cpp",
- "IProcessInfoService.cpp",
"IResultReceiver.cpp",
"IServiceManager.cpp",
"IShellCallback.cpp",
- "IUidObserver.cpp",
"MemoryBase.cpp",
"MemoryDealer.cpp",
"MemoryHeapBase.cpp",
"Parcel.cpp",
"ParcelFileDescriptor.cpp",
- "PermissionCache.cpp",
- "PermissionController.cpp",
"PersistableBundle.cpp",
- "ProcessInfoService.cpp",
"ProcessState.cpp",
"Static.cpp",
"Stability.cpp",
"Status.cpp",
"TextOutput.cpp",
- "IpPrefix.cpp",
":libbinder_aidl",
],
target: {
+ android: {
+ srcs: libbinder_device_interface_sources,
+ },
+ host: {
+ cflags: ["-D__ANDROID_HOST__"],
+ },
vendor: {
- exclude_srcs: [
- "ActivityManager.cpp",
- "AppOpsManager.cpp",
- "IActivityManager.cpp",
- "IAppOpsCallback.cpp",
- "IAppOpsService.cpp",
- "IBatteryStats.cpp",
- "IMediaResourceMonitor.cpp",
- "IPermissionController.cpp",
- "IProcessInfoService.cpp",
- "IUidObserver.cpp",
- "PermissionCache.cpp",
- "PermissionController.cpp",
- "ProcessInfoService.cpp",
- "IpPrefix.cpp",
- ],
+ exclude_srcs: libbinder_device_interface_sources,
},
},
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index 715a4609d6..a603c83ddb 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -20,15 +20,19 @@
#include <android/os/BnServiceCallback.h>
#include <android/os/IServiceManager.h>
-#include <utils/Log.h>
#include <binder/IPCThreadState.h>
+#include <binder/Parcel.h>
+#include <utils/Log.h>
+#include <utils/String8.h>
+#include <utils/SystemClock.h>
+
#ifndef __ANDROID_VNDK__
#include <binder/IPermissionController.h>
#endif
-#include <binder/Parcel.h>
+
+#ifndef __ANDROID_HOST__
#include <cutils/properties.h>
-#include <utils/String8.h>
-#include <utils/SystemClock.h>
+#endif
#include "Static.h"
@@ -59,7 +63,7 @@ sp<IServiceManager> defaultServiceManager()
return gDefaultServiceManager;
}
-#ifndef __ANDROID_VNDK__
+#if !defined(__ANDROID_VNDK__) && !defined(__ANDROID_HOST__)
// IPermissionController is not accessible to vendors
bool checkCallingPermission(const String16& permission)
@@ -163,10 +167,14 @@ public:
strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder") == 0;
const long timeout = uptimeMillis() + 5000;
if (!gSystemBootCompleted && !isVendorService) {
+#ifdef __ANDROID_HOST__
+ gSystemBootCompleted = true;
+#else
// Vendor code can't access system properties
char bootCompleted[PROPERTY_VALUE_MAX];
property_get("sys.boot_completed", bootCompleted, "0");
gSystemBootCompleted = strcmp(bootCompleted, "1") == 0 ? true : false;
+#endif
}
// retry interval in millisecond; note that vendor services stay at 100ms
const long sleepTime = gSystemBootCompleted ? 1000 : 100;
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index ed6c834af8..ee26997912 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -67,7 +67,7 @@
#define PAD_SIZE_UNSAFE(s) (((s)+3)&~3)
static size_t pad_size(size_t s) {
- if (s > (SIZE_T_MAX - 3)) {
+ if (s > (std::numeric_limits<size_t>::max() - 3)) {
abort();
}
return PAD_SIZE_UNSAFE(s);
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index 07db50f7b3..eb828c3ce4 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -189,7 +189,8 @@ ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf)
}
void ProcessState::setCallRestriction(CallRestriction restriction) {
- LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull(), "Call restrictions must be set before the threadpool is started.");
+ LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull() != nullptr,
+ "Call restrictions must be set before the threadpool is started.");
mCallRestriction = restriction;
}
diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp
index a6fd8c49e9..bd40536884 100644
--- a/libs/binder/Static.cpp
+++ b/libs/binder/Static.cpp
@@ -54,7 +54,9 @@ public:
protected:
virtual status_t writeLines(const struct iovec& vec, size_t N)
{
- writev(mFD, &vec, N);
+ ssize_t ret = writev(mFD, &vec, N);
+ if (ret == -1) return -errno;
+ if (static_cast<size_t>(ret) != N) return UNKNOWN_ERROR;
return NO_ERROR;
}
diff --git a/libs/binder/include/binder/IBinder.h b/libs/binder/include/binder/IBinder.h
index 408037e711..027e088be6 100644
--- a/libs/binder/include/binder/IBinder.h
+++ b/libs/binder/include/binder/IBinder.h
@@ -22,9 +22,8 @@
#include <utils/String16.h>
#include <utils/Vector.h>
-
-// linux/binder.h already defines this, but we can't just include it from there
-// because there are host builds that include this file.
+// linux/binder.h defines this, but we don't want to include it here in order to
+// avoid exporting the kernel headers
#ifndef B_PACK_CHARS
#define B_PACK_CHARS(c1, c2, c3, c4) \
((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index b1b8ff18f4..3471e1356d 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -33,9 +33,9 @@
#include <binder/Parcelable.h>
#ifdef BINDER_IPC_32BIT
-typedef __u32 binder_size_t;
+typedef unsigned int binder_size_t;
#else
-typedef __u64 binder_size_t;
+typedef unsigned long long binder_size_t;
#endif
diff --git a/libs/binder/include/private/binder/binder_module.h b/libs/binder/include/private/binder/binder_module.h
index 2f11622e70..09e6ba0104 100644
--- a/libs/binder/include/private/binder/binder_module.h
+++ b/libs/binder/include/private/binder/binder_module.h
@@ -23,6 +23,16 @@ namespace android {
/* obtain structures and constants from the kernel header */
+// TODO(b/31559095): bionic on host
+#ifdef __ANDROID_HOST__
+#define __packed __attribute__((__packed__))
+#endif
+
+// TODO(b/31559095): bionic on host
+#if defined(B_PACK_CHARS) && !defined(_UAPI_LINUX_BINDER_H)
+#undef B_PACK_CHARS
+#endif
+
#include <sys/ioctl.h>
#include <linux/android/binder.h>
diff --git a/libs/binderthreadstate/Android.bp b/libs/binderthreadstate/Android.bp
index 512b0698d3..ee1a6a4860 100644
--- a/libs/binderthreadstate/Android.bp
+++ b/libs/binderthreadstate/Android.bp
@@ -20,6 +20,8 @@ cc_library {
enabled: true,
support_system_process: true,
},
+ host_supported: true,
+
srcs: [
"IPCThreadStateBase.cpp",
],