blob: f3861bb2b54a83ef40e9529ec1bd90da4479bde1 [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>
Steven Morelandc709dd82019-08-05 20:30:14 -070024#include <binder/Stability.h>
Steven Moreland2716e112018-02-23 14:57:20 -080025#include <cutils/atomic.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026#include <utils/Log.h>
27#include <utils/String8.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include <utils/threads.h>
29
Mathias Agopian208059f2009-05-18 15:08:03 -070030#include <private/binder/binder_module.h>
Steven Morelanda4853cd2019-07-12 15:44:37 -070031#include "Static.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032
33#include <errno.h>
34#include <fcntl.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <unistd.h>
38#include <sys/ioctl.h>
39#include <sys/mman.h>
40#include <sys/stat.h>
Philip Cuadraa082fa82016-04-08 10:29:14 -070041#include <sys/types.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Steven Moreland072cc7e2019-07-12 21:01:54 +000043#define BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
Wale Ogunwale376b8222015-04-13 16:16:10 -070044#define DEFAULT_MAX_BINDER_THREADS 15
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
Martijn Coenen7bca77a2019-03-13 11:51:08 +000046#ifdef __ANDROID_VNDK__
47const char* kDefaultDriver = "/dev/vndbinder";
48#else
Steven Moreland2ae2f5e2018-07-06 13:02:53 -070049const char* kDefaultDriver = "/dev/binder";
Martijn Coenen7bca77a2019-03-13 11:51:08 +000050#endif
Steven Moreland2ae2f5e2018-07-06 13:02:53 -070051
Philip Cuadraa082fa82016-04-08 10:29:14 -070052// -------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053
54namespace android {
Wale Ogunwale376b8222015-04-13 16:16:10 -070055
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056class PoolThread : public Thread
57{
58public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070059 explicit PoolThread(bool isMain)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 : mIsMain(isMain)
61 {
62 }
Jooyung Han1b228f42020-01-30 13:41:12 +090063
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064protected:
65 virtual bool threadLoop()
66 {
67 IPCThreadState::self()->joinThreadPool(mIsMain);
68 return false;
69 }
Jooyung Han1b228f42020-01-30 13:41:12 +090070
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 const bool mIsMain;
72};
73
74sp<ProcessState> ProcessState::self()
75{
Mathias Agopiane8db8712012-04-16 19:30:56 -070076 Mutex::Autolock _l(gProcessMutex);
Yi Kongfdd8da92018-06-07 17:52:27 -070077 if (gProcess != nullptr) {
Mathias Agopiane8db8712012-04-16 19:30:56 -070078 return gProcess;
79 }
Steven Moreland072cc7e2019-07-12 21:01:54 +000080 gProcess = new ProcessState(kDefaultDriver);
Martijn Coenen55d871c2017-03-21 15:56:40 -070081 return gProcess;
82}
83
84sp<ProcessState> ProcessState::initWithDriver(const char* driver)
85{
86 Mutex::Autolock _l(gProcessMutex);
Yi Kongfdd8da92018-06-07 17:52:27 -070087 if (gProcess != nullptr) {
Iliyan Malcheved1ffe02017-04-14 00:34:57 -070088 // Allow for initWithDriver to be called repeatedly with the same
89 // driver.
90 if (!strcmp(gProcess->getDriverName().c_str(), driver)) {
91 return gProcess;
92 }
Martijn Coenen55d871c2017-03-21 15:56:40 -070093 LOG_ALWAYS_FATAL("ProcessState was already initialized.");
94 }
Steven Moreland376a5592017-12-19 15:42:16 -080095
96 if (access(driver, R_OK) == -1) {
97 ALOGE("Binder driver %s is unavailable. Using /dev/binder instead.", driver);
98 driver = "/dev/binder";
99 }
100
Steven Moreland072cc7e2019-07-12 21:01:54 +0000101 gProcess = new ProcessState(driver);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 return gProcess;
103}
104
Steven Moreland072cc7e2019-07-12 21:01:54 +0000105sp<ProcessState> ProcessState::selfOrNull()
106{
Colin Cross9d45ccc2017-06-20 17:48:33 -0700107 Mutex::Autolock _l(gProcessMutex);
108 return gProcess;
109}
110
Colin Cross6f4f3ab2014-02-05 17:42:44 -0800111sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112{
Steven Morelandc709dd82019-08-05 20:30:14 -0700113 sp<IBinder> context = getStrongProxyForHandle(0);
114
Steven Moreland8d93a712020-02-19 15:16:15 -0800115 if (context == nullptr) {
116 ALOGW("Not able to get context object on %s.", mDriverName.c_str());
117 }
118
Steven Morelandc709dd82019-08-05 20:30:14 -0700119 // The root object is special since we get it directly from the driver, it is never
120 // written by Parcell::writeStrongBinder.
121 internal::Stability::tryMarkCompilationUnit(context.get());
122
123 return context;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124}
125
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126void ProcessState::startThreadPool()
127{
128 AutoMutex _l(mLock);
129 if (!mThreadPoolStarted) {
130 mThreadPoolStarted = true;
131 spawnPooledThread(true);
132 }
133}
134
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135bool ProcessState::becomeContextManager(context_check_func checkFunc, void* userData)
136{
Steven Moreland4411d712019-07-12 14:02:53 -0700137 AutoMutex _l(mLock);
138 mBinderContextCheckFunc = checkFunc;
139 mBinderContextUserData = userData;
Jeff Browne16986c2011-07-08 18:52:57 -0700140
Steven Moreland4411d712019-07-12 14:02:53 -0700141 flat_binder_object obj {
142 .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX,
143 };
Steven Moreland3085a472018-12-26 13:59:23 -0800144
Steven Moreland4411d712019-07-12 14:02:53 -0700145 int result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj);
Steven Moreland3085a472018-12-26 13:59:23 -0800146
Steven Moreland4411d712019-07-12 14:02:53 -0700147 // fallback to original method
148 if (result != 0) {
149 android_errorWriteLog(0x534e4554, "121035042");
Steven Moreland3085a472018-12-26 13:59:23 -0800150
Steven Moreland4411d712019-07-12 14:02:53 -0700151 int dummy = 0;
152 result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153 }
Steven Moreland4411d712019-07-12 14:02:53 -0700154
155 if (result == -1) {
156 mBinderContextCheckFunc = nullptr;
157 mBinderContextUserData = nullptr;
158 ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno));
159 }
160
161 return result == 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162}
163
Colin Cross9d45ccc2017-06-20 17:48:33 -0700164// Get references to userspace objects held by the kernel binder driver
165// Writes up to count elements into buf, and returns the total number
166// of references the kernel has, which may be larger than count.
167// buf may be NULL if count is 0. The pointers returned by this method
168// should only be used for debugging and not dereferenced, they may
169// already be invalid.
170ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf)
171{
Colin Cross9d45ccc2017-06-20 17:48:33 -0700172 binder_node_debug_info info = {};
173
Yi Kongfdd8da92018-06-07 17:52:27 -0700174 uintptr_t* end = buf ? buf + buf_count : nullptr;
Colin Cross9d45ccc2017-06-20 17:48:33 -0700175 size_t count = 0;
176
177 do {
178 status_t result = ioctl(mDriverFD, BINDER_GET_NODE_DEBUG_INFO, &info);
179 if (result < 0) {
180 return -1;
181 }
182 if (info.ptr != 0) {
183 if (buf && buf < end)
184 *buf++ = info.ptr;
185 count++;
186 if (buf && buf < end)
187 *buf++ = info.cookie;
188 count++;
189 }
190 } while (info.ptr != 0);
191
192 return count;
193}
194
Jon Spivack902e6fc2019-10-18 21:22:37 -0700195// Queries the driver for the current strong reference count of the node
196// that the handle points to. Can only be used by the servicemanager.
197//
198// Returns -1 in case of failure, otherwise the strong reference count.
199ssize_t ProcessState::getStrongRefCountForNodeByHandle(int32_t handle) {
200 binder_node_info_for_ref info;
201 memset(&info, 0, sizeof(binder_node_info_for_ref));
202
203 info.handle = handle;
204
205 status_t result = ioctl(mDriverFD, BINDER_GET_NODE_INFO_FOR_REF, &info);
206
207 if (result != OK) {
208 static bool logged = false;
209 if (!logged) {
210 ALOGW("Kernel does not support BINDER_GET_NODE_INFO_FOR_REF.");
211 logged = true;
212 }
213 return -1;
214 }
215
216 return info.strong_count;
217}
218
Steven Moreland7732a092019-01-02 17:54:16 -0800219void ProcessState::setCallRestriction(CallRestriction restriction) {
Steven Moreland28723ae2019-04-01 18:52:30 -0700220 LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull() != nullptr,
221 "Call restrictions must be set before the threadpool is started.");
Steven Moreland7732a092019-01-02 17:54:16 -0800222
223 mCallRestriction = restriction;
224}
225
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800226ProcessState::handle_entry* ProcessState::lookupHandleLocked(int32_t handle)
227{
228 const size_t N=mHandleToObject.size();
229 if (N <= (size_t)handle) {
230 handle_entry e;
Yi Kongfdd8da92018-06-07 17:52:27 -0700231 e.binder = nullptr;
232 e.refs = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800233 status_t err = mHandleToObject.insertAt(e, N, handle+1-N);
Yi Kongfdd8da92018-06-07 17:52:27 -0700234 if (err < NO_ERROR) return nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235 }
236 return &mHandleToObject.editItemAt(handle);
237}
238
239sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
240{
241 sp<IBinder> result;
242
243 AutoMutex _l(mLock);
244
245 handle_entry* e = lookupHandleLocked(handle);
246
Yi Kongfdd8da92018-06-07 17:52:27 -0700247 if (e != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800248 // We need to create a new BpBinder if there isn't currently one, OR we
Steven Morelande171d622019-07-17 16:06:01 -0700249 // are unable to acquire a weak reference on this current one. The
250 // attemptIncWeak() is safe because we know the BpBinder destructor will always
251 // call expungeHandle(), which acquires the same lock we are holding now.
252 // We need to do this because there is a race condition between someone
253 // releasing a reference on this BpBinder, and a new reference on its handle
254 // arriving from the driver.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800255 IBinder* b = e->binder;
Yi Kongfdd8da92018-06-07 17:52:27 -0700256 if (b == nullptr || !e->refs->attemptIncWeak(this)) {
Todd Poynora7b0f042013-06-18 17:25:37 -0700257 if (handle == 0) {
258 // Special case for context manager...
259 // The context manager is the only object for which we create
260 // a BpBinder proxy without already holding a reference.
261 // Perform a dummy transaction to ensure the context manager
262 // is registered before we create the first local reference
263 // to it (which will occur when creating the BpBinder).
264 // If a local reference is created for the BpBinder when the
265 // context manager is not present, the driver will fail to
266 // provide a reference to the context manager, but the
267 // driver API does not return status.
268 //
269 // Note that this is not race-free if the context manager
270 // dies while this code runs.
271 //
272 // TODO: add a driver API to wait for context manager, or
273 // stop special casing handle 0 for context manager and add
274 // a driver API to get a handle to the context manager with
275 // proper reference counting.
276
277 Parcel data;
278 status_t status = IPCThreadState::self()->transact(
Yi Kongfdd8da92018-06-07 17:52:27 -0700279 0, IBinder::PING_TRANSACTION, data, nullptr, 0);
Todd Poynora7b0f042013-06-18 17:25:37 -0700280 if (status == DEAD_OBJECT)
Yi Kongfdd8da92018-06-07 17:52:27 -0700281 return nullptr;
Todd Poynora7b0f042013-06-18 17:25:37 -0700282 }
283
Michael Wachenschwanz2d349902017-08-15 00:57:14 -0700284 b = BpBinder::create(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800285 e->binder = b;
286 if (b) e->refs = b->getWeakRefs();
287 result = b;
288 } else {
289 // This little bit of nastyness is to allow us to add a primary
290 // reference to the remote proxy when this team doesn't have one
291 // but another team is sending the handle to us.
292 result.force_set(b);
293 e->refs->decWeak(this);
294 }
295 }
296
297 return result;
298}
299
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800300void ProcessState::expungeHandle(int32_t handle, IBinder* binder)
301{
302 AutoMutex _l(mLock);
Jooyung Han1b228f42020-01-30 13:41:12 +0900303
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800304 handle_entry* e = lookupHandleLocked(handle);
305
306 // This handle may have already been replaced with a new BpBinder
307 // (if someone failed the AttemptIncWeak() above); we don't want
308 // to overwrite it.
Yi Kongfdd8da92018-06-07 17:52:27 -0700309 if (e && e->binder == binder) e->binder = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800310}
311
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800312String8 ProcessState::makeBinderThreadName() {
313 int32_t s = android_atomic_add(1, &mThreadPoolSeq);
Philip Cuadraa082fa82016-04-08 10:29:14 -0700314 pid_t pid = getpid();
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800315 String8 name;
Philip Cuadraa082fa82016-04-08 10:29:14 -0700316 name.appendFormat("Binder:%d_%X", pid, s);
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800317 return name;
318}
319
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800320void ProcessState::spawnPooledThread(bool isMain)
321{
322 if (mThreadPoolStarted) {
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800323 String8 name = makeBinderThreadName();
324 ALOGV("Spawning new pooled thread, name=%s\n", name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800325 sp<Thread> t = new PoolThread(isMain);
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800326 t->run(name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800327 }
328}
329
Mathias Agopian1b80f792012-04-17 16:11:08 -0700330status_t ProcessState::setThreadPoolMaxThreadCount(size_t maxThreads) {
Steven Moreland1fdb98b2020-03-06 21:42:12 +0000331 LOG_ALWAYS_FATAL_IF(mThreadPoolStarted && maxThreads < mMaxThreads,
332 "Binder threadpool cannot be shrunk after starting");
Mathias Agopian1b80f792012-04-17 16:11:08 -0700333 status_t result = NO_ERROR;
Wale Ogunwale376b8222015-04-13 16:16:10 -0700334 if (ioctl(mDriverFD, BINDER_SET_MAX_THREADS, &maxThreads) != -1) {
335 mMaxThreads = maxThreads;
336 } else {
Mathias Agopian1b80f792012-04-17 16:11:08 -0700337 result = -errno;
338 ALOGE("Binder ioctl to set max threads failed: %s", strerror(-result));
339 }
340 return result;
341}
342
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800343void ProcessState::giveThreadPoolName() {
344 androidSetThreadName( makeBinderThreadName().string() );
345}
346
Iliyan Malchev32062242017-04-10 14:06:11 -0700347String8 ProcessState::getDriverName() {
348 return mDriverName;
349}
350
Martijn Coenen55d871c2017-03-21 15:56:40 -0700351static int open_driver(const char *driver)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800352{
Martijn Coenen55d871c2017-03-21 15:56:40 -0700353 int fd = open(driver, O_RDWR | O_CLOEXEC);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800354 if (fd >= 0) {
Jin Wei78181df2012-10-18 17:00:48 +0800355 int vers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800356 status_t result = ioctl(fd, BINDER_VERSION, &vers);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800357 if (result == -1) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000358 ALOGE("Binder ioctl to obtain version failed: %s", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359 close(fd);
360 fd = -1;
361 }
362 if (result != 0 || vers != BINDER_CURRENT_PROTOCOL_VERSION) {
Greg Hartman67ac00f2017-01-03 16:54:59 -0800363 ALOGE("Binder driver protocol(%d) does not match user space protocol(%d)! ioctl() return value: %d",
364 vers, BINDER_CURRENT_PROTOCOL_VERSION, result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800365 close(fd);
366 fd = -1;
367 }
Wale Ogunwale376b8222015-04-13 16:16:10 -0700368 size_t maxThreads = DEFAULT_MAX_BINDER_THREADS;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800369 result = ioctl(fd, BINDER_SET_MAX_THREADS, &maxThreads);
370 if (result == -1) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000371 ALOGE("Binder ioctl to set max threads failed: %s", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800372 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373 } else {
Martijn Coenen55d871c2017-03-21 15:56:40 -0700374 ALOGW("Opening '%s' failed: %s\n", driver, strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800375 }
376 return fd;
377}
378
Steven Moreland072cc7e2019-07-12 21:01:54 +0000379ProcessState::ProcessState(const char *driver)
Iliyan Malchev32062242017-04-10 14:06:11 -0700380 : mDriverName(String8(driver))
381 , mDriverFD(open_driver(driver))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800382 , mVMStart(MAP_FAILED)
Wale Ogunwale376b8222015-04-13 16:16:10 -0700383 , mThreadCountLock(PTHREAD_MUTEX_INITIALIZER)
384 , mThreadCountDecrement(PTHREAD_COND_INITIALIZER)
385 , mExecutingThreadsCount(0)
386 , mMaxThreads(DEFAULT_MAX_BINDER_THREADS)
Colin Cross96e83222016-04-15 14:29:55 -0700387 , mStarvationStartTimeMs(0)
Yi Kongfdd8da92018-06-07 17:52:27 -0700388 , mBinderContextCheckFunc(nullptr)
389 , mBinderContextUserData(nullptr)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800390 , mThreadPoolStarted(false)
391 , mThreadPoolSeq(1)
Steven Moreland7732a092019-01-02 17:54:16 -0800392 , mCallRestriction(CallRestriction::NONE)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800393{
Steven Morelandb6d0e762019-11-15 00:51:42 -0800394
395// TODO(b/139016109): enforce in build system
Jooyung Han1b228f42020-01-30 13:41:12 +0900396#if defined(__ANDROID_APEX__)
Steven Morelandb6d0e762019-11-15 00:51:42 -0800397 LOG_ALWAYS_FATAL("Cannot use libbinder in APEX (only system.img libbinder) since it is not stable.");
398#endif
399
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800400 if (mDriverFD >= 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800401 // mmap the binder, providing a chunk of virtual address space to receive transactions.
Steven Moreland072cc7e2019-07-12 21:01:54 +0000402 mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800403 if (mVMStart == MAP_FAILED) {
404 // *sigh*
Steven Moreland376a5592017-12-19 15:42:16 -0800405 ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800406 close(mDriverFD);
407 mDriverFD = -1;
Iliyan Malchev32062242017-04-10 14:06:11 -0700408 mDriverName.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800409 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800410 }
Jeff Browne16986c2011-07-08 18:52:57 -0700411
Steven Moreland24bc0d12019-10-11 12:29:20 -0700412#ifdef __ANDROID__
Steven Moreland8c78e2e2019-07-10 16:13:12 -0700413 LOG_ALWAYS_FATAL_IF(mDriverFD < 0, "Binder driver '%s' could not be opened. Terminating.", driver);
Steven Moreland24bc0d12019-10-11 12:29:20 -0700414#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800415}
416
417ProcessState::~ProcessState()
418{
zhongjieff405782016-03-09 15:05:04 +0800419 if (mDriverFD >= 0) {
420 if (mVMStart != MAP_FAILED) {
Steven Moreland072cc7e2019-07-12 21:01:54 +0000421 munmap(mVMStart, BINDER_VM_SIZE);
zhongjieff405782016-03-09 15:05:04 +0800422 }
423 close(mDriverFD);
424 }
425 mDriverFD = -1;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800426}
Jooyung Han1b228f42020-01-30 13:41:12 +0900427
Steven Moreland6511af52019-09-26 16:05:45 -0700428} // namespace android