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

Commit b3395b54 authored by Aaron Okano's avatar Aaron Okano
Browse files

binder: Add method to enable RT inheritance for all Binders in process

It may be useful to enable RT inheritance for all Binders within a
process (for example, system_server). Today, if you want to do that, you
need to call setInheritRt for each new Binder. However, in a situation
where your process has a lot of services (ex: system_server) this needs
to be called in a lot of places, and it would be easy to miss one.

This change adds a feature to add a global flag that specifies that all
binders should have RT inheritance enabled, so rather than call
setInheritRt when creating each individual service, you can call
setGlobalInheritRt to make sure that every new service created
afterwards will get the inherit_rt flag.

Flag: android.server.allow_system_server_inherit_rt
bug: 397169625
Change-Id: Ic03d2cbc073e461505a435c94cfc083974e5f5a8
parent 3191383d
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -593,8 +593,9 @@ int BBinder::getMinSchedulerPriority() {

bool BBinder::isInheritRt() {
    Extras* e = mExtras.load(std::memory_order_acquire);

    return e && e->mInheritRt;
    // Return configured default value if it has not been overridden
    if (e == nullptr) return sGlobalInheritRt.load(std::memory_order_acquire);
    return e->mInheritRt;
}

void BBinder::setInheritRt(bool inheritRt) {
@@ -616,6 +617,12 @@ void BBinder::setInheritRt(bool inheritRt) {
    e->mInheritRt = inheritRt;
}

std::atomic<bool> BBinder::sGlobalInheritRt(false);

void BBinder::setGlobalInheritRt(bool enabled) {
    sGlobalInheritRt.store(enabled, std::memory_order_release);
}

pid_t BBinder::getDebugPid() {
#ifdef __linux__
    return getpid();
@@ -744,7 +751,7 @@ BBinder::~BBinder()
        if (isRequestingSid()) {
            ALOGW("Binder %p destroyed when requesting SID before being parceled.", this);
        }
        if (isInheritRt()) {
        if (sGlobalInheritRt.load(std::memory_order_acquire) != isInheritRt()) {
            ALOGW("Binder %p destroyed after setInheritRt before being parceled.", this);
        }
#ifdef __linux__
+7 −0
Original line number Diff line number Diff line
@@ -91,6 +91,11 @@ public:
    // This must be called before the object is sent to another process. Not thread safe.
    LIBBINDER_EXPORTED void setInheritRt(bool inheritRt);

    // Set default, overridden by setInheritRt. You must set this default early.
    // Any binder objects sent out of the process before this is called will
    // not use the updated value.
    LIBBINDER_EXPORTED static void setGlobalInheritRt(bool enabled);

    LIBBINDER_EXPORTED pid_t getDebugPid();

    // Whether this binder has been sent to another process.
@@ -124,6 +129,8 @@ private:
    [[nodiscard]] status_t startRecordingTransactions(const Parcel& data);
    [[nodiscard]] status_t stopRecordingTransactions();

    static std::atomic<bool> sGlobalInheritRt;

    std::atomic<Extras*> mExtras;

    friend ::android::internal::Stability;