Loading libs/binder/IMemory.cpp +23 −27 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ #define LOG_TAG "IMemory" #include <atomic> #include <stdatomic.h> #include <fcntl.h> #include <stdint.h> Loading Loading @@ -261,7 +260,7 @@ BpMemoryHeap::BpMemoryHeap(const sp<IBinder>& impl) } BpMemoryHeap::~BpMemoryHeap() { int32_t heapId = mHeapId.load(memory_order_relaxed); int32_t heapId = mHeapId.load(std::memory_order_relaxed); if (heapId != -1) { close(heapId); if (mRealHeap) { Loading @@ -286,21 +285,21 @@ BpMemoryHeap::~BpMemoryHeap() { void BpMemoryHeap::assertMapped() const { int32_t heapId = mHeapId.load(memory_order_acquire); int32_t heapId = mHeapId.load(std::memory_order_acquire); if (heapId == -1) { sp<IBinder> binder(IInterface::asBinder(const_cast<BpMemoryHeap*>(this))); sp<BpMemoryHeap> heap = sp<BpMemoryHeap>::cast(find_heap(binder)); heap->assertReallyMapped(); if (heap->mBase != MAP_FAILED) { Mutex::Autolock _l(mLock); if (mHeapId.load(memory_order_relaxed) == -1) { if (mHeapId.load(std::memory_order_relaxed) == -1) { mBase = heap->mBase; mSize = heap->mSize; mOffset = heap->mOffset; int fd = fcntl(heap->mHeapId.load(memory_order_relaxed), F_DUPFD_CLOEXEC, 0); int fd = fcntl(heap->mHeapId.load(std::memory_order_relaxed), F_DUPFD_CLOEXEC, 0); ALOGE_IF(fd == -1, "cannot dup fd=%d", heap->mHeapId.load(memory_order_relaxed)); mHeapId.store(fd, memory_order_release); heap->mHeapId.load(std::memory_order_relaxed)); mHeapId.store(fd, std::memory_order_release); } } else { // something went wrong Loading @@ -311,7 +310,7 @@ void BpMemoryHeap::assertMapped() const void BpMemoryHeap::assertReallyMapped() const { int32_t heapId = mHeapId.load(memory_order_acquire); int32_t heapId = mHeapId.load(std::memory_order_acquire); if (heapId == -1) { // remote call without mLock held, worse case scenario, we end up Loading @@ -336,7 +335,7 @@ void BpMemoryHeap::assertReallyMapped() const } Mutex::Autolock _l(mLock); if (mHeapId.load(memory_order_relaxed) == -1) { if (mHeapId.load(std::memory_order_relaxed) == -1) { int fd = fcntl(parcel_fd, F_DUPFD_CLOEXEC, 0); ALOGE_IF(fd == -1, "cannot dup fd=%d, size=%zu, err=%d (%s)", parcel_fd, size, err, strerror(errno)); Loading @@ -355,7 +354,7 @@ void BpMemoryHeap::assertReallyMapped() const mSize = size; mFlags = flags; mOffset = offset; mHeapId.store(fd, memory_order_release); mHeapId.store(fd, std::memory_order_release); } } } Loading @@ -364,7 +363,7 @@ void BpMemoryHeap::assertReallyMapped() const int BpMemoryHeap::getHeapID() const { assertMapped(); // We either stored mHeapId ourselves, or loaded it with acquire semantics. return mHeapId.load(memory_order_relaxed); return mHeapId.load(std::memory_order_relaxed); } void* BpMemoryHeap::getBase() const { Loading Loading @@ -438,12 +437,10 @@ sp<IMemoryHeap> HeapCache::find_heap(const sp<IBinder>& binder) auto i = mHeapCache.find(binder); if (i != mHeapCache.end()) { heap_info_t& info = i->second; ALOGD_IF(VERBOSE, "found binder=%p, heap=%p, size=%zu, fd=%d, count=%d", binder.get(), info.heap.get(), static_cast<BpMemoryHeap*>(info.heap.get())->mSize, ALOGD_IF(VERBOSE, "found binder=%p, heap=%p, size=%zu, fd=%d, count=%d", binder.get(), info.heap.get(), static_cast<BpMemoryHeap*>(info.heap.get())->mSize, static_cast<BpMemoryHeap*>(info.heap.get()) ->mHeapId.load(memory_order_relaxed), ->mHeapId.load(std::memory_order_relaxed), info.count); ++info.count; return info.heap; Loading Loading @@ -471,12 +468,11 @@ void HeapCache::free_heap(const wp<IBinder>& binder) if (i != mHeapCache.end()) { heap_info_t& info = i->second; if (--info.count == 0) { ALOGD_IF(VERBOSE, "removing binder=%p, heap=%p, size=%zu, fd=%d, count=%d", ALOGD_IF(VERBOSE, "removing binder=%p, heap=%p, size=%zu, fd=%d, count=%d", binder.unsafe_get(), info.heap.get(), static_cast<BpMemoryHeap*>(info.heap.get())->mSize, static_cast<BpMemoryHeap*>(info.heap.get()) ->mHeapId.load(memory_order_relaxed), ->mHeapId.load(std::memory_order_relaxed), info.count); rel = i->second.heap; mHeapCache.erase(i); Loading Loading @@ -506,7 +502,7 @@ void HeapCache::dump_heaps() const heap_info_t& info = i.second; BpMemoryHeap const* h(static_cast<BpMemoryHeap const *>(info.heap.get())); ALOGD("hey=%p, heap=%p, count=%d, (fd=%d, base=%p, size=%zu)", i.first.unsafe_get(), info.heap.get(), info.count, h->mHeapId.load(memory_order_relaxed), h->mBase, info.heap.get(), info.count, h->mHeapId.load(std::memory_order_relaxed), h->mBase, h->mSize); } } Loading Loading
libs/binder/IMemory.cpp +23 −27 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ #define LOG_TAG "IMemory" #include <atomic> #include <stdatomic.h> #include <fcntl.h> #include <stdint.h> Loading Loading @@ -261,7 +260,7 @@ BpMemoryHeap::BpMemoryHeap(const sp<IBinder>& impl) } BpMemoryHeap::~BpMemoryHeap() { int32_t heapId = mHeapId.load(memory_order_relaxed); int32_t heapId = mHeapId.load(std::memory_order_relaxed); if (heapId != -1) { close(heapId); if (mRealHeap) { Loading @@ -286,21 +285,21 @@ BpMemoryHeap::~BpMemoryHeap() { void BpMemoryHeap::assertMapped() const { int32_t heapId = mHeapId.load(memory_order_acquire); int32_t heapId = mHeapId.load(std::memory_order_acquire); if (heapId == -1) { sp<IBinder> binder(IInterface::asBinder(const_cast<BpMemoryHeap*>(this))); sp<BpMemoryHeap> heap = sp<BpMemoryHeap>::cast(find_heap(binder)); heap->assertReallyMapped(); if (heap->mBase != MAP_FAILED) { Mutex::Autolock _l(mLock); if (mHeapId.load(memory_order_relaxed) == -1) { if (mHeapId.load(std::memory_order_relaxed) == -1) { mBase = heap->mBase; mSize = heap->mSize; mOffset = heap->mOffset; int fd = fcntl(heap->mHeapId.load(memory_order_relaxed), F_DUPFD_CLOEXEC, 0); int fd = fcntl(heap->mHeapId.load(std::memory_order_relaxed), F_DUPFD_CLOEXEC, 0); ALOGE_IF(fd == -1, "cannot dup fd=%d", heap->mHeapId.load(memory_order_relaxed)); mHeapId.store(fd, memory_order_release); heap->mHeapId.load(std::memory_order_relaxed)); mHeapId.store(fd, std::memory_order_release); } } else { // something went wrong Loading @@ -311,7 +310,7 @@ void BpMemoryHeap::assertMapped() const void BpMemoryHeap::assertReallyMapped() const { int32_t heapId = mHeapId.load(memory_order_acquire); int32_t heapId = mHeapId.load(std::memory_order_acquire); if (heapId == -1) { // remote call without mLock held, worse case scenario, we end up Loading @@ -336,7 +335,7 @@ void BpMemoryHeap::assertReallyMapped() const } Mutex::Autolock _l(mLock); if (mHeapId.load(memory_order_relaxed) == -1) { if (mHeapId.load(std::memory_order_relaxed) == -1) { int fd = fcntl(parcel_fd, F_DUPFD_CLOEXEC, 0); ALOGE_IF(fd == -1, "cannot dup fd=%d, size=%zu, err=%d (%s)", parcel_fd, size, err, strerror(errno)); Loading @@ -355,7 +354,7 @@ void BpMemoryHeap::assertReallyMapped() const mSize = size; mFlags = flags; mOffset = offset; mHeapId.store(fd, memory_order_release); mHeapId.store(fd, std::memory_order_release); } } } Loading @@ -364,7 +363,7 @@ void BpMemoryHeap::assertReallyMapped() const int BpMemoryHeap::getHeapID() const { assertMapped(); // We either stored mHeapId ourselves, or loaded it with acquire semantics. return mHeapId.load(memory_order_relaxed); return mHeapId.load(std::memory_order_relaxed); } void* BpMemoryHeap::getBase() const { Loading Loading @@ -438,12 +437,10 @@ sp<IMemoryHeap> HeapCache::find_heap(const sp<IBinder>& binder) auto i = mHeapCache.find(binder); if (i != mHeapCache.end()) { heap_info_t& info = i->second; ALOGD_IF(VERBOSE, "found binder=%p, heap=%p, size=%zu, fd=%d, count=%d", binder.get(), info.heap.get(), static_cast<BpMemoryHeap*>(info.heap.get())->mSize, ALOGD_IF(VERBOSE, "found binder=%p, heap=%p, size=%zu, fd=%d, count=%d", binder.get(), info.heap.get(), static_cast<BpMemoryHeap*>(info.heap.get())->mSize, static_cast<BpMemoryHeap*>(info.heap.get()) ->mHeapId.load(memory_order_relaxed), ->mHeapId.load(std::memory_order_relaxed), info.count); ++info.count; return info.heap; Loading Loading @@ -471,12 +468,11 @@ void HeapCache::free_heap(const wp<IBinder>& binder) if (i != mHeapCache.end()) { heap_info_t& info = i->second; if (--info.count == 0) { ALOGD_IF(VERBOSE, "removing binder=%p, heap=%p, size=%zu, fd=%d, count=%d", ALOGD_IF(VERBOSE, "removing binder=%p, heap=%p, size=%zu, fd=%d, count=%d", binder.unsafe_get(), info.heap.get(), static_cast<BpMemoryHeap*>(info.heap.get())->mSize, static_cast<BpMemoryHeap*>(info.heap.get()) ->mHeapId.load(memory_order_relaxed), ->mHeapId.load(std::memory_order_relaxed), info.count); rel = i->second.heap; mHeapCache.erase(i); Loading Loading @@ -506,7 +502,7 @@ void HeapCache::dump_heaps() const heap_info_t& info = i.second; BpMemoryHeap const* h(static_cast<BpMemoryHeap const *>(info.heap.get())); ALOGD("hey=%p, heap=%p, count=%d, (fd=%d, base=%p, size=%zu)", i.first.unsafe_get(), info.heap.get(), info.count, h->mHeapId.load(memory_order_relaxed), h->mBase, info.heap.get(), info.count, h->mHeapId.load(std::memory_order_relaxed), h->mBase, h->mSize); } } Loading