blob: 4f818366d1fad0cc76121bfa399fb4a414a76355 [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>
Steven Moreland4fdb12f2020-07-21 02:21:48 +000035#include <mutex>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036#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
Steven Moreland072cc7e2019-07-12 21:01:54 +000044#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
Martijn Coenen7bca77a2019-03-13 11:51:08 +000047#ifdef __ANDROID_VNDK__
48const char* kDefaultDriver = "/dev/vndbinder";
49#else
Steven Moreland2ae2f5e2018-07-06 13:02:53 -070050const char* kDefaultDriver = "/dev/binder";
Martijn Coenen7bca77a2019-03-13 11:51:08 +000051#endif
Steven Moreland2ae2f5e2018-07-06 13:02:53 -070052
Philip Cuadraa082fa82016-04-08 10:29:14 -070053// -------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054
55namespace android {
Wale Ogunwale376b8222015-04-13 16:16:10 -070056
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057class PoolThread : public Thread
58{
59public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070060 explicit PoolThread(bool isMain)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 : mIsMain(isMain)
62 {
63 }
Jooyung Han1b228f42020-01-30 13:41:12 +090064
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065protected:
66 virtual bool threadLoop()
67 {
68 IPCThreadState::self()->joinThreadPool(mIsMain);
69 return false;
70 }
Jooyung Han1b228f42020-01-30 13:41:12 +090071
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080072 const bool mIsMain;
73};
74
75sp<ProcessState> ProcessState::self()
76{
Steven Moreland4fdb12f2020-07-21 02:21:48 +000077 return init(kDefaultDriver, false /*requireDefault*/);
Martijn Coenen55d871c2017-03-21 15:56:40 -070078}
79
80sp<ProcessState> ProcessState::initWithDriver(const char* driver)
81{
Steven Moreland4fdb12f2020-07-21 02:21:48 +000082 return init(driver, true /*requireDefault*/);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083}
84
Steven Moreland072cc7e2019-07-12 21:01:54 +000085sp<ProcessState> ProcessState::selfOrNull()
86{
Steven Moreland4fdb12f2020-07-21 02:21:48 +000087 return init(nullptr, false /*requireDefault*/);
88}
89
90sp<ProcessState> ProcessState::init(const char *driver, bool requireDefault)
91{
92 [[clang::no_destroy]] static sp<ProcessState> gProcess;
93 [[clang::no_destroy]] static std::mutex gProcessMutex;
94
95 if (driver == nullptr) {
96 std::lock_guard<std::mutex> l(gProcessMutex);
97 return gProcess;
98 }
99
100 [[clang::no_destroy]] static std::once_flag gProcessOnce;
101 std::call_once(gProcessOnce, [&](){
102 if (access(driver, R_OK) == -1) {
103 ALOGE("Binder driver %s is unavailable. Using /dev/binder instead.", driver);
104 driver = "/dev/binder";
105 }
106
107 std::lock_guard<std::mutex> l(gProcessMutex);
108 gProcess = new ProcessState(driver);
109 });
110
111 if (requireDefault) {
112 // Detect if we are trying to initialize with a different driver, and
113 // consider that an error. ProcessState will only be initialized once above.
114 LOG_ALWAYS_FATAL_IF(gProcess->getDriverName() != driver,
115 "ProcessState was already initialized with %s,"
116 " can't initialize with %s.",
117 gProcess->getDriverName().c_str(), driver);
118 }
119
Colin Cross9d45ccc2017-06-20 17:48:33 -0700120 return gProcess;
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{
Steven Morelandc709dd82019-08-05 20:30:14 -0700125 sp<IBinder> context = getStrongProxyForHandle(0);
126
Steven Moreland8d93a712020-02-19 15:16:15 -0800127 if (context == nullptr) {
128 ALOGW("Not able to get context object on %s.", mDriverName.c_str());
129 }
130
Steven Morelandc709dd82019-08-05 20:30:14 -0700131 // The root object is special since we get it directly from the driver, it is never
132 // written by Parcell::writeStrongBinder.
133 internal::Stability::tryMarkCompilationUnit(context.get());
134
135 return context;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136}
137
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138void ProcessState::startThreadPool()
139{
140 AutoMutex _l(mLock);
141 if (!mThreadPoolStarted) {
142 mThreadPoolStarted = true;
143 spawnPooledThread(true);
144 }
145}
146
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147bool ProcessState::becomeContextManager(context_check_func checkFunc, void* userData)
148{
Steven Moreland4411d712019-07-12 14:02:53 -0700149 AutoMutex _l(mLock);
150 mBinderContextCheckFunc = checkFunc;
151 mBinderContextUserData = userData;
Jeff Browne16986c2011-07-08 18:52:57 -0700152
Steven Moreland4411d712019-07-12 14:02:53 -0700153 flat_binder_object obj {
154 .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX,
155 };
Steven Moreland3085a472018-12-26 13:59:23 -0800156
Steven Moreland4411d712019-07-12 14:02:53 -0700157 int result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj);
Steven Moreland3085a472018-12-26 13:59:23 -0800158
Steven Moreland4411d712019-07-12 14:02:53 -0700159 // fallback to original method
160 if (result != 0) {
161 android_errorWriteLog(0x534e4554, "121035042");
Steven Moreland3085a472018-12-26 13:59:23 -0800162
Hungming Chen28b42522020-08-28 17:29:55 +0800163 int unused = 0;
164 result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &unused);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165 }
Steven Moreland4411d712019-07-12 14:02:53 -0700166
167 if (result == -1) {
168 mBinderContextCheckFunc = nullptr;
169 mBinderContextUserData = nullptr;
170 ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno));
171 }
172
173 return result == 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800174}
175
Colin Cross9d45ccc2017-06-20 17:48:33 -0700176// Get references to userspace objects held by the kernel binder driver
177// Writes up to count elements into buf, and returns the total number
178// of references the kernel has, which may be larger than count.
179// buf may be NULL if count is 0. The pointers returned by this method
180// should only be used for debugging and not dereferenced, they may
181// already be invalid.
182ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf)
183{
Colin Cross9d45ccc2017-06-20 17:48:33 -0700184 binder_node_debug_info info = {};
185
Yi Kongfdd8da92018-06-07 17:52:27 -0700186 uintptr_t* end = buf ? buf + buf_count : nullptr;
Colin Cross9d45ccc2017-06-20 17:48:33 -0700187 size_t count = 0;
188
189 do {
190 status_t result = ioctl(mDriverFD, BINDER_GET_NODE_DEBUG_INFO, &info);
191 if (result < 0) {
192 return -1;
193 }
194 if (info.ptr != 0) {
195 if (buf && buf < end)
196 *buf++ = info.ptr;
197 count++;
198 if (buf && buf < end)
199 *buf++ = info.cookie;
200 count++;
201 }
202 } while (info.ptr != 0);
203
204 return count;
205}
206
Jon Spivack902e6fc2019-10-18 21:22:37 -0700207// Queries the driver for the current strong reference count of the node
208// that the handle points to. Can only be used by the servicemanager.
209//
210// Returns -1 in case of failure, otherwise the strong reference count.
211ssize_t ProcessState::getStrongRefCountForNodeByHandle(int32_t handle) {
212 binder_node_info_for_ref info;
213 memset(&info, 0, sizeof(binder_node_info_for_ref));
214
215 info.handle = handle;
216
217 status_t result = ioctl(mDriverFD, BINDER_GET_NODE_INFO_FOR_REF, &info);
218
219 if (result != OK) {
220 static bool logged = false;
221 if (!logged) {
222 ALOGW("Kernel does not support BINDER_GET_NODE_INFO_FOR_REF.");
223 logged = true;
224 }
225 return -1;
226 }
227
228 return info.strong_count;
229}
230
Steven Moreland7732a092019-01-02 17:54:16 -0800231void ProcessState::setCallRestriction(CallRestriction restriction) {
Steven Moreland28723ae2019-04-01 18:52:30 -0700232 LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull() != nullptr,
233 "Call restrictions must be set before the threadpool is started.");
Steven Moreland7732a092019-01-02 17:54:16 -0800234
235 mCallRestriction = restriction;
236}
237
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800238ProcessState::handle_entry* ProcessState::lookupHandleLocked(int32_t handle)
239{
240 const size_t N=mHandleToObject.size();
241 if (N <= (size_t)handle) {
242 handle_entry e;
Yi Kongfdd8da92018-06-07 17:52:27 -0700243 e.binder = nullptr;
244 e.refs = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800245 status_t err = mHandleToObject.insertAt(e, N, handle+1-N);
Yi Kongfdd8da92018-06-07 17:52:27 -0700246 if (err < NO_ERROR) return nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800247 }
248 return &mHandleToObject.editItemAt(handle);
249}
250
251sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
252{
253 sp<IBinder> result;
254
255 AutoMutex _l(mLock);
256
257 handle_entry* e = lookupHandleLocked(handle);
258
Yi Kongfdd8da92018-06-07 17:52:27 -0700259 if (e != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800260 // We need to create a new BpBinder if there isn't currently one, OR we
Steven Morelande171d622019-07-17 16:06:01 -0700261 // are unable to acquire a weak reference on this current one. The
262 // attemptIncWeak() is safe because we know the BpBinder destructor will always
263 // call expungeHandle(), which acquires the same lock we are holding now.
264 // We need to do this because there is a race condition between someone
265 // releasing a reference on this BpBinder, and a new reference on its handle
266 // arriving from the driver.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800267 IBinder* b = e->binder;
Yi Kongfdd8da92018-06-07 17:52:27 -0700268 if (b == nullptr || !e->refs->attemptIncWeak(this)) {
Todd Poynora7b0f042013-06-18 17:25:37 -0700269 if (handle == 0) {
270 // Special case for context manager...
271 // The context manager is the only object for which we create
272 // a BpBinder proxy without already holding a reference.
273 // Perform a dummy transaction to ensure the context manager
274 // is registered before we create the first local reference
275 // to it (which will occur when creating the BpBinder).
276 // If a local reference is created for the BpBinder when the
277 // context manager is not present, the driver will fail to
278 // provide a reference to the context manager, but the
279 // driver API does not return status.
280 //
281 // Note that this is not race-free if the context manager
282 // dies while this code runs.
283 //
284 // TODO: add a driver API to wait for context manager, or
285 // stop special casing handle 0 for context manager and add
286 // a driver API to get a handle to the context manager with
287 // proper reference counting.
288
289 Parcel data;
290 status_t status = IPCThreadState::self()->transact(
Yi Kongfdd8da92018-06-07 17:52:27 -0700291 0, IBinder::PING_TRANSACTION, data, nullptr, 0);
Todd Poynora7b0f042013-06-18 17:25:37 -0700292 if (status == DEAD_OBJECT)
Yi Kongfdd8da92018-06-07 17:52:27 -0700293 return nullptr;
Todd Poynora7b0f042013-06-18 17:25:37 -0700294 }
295
Michael Wachenschwanz2d349902017-08-15 00:57:14 -0700296 b = BpBinder::create(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800297 e->binder = b;
298 if (b) e->refs = b->getWeakRefs();
299 result = b;
300 } else {
301 // This little bit of nastyness is to allow us to add a primary
302 // reference to the remote proxy when this team doesn't have one
303 // but another team is sending the handle to us.
304 result.force_set(b);
305 e->refs->decWeak(this);
306 }
307 }
308
309 return result;
310}
311
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800312void ProcessState::expungeHandle(int32_t handle, IBinder* binder)
313{
314 AutoMutex _l(mLock);
Jooyung Han1b228f42020-01-30 13:41:12 +0900315
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800316 handle_entry* e = lookupHandleLocked(handle);
317
318 // This handle may have already been replaced with a new BpBinder
319 // (if someone failed the AttemptIncWeak() above); we don't want
320 // to overwrite it.
Yi Kongfdd8da92018-06-07 17:52:27 -0700321 if (e && e->binder == binder) e->binder = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800322}
323
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800324String8 ProcessState::makeBinderThreadName() {
325 int32_t s = android_atomic_add(1, &mThreadPoolSeq);
Philip Cuadraa082fa82016-04-08 10:29:14 -0700326 pid_t pid = getpid();
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800327 String8 name;
Philip Cuadraa082fa82016-04-08 10:29:14 -0700328 name.appendFormat("Binder:%d_%X", pid, s);
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800329 return name;
330}
331
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800332void ProcessState::spawnPooledThread(bool isMain)
333{
334 if (mThreadPoolStarted) {
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800335 String8 name = makeBinderThreadName();
336 ALOGV("Spawning new pooled thread, name=%s\n", name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800337 sp<Thread> t = new PoolThread(isMain);
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800338 t->run(name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800339 }
340}
341
Mathias Agopian1b80f792012-04-17 16:11:08 -0700342status_t ProcessState::setThreadPoolMaxThreadCount(size_t maxThreads) {
Steven Moreland1fdb98b2020-03-06 21:42:12 +0000343 LOG_ALWAYS_FATAL_IF(mThreadPoolStarted && maxThreads < mMaxThreads,
344 "Binder threadpool cannot be shrunk after starting");
Mathias Agopian1b80f792012-04-17 16:11:08 -0700345 status_t result = NO_ERROR;
Wale Ogunwale376b8222015-04-13 16:16:10 -0700346 if (ioctl(mDriverFD, BINDER_SET_MAX_THREADS, &maxThreads) != -1) {
347 mMaxThreads = maxThreads;
348 } else {
Mathias Agopian1b80f792012-04-17 16:11:08 -0700349 result = -errno;
350 ALOGE("Binder ioctl to set max threads failed: %s", strerror(-result));
351 }
352 return result;
353}
354
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800355void ProcessState::giveThreadPoolName() {
356 androidSetThreadName( makeBinderThreadName().string() );
357}
358
Iliyan Malchev32062242017-04-10 14:06:11 -0700359String8 ProcessState::getDriverName() {
360 return mDriverName;
361}
362
Martijn Coenen55d871c2017-03-21 15:56:40 -0700363static int open_driver(const char *driver)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800364{
Martijn Coenen55d871c2017-03-21 15:56:40 -0700365 int fd = open(driver, O_RDWR | O_CLOEXEC);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800366 if (fd >= 0) {
Jin Wei78181df2012-10-18 17:00:48 +0800367 int vers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368 status_t result = ioctl(fd, BINDER_VERSION, &vers);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800369 if (result == -1) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000370 ALOGE("Binder ioctl to obtain version failed: %s", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800371 close(fd);
372 fd = -1;
373 }
374 if (result != 0 || vers != BINDER_CURRENT_PROTOCOL_VERSION) {
Greg Hartman67ac00f2017-01-03 16:54:59 -0800375 ALOGE("Binder driver protocol(%d) does not match user space protocol(%d)! ioctl() return value: %d",
376 vers, BINDER_CURRENT_PROTOCOL_VERSION, result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800377 close(fd);
378 fd = -1;
379 }
Wale Ogunwale376b8222015-04-13 16:16:10 -0700380 size_t maxThreads = DEFAULT_MAX_BINDER_THREADS;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800381 result = ioctl(fd, BINDER_SET_MAX_THREADS, &maxThreads);
382 if (result == -1) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000383 ALOGE("Binder ioctl to set max threads failed: %s", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800384 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800385 } else {
Martijn Coenen55d871c2017-03-21 15:56:40 -0700386 ALOGW("Opening '%s' failed: %s\n", driver, strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800387 }
388 return fd;
389}
390
Steven Moreland072cc7e2019-07-12 21:01:54 +0000391ProcessState::ProcessState(const char *driver)
Iliyan Malchev32062242017-04-10 14:06:11 -0700392 : mDriverName(String8(driver))
393 , mDriverFD(open_driver(driver))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800394 , mVMStart(MAP_FAILED)
Wale Ogunwale376b8222015-04-13 16:16:10 -0700395 , mThreadCountLock(PTHREAD_MUTEX_INITIALIZER)
396 , mThreadCountDecrement(PTHREAD_COND_INITIALIZER)
397 , mExecutingThreadsCount(0)
398 , mMaxThreads(DEFAULT_MAX_BINDER_THREADS)
Colin Cross96e83222016-04-15 14:29:55 -0700399 , mStarvationStartTimeMs(0)
Yi Kongfdd8da92018-06-07 17:52:27 -0700400 , mBinderContextCheckFunc(nullptr)
401 , mBinderContextUserData(nullptr)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800402 , mThreadPoolStarted(false)
403 , mThreadPoolSeq(1)
Steven Moreland7732a092019-01-02 17:54:16 -0800404 , mCallRestriction(CallRestriction::NONE)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800405{
Steven Morelandb6d0e762019-11-15 00:51:42 -0800406
Steven Morelande09b0822020-08-26 18:06:13 +0000407// TODO(b/166468760): enforce in build system
Jooyung Han1b228f42020-01-30 13:41:12 +0900408#if defined(__ANDROID_APEX__)
Steven Morelandb6d0e762019-11-15 00:51:42 -0800409 LOG_ALWAYS_FATAL("Cannot use libbinder in APEX (only system.img libbinder) since it is not stable.");
410#endif
411
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800412 if (mDriverFD >= 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800413 // mmap the binder, providing a chunk of virtual address space to receive transactions.
Steven Moreland072cc7e2019-07-12 21:01:54 +0000414 mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800415 if (mVMStart == MAP_FAILED) {
416 // *sigh*
Steven Moreland376a5592017-12-19 15:42:16 -0800417 ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800418 close(mDriverFD);
419 mDriverFD = -1;
Iliyan Malchev32062242017-04-10 14:06:11 -0700420 mDriverName.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800422 }
Jeff Browne16986c2011-07-08 18:52:57 -0700423
Steven Moreland8c78e2e2019-07-10 16:13:12 -0700424 LOG_ALWAYS_FATAL_IF(mDriverFD < 0, "Binder driver '%s' could not be opened. Terminating.", driver);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800425}
426
427ProcessState::~ProcessState()
428{
zhongjieff405782016-03-09 15:05:04 +0800429 if (mDriverFD >= 0) {
430 if (mVMStart != MAP_FAILED) {
Steven Moreland072cc7e2019-07-12 21:01:54 +0000431 munmap(mVMStart, BINDER_VM_SIZE);
zhongjieff405782016-03-09 15:05:04 +0800432 }
433 close(mDriverFD);
434 }
435 mDriverFD = -1;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800436}
Jooyung Han1b228f42020-01-30 13:41:12 +0900437
Steven Moreland61ff8492019-09-26 16:05:45 -0700438} // namespace android