diff options
author | Andrei Homescu <ahomescu@google.com> | 2024-03-28 05:26:23 +0000 |
---|---|---|
committer | Andrei Homescu <ahomescu@google.com> | 2024-04-08 22:57:24 +0000 |
commit | 77112778b47b23d901ccf67218d9fee297821b8c (patch) | |
tree | 08a26b59fef9189de141e8dfcdd8238d84077b5f | |
parent | e16986ea78bfbdf7be7390677b21d0f51768bd8e (diff) | |
download | native-77112778b47b23d901ccf67218d9fee297821b8c.tar.gz |
libbinder: Add internal API to RpcServerTrusty for Rust
Add an internal API for the tipc connection handlers
that we can plug into the Rust service implementation.
Bug: 242243245
Test: m libbinder_on_trusty_mock
Test: trusty/vendor/google/aosp/scripts/build.py \
--test "boot-test:com.android.trusty.binderRpcTest" \
qemu-generic-arm64-test-debug
Change-Id: I667c2f8dfc495ece5f9b1309b124737e30e82909
-rw-r--r-- | libs/binder/trusty/RpcServerTrusty.cpp | 27 | ||||
-rw-r--r-- | libs/binder/trusty/include/binder/RpcServerTrusty.h | 17 |
2 files changed, 35 insertions, 9 deletions
diff --git a/libs/binder/trusty/RpcServerTrusty.cpp b/libs/binder/trusty/RpcServerTrusty.cpp index 1f857a0edb..17919c2a25 100644 --- a/libs/binder/trusty/RpcServerTrusty.cpp +++ b/libs/binder/trusty/RpcServerTrusty.cpp @@ -60,7 +60,7 @@ sp<RpcServerTrusty> RpcServerTrusty::make( RpcServerTrusty::RpcServerTrusty(std::unique_ptr<RpcTransportCtx> ctx, std::string&& portName, std::shared_ptr<const PortAcl>&& portAcl, size_t msgMaxSize) - : mRpcServer(sp<RpcServer>::make(std::move(ctx))), + : mRpcServer(makeRpcServer(std::move(ctx))), mPortName(std::move(portName)), mPortAcl(std::move(portAcl)) { mTipcPort.name = mPortName.c_str(); @@ -68,10 +68,6 @@ RpcServerTrusty::RpcServerTrusty(std::unique_ptr<RpcTransportCtx> ctx, std::stri mTipcPort.msg_queue_len = 6; // Three each way mTipcPort.priv = this; - // TODO(b/266741352): follow-up to prevent needing this in the future - // Trusty needs to be set to the latest stable version that is in prebuilts there. - LOG_ALWAYS_FATAL_IF(!mRpcServer->setProtocolVersion(0)); - if (mPortAcl) { // Initialize the array of pointers to uuids. // The pointers in mUuidPtrs should stay valid across moves of @@ -101,8 +97,13 @@ RpcServerTrusty::RpcServerTrusty(std::unique_ptr<RpcTransportCtx> ctx, std::stri int RpcServerTrusty::handleConnect(const tipc_port* port, handle_t chan, const uuid* peer, void** ctx_p) { auto* server = reinterpret_cast<RpcServerTrusty*>(const_cast<void*>(port->priv)); - server->mRpcServer->mShutdownTrigger = FdTrigger::make(); - server->mRpcServer->mConnectingThreads[rpc_this_thread::get_id()] = RpcMaybeThread(); + return handleConnectInternal(server->mRpcServer.get(), chan, peer, ctx_p); +} + +int RpcServerTrusty::handleConnectInternal(RpcServer* rpcServer, handle_t chan, const uuid* peer, + void** ctx_p) { + rpcServer->mShutdownTrigger = FdTrigger::make(); + rpcServer->mConnectingThreads[rpc_this_thread::get_id()] = RpcMaybeThread(); int rc = NO_ERROR; auto joinFn = [&](sp<RpcSession>&& session, RpcSession::PreJoinSetupResult&& result) { @@ -138,13 +139,17 @@ int RpcServerTrusty::handleConnect(const tipc_port* port, handle_t chan, const u std::array<uint8_t, RpcServer::kRpcAddressSize> addr; constexpr size_t addrLen = sizeof(*peer); memcpy(addr.data(), peer, addrLen); - RpcServer::establishConnection(sp(server->mRpcServer), std::move(transportFd), addr, addrLen, - joinFn); + RpcServer::establishConnection(sp<RpcServer>::fromExisting(rpcServer), std::move(transportFd), + addr, addrLen, joinFn); return rc; } int RpcServerTrusty::handleMessage(const tipc_port* /*port*/, handle_t /*chan*/, void* ctx) { + return handleMessageInternal(ctx); +} + +int RpcServerTrusty::handleMessageInternal(void* ctx) { auto* channelContext = reinterpret_cast<ChannelContext*>(ctx); LOG_ALWAYS_FATAL_IF(channelContext == nullptr, "bad state: message received on uninitialized channel"); @@ -162,6 +167,10 @@ int RpcServerTrusty::handleMessage(const tipc_port* /*port*/, handle_t /*chan*/, } void RpcServerTrusty::handleDisconnect(const tipc_port* /*port*/, handle_t /*chan*/, void* ctx) { + return handleDisconnectInternal(ctx); +} + +void RpcServerTrusty::handleDisconnectInternal(void* ctx) { auto* channelContext = reinterpret_cast<ChannelContext*>(ctx); if (channelContext == nullptr) { // Connections marked "incoming" (outgoing from the server's side) diff --git a/libs/binder/trusty/include/binder/RpcServerTrusty.h b/libs/binder/trusty/include/binder/RpcServerTrusty.h index f35d6c2252..bd1d90f588 100644 --- a/libs/binder/trusty/include/binder/RpcServerTrusty.h +++ b/libs/binder/trusty/include/binder/RpcServerTrusty.h @@ -88,6 +88,18 @@ private: explicit RpcServerTrusty(std::unique_ptr<RpcTransportCtx> ctx, std::string&& portName, std::shared_ptr<const PortAcl>&& portAcl, size_t msgMaxSize); + // Internal helper that creates the RpcServer. + // This is used both from here and Rust. + static sp<RpcServer> makeRpcServer(std::unique_ptr<RpcTransportCtx> ctx) { + auto rpcServer = sp<RpcServer>::make(std::move(ctx)); + + // TODO(b/266741352): follow-up to prevent needing this in the future + // Trusty needs to be set to the latest stable version that is in prebuilts there. + LOG_ALWAYS_FATAL_IF(!rpcServer->setProtocolVersion(0)); + + return rpcServer; + } + // The Rpc-specific context maintained for every open TIPC channel. struct ChannelContext { sp<RpcSession> session; @@ -99,6 +111,11 @@ private: static void handleDisconnect(const tipc_port* port, handle_t chan, void* ctx); static void handleChannelCleanup(void* ctx); + static int handleConnectInternal(RpcServer* rpcServer, handle_t chan, const uuid* peer, + void** ctx_p); + static int handleMessageInternal(void* ctx); + static void handleDisconnectInternal(void* ctx); + static constexpr tipc_srv_ops kTipcOps = { .on_connect = &handleConnect, .on_message = &handleMessage, |