summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Martijn Coenen <maco@google.com> 2017-03-21 15:56:40 -0700
committer Martijn Coenen <maco@google.com> 2017-03-21 16:04:09 -0700
commit55d871cc09b7493e2b7e5705ea9774fd5f4c626c (patch)
treeaf239691f979e94c169a8101c1f578695c1ef230
parent4856e00f0e001185b107480fe27ef3360923eb87 (diff)
Allow ProcessState to use another binder dev node.
Since we have different binder domains at different /dev nodes now, processes using libbinder must be able to select which /dev node they want to use. This is achieved with a new ProcessState::initWithDriver() API, which takes the /dev node to talk to as an argument. Bug: 36052864 Test: system boots without issues Change-Id: I5b3b13decf254ca0957665c91abac4b287e448c4
-rw-r--r--include/binder/ProcessState.h7
-rw-r--r--libs/binder/ProcessState.cpp22
2 files changed, 22 insertions, 7 deletions
diff --git a/include/binder/ProcessState.h b/include/binder/ProcessState.h
index 64cf72e170..05e9d09ee8 100644
--- a/include/binder/ProcessState.h
+++ b/include/binder/ProcessState.h
@@ -35,6 +35,11 @@ class ProcessState : public virtual RefBase
{
public:
static sp<ProcessState> self();
+ /* initWithDriver() can be used to configure libbinder to use
+ * a different binder driver dev node. It must be called *before*
+ * any call to ProcessState::self(). /dev/binder remains the default.
+ */
+ static sp<ProcessState> initWithDriver(const char *driver);
void setContextObject(const sp<IBinder>& object);
sp<IBinder> getContextObject(const sp<IBinder>& caller);
@@ -67,7 +72,7 @@ public:
private:
friend class IPCThreadState;
- ProcessState();
+ ProcessState(const char* driver);
~ProcessState();
ProcessState(const ProcessState& o);
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index 98107c578d..5c4cfe2156 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -71,7 +71,17 @@ sp<ProcessState> ProcessState::self()
if (gProcess != NULL) {
return gProcess;
}
- gProcess = new ProcessState;
+ gProcess = new ProcessState("/dev/binder");
+ return gProcess;
+}
+
+sp<ProcessState> ProcessState::initWithDriver(const char* driver)
+{
+ Mutex::Autolock _l(gProcessMutex);
+ if (gProcess != NULL) {
+ LOG_ALWAYS_FATAL("ProcessState was already initialized.");
+ }
+ gProcess = new ProcessState(driver);
return gProcess;
}
@@ -307,9 +317,9 @@ void ProcessState::giveThreadPoolName() {
androidSetThreadName( makeBinderThreadName().string() );
}
-static int open_driver()
+static int open_driver(const char *driver)
{
- int fd = open("/dev/binder", O_RDWR | O_CLOEXEC);
+ int fd = open(driver, O_RDWR | O_CLOEXEC);
if (fd >= 0) {
int vers = 0;
status_t result = ioctl(fd, BINDER_VERSION, &vers);
@@ -330,13 +340,13 @@ static int open_driver()
ALOGE("Binder ioctl to set max threads failed: %s", strerror(errno));
}
} else {
- ALOGW("Opening '/dev/binder' failed: %s\n", strerror(errno));
+ ALOGW("Opening '%s' failed: %s\n", driver, strerror(errno));
}
return fd;
}
-ProcessState::ProcessState()
- : mDriverFD(open_driver())
+ProcessState::ProcessState(const char *driver)
+ : mDriverFD(open_driver(driver))
, mVMStart(MAP_FAILED)
, mThreadCountLock(PTHREAD_MUTEX_INITIALIZER)
, mThreadCountDecrement(PTHREAD_COND_INITIALIZER)