Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64d7900e authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk Committed by Automerger Merge Worker
Browse files

Merge "Binder: migrate off libutils Mutex" into main am: 29c9a960 am: 156adea4

parents d31a2b0d 156adea4
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -271,7 +271,7 @@ public:
    bool mInheritRt = false;

    // for below objects
    Mutex mLock;
    RpcMutex mLock;
    std::set<sp<RpcServerLink>> mRpcServerLinks;
    BpBinder::ObjectManager mObjects;

@@ -307,7 +307,7 @@ status_t BBinder::startRecordingTransactions(const Parcel& data) {
        return PERMISSION_DENIED;
    }
    Extras* e = getOrCreateExtras();
    AutoMutex lock(e->mLock);
    RpcMutexUniqueLock lock(e->mLock);
    if (mRecordingOn) {
        LOG(INFO) << "Could not start Binder recording. Another is already in progress.";
        return INVALID_OPERATION;
@@ -337,7 +337,7 @@ status_t BBinder::stopRecordingTransactions() {
        return PERMISSION_DENIED;
    }
    Extras* e = getOrCreateExtras();
    AutoMutex lock(e->mLock);
    RpcMutexUniqueLock lock(e->mLock);
    if (mRecordingOn) {
        e->mRecordingFd.reset();
        mRecordingOn = false;
@@ -405,7 +405,7 @@ status_t BBinder::transact(

    if (kEnableKernelIpc && mRecordingOn && code != START_RECORDING_TRANSACTION) [[unlikely]] {
        Extras* e = mExtras.load(std::memory_order_acquire);
        AutoMutex lock(e->mLock);
        RpcMutexUniqueLock lock(e->mLock);
        if (mRecordingOn) {
            Parcel emptyReply;
            timespec ts;
@@ -452,7 +452,7 @@ void* BBinder::attachObject(const void* objectID, void* object, void* cleanupCoo
    Extras* e = getOrCreateExtras();
    LOG_ALWAYS_FATAL_IF(!e, "no memory");

    AutoMutex _l(e->mLock);
    RpcMutexUniqueLock _l(e->mLock);
    return e->mObjects.attach(objectID, object, cleanupCookie, func);
}

@@ -461,7 +461,7 @@ void* BBinder::findObject(const void* objectID) const
    Extras* e = mExtras.load(std::memory_order_acquire);
    if (!e) return nullptr;

    AutoMutex _l(e->mLock);
    RpcMutexUniqueLock _l(e->mLock);
    return e->mObjects.find(objectID);
}

@@ -469,7 +469,7 @@ void* BBinder::detachObject(const void* objectID) {
    Extras* e = mExtras.load(std::memory_order_acquire);
    if (!e) return nullptr;

    AutoMutex _l(e->mLock);
    RpcMutexUniqueLock _l(e->mLock);
    return e->mObjects.detach(objectID);
}

@@ -477,7 +477,7 @@ void BBinder::withLock(const std::function<void()>& doWithLock) {
    Extras* e = getOrCreateExtras();
    LOG_ALWAYS_FATAL_IF(!e, "no memory");

    AutoMutex _l(e->mLock);
    RpcMutexUniqueLock _l(e->mLock);
    doWithLock();
}

@@ -485,7 +485,7 @@ sp<IBinder> BBinder::lookupOrCreateWeak(const void* objectID, object_make_func m
                                        const void* makeArgs) {
    Extras* e = getOrCreateExtras();
    LOG_ALWAYS_FATAL_IF(!e, "no memory");
    AutoMutex _l(e->mLock);
    RpcMutexUniqueLock _l(e->mLock);
    return e->mObjects.lookupOrCreateWeak(objectID, make, makeArgs);
}

@@ -692,7 +692,7 @@ status_t BBinder::setRpcClientDebug(android::base::unique_fd socketFd,
    auto weakThis = wp<BBinder>::fromExisting(this);

    Extras* e = getOrCreateExtras();
    AutoMutex _l(e->mLock);
    RpcMutexUniqueLock _l(e->mLock);
    auto rpcServer = RpcServer::make();
    LOG_ALWAYS_FATAL_IF(rpcServer == nullptr, "RpcServer::make returns null");
    auto link = sp<RpcServerLink>::make(rpcServer, keepAliveBinder, weakThis);
@@ -716,7 +716,7 @@ status_t BBinder::setRpcClientDebug(android::base::unique_fd socketFd,
void BBinder::removeRpcServerLink(const sp<RpcServerLink>& link) {
    Extras* e = mExtras.load(std::memory_order_acquire);
    if (!e) return;
    AutoMutex _l(e->mLock);
    RpcMutexUniqueLock _l(e->mLock);
    (void)e->mRpcServerLinks.erase(link);
}

+17 −17
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ namespace android {

// ---------------------------------------------------------------------------

Mutex BpBinder::sTrackingLock;
RpcMutex BpBinder::sTrackingLock;
std::unordered_map<int32_t, uint32_t> BpBinder::sTrackingMap;
std::unordered_map<int32_t, uint32_t> BpBinder::sLastLimitCallbackMap;
int BpBinder::sNumTrackedUids = 0;
@@ -163,7 +163,7 @@ sp<BpBinder> BpBinder::create(int32_t handle) {
    int32_t trackedUid = -1;
    if (sCountByUidEnabled) {
        trackedUid = IPCThreadState::self()->getCallingUid();
        AutoMutex _l(sTrackingLock);
        RpcMutexUniqueLock _l(sTrackingLock);
        uint32_t trackedValue = sTrackingMap[trackedUid];
        if (trackedValue & LIMIT_REACHED_MASK) [[unlikely]] {
            if (sBinderProxyThrottleCreate) {
@@ -276,7 +276,7 @@ std::optional<int32_t> BpBinder::getDebugBinderHandle() const {
}

bool BpBinder::isDescriptorCached() const {
    Mutex::Autolock _l(mLock);
    RpcMutexUniqueLock _l(mLock);
    return mDescriptorCache.c_str() != kDescriptorUninit.c_str();
}

@@ -292,7 +292,7 @@ const String16& BpBinder::getInterfaceDescriptor() const
        status_t err = thiz->transact(INTERFACE_TRANSACTION, data, &reply);
        if (err == NO_ERROR) {
            String16 res(reply.readString16());
            Mutex::Autolock _l(mLock);
            RpcMutexUniqueLock _l(mLock);
            // mDescriptorCache could have been assigned while the lock was
            // released.
            if (mDescriptorCache.c_str() == kDescriptorUninit.c_str()) mDescriptorCache = res;
@@ -385,7 +385,7 @@ status_t BpBinder::transact(
            status = IPCThreadState::self()->transact(binderHandle(), code, data, reply, flags);
        }
        if (data.dataSize() > LOG_TRANSACTIONS_OVER_SIZE) {
            Mutex::Autolock _l(mLock);
            RpcMutexUniqueLock _l(mLock);
            ALOGW("Large outgoing transaction of %zu bytes, interface descriptor %s, code %d",
                  data.dataSize(), String8(mDescriptorCache).c_str(), code);
        }
@@ -431,7 +431,7 @@ status_t BpBinder::linkToDeath(
                        "linkToDeath(): recipient must be non-NULL");

    {
        AutoMutex _l(mLock);
        RpcMutexUniqueLock _l(mLock);

        if (!mObitsSent) {
            if (!mObituaries) {
@@ -467,7 +467,7 @@ status_t BpBinder::unlinkToDeath(
        return INVALID_OPERATION;
    }

    AutoMutex _l(mLock);
    RpcMutexUniqueLock _l(mLock);

    if (mObitsSent) {
        return DEAD_OBJECT;
@@ -555,30 +555,30 @@ void BpBinder::reportOneDeath(const Obituary& obit)

void* BpBinder::attachObject(const void* objectID, void* object, void* cleanupCookie,
                             object_cleanup_func func) {
    AutoMutex _l(mLock);
    RpcMutexUniqueLock _l(mLock);
    ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects);
    return mObjects.attach(objectID, object, cleanupCookie, func);
}

void* BpBinder::findObject(const void* objectID) const
{
    AutoMutex _l(mLock);
    RpcMutexUniqueLock _l(mLock);
    return mObjects.find(objectID);
}

void* BpBinder::detachObject(const void* objectID) {
    AutoMutex _l(mLock);
    RpcMutexUniqueLock _l(mLock);
    return mObjects.detach(objectID);
}

void BpBinder::withLock(const std::function<void()>& doWithLock) {
    AutoMutex _l(mLock);
    RpcMutexUniqueLock _l(mLock);
    doWithLock();
}

sp<IBinder> BpBinder::lookupOrCreateWeak(const void* objectID, object_make_func make,
                                         const void* makeArgs) {
    AutoMutex _l(mLock);
    RpcMutexUniqueLock _l(mLock);
    return mObjects.lookupOrCreateWeak(objectID, make, makeArgs);
}

@@ -602,7 +602,7 @@ BpBinder::~BpBinder() {
    IPCThreadState* ipc = IPCThreadState::self();

    if (mTrackedUid >= 0) {
        AutoMutex _l(sTrackingLock);
        RpcMutexUniqueLock _l(sTrackingLock);
        uint32_t trackedValue = sTrackingMap[mTrackedUid];
        if ((trackedValue & COUNTING_VALUE_MASK) == 0) [[unlikely]] {
            ALOGE("Unexpected Binder Proxy tracking decrement in %p handle %d\n", this,
@@ -702,7 +702,7 @@ bool BpBinder::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/)

uint32_t BpBinder::getBinderProxyCount(uint32_t uid)
{
    AutoMutex _l(sTrackingLock);
    RpcMutexUniqueLock _l(sTrackingLock);
    auto it = sTrackingMap.find(uid);
    if (it != sTrackingMap.end()) {
        return it->second & COUNTING_VALUE_MASK;
@@ -717,7 +717,7 @@ uint32_t BpBinder::getBinderProxyCount()

void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts)
{
    AutoMutex _l(sTrackingLock);
    RpcMutexUniqueLock _l(sTrackingLock);
    uids.setCapacity(sTrackingMap.size());
    counts.setCapacity(sTrackingMap.size());
    for (const auto& it : sTrackingMap) {
@@ -731,12 +731,12 @@ void BpBinder::disableCountByUid() { sCountByUidEnabled.store(false); }
void BpBinder::setCountByUidEnabled(bool enable) { sCountByUidEnabled.store(enable); }

void BpBinder::setLimitCallback(binder_proxy_limit_callback cb) {
    AutoMutex _l(sTrackingLock);
    RpcMutexUniqueLock _l(sTrackingLock);
    sLimitCallback = cb;
}

void BpBinder::setBinderProxyCountWatermarks(int high, int low) {
    AutoMutex _l(sTrackingLock);
    RpcMutexUniqueLock _l(sTrackingLock);
    sBinderProxyCountHighWatermark = high;
    sBinderProxyCountLowWatermark = low;
}
+1 −1
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ bool checkCallingPermission(const String16& permission, int32_t* outPid, int32_t
}

bool checkPermission(const String16& permission, pid_t pid, uid_t uid, bool logPermissionFailure) {
    static Mutex gPermissionControllerLock;
    static std::mutex gPermissionControllerLock;
    static sp<IPermissionController> gPermissionController;

    sp<IPermissionController> pc;
+5 −5
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ private:
    void     dump_l(String8& res, const char* what) const;

    static const int    kMemoryAlign;
    mutable Mutex       mLock;
    mutable std::mutex mLock;
    LinkedList<chunk_t> mList;
    size_t              mHeapSize;
};
@@ -305,14 +305,14 @@ size_t SimpleBestFitAllocator::size() const

size_t SimpleBestFitAllocator::allocate(size_t size, uint32_t flags)
{
    Mutex::Autolock _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);
    ssize_t offset = alloc(size, flags);
    return offset;
}

status_t SimpleBestFitAllocator::deallocate(size_t offset)
{
    Mutex::Autolock _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);
    chunk_t const * const freed = dealloc(offset);
    if (freed) {
        return NO_ERROR;
@@ -420,7 +420,7 @@ SimpleBestFitAllocator::chunk_t* SimpleBestFitAllocator::dealloc(size_t start)

void SimpleBestFitAllocator::dump(const char* what) const
{
    Mutex::Autolock _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);
    dump_l(what);
}

@@ -434,7 +434,7 @@ void SimpleBestFitAllocator::dump_l(const char* what) const
void SimpleBestFitAllocator::dump(String8& result,
        const char* what) const
{
    Mutex::Autolock _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);
    dump_l(result, what);
}

+4 −4
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ void ProcessState::childPostFork() {

void ProcessState::startThreadPool()
{
    AutoMutex _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);
    if (!mThreadPoolStarted) {
        if (mMaxThreads == 0) {
            // see also getThreadPoolMaxTotalThreadCount
@@ -203,7 +203,7 @@ void ProcessState::startThreadPool()

bool ProcessState::becomeContextManager()
{
    AutoMutex _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);

    flat_binder_object obj {
        .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX,
@@ -310,7 +310,7 @@ sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)
{
    sp<IBinder> result;

    AutoMutex _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);

    if (handle == 0 && the_context_object != nullptr) return the_context_object;

@@ -374,7 +374,7 @@ sp<IBinder> ProcessState::getStrongProxyForHandle(int32_t handle)

void ProcessState::expungeHandle(int32_t handle, IBinder* binder)
{
    AutoMutex _l(mLock);
    std::unique_lock<std::mutex> _l(mLock);

    handle_entry* e = lookupHandleLocked(handle);

Loading