Loading libs/binder/Binder.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ class BBinder::Extras public: // unlocked objects bool mRequestingSid = false; bool mInheritRt = false; sp<IBinder> mExtension; int mPolicy = SCHED_NORMAL; int mPriority = 0; Loading Loading @@ -327,6 +328,27 @@ int BBinder::getMinSchedulerPriority() { return e->mPriority; } bool BBinder::isInheritRt() { Extras* e = mExtras.load(std::memory_order_acquire); return e && e->mInheritRt; } void BBinder::setInheritRt(bool inheritRt) { Extras* e = mExtras.load(std::memory_order_acquire); if (!e) { if (!inheritRt) { return; } e = getOrCreateExtras(); if (!e) return; // out of memory } e->mInheritRt = inheritRt; } pid_t BBinder::getDebugPid() { return getpid(); } Loading libs/binder/Parcel.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -222,6 +222,9 @@ status_t Parcel::flattenBinder(const sp<IBinder>& binder) if (local->isRequestingSid()) { obj.flags |= FLAT_BINDER_FLAG_TXN_SECURITY_CTX; } if (local->isInheritRt()) { obj.flags |= FLAT_BINDER_FLAG_INHERIT_RT; } obj.hdr.type = BINDER_TYPE_BINDER; obj.binder = reinterpret_cast<uintptr_t>(local->getWeakRefs()); obj.cookie = reinterpret_cast<uintptr_t>(local); Loading libs/binder/include/binder/Binder.h +5 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,11 @@ public: int getMinSchedulerPolicy(); int getMinSchedulerPriority(); // Whether realtime scheduling policies are inherited. bool isInheritRt(); // This must be called before the object is sent to another process. Not thread safe. void setInheritRt(bool inheritRt); pid_t getDebugPid(); protected: Loading libs/binder/tests/binderLibTest.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ #include <binder/IServiceManager.h> #include <private/binder/binder_module.h> #include <linux/sched.h> #include <sys/epoll.h> #include <sys/prctl.h> Loading @@ -53,6 +54,7 @@ static char binderserverarg[] = "--binderserver"; static constexpr int kSchedPolicy = SCHED_RR; static constexpr int kSchedPriority = 7; static constexpr int kSchedPriorityMore = 8; static String16 binderLibTestServiceName = String16("test.binderLib"); Loading Loading @@ -1088,6 +1090,25 @@ TEST_F(BinderLibTest, SchedPolicySet) { EXPECT_EQ(kSchedPriority, priority); } TEST_F(BinderLibTest, InheritRt) { sp<IBinder> server = addServer(); ASSERT_TRUE(server != nullptr); const struct sched_param param { .sched_priority = kSchedPriorityMore, }; EXPECT_EQ(0, sched_setscheduler(getpid(), SCHED_RR, ¶m)); Parcel data, reply; status_t ret = server->transact(BINDER_LIB_TEST_GET_SCHEDULING_POLICY, data, &reply); EXPECT_EQ(NO_ERROR, ret); int policy = reply.readInt32(); int priority = reply.readInt32(); EXPECT_EQ(kSchedPolicy, policy & (~SCHED_RESET_ON_FORK)); EXPECT_EQ(kSchedPriorityMore, priority); } TEST_F(BinderLibTest, VectorSent) { Parcel data, reply; Loading Loading @@ -1460,6 +1481,8 @@ int run_server(int index, int readypipefd, bool usePoll) testService->setMinSchedulerPolicy(kSchedPolicy, kSchedPriority); testService->setInheritRt(true); /* * Normally would also contain functionality as well, but we are only * testing the extension mechanism. Loading libs/binder/tests/fuzzers/BinderFuzzFunctions.h +9 −2 Original line number Diff line number Diff line Loading @@ -37,8 +37,8 @@ static const std::vector<std::function<void(FuzzedDataProvider*, const sp<BBinde bbinder->isRequestingSid(); }, [](FuzzedDataProvider* fdp, const sp<BBinder>& bbinder) -> void { bool request_sid = fdp->ConsumeBool(); bbinder->setRequestingSid(request_sid); bool requestSid = fdp->ConsumeBool(); bbinder->setRequestingSid(requestSid); }, [](FuzzedDataProvider*, const sp<BBinder>& bbinder) -> void { bbinder->getExtension(); Loading @@ -63,6 +63,13 @@ static const std::vector<std::function<void(FuzzedDataProvider*, const sp<BBinde [](FuzzedDataProvider*, const sp<BBinder>& bbinder) -> void { bbinder->getMinSchedulerPriority(); }, [](FuzzedDataProvider* fdp, const sp<BBinder>& bbinder) -> void { bool inheritRt = fdp->ConsumeBool(); bbinder->setInheritRt(inheritRt); }, [](FuzzedDataProvider*, const sp<BBinder>& bbinder) -> void { bbinder->isInheritRt(); }, [](FuzzedDataProvider*, const sp<BBinder>& bbinder) -> void { bbinder->getDebugPid(); }}; Loading Loading
libs/binder/Binder.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ class BBinder::Extras public: // unlocked objects bool mRequestingSid = false; bool mInheritRt = false; sp<IBinder> mExtension; int mPolicy = SCHED_NORMAL; int mPriority = 0; Loading Loading @@ -327,6 +328,27 @@ int BBinder::getMinSchedulerPriority() { return e->mPriority; } bool BBinder::isInheritRt() { Extras* e = mExtras.load(std::memory_order_acquire); return e && e->mInheritRt; } void BBinder::setInheritRt(bool inheritRt) { Extras* e = mExtras.load(std::memory_order_acquire); if (!e) { if (!inheritRt) { return; } e = getOrCreateExtras(); if (!e) return; // out of memory } e->mInheritRt = inheritRt; } pid_t BBinder::getDebugPid() { return getpid(); } Loading
libs/binder/Parcel.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -222,6 +222,9 @@ status_t Parcel::flattenBinder(const sp<IBinder>& binder) if (local->isRequestingSid()) { obj.flags |= FLAT_BINDER_FLAG_TXN_SECURITY_CTX; } if (local->isInheritRt()) { obj.flags |= FLAT_BINDER_FLAG_INHERIT_RT; } obj.hdr.type = BINDER_TYPE_BINDER; obj.binder = reinterpret_cast<uintptr_t>(local->getWeakRefs()); obj.cookie = reinterpret_cast<uintptr_t>(local); Loading
libs/binder/include/binder/Binder.h +5 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,11 @@ public: int getMinSchedulerPolicy(); int getMinSchedulerPriority(); // Whether realtime scheduling policies are inherited. bool isInheritRt(); // This must be called before the object is sent to another process. Not thread safe. void setInheritRt(bool inheritRt); pid_t getDebugPid(); protected: Loading
libs/binder/tests/binderLibTest.cpp +23 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ #include <binder/IServiceManager.h> #include <private/binder/binder_module.h> #include <linux/sched.h> #include <sys/epoll.h> #include <sys/prctl.h> Loading @@ -53,6 +54,7 @@ static char binderserverarg[] = "--binderserver"; static constexpr int kSchedPolicy = SCHED_RR; static constexpr int kSchedPriority = 7; static constexpr int kSchedPriorityMore = 8; static String16 binderLibTestServiceName = String16("test.binderLib"); Loading Loading @@ -1088,6 +1090,25 @@ TEST_F(BinderLibTest, SchedPolicySet) { EXPECT_EQ(kSchedPriority, priority); } TEST_F(BinderLibTest, InheritRt) { sp<IBinder> server = addServer(); ASSERT_TRUE(server != nullptr); const struct sched_param param { .sched_priority = kSchedPriorityMore, }; EXPECT_EQ(0, sched_setscheduler(getpid(), SCHED_RR, ¶m)); Parcel data, reply; status_t ret = server->transact(BINDER_LIB_TEST_GET_SCHEDULING_POLICY, data, &reply); EXPECT_EQ(NO_ERROR, ret); int policy = reply.readInt32(); int priority = reply.readInt32(); EXPECT_EQ(kSchedPolicy, policy & (~SCHED_RESET_ON_FORK)); EXPECT_EQ(kSchedPriorityMore, priority); } TEST_F(BinderLibTest, VectorSent) { Parcel data, reply; Loading Loading @@ -1460,6 +1481,8 @@ int run_server(int index, int readypipefd, bool usePoll) testService->setMinSchedulerPolicy(kSchedPolicy, kSchedPriority); testService->setInheritRt(true); /* * Normally would also contain functionality as well, but we are only * testing the extension mechanism. Loading
libs/binder/tests/fuzzers/BinderFuzzFunctions.h +9 −2 Original line number Diff line number Diff line Loading @@ -37,8 +37,8 @@ static const std::vector<std::function<void(FuzzedDataProvider*, const sp<BBinde bbinder->isRequestingSid(); }, [](FuzzedDataProvider* fdp, const sp<BBinder>& bbinder) -> void { bool request_sid = fdp->ConsumeBool(); bbinder->setRequestingSid(request_sid); bool requestSid = fdp->ConsumeBool(); bbinder->setRequestingSid(requestSid); }, [](FuzzedDataProvider*, const sp<BBinder>& bbinder) -> void { bbinder->getExtension(); Loading @@ -63,6 +63,13 @@ static const std::vector<std::function<void(FuzzedDataProvider*, const sp<BBinde [](FuzzedDataProvider*, const sp<BBinder>& bbinder) -> void { bbinder->getMinSchedulerPriority(); }, [](FuzzedDataProvider* fdp, const sp<BBinder>& bbinder) -> void { bool inheritRt = fdp->ConsumeBool(); bbinder->setInheritRt(inheritRt); }, [](FuzzedDataProvider*, const sp<BBinder>& bbinder) -> void { bbinder->isInheritRt(); }, [](FuzzedDataProvider*, const sp<BBinder>& bbinder) -> void { bbinder->getDebugPid(); }}; Loading