diff options
author | 2022-08-03 21:19:11 +0000 | |
---|---|---|
committer | 2022-08-26 08:41:15 +0000 | |
commit | 49d74cbbbd75ade6b7002cad417bd168b9cd0f0e (patch) | |
tree | ee9cea6b677f66d60a89712392430895249bed89 /libs/binder/FdTrigger.cpp | |
parent | ec646539825294a4f33f94857d224a1946fb540f (diff) |
libbinder : Adding new type TransportFd
Adding a new struct TransportFd which will contain unique_fd and
polling state of file descriptor. This will be useful in detecting
if all the descriptors are being polled. unique_fd and borrowed_fd
are replaced in these changes.
Test: m
Test: m libbinder binderRpcTest && atest binderRpcTest
Test: trusty/vendor/google/aosp/scripts/build.py --test
"boot-test:com.android.trusty.binder.test" qemu-generic-arm64-test-debug
Bug: 218518615
Change-Id: Id108806b98184582e5d93186b3b1884017c441ea
Diffstat (limited to 'libs/binder/FdTrigger.cpp')
-rw-r--r-- | libs/binder/FdTrigger.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libs/binder/FdTrigger.cpp b/libs/binder/FdTrigger.cpp index d123fd1f2b..256d587866 100644 --- a/libs/binder/FdTrigger.cpp +++ b/libs/binder/FdTrigger.cpp @@ -22,6 +22,7 @@ #include <poll.h> #include <android-base/macros.h> +#include <android-base/scopeguard.h> #include "RpcState.h" namespace android { @@ -53,25 +54,34 @@ bool FdTrigger::isTriggered() { #endif } -status_t FdTrigger::triggerablePoll(base::borrowed_fd fd, int16_t event) { +status_t FdTrigger::triggerablePoll(const android::TransportFd& transportFd, int16_t event) { #ifdef BINDER_RPC_SINGLE_THREADED if (mTriggered) { return DEAD_OBJECT; } #endif - LOG_ALWAYS_FATAL_IF(event == 0, "triggerablePoll %d with event 0 is not allowed", fd.get()); + LOG_ALWAYS_FATAL_IF(event == 0, "triggerablePoll %d with event 0 is not allowed", + transportFd.fd.get()); pollfd pfd[]{ - {.fd = fd.get(), .events = static_cast<int16_t>(event), .revents = 0}, + {.fd = transportFd.fd.get(), .events = static_cast<int16_t>(event), .revents = 0}, #ifndef BINDER_RPC_SINGLE_THREADED {.fd = mRead.get(), .events = 0, .revents = 0}, #endif }; + + LOG_ALWAYS_FATAL_IF(transportFd.isInPollingState() == true, + "Only one thread should be polling on Fd!"); + + transportFd.setPollingState(true); + auto pollingStateGuard = + android::base::make_scope_guard([&]() { transportFd.setPollingState(false); }); + int ret = TEMP_FAILURE_RETRY(poll(pfd, arraysize(pfd), -1)); if (ret < 0) { return -errno; } - LOG_ALWAYS_FATAL_IF(ret == 0, "poll(%d) returns 0 with infinite timeout", fd.get()); + LOG_ALWAYS_FATAL_IF(ret == 0, "poll(%d) returns 0 with infinite timeout", transportFd.fd.get()); // At least one FD has events. Check them. |