blob: c38249ef7c7a416e44788cd1f4d1ed512636952a [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 Moreland4da8fb02020-12-29 22:51:32 +0000127 if (context) {
128 // The root object is special since we get it directly from the driver, it is never
129 // written by Parcell::writeStrongBinder.
130 internal::Stability::markCompilationUnit(context.get());
131 } else {
132 ALOGW("Not able to get context object on %s.", mDriverName.c_str());
Steven Moreland8d93a712020-02-19 15:16:15 -0800133 }
134
Steven Morelandc709dd82019-08-05 20:30:14 -0700135 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
Steven Moreland61096622020-08-31 23:36:39 +0000147bool ProcessState::becomeContextManager()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148{
Steven Moreland4411d712019-07-12 14:02:53 -0700149 AutoMutex _l(mLock);
Jeff Browne16986c2011-07-08 18:52:57 -0700150
Steven Moreland4411d712019-07-12 14:02:53 -0700151 flat_binder_object obj {
152 .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX,
153 };
Steven Moreland3085a472018-12-26 13:59:23 -0800154
Steven Moreland4411d712019-07-12 14:02:53 -0700155 int result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj);
Steven Moreland3085a472018-12-26 13:59:23 -0800156
Steven Moreland4411d712019-07-12 14:02:53 -0700157 // fallback to original method
158 if (result != 0) {
159 android_errorWriteLog(0x534e4554, "121035042");
Steven Moreland3085a472018-12-26 13:59:23 -0800160
Hungming Chen28b42522020-08-28 17:29:55 +0800161 int unused = 0;
162 result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &unused);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800163 }
Steven Moreland4411d712019-07-12 14:02:53 -0700164
165 if (result == -1) {
Steven Moreland4411d712019-07-12 14:02:53 -0700166 ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno));
167 }
168
169 return result == 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170}
171
Colin Cross9d45ccc2017-06-20 17:48:33 -0700172// Get references to userspace objects held by the kernel binder driver
173// Writes up to count elements into buf, and returns the total number
174// of references the kernel has, which may be larger than count.
175// buf may be NULL if count is 0. The pointers returned by this method
176// should only be used for debugging and not dereferenced, they may
177// already be invalid.
178ssize_t ProcessState::getKernelReferences(size_t buf_count, uintptr_t* buf)
179{
Colin Cross9d45ccc2017-06-20 17:48:33 -0700180 binder_node_debug_info info = {};
181
Yi Kongfdd8da92018-06-07 17:52:27 -0700182 uintptr_t* end = buf ? buf + buf_count : nullptr;
Colin Cross9d45ccc2017-06-20 17:48:33 -0700183 size_t count = 0;
184
185 do {
186 status_t result = ioctl(mDriverFD, BINDER_GET_NODE_DEBUG_INFO, &info);
187 if (result < 0) {
188 return -1;
189 }
190 if (info.ptr != 0) {
191 if (buf && buf < end)
192 *buf++ = info.ptr;
193 count++;
194 if (buf && buf < end)
195 *buf++ = info.cookie;
196 count++;
197 }
198 } while (info.ptr != 0);
199
200 return count;
201}
202
Jon Spivack902e6fc2019-10-18 21:22:37 -0700203// Queries the driver for the current strong reference count of the node
204// that the handle points to. Can only be used by the servicemanager.
205//
206// Returns -1 in case of failure, otherwise the strong reference count.
Steven Morelande8393882020-12-18 02:27:20 +0000207ssize_t ProcessState::getStrongRefCountForNode(const sp<BpBinder>& binder) {
Jon Spivack902e6fc2019-10-18 21:22:37 -0700208 binder_node_info_for_ref info;
209 memset(&info, 0, sizeof(binder_node_info_for_ref));
210
Steven Morelande8393882020-12-18 02:27:20 +0000211 info.handle = binder->getPrivateAccessorForHandle().handle();
Jon Spivack902e6fc2019-10-18 21:22:37 -0700212
213 status_t result = ioctl(mDriverFD, BINDER_GET_NODE_INFO_FOR_REF, &info);
214
215 if (result != OK) {
216 static bool logged = false;
217 if (!logged) {
218 ALOGW("Kernel does not support BINDER_GET_NODE_INFO_FOR_REF.");
219 logged = true;
220 }
221 return -1;
222 }
223
224 return info.strong_count;
225}
226
Steven Moreland7732a092019-01-02 17:54:16 -0800227void ProcessState::setCallRestriction(CallRestriction restriction) {
Steven Moreland28723ae2019-04-01 18:52:30 -0700228 LOG_ALWAYS_FATAL_IF(IPCThreadState::selfOrNull() != nullptr,
229 "Call restrictions must be set before the threadpool is started.");
Steven Moreland7732a092019-01-02 17:54:16 -0800230
231 mCallRestriction = restriction;
232}
233
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800234ProcessState::handle_entry* ProcessState::lookupHandleLocked(int32_t handle)
235{
236 const size_t N=mHandleToObject.size();
237 if (N <= (size_t)handle) {
238 handle_entry e;
Yi Kongfdd8da92018-06-07 17:52:27 -0700239 e.binder = nullptr;
240 e.refs = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800241 status_t err = mHandleToObject.insertAt(e, N, handle+1-N);
Yi Kongfdd8da92018-06-07 17:52:27 -0700242 if (err < NO_ERROR) return nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243 }
244 return &mHandleToObject.editItemAt(handle);
245}
246
247sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
248{
249 sp<IBinder> result;
250
251 AutoMutex _l(mLock);
252
253 handle_entry* e = lookupHandleLocked(handle);
254
Yi Kongfdd8da92018-06-07 17:52:27 -0700255 if (e != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800256 // We need to create a new BpBinder if there isn't currently one, OR we
Steven Morelande171d622019-07-17 16:06:01 -0700257 // are unable to acquire a weak reference on this current one. The
258 // attemptIncWeak() is safe because we know the BpBinder destructor will always
259 // call expungeHandle(), which acquires the same lock we are holding now.
260 // We need to do this because there is a race condition between someone
261 // releasing a reference on this BpBinder, and a new reference on its handle
262 // arriving from the driver.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800263 IBinder* b = e->binder;
Yi Kongfdd8da92018-06-07 17:52:27 -0700264 if (b == nullptr || !e->refs->attemptIncWeak(this)) {
Todd Poynora7b0f042013-06-18 17:25:37 -0700265 if (handle == 0) {
266 // Special case for context manager...
267 // The context manager is the only object for which we create
268 // a BpBinder proxy without already holding a reference.
269 // Perform a dummy transaction to ensure the context manager
270 // is registered before we create the first local reference
271 // to it (which will occur when creating the BpBinder).
272 // If a local reference is created for the BpBinder when the
273 // context manager is not present, the driver will fail to
274 // provide a reference to the context manager, but the
275 // driver API does not return status.
276 //
277 // Note that this is not race-free if the context manager
278 // dies while this code runs.
279 //
280 // TODO: add a driver API to wait for context manager, or
281 // stop special casing handle 0 for context manager and add
282 // a driver API to get a handle to the context manager with
283 // proper reference counting.
284
Steven Moreland9514b202020-09-21 18:03:27 +0000285 IPCThreadState* ipc = IPCThreadState::self();
286
287 CallRestriction originalCallRestriction = ipc->getCallRestriction();
288 ipc->setCallRestriction(CallRestriction::NONE);
289
Todd Poynora7b0f042013-06-18 17:25:37 -0700290 Parcel data;
Steven Moreland9514b202020-09-21 18:03:27 +0000291 status_t status = ipc->transact(
Yi Kongfdd8da92018-06-07 17:52:27 -0700292 0, IBinder::PING_TRANSACTION, data, nullptr, 0);
Steven Moreland9514b202020-09-21 18:03:27 +0000293
294 ipc->setCallRestriction(originalCallRestriction);
295
Todd Poynora7b0f042013-06-18 17:25:37 -0700296 if (status == DEAD_OBJECT)
Yi Kongfdd8da92018-06-07 17:52:27 -0700297 return nullptr;
Todd Poynora7b0f042013-06-18 17:25:37 -0700298 }
299
Michael Wachenschwanz2d349902017-08-15 00:57:14 -0700300 b = BpBinder::create(handle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800301 e->binder = b;
302 if (b) e->refs = b->getWeakRefs();
303 result = b;
304 } else {
305 // This little bit of nastyness is to allow us to add a primary
306 // reference to the remote proxy when this team doesn't have one
307 // but another team is sending the handle to us.
308 result.force_set(b);
309 e->refs->decWeak(this);
310 }
311 }
312
313 return result;
314}
315
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800316void ProcessState::expungeHandle(int32_t handle, IBinder* binder)
317{
318 AutoMutex _l(mLock);
Jooyung Han1b228f42020-01-30 13:41:12 +0900319
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800320 handle_entry* e = lookupHandleLocked(handle);
321
322 // This handle may have already been replaced with a new BpBinder
323 // (if someone failed the AttemptIncWeak() above); we don't want
324 // to overwrite it.
Yi Kongfdd8da92018-06-07 17:52:27 -0700325 if (e && e->binder == binder) e->binder = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800326}
327
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800328String8 ProcessState::makeBinderThreadName() {
329 int32_t s = android_atomic_add(1, &mThreadPoolSeq);
Philip Cuadraa082fa82016-04-08 10:29:14 -0700330 pid_t pid = getpid();
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800331 String8 name;
Philip Cuadraa082fa82016-04-08 10:29:14 -0700332 name.appendFormat("Binder:%d_%X", pid, s);
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800333 return name;
334}
335
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800336void ProcessState::spawnPooledThread(bool isMain)
337{
338 if (mThreadPoolStarted) {
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800339 String8 name = makeBinderThreadName();
340 ALOGV("Spawning new pooled thread, name=%s\n", name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800341 sp<Thread> t = new PoolThread(isMain);
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800342 t->run(name.string());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800343 }
344}
345
Mathias Agopian1b80f792012-04-17 16:11:08 -0700346status_t ProcessState::setThreadPoolMaxThreadCount(size_t maxThreads) {
Steven Moreland1fdb98b2020-03-06 21:42:12 +0000347 LOG_ALWAYS_FATAL_IF(mThreadPoolStarted && maxThreads < mMaxThreads,
348 "Binder threadpool cannot be shrunk after starting");
Mathias Agopian1b80f792012-04-17 16:11:08 -0700349 status_t result = NO_ERROR;
Wale Ogunwale376b8222015-04-13 16:16:10 -0700350 if (ioctl(mDriverFD, BINDER_SET_MAX_THREADS, &maxThreads) != -1) {
351 mMaxThreads = maxThreads;
352 } else {
Mathias Agopian1b80f792012-04-17 16:11:08 -0700353 result = -errno;
354 ALOGE("Binder ioctl to set max threads failed: %s", strerror(-result));
355 }
356 return result;
357}
358
Mathias Agopiane3e43b32013-03-07 15:34:28 -0800359void ProcessState::giveThreadPoolName() {
360 androidSetThreadName( makeBinderThreadName().string() );
361}
362
Iliyan Malchev32062242017-04-10 14:06:11 -0700363String8 ProcessState::getDriverName() {
364 return mDriverName;
365}
366
Martijn Coenen55d871c2017-03-21 15:56:40 -0700367static int open_driver(const char *driver)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368{
Martijn Coenen55d871c2017-03-21 15:56:40 -0700369 int fd = open(driver, O_RDWR | O_CLOEXEC);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800370 if (fd >= 0) {
Jin Wei78181df2012-10-18 17:00:48 +0800371 int vers = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800372 status_t result = ioctl(fd, BINDER_VERSION, &vers);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373 if (result == -1) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000374 ALOGE("Binder ioctl to obtain version failed: %s", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800375 close(fd);
376 fd = -1;
377 }
378 if (result != 0 || vers != BINDER_CURRENT_PROTOCOL_VERSION) {
Greg Hartman67ac00f2017-01-03 16:54:59 -0800379 ALOGE("Binder driver protocol(%d) does not match user space protocol(%d)! ioctl() return value: %d",
380 vers, BINDER_CURRENT_PROTOCOL_VERSION, result);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800381 close(fd);
382 fd = -1;
383 }
Wale Ogunwale376b8222015-04-13 16:16:10 -0700384 size_t maxThreads = DEFAULT_MAX_BINDER_THREADS;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800385 result = ioctl(fd, BINDER_SET_MAX_THREADS, &maxThreads);
386 if (result == -1) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000387 ALOGE("Binder ioctl to set max threads failed: %s", strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800388 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800389 } else {
Martijn Coenen55d871c2017-03-21 15:56:40 -0700390 ALOGW("Opening '%s' failed: %s\n", driver, strerror(errno));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800391 }
392 return fd;
393}
394
Steven Moreland072cc7e2019-07-12 21:01:54 +0000395ProcessState::ProcessState(const char *driver)
Iliyan Malchev32062242017-04-10 14:06:11 -0700396 : mDriverName(String8(driver))
397 , mDriverFD(open_driver(driver))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800398 , mVMStart(MAP_FAILED)
Wale Ogunwale376b8222015-04-13 16:16:10 -0700399 , mThreadCountLock(PTHREAD_MUTEX_INITIALIZER)
400 , mThreadCountDecrement(PTHREAD_COND_INITIALIZER)
401 , mExecutingThreadsCount(0)
Steven Morelandc648a762021-01-16 02:39:45 +0000402 , mWaitingForThreads(0)
Wale Ogunwale376b8222015-04-13 16:16:10 -0700403 , mMaxThreads(DEFAULT_MAX_BINDER_THREADS)
Colin Cross96e83222016-04-15 14:29:55 -0700404 , mStarvationStartTimeMs(0)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800405 , mThreadPoolStarted(false)
406 , mThreadPoolSeq(1)
Steven Moreland7732a092019-01-02 17:54:16 -0800407 , mCallRestriction(CallRestriction::NONE)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800408{
Steven Moreland15b70292021-02-18 19:10:15 +0000409
410// TODO(b/166468760): enforce in build system
411#if defined(__ANDROID_APEX__)
412 LOG_ALWAYS_FATAL("Cannot use libbinder in APEX (only system.img libbinder) since it is not stable.");
413#endif
414
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800415 if (mDriverFD >= 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800416 // mmap the binder, providing a chunk of virtual address space to receive transactions.
Steven Moreland072cc7e2019-07-12 21:01:54 +0000417 mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800418 if (mVMStart == MAP_FAILED) {
419 // *sigh*
Steven Moreland376a5592017-12-19 15:42:16 -0800420 ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421 close(mDriverFD);
422 mDriverFD = -1;
Iliyan Malchev32062242017-04-10 14:06:11 -0700423 mDriverName.clear();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800424 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800425 }
Jeff Browne16986c2011-07-08 18:52:57 -0700426
Steven Moreland24bc0d12019-10-11 12:29:20 -0700427#ifdef __ANDROID__
Steven Moreland8c78e2e2019-07-10 16:13:12 -0700428 LOG_ALWAYS_FATAL_IF(mDriverFD < 0, "Binder driver '%s' could not be opened. Terminating.", driver);
Steven Moreland24bc0d12019-10-11 12:29:20 -0700429#endif
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800430}
431
432ProcessState::~ProcessState()
433{
zhongjieff405782016-03-09 15:05:04 +0800434 if (mDriverFD >= 0) {
435 if (mVMStart != MAP_FAILED) {
Steven Moreland072cc7e2019-07-12 21:01:54 +0000436 munmap(mVMStart, BINDER_VM_SIZE);
zhongjieff405782016-03-09 15:05:04 +0800437 }
438 close(mDriverFD);
439 }
440 mDriverFD = -1;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800441}
Jooyung Han1b228f42020-01-30 13:41:12 +0900442
Steven Moreland61ff8492019-09-26 16:05:45 -0700443} // namespace android