diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-04-09 20:57:40 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-09 20:57:40 +0000 |
commit | 5d84fd8ba689800f30258f0a7572c5a0cbf0750f (patch) | |
tree | 65dc6b03986d4a5ebbbb351fcf7fe9642276a176 | |
parent | 3bd01f6482036ff0a6779e60d7a36c83ff81ed33 (diff) | |
parent | 77112778b47b23d901ccf67218d9fee297821b8c (diff) | |
download | native-5d84fd8ba689800f30258f0a7572c5a0cbf0750f.tar.gz |
Merge "libbinder: Add internal API to RpcServerTrusty for Rust" into main
-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, |