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

Commit 9f268673 authored by Steven Moreland's avatar Steven Moreland Committed by Gerrit Code Review
Browse files

Merge "libbinder: stability check moved to trans time"

parents 6f65b7f0 c709dd89
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -124,7 +124,6 @@ status_t BBinder::transact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
{
    data.setDataPosition(0);
    data.setDataPosition(0);
    data.setTransactingBinder(this);


    status_t err = NO_ERROR;
    status_t err = NO_ERROR;
    switch (code) {
    switch (code) {
@@ -139,7 +138,6 @@ status_t BBinder::transact(
    // In case this is being transacted on in the same process.
    // In case this is being transacted on in the same process.
    if (reply != nullptr) {
    if (reply != nullptr) {
        reply->setDataPosition(0);
        reply->setDataPosition(0);
        reply->setTransactingBinder(this);
    }
    }


    return err;
    return err;
+13 −4
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@


#include <binder/IPCThreadState.h>
#include <binder/IPCThreadState.h>
#include <binder/IResultReceiver.h>
#include <binder/IResultReceiver.h>
#include <binder/Stability.h>
#include <cutils/compiler.h>
#include <cutils/compiler.h>
#include <utils/Log.h>
#include <utils/Log.h>


@@ -213,14 +214,22 @@ status_t BpBinder::transact(
{
{
    // Once a binder has died, it will never come back to life.
    // Once a binder has died, it will never come back to life.
    if (mAlive) {
    if (mAlive) {
        // user transactions require a given stability level
        // Cannot add requirement w/o SM update
        // if (code >= FIRST_CALL_TRANSACTION && code <= LAST_CALL_TRANSACTION) {
        //     using android::internal::Stability;

        //     auto stability = Stability::get(this);

        //     if (CC_UNLIKELY(!Stability::check(stability, Stability::kLocalStability))) {
        //         return BAD_TYPE;
        //     }
        // }

        status_t status = IPCThreadState::self()->transact(
        status_t status = IPCThreadState::self()->transact(
            mHandle, code, data, reply, flags);
            mHandle, code, data, reply, flags);
        if (status == DEAD_OBJECT) mAlive = 0;
        if (status == DEAD_OBJECT) mAlive = 0;


        if (reply != nullptr) {
            reply->setTransactingBinder(this);
        }

        return status;
        return status;
    }
    }


+3 −12
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@
#include <binder/IPCThreadState.h>
#include <binder/IPCThreadState.h>
#include <binder/Parcel.h>
#include <binder/Parcel.h>
#include <binder/ProcessState.h>
#include <binder/ProcessState.h>
#include <binder/Stability.h>
#include <binder/Status.h>
#include <binder/Status.h>
#include <binder/TextOutput.h>
#include <binder/TextOutput.h>


@@ -167,11 +168,10 @@ static void release_object(const sp<ProcessState>& proc,
status_t Parcel::finishFlattenBinder(
status_t Parcel::finishFlattenBinder(
    const sp<IBinder>& /*binder*/, const flat_binder_object& flat)
    const sp<IBinder>& /*binder*/, const flat_binder_object& flat)
{
{
    // internal::Stability::tryMarkCompilationUnit(binder.get());

    status_t status = writeObject(flat, false);
    status_t status = writeObject(flat, false);
    if (status != OK) return status;
    if (status != OK) return status;


    // internal::Stability::tryMarkCompilationUnit(binder.get());
    // Cannot change wire protocol w/o SM update
    // Cannot change wire protocol w/o SM update
    // return writeInt32(internal::Stability::get(binder.get()));
    // return writeInt32(internal::Stability::get(binder.get()));
    return OK;
    return OK;
@@ -185,10 +185,6 @@ status_t Parcel::finishUnflattenBinder(
    // status_t status = readInt32(&stability);
    // status_t status = readInt32(&stability);
    // if (status != OK) return status;
    // if (status != OK) return status;


    // if (binder != nullptr && !internal::Stability::check(stability, mRequiredStability)) {
    //     return BAD_TYPE;
    // }

    // status = internal::Stability::set(binder.get(), stability, true /*log*/);
    // status = internal::Stability::set(binder.get(), stability, true /*log*/);
    // if (status != OK) return status;
    // if (status != OK) return status;


@@ -356,10 +352,6 @@ status_t Parcel::setDataCapacity(size_t size)
    return NO_ERROR;
    return NO_ERROR;
}
}


void Parcel::setTransactingBinder(const sp<IBinder>& binder) const {
    mRequiredStability = internal::Stability::get(binder.get());
}

status_t Parcel::setData(const uint8_t* buffer, size_t len)
status_t Parcel::setData(const uint8_t* buffer, size_t len)
{
{
    if (len > INT32_MAX) {
    if (len > INT32_MAX) {
@@ -2615,10 +2607,9 @@ void Parcel::initState()
    mObjectsCapacity = 0;
    mObjectsCapacity = 0;
    mNextObjectHint = 0;
    mNextObjectHint = 0;
    mObjectsSorted = false;
    mObjectsSorted = false;
    mAllowFds = true;
    mHasFds = false;
    mHasFds = false;
    mFdsKnown = true;
    mFdsKnown = true;
    mRequiredStability = internal::Stability::UNDECLARED;
    mAllowFds = true;
    mOwner = nullptr;
    mOwner = nullptr;
    mOpenAshmemSize = 0;
    mOpenAshmemSize = 0;


+8 −1
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@
#include <binder/BpBinder.h>
#include <binder/BpBinder.h>
#include <binder/IPCThreadState.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/IServiceManager.h>
#include <binder/Stability.h>
#include <cutils/atomic.h>
#include <cutils/atomic.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <utils/String8.h>
#include <utils/String8.h>
@@ -109,7 +110,13 @@ sp<ProcessState> ProcessState::selfOrNull()


sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/)
sp<IBinder> ProcessState::getContextObject(const sp<IBinder>& /*caller*/)
{
{
    return getStrongProxyForHandle(0);
    sp<IBinder> context = getStrongProxyForHandle(0);

    // The root object is special since we get it directly from the driver, it is never
    // written by Parcell::writeStrongBinder.
    internal::Stability::tryMarkCompilationUnit(context.get());

    return context;
}
}


void ProcessState::startThreadPool()
void ProcessState::startThreadPool()
+8 −3
Original line number Original line Diff line number Diff line
@@ -32,6 +32,11 @@ void Stability::debugLogStability(const std::string& tag, const sp<IBinder>& bin
    ALOGE("%s: stability is %s", tag.c_str(), stabilityString(get(binder.get())).c_str());
    ALOGE("%s: stability is %s", tag.c_str(), stabilityString(get(binder.get())).c_str());
}
}


void Stability::markVndk(IBinder* binder) {
    status_t result = set(binder, Level::VENDOR, true /*log*/);
    LOG_ALWAYS_FATAL_IF(result != OK, "Should only mark known object.");
}

void Stability::tryMarkCompilationUnit(IBinder* binder) {
void Stability::tryMarkCompilationUnit(IBinder* binder) {
    (void) set(binder, kLocalStability, false /*log*/);
    (void) set(binder, kLocalStability, false /*log*/);
}
}
@@ -95,9 +100,9 @@ bool Stability::check(int32_t provided, Level required) {
    }
    }


    if (!stable) {
    if (!stable) {
        ALOGE("Interface with %s cannot accept interface with %s.",
        ALOGE("Cannot do a user transaction on a %s binder in a %s context.",
            stabilityString(required).c_str(),
            stabilityString(provided).c_str(),
            stabilityString(provided).c_str());
            stabilityString(required).c_str());
    }
    }


    return stable;
    return stable;
Loading