Loading libs/binder/RpcServer.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ void RpcServer::setRootObjectWeak(const wp<IBinder>& binder) { mRootObjectWeak = binder; } void RpcServer::setPerSessionRootObject( std::function<sp<IBinder>(const void*, size_t)>&& makeObject) { std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& makeObject) { RpcMutexLockGuard _l(mLock); mRootObject.clear(); mRootObjectWeak.clear(); Loading Loading @@ -515,7 +515,8 @@ void RpcServer::establishConnection( // if null, falls back to server root sp<IBinder> sessionSpecificRoot; if (server->mRootObjectFactory != nullptr) { sessionSpecificRoot = server->mRootObjectFactory(addr.data(), addrLen); sessionSpecificRoot = server->mRootObjectFactory(wp<RpcSession>(session), addr.data(), addrLen); if (sessionSpecificRoot == nullptr) { ALOGE("Warning: server returned null from root object factory"); } Loading libs/binder/include/binder/RpcServer.h +12 −8 Original line number Diff line number Diff line Loading @@ -163,14 +163,18 @@ public: * Allows a root object to be created for each session. * * Takes one argument: a callable that is invoked once per new session. * The callable takes two arguments: a type-erased pointer to an OS- and * transport-specific address structure, e.g., sockaddr_vm for vsock, and * an integer representing the size in bytes of that structure. The * callable should validate the size, then cast the type-erased pointer * to a pointer to the actual type of the address, e.g., const void* to * const sockaddr_vm*. * The callable takes three arguments: * - a weak pointer to the session. If you want to hold onto this in the root object, then * you should keep a weak pointer, and promote it when needed. For instance, if you refer * to this from the root object, then you could get ahold of transport-specific information. * - a type-erased pointer to an OS- and transport-specific address structure, e.g., * sockaddr_vm for vsock * - an integer representing the size in bytes of that structure. The callable should * validate the size, then cast the type-erased pointer to a pointer to the actual type of the * address, e.g., const void* to const sockaddr_vm*. */ void setPerSessionRootObject(std::function<sp<IBinder>(const void*, size_t)>&& object); void setPerSessionRootObject( std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& object); sp<IBinder> getRootObject(); /** Loading Loading @@ -272,7 +276,7 @@ private: sp<IBinder> mRootObject; wp<IBinder> mRootObjectWeak; std::function<sp<IBinder>(const void*, size_t)> mRootObjectFactory; std::function<sp<IBinder>(wp<RpcSession>, const void*, size_t)> mRootObjectFactory; std::function<bool(const void*, size_t)> mConnectionFilter; std::function<void(base::borrowed_fd)> mServerSocketModifier; std::map<std::vector<uint8_t>, sp<RpcSession>> mSessions; Loading libs/binder/tests/binderRpcTestService.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -164,7 +164,12 @@ int main(int argc, char* argv[]) { } } server->setPerSessionRootObject([&](const void* addrPtr, size_t len) { server->setPerSessionRootObject([&](wp<RpcSession> session, const void* addrPtr, size_t len) { { sp<RpcSession> spSession = session.promote(); CHECK_NE(nullptr, spSession.get()); } // UNIX sockets with abstract addresses return // sizeof(sa_family_t)==2 in addrlen CHECK_GE(len, sizeof(sa_family_t)); Loading libs/binder/tests/binderRpcTestServiceTrusty.cpp +9 −8 Original line number Diff line number Diff line Loading @@ -93,7 +93,8 @@ int main(void) { if (!serverInfo.server->setProtocolVersion(serverVersion)) { return EXIT_FAILURE; } serverInfo.server->setPerSessionRootObject([=](const void* /*addrPtr*/, size_t /*len*/) { serverInfo.server->setPerSessionRootObject( [=](wp<RpcSession> /*session*/, const void* /*addrPtr*/, size_t /*len*/) { auto service = sp<MyBinderRpcTestTrusty>::make(); // Assign a unique connection identifier to service->port so // getClientPort returns a unique value per connection Loading libs/binder/trusty/include/binder/RpcServerTrusty.h +2 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,8 @@ public: } void setRootObject(const sp<IBinder>& binder) { mRpcServer->setRootObject(binder); } void setRootObjectWeak(const wp<IBinder>& binder) { mRpcServer->setRootObjectWeak(binder); } void setPerSessionRootObject(std::function<sp<IBinder>(const void*, size_t)>&& object) { void setPerSessionRootObject( std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& object) { mRpcServer->setPerSessionRootObject(std::move(object)); } sp<IBinder> getRootObject() { return mRpcServer->getRootObject(); } Loading Loading
libs/binder/RpcServer.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -154,7 +154,7 @@ void RpcServer::setRootObjectWeak(const wp<IBinder>& binder) { mRootObjectWeak = binder; } void RpcServer::setPerSessionRootObject( std::function<sp<IBinder>(const void*, size_t)>&& makeObject) { std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& makeObject) { RpcMutexLockGuard _l(mLock); mRootObject.clear(); mRootObjectWeak.clear(); Loading Loading @@ -515,7 +515,8 @@ void RpcServer::establishConnection( // if null, falls back to server root sp<IBinder> sessionSpecificRoot; if (server->mRootObjectFactory != nullptr) { sessionSpecificRoot = server->mRootObjectFactory(addr.data(), addrLen); sessionSpecificRoot = server->mRootObjectFactory(wp<RpcSession>(session), addr.data(), addrLen); if (sessionSpecificRoot == nullptr) { ALOGE("Warning: server returned null from root object factory"); } Loading
libs/binder/include/binder/RpcServer.h +12 −8 Original line number Diff line number Diff line Loading @@ -163,14 +163,18 @@ public: * Allows a root object to be created for each session. * * Takes one argument: a callable that is invoked once per new session. * The callable takes two arguments: a type-erased pointer to an OS- and * transport-specific address structure, e.g., sockaddr_vm for vsock, and * an integer representing the size in bytes of that structure. The * callable should validate the size, then cast the type-erased pointer * to a pointer to the actual type of the address, e.g., const void* to * const sockaddr_vm*. * The callable takes three arguments: * - a weak pointer to the session. If you want to hold onto this in the root object, then * you should keep a weak pointer, and promote it when needed. For instance, if you refer * to this from the root object, then you could get ahold of transport-specific information. * - a type-erased pointer to an OS- and transport-specific address structure, e.g., * sockaddr_vm for vsock * - an integer representing the size in bytes of that structure. The callable should * validate the size, then cast the type-erased pointer to a pointer to the actual type of the * address, e.g., const void* to const sockaddr_vm*. */ void setPerSessionRootObject(std::function<sp<IBinder>(const void*, size_t)>&& object); void setPerSessionRootObject( std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& object); sp<IBinder> getRootObject(); /** Loading Loading @@ -272,7 +276,7 @@ private: sp<IBinder> mRootObject; wp<IBinder> mRootObjectWeak; std::function<sp<IBinder>(const void*, size_t)> mRootObjectFactory; std::function<sp<IBinder>(wp<RpcSession>, const void*, size_t)> mRootObjectFactory; std::function<bool(const void*, size_t)> mConnectionFilter; std::function<void(base::borrowed_fd)> mServerSocketModifier; std::map<std::vector<uint8_t>, sp<RpcSession>> mSessions; Loading
libs/binder/tests/binderRpcTestService.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -164,7 +164,12 @@ int main(int argc, char* argv[]) { } } server->setPerSessionRootObject([&](const void* addrPtr, size_t len) { server->setPerSessionRootObject([&](wp<RpcSession> session, const void* addrPtr, size_t len) { { sp<RpcSession> spSession = session.promote(); CHECK_NE(nullptr, spSession.get()); } // UNIX sockets with abstract addresses return // sizeof(sa_family_t)==2 in addrlen CHECK_GE(len, sizeof(sa_family_t)); Loading
libs/binder/tests/binderRpcTestServiceTrusty.cpp +9 −8 Original line number Diff line number Diff line Loading @@ -93,7 +93,8 @@ int main(void) { if (!serverInfo.server->setProtocolVersion(serverVersion)) { return EXIT_FAILURE; } serverInfo.server->setPerSessionRootObject([=](const void* /*addrPtr*/, size_t /*len*/) { serverInfo.server->setPerSessionRootObject( [=](wp<RpcSession> /*session*/, const void* /*addrPtr*/, size_t /*len*/) { auto service = sp<MyBinderRpcTestTrusty>::make(); // Assign a unique connection identifier to service->port so // getClientPort returns a unique value per connection Loading
libs/binder/trusty/include/binder/RpcServerTrusty.h +2 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,8 @@ public: } void setRootObject(const sp<IBinder>& binder) { mRpcServer->setRootObject(binder); } void setRootObjectWeak(const wp<IBinder>& binder) { mRpcServer->setRootObjectWeak(binder); } void setPerSessionRootObject(std::function<sp<IBinder>(const void*, size_t)>&& object) { void setPerSessionRootObject( std::function<sp<IBinder>(wp<RpcSession> session, const void*, size_t)>&& object) { mRpcServer->setPerSessionRootObject(std::move(object)); } sp<IBinder> getRootObject() { return mRpcServer->getRootObject(); } Loading