blob: 86afffc079cbb4ce9d65c2c70467d876e94a642a [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2005 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#define LOG_TAG "ProcessState"
18
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070019#include <binder/ProcessState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070021#include <binder/BpBinder.h>
22#include <binder/IPCThreadState.h>
Steven Moreland2716e112018-02-23 14:57:20 -080023#include <binder/IServiceManager.h>
24#include <cutils/atomic.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <utils/Log.h>
26#include <utils/String8.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027#include <utils/String8.h>
28#include <utils/threads.h>
Jayant Chowdhary46f95532019-03-08 10:08:20 -080029#include <vndksupport/linker.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030
Mathias Agopian208059f2009-05-18 15:08:03 -070031#include <private/binder/binder_module.h>
32#include <private/binder/Static.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
34#include <errno.h>
35#include <fcntl.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <unistd.h>
39#include <sys/ioctl.h>
40#include <sys/mman.h>
41#include <sys/stat.h>
Philip Cuadraa082fa82016-04-08 10:29:14 -070042#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Ganesh Mahendran6ac7fb52017-03-03 09:41:14 +080044#define BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
Wale Ogunwale376b8222015-04-13 16:16:10 -070045#define DEFAULT_MAX_BINDER_THREADS 15
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046
Jayant Chowdhary46f95532019-03-08 10:08:20 -080047const char* kDefaultVendorDriver = "/dev/vndbinder";
Steven Moreland2ae2f5e2018-07-06 13:02:53 -070048const char* kDefaultDriver = "/dev/binder";
Steven Moreland2ae2f5e2018-07-06 13:02:53 -070049
Philip Cuadraa082fa82016-04-08 10:29:14 -070050// -------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051
52namespace android {
Wale Ogunwale376b8222015-04-13 16:16:10 -070053
Jayant Chowdhary46f95532019-03-08 10:08:20 -080054static const char *getDefaultBinderDriver() {
55 // Some libs might have their system variants loaded in a vendor process, so
56 // we cannot depend on a compile time check.
57 if (android_is_in_vendor_process()) {
58 return kDefaultVendorDriver;
59 }
60 return kDefaultDriver;
61}
62
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063class PoolThread : public Thread
64{
65public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070066 explicit PoolThread(bool isMain)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 : mIsMain(isMain)
68 {
69 }
70
71protected:
72 virtual bool threadLoop()
73 {
74 IPCThreadState::self()->joinThreadPool(mIsMain);
75 return false;
76 }
77
78 const bool mIsMain;
79};
80
81sp<ProcessState> ProcessState::self()
82{
Mathias Agopiane8db8712012-04-16 19:30:56 -070083 Mutex::Autolock _l(gProcessMutex);
Yi Kongfdd8da92018-06-07 17:52:27 -070084 if (gProcess != nullptr) {
Mathias Agopiane8db8712012-04-16 19:30:56 -070085 return gProcess;
86 }
Jayant Chowdhary46f95532019-03-08 10:08:20 -080087 gProcess = new ProcessState(getDefaultBinderDriver());
Martijn Coenen55d871c2017-03-21 15:56:40 -070088 return gProcess;
89}
90
91sp<ProcessState> ProcessState::initWithDriver(const char* driver)
92{
93 Mutex::Autolock _l(gProcessMutex);
Yi Kongfdd8da92018-06-07 17:52:27 -070094 if (gProcess != nullptr) {
Iliyan Malcheved1ffe02017-04-14 00:34:57 -070095 // Allow for initWithDriver to be called repeatedly with the same
96 // driver.
97 if (!strcmp(gProcess->getDriverName().c_str(), driver)) {
98 return gProcess;
99 }
Martijn Coenen55d871c2017-03-21 15:56:40 -0700100 LOG_ALWAYS_FATAL("ProcessState was already initialized.");
101 }
Steven Moreland376a5592017-12-19 15:42:16 -0800102
103 if (access(driver, R_OK) == -1) {
104 ALOGE("Binder driver %s is unavailable. Using /dev/binder instead.", driver);
105 driver = "/dev/binder";
106 }
107
Martijn Coenen55d871c2017-03-21 15:56:40 -0700108 gProcess = new ProcessState(driver);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 return gProcess;
110}
111
Colin Cross9d45ccc2017-06-20 17:48:33 -0700112sp<ProcessState> ProcessState::selfOrNull()
113{
114 Mutex::Autolock _l(gProcessMutex);
115 return gProcess;
116}
117
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118void ProcessState::setContextObject(const sp<IBinder>& object)
119{
120 setContextObject(object, String16("default"));
121}
122
Colin Cross6f4f3ab2014-02-05 17:42:44 -0800123sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124{
Jeff Browne16986c2011-07-08 18:52:57 -0700125 return getStrongProxyForHandle(0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126}
127
128void ProcessState::setContextObject(const sp<IBinder>& object, const String16& name)
129{
130 AutoMutex _l(mLock);
131 mContexts.add(name, object);
132}
133
134sp<IBinder> ProcessState::getContextObject(const String16& name, const sp<IBinder>& caller)
135{
136 mLock.lock();
137 sp<IBinder> object(
Yi Kongfdd8da92018-06-07 17:52:27 -0700138 mContexts.indexOfKey(name) >= 0 ? mContexts.valueFor(name) : nullptr);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139 mLock.unlock();
140
141 //printf("Getting context object %s for %p\n", String8(name).string(), caller.get());
142
Yi Kongfdd8da92018-06-07 17:52:27 -0700143 if (object != nullptr) return object;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144
145 // Don't attempt to retrieve contexts if we manage them
146 if (mManagesContexts) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000147 ALOGE("getContextObject(%s) failed, but we manage the contexts!\n",
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148 String8(name).string());
Yi Kongfdd8da92018-06-07 17:52:27 -0700149 return nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150 }
151
152 IPCThreadState* ipc = IPCThreadState::self();
153 {
154 Parcel data, reply;
155 // no interface token on this magic transaction
156 data.writeString16(name);
157 data.writeStrongBinder(caller);
158 status_t result = ipc->transact(0 /*magic*/, 0, data, &reply, 0);
159 if (result == NO_ERROR) {
160 object = reply.readStrongBinder();
161 }
162 }
163
164 ipc->flushCommands();
165
Yi Kongfdd8da92018-06-07 17:52:27 -0700166 if (object != nullptr) setContextObject(object, name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800167 return object;
168}
169
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170void ProcessState::startThreadPool()
171{
172 AutoMutex _l(mLock);
173 if (!mThreadPoolStarted) {
174 mThreadPoolStarted = true;
175 spawnPooledThread(true);
176 }
177}
178
179bool ProcessState::isContextManager(void) const
180{
181 return mManagesContexts;
182}
183
184bool ProcessState::becomeContextManager(context_check_func checkFunc, void* userData)
185{
186 if (!mManagesContexts) {
187 AutoMutex _l(mLock);
188 mBinderContextCheckFunc = checkFunc;
189 mBinderContextUserData = userData;
Jeff Browne16986c2011-07-08 18:52:57 -0700190
191 int dummy = 0;
Jeff Browne16986c2011-07-08 18:52:57 -0700192 status_t result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy);
Jeff Browne16986c2011-07-08 18:52:57 -0700193 if (result == 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800194 mManagesContexts = true;
Jeff Browne16986c2011-07-08 18:52:57 -0700195 } else if (result == -1) {
Yi Kongfdd8da92018-06-07 17:52:27 -0700196 mBinderContextCheckFunc = nullptr;
197 mBinderContextUserData = nullptr;
Steve Blocke6f43dd2012-01-06 19:20:56 +0000198 ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800199 }
200 }
201 return mManagesContexts;
202}
203
Colin Cross9d45ccc2017-06-20 17:48:33 -0700204// Get references to userspace objects held by the kernel binder driver
205// Writes up to count elements into buf, and returns the total number
206// of references the kernel has, which may be larger than count.
207// buf may be NULL if count is 0. The pointers returned by this method
208// should only be used for debugging and not dereferenced, they may
209// already be invalid.
210ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf)
211{
212 // TODO: remove these when they are defined by bionic's binder.h
213 struct binder_node_debug_info {
214 binder_uintptr_t ptr;
215 binder_uintptr_t cookie;
216 __u32 has_strong_ref;
217 __u32 has_weak_ref;
218 };
219#define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info)
220
221 binder_node_debug_info info = {};
222
Yi Kongfdd8da92018-06-07 17:52:27 -0700223 uintptr_t* end = buf ? buf + buf_count : nullptr;
Colin Cross9d45ccc2017-06-20 17:48:33 -0700224 size_t count = 0;
225
226 do {
227 status_t result = ioctl(mDriverFD, BINDER_GET_NODE_DEBUG_INFO, &info);
228 if (result < 0) {
229 return -1;
230 }
231 if (info.ptr != 0) {
232 if (buf && buf < end)
233 *buf++ = info.ptr;
234 count++;
235 if (buf && buf < end)
236 *buf++ = info.cookie;
237 count++;
238 }
239 } while (info.ptr != 0);
240
241 return count;
242}
243
Steven Moreland7732a092019-01-02 17:54:16 -0800244void ProcessState::setCallRestriction(CallRestriction restriction) {
245 LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull(), "Call restrictions must be set before the threadpool is started.");
246
247 mCallRestriction = restriction;
248}
249
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800250ProcessState::handle_entry* ProcessState::lookupHandleLocked(int32_t handle)
251{
252 const size_t N=mHandleToObject.size();
253 if (N <= (size_t)handle) {
254 handle_entry e;
Yi Kongfdd8da92018-06-07 17:52:27 -0700255 e.binder = nullptr;
256 e.refs = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800257 status_t err = mHandleToObject.insertAt(e, N, handle+1-N);
Yi Kongfdd8da92018-06-07 17:52:27 -0700258 if (err < NO_ERROR) return nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800259 }
260 return &mHandleToObject.editItemAt(handle);
261}
262
263sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
264{
265 sp<IBinder> result;
266
267 AutoMutex _l(mLock);
268
269 handle_entry* e = lookupHandleLocked(handle);
270
Yi Kongfdd8da92018-06-07 17:52:27 -0700271 if (e != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800272 // We need to create a new BpBinder if there isn't currently one, OR we
273 // are unable to acquire a weak reference on this current one. See comment
274 // in getWeakProxyForHandle() for more info about this.
275 IBinder* b = e->binder;
Yi Kongfdd8da92018-06-07 17:52:27 -0700276 if (b == nullptr || !e->refs->attemptIncWeak(this)) {
Todd Poynora7b0f042013-06-18 17:25:37 -0700277 if (handle == 0) {
278 // Special case for context manager...
279 // The context manager is the only object for which we create
280 // a BpBinder proxy without already holding a reference.
281 // Perform a dummy transaction to ensure the context manager
282 // is registered before we create the first local reference
283 // to it (which will occur when creating the BpBinder).
284 // If a local reference is created for the BpBinder when the
285 // context manager is not present, the driver will fail to
286 // provide a reference to the context manager, but the
287 // driver API does not return status.
288 //
289 // Note that this is not race-free if the context manager
290 // dies while this code runs.
291 //
292 // TODO: add a driver API to wait for context manager, or
293 // stop special casing handle 0 for context manager and add
294 // a driver API to get a handle to the context manager with
295 // proper reference counting.
296
297 Parcel data;
298 status_t status = IPCThreadState::self()->transact(
Yi Kongfdd8da92018-06-07 17:52:27 -0700299 0, IBinder::PING_TRANSACTION, data, nullptr, 0);
Todd Poynora7b0f042013-06-18 17:25:37 -0700300 if (status == DEAD_OBJECT)
Yi Kongfdd8da92018-06-07 17:52:27 -0700301 return nullptr;
Todd Poynora7b0f042013-06-18 17:25:37 -0700302 }
303
Michael Wachenschwanz2d349902017-08-15 00:57:14 -0700304 b = BpBinder::create(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800305 e->binder = b;
306 if (b) e->refs = b->getWeakRefs();
307 result = b;
308 } else {
309 // This little bit of nastyness is to allow us to add a primary
310 // reference to the remote proxy when this team doesn't have one
311 // but another team is sending the handle to us.
312 result.force_set(b);
313 e->refs->decWeak(this);
314 }
315 }
316
317 return result;
318}
319
320wp<IBinder> ProcessState::getWeakProxyForHandle(int32_t handle)
321{
322 wp<IBinder> result;
323
324 AutoMutex _l(mLock);
325
326 handle_entry* e = lookupHandleLocked(handle);
327
Yi Kongfdd8da92018-06-07 17:52:27 -0700328 if (e != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800329 // We need to create a new BpBinder if there isn't currently one, OR we
330 // are unable to acquire a weak reference on this current one. The
331 // attemptIncWeak() is safe because we know the BpBinder destructor will always
332 // call expungeHandle(), which acquires the same lock we are holding now.
333 // We need to do this because there is a race condition between someone
334 // releasing a reference on this BpBinder, and a new reference on its handle
335 // arriving from the driver.
336 IBinder* b = e->binder;
Yi Kongfdd8da92018-06-07 17:52:27 -0700337 if (b == nullptr || !e->refs->attemptIncWeak(this)) {
Michael Wachenschwanz2d349902017-08-15 00:57:14 -0700338 b = BpBinder::create(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339 result = b;
340 e->binder = b;
341 if (b) e->refs = b->getWeakRefs();
342 } else {
343 result = b;
344 e->refs->decWeak(this);
345 }
346 }
347
348 return result;
349}
350
351void ProcessState::expungeHandle(int32_t handle, IBinder* binder)
352{
353 AutoMutex _l(mLock);
354
355 handle_entry* e = lookupHandleLocked(handle);
356
357 // This handle may have already been replaced with a new BpBinder
358 // (if someone failed the AttemptIncWeak() above); we don't want
359 // to overwrite it.
Yi Kongfdd8da92018-06-07 17:52:27 -0700360 if (e && e->binder == binder) e->binder = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800361}
362
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800363String8 ProcessState::makeBinderThreadName() {
364 int32_t s = android_atomic_add(1, &mThreadPoolSeq);
Philip Cuadraa082fa82016-04-08 10:29:14 -0700365 pid_t pid = getpid();
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800366 String8 name;
Philip Cuadraa082fa82016-04-08 10:29:14 -0700367 name.appendFormat("Binder:%d_%X", pid, s);
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800368 return name;
369}
370
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800371void ProcessState::spawnPooledThread(bool isMain)
372{
373 if (mThreadPoolStarted) {
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800374 String8 name = makeBinderThreadName();
375 ALOGV("Spawning new pooled thread, name=%s\n", name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800376 sp<Thread> t = new PoolThread(isMain);
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800377 t->run(name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800378 }
379}
380
Mathias Agopian1b80f792012-04-17 16:11:08 -0700381status_t ProcessState::setThreadPoolMaxThreadCount(size_t maxThreads) {
382 status_t result = NO_ERROR;
Wale Ogunwale376b8222015-04-13 16:16:10 -0700383 if (ioctl(mDriverFD, BINDER_SET_MAX_THREADS, &maxThreads) != -1) {
384 mMaxThreads = maxThreads;
385 } else {
Mathias Agopian1b80f792012-04-17 16:11:08 -0700386 result = -errno;
387 ALOGE("Binder ioctl to set max threads failed: %s", strerror(-result));
388 }
389 return result;
390}
391
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800392void ProcessState::giveThreadPoolName() {
393 androidSetThreadName( makeBinderThreadName().string() );
394}
395
Iliyan Malchev32062242017-04-10 14:06:11 -0700396String8 ProcessState::getDriverName() {
397 return mDriverName;
398}
399
Martijn Coenen55d871c2017-03-21 15:56:40 -0700400static int open_driver(const char *driver)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800401{
Martijn Coenen55d871c2017-03-21 15:56:40 -0700402 int fd = open(driver, O_RDWR | O_CLOEXEC);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800403 if (fd >= 0) {
Jin Wei78181df2012-10-18 17:00:48 +0800404 int vers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800405 status_t result = ioctl(fd, BINDER_VERSION, &vers);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800406 if (result == -1) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000407 ALOGE("Binder ioctl to obtain version failed: %s", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800408 close(fd);
409 fd = -1;
410 }
411 if (result != 0 || vers != BINDER_CURRENT_PROTOCOL_VERSION) {
Greg Hartman67ac00f2017-01-03 16:54:59 -0800412 ALOGE("Binder driver protocol(%d) does not match user space protocol(%d)! ioctl() return value: %d",
413 vers, BINDER_CURRENT_PROTOCOL_VERSION, result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800414 close(fd);
415 fd = -1;
416 }
Wale Ogunwale376b8222015-04-13 16:16:10 -0700417 size_t maxThreads = DEFAULT_MAX_BINDER_THREADS;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800418 result = ioctl(fd, BINDER_SET_MAX_THREADS, &maxThreads);
419 if (result == -1) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000420 ALOGE("Binder ioctl to set max threads failed: %s", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800422 } else {
Martijn Coenen55d871c2017-03-21 15:56:40 -0700423 ALOGW("Opening '%s' failed: %s\n", driver, strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800424 }
425 return fd;
426}
427
Martijn Coenen55d871c2017-03-21 15:56:40 -0700428ProcessState::ProcessState(const char *driver)
Iliyan Malchev32062242017-04-10 14:06:11 -0700429 : mDriverName(String8(driver))
430 , mDriverFD(open_driver(driver))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800431 , mVMStart(MAP_FAILED)
Wale Ogunwale376b8222015-04-13 16:16:10 -0700432 , mThreadCountLock(PTHREAD_MUTEX_INITIALIZER)
433 , mThreadCountDecrement(PTHREAD_COND_INITIALIZER)
434 , mExecutingThreadsCount(0)
435 , mMaxThreads(DEFAULT_MAX_BINDER_THREADS)
Colin Cross96e83222016-04-15 14:29:55 -0700436 , mStarvationStartTimeMs(0)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800437 , mManagesContexts(false)
Yi Kongfdd8da92018-06-07 17:52:27 -0700438 , mBinderContextCheckFunc(nullptr)
439 , mBinderContextUserData(nullptr)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800440 , mThreadPoolStarted(false)
441 , mThreadPoolSeq(1)
Steven Moreland7732a092019-01-02 17:54:16 -0800442 , mCallRestriction(CallRestriction::NONE)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800443{
444 if (mDriverFD >= 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800445 // mmap the binder, providing a chunk of virtual address space to receive transactions.
Yi Kongfdd8da92018-06-07 17:52:27 -0700446 mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800447 if (mVMStart == MAP_FAILED) {
448 // *sigh*
Steven Moreland376a5592017-12-19 15:42:16 -0800449 ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800450 close(mDriverFD);
451 mDriverFD = -1;
Iliyan Malchev32062242017-04-10 14:06:11 -0700452 mDriverName.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800453 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454 }
Jeff Browne16986c2011-07-08 18:52:57 -0700455
456 LOG_ALWAYS_FATAL_IF(mDriverFD < 0, "Binder driver could not be opened. Terminating.");
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800457}
458
459ProcessState::~ProcessState()
460{
zhongjieff405782016-03-09 15:05:04 +0800461 if (mDriverFD >= 0) {
462 if (mVMStart != MAP_FAILED) {
463 munmap(mVMStart, BINDER_VM_SIZE);
464 }
465 close(mDriverFD);
466 }
467 mDriverFD = -1;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800468}
469
470}; // namespace android