summaryrefslogtreecommitdiff
path: root/libs/binder/RpcSession.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Binder unique_fdTomasz Wasilczyk2023-11-171-4/+4
| | | | | | Test: mma Bug: 302723053 Change-Id: I52f14cadb027b3f854946d5315dce3d23aa21b19
* Use unique_fd::ok() instead of -1 comparisonTomasz Wasilczyk2023-11-141-2/+2
| | | | | | Test: mma Bug: 302723053 Change-Id: I744bdfe735624ad9f95a7d448919e7bd2e430098
* Revert^2 "Use std::unique_ptr instead of ScopeGuard"Tomasz Wasilczyk2023-11-041-3/+4
| | | | | | | | 25c1a3b8543dd1756308424dd65030f90bb7a99f Test: m Bug: 302723053 Change-Id: Id9355c10d78d0c55afb49f512b78bb0923fbc4f7
* Don't depend on libbase result.hTomasz Wasilczyk2023-11-031-4/+1
| | | | | | Test: mma Bug: 302723053 Change-Id: Iea797d6af825d58543ba899f6e712b27e48d859a
* Binder: migrate off libbase macrosTomasz Wasilczyk2023-11-031-2/+3
| | | | | | Test: mma Bug: 302723053 Change-Id: Ie7c13c324311f600d72bc8ecc4157ad6c46259a0
* Binder: don't depend on libutils headersTomasz Wasilczyk2023-10-311-1/+0
| | | | | | Bug: 302723053 Test: mma Change-Id: Id68a10a491e3db7f27ea2cbf843078544bb0ab85
* Revert "Use std::unique_ptr instead of ScopeGuard"Sebastian Pickl2023-10-301-4/+3
| | | | | | | | | | | | Revert submission 2780893 Reason for revert: breaking boot tests Bug: 308214260 Reverted changes: /q/submissionid:2780893 Change-Id: I7a4ee9a45583a8a1d4a33447de55c63e6ce9d42a
* Use std::unique_ptr instead of ScopeGuardTomasz Wasilczyk2023-10-271-3/+4
| | | | | | Bug: 302723053 Test: mma Change-Id: I27226885b8b5e771d675ba2d83d0a2e14551d13e
* Merge "Binder: Split OS to Android and Unix part, abstract GetThreadId out" ↵Tomasz Wasilczyk2023-10-161-5/+5
|\ | | | | | | into main
| * Binder: Split OS to Android and Unix part, abstract GetThreadId outTomasz Wasilczyk2023-10-161-5/+5
| | | | | | | | | | | | | | Bug: 302723053 Test: mma in binder folder Test: aosp/2616196 Change-Id: I73df8fc453df0edf496960853cb0004f1c3a6a43
* | Copy HexString to libbinderTomasz Wasilczyk2023-10-121-4/+2
|/ | | | | | Bug: 302723053 Test: mma Change-Id: I5c7a71a91b7dc95bfa0cd653eabe554bdd3f7812
* libbinder: RpcServer protocol version errorSteven Moreland2023-05-121-5/+1
| | | | | | | | | | | | Return an error if you set an invalid protocol version on an RpcServer. Previously, this would cause errors later down the line. Bug: 278946301 Test: binderRpcTest Change-Id: Id496f1d39b2a32ce775e585f7690ae59503dc3aa
* Merge "RPC Binder: disable Nagle's algorithm"Steven Moreland2023-03-081-0/+13
|\
| * RPC Binder: disable Nagle's algorithmSteven Moreland2023-03-071-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For some reason, I thought we did this - I thought it was incidental to some other API we used. RPC Binder is an RPC system, AND ONE WITH SYNCHRONOUS CALLS! It should not hold these packets. Bug: 271860373 Test: run inet cases before/after: binderRpcTest --gtest_filter="*PerSocket/BinderRpc.RepeatBinderNull/inet_socket_tls_clientV0_serverV4026531840_single_threaded_no_kernel*" before: 0m26.845s after: 0m12.271s Change-Id: Ib257b53cd2e4ca19041cdb5fd985be346e3fac5e
* | libbinder: finish outgoing thread->conn. renameSteven Moreland2023-03-041-10/+10
|/ | | | | | Fixes: 270374393 Test: N/A Change-Id: I026a8bb44b6e4f2863fb1971a38b8d67db36cfd8
* RPC Binder: setMaxOutgoing{Threads,Connections}Steven Moreland2023-03-011-2/+3
| | | | | | | | | | | | | | This API is updated to emphasize that it is placing a limit on the number of connections that will be started corresponding to threads in a remote pool. These connections won't actually correspond to threads in the process that this API is called. Documentation has also been updated to clarify a few questions from an internal discussion forum. Fixes: 270374393 Test: binderRpcTest Change-Id: Ia0d9f0d0f42f58a2c63bf506476b33985f091a34
* Merge "libbinder: rpc java detach error code"Steven Moreland2022-10-251-2/+3
|\
| * libbinder: rpc java detach error codeSteven Moreland2022-10-241-2/+3
| | | | | | | | | | | | Bug: N/A Change-Id: I074cefd859f1967a662bdda71f285a60a4bc3cad Test: N/A
* | Remove libandroid_runtime_vm_headers dependency from libbinderJeongik Cha2022-10-201-1/+1
|/ | | | | | | | Instead, add extern C definition in the RpcSession.cpp directly Bug: 254459965 Test: m libbinder Change-Id: I093f0952f12d575b4a517314c5dadef5b7125a62
* libbinder: no temp rpc sess leak w spurious wakeupSteven Moreland2022-10-101-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | RpcSession incoming threads continued to hold an RpcSession instance after they set the shutdown condition (removing the associated 1:1 thread connection object from RpcSession's mConnections object). Since the shutdown condition must include cleaning up RpcSession, we cannot delay or remove clearing the associated connections. Instead, a new explicit shutdown condition is added, which does not restrict the manipulation of the session object. Interestingly, this issue was blocking several changes on-and-off for a few weeks. Though, test hub doesn't show it failing at all. I couldn't reproduce it locally even with 5 days (24hr/day) and one of these failing tests running in a tight loop, with builds running in the background (devinmoore@ reported a local failure with a build running). I submitted several changes to debug this, and one of them (that dumped backtraces), should have caught it, except the race is just too rare. When we have this situation: a retrospectively benign problem causing a big failure, the obvious question to ask is, is the test too brittle? No! If this is the sensitivity at which it finds a bug, we can hardly imagine an error going unnoticed here. Only if this situation repeated several times or some of these issues became too plenty to maintain would I think that we needed to "tone down the tests". Finally, how did this get fixed: dump every incStrong backtrace in RpcSession and investigate all the code that is responsible for maintaining those sp<>s. Wheeee :) Bug: 244325464 Test: binderRpcTest Change-Id: I76ac8f21900d6ce095a1acfb246ca7acf1591e0b
* RpcBinder: Add AF_UNIX socketpair transportDavid Brazdil2022-10-071-0/+29
| | | | | | | | | | | | | | | | | | | Add support for running RpcBinder over unnamed Unix domain sockets created by socketpair(). This is useful e.g. between parent/child processes. The implementation uses the initial socket pair only to create more socket pairs for individual connections. This creates a natural mapping to syscalls used on sockets bound to an address: socket() socketpair() bind() n/a (preconnected) connect() sendmsg() listen() recvmsg() Bug: 250685929 Test: atest binderRpcTest Change-Id: Id4ff3946ddcfefe3592eb1149c61582f7369aa29
* libbinder : Avoid waiting in binder_rpc_fuzzerPawan2022-08-301-0/+20
| | | | | | | | | | | | Introducing new APIs in RpcServer and RpcSession to check polling state of file descriptor. Removing fixed wait time in binder_rpc_fuzzer. Test: m binder_rpc_fuzzer && $ANDROID_HOST_OUT/fuzz/x86_64/binder_rpc_fuzzer/binder_rpc_fuzzer Bug: 218518615 Change-Id: Ied82cd9c16514761a489731488924274a17053a6
* libbinder : Renaming TransportFd to RpcTransportFdPawan2022-08-261-4/+4
| | | | | | | Test: m Test: m libbinder binderRpcTest Bug: 218518615 Change-Id: I822bdb751f68c83e1b10c5fd16c9d8439646b771
* Merge "libbinder : Adding new type TransportFd"Pawan Wagh2022-08-261-10/+17
|\
| * libbinder : Adding new type TransportFdPawan2022-08-261-10/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | libbinder: add makeDefaultRpcTransportCtxFactoryAndrei Homescu2022-08-251-1/+1
|/ | | | | | | | | | | | Add a new OS-specific function that creates a new instance of the default RpcTransportCtxFactory. This is needed because Android and Trusty have different default transports: RpcTransportRaw and RpcTransportTipcTrusty, respectively. Bug: 230135749 Test: presubmit Change-Id: I4abd443fe9a08c1fa0cc41dfca7ef1cdb69fe0fb
* libbinder: clear RpcSession::mStartedSetup in case of errorAndrei Homescu2022-08-231-0/+3
| | | | | | | | | | Clear the mStartedSetup flag in case of error return from RpcSession::setupClient and its callees so that the setup can be retried and/or the RpcSession reused. Bug: 242473043 Test: m Change-Id: I4fa99ab9eb136756ee7344c73f2b3f57a7412e3f
* libbinder: allow multiple outgoing threads for single-threadedAndrei Homescu2022-08-051-17/+26
| | | | | | | | | | | | | | | | Additional outgoing threads in a single-threaded client do not actually require more threads, so they should be safe to enable. We check the number of incoming threads per RpcSession instead, since those create actual OS threads. Prevents a TOCTTOU issue between calls to setup*Client() and setMaxIncomingThreads() by adding a new mStartedSetup variable that is set early during setupClient, and any calls to RpcSession setters are fatal failures after that point. Bug: 224644083 Test: atest binderRpcTest* Change-Id: Id0ce2cda63e781ecfba86180f3c523be9044d408
* Add linkToDeath support for RPC binder so a client can act on disconnectDevin Moore2022-07-201-0/+5
| | | | | | | | | | This requires an incoming thread to be listening to the connection in order to be notified. Test: atest binderRpcTest Test: atest binderRpcTestSingleThreaded Bug: 182939380 Change-Id: I3746de6e8cff99bb267867c5dc60a6815b19fb92
* libbinder: separate OS-specific code from Utils.cppAndrei Homescu2022-07-081-0/+1
| | | | | | | | | | | Separate the OS-specific functions setNonBlocking and getRandomBytes from Utils.cpp into a separate OS-specific OS.cpp file that other operating systems can override at build time. Bug: 224644083 Test: build Trusty Change-Id: I2703fb81d4370b5f6264556ae57fdddb0573971a
* libbinder: add build option for single-threaded RPCAndrei Homescu2022-07-011-31/+36
| | | | | | | | | | Trusty does not support threading. This adds a build option to disable mutexes and other threading code from RpcState, RpcSession, and RpcServer. Bug: 224644083 Test: build Trusty Change-Id: Iaa78caca1ddee45be7c2def2755598decc0d4d15
* binder: Add FD support to RPC BinderFrederick Mayle2022-06-291-4/+14
| | | | | | Bug: 185909244 Test: TH Change-Id: Ic4fc1b1edfe9d69984e785553cd1aaca97a07da3
* libbinder: fix hanging wait in RpcSessionAndrei Homescu2022-06-231-10/+11
| | | | | | | | | | Fixes a hanging wait in RpcSession by notifying the condition variable for available connections immediately after adding a new outgoing connection. Bug: 224644083 Test: atest binderRpcTest Change-Id: I27c81127482859342cb789eaac087f55ae5c16d9
* libbinder: clear RpcTransportCtx for new sessions in RpcServerAndrei Homescu2022-06-101-0/+1
| | | | | | | | | | | RpcServer previously created new RpcSession instances using the default transport. There is currently no code in RpcSession that uses that transport for server sessions, so this patch initializes the transport to nullptr instead. Bug: 224644083 Test: atest binderRpcTest Change-Id: Ie9fa8c9c758821614fb161b360a9935955e7e62b
* Use android::base::function_ref isntead of std::functionDevin Moore2022-06-061-3/+3
| | | | | | | | This removes an allocation from the binder RPC calls. Test: atest binderAllocationLimits Bug: 230625474 Change-Id: I70ebb4e320323149c3c66809f1077cbf332c07ef
* libbinder: disable JavaThreadAttacher on non-Android OSesAndrei Homescu2022-05-191-2/+2
| | | | | | Bug: 224644083 Test: m Change-Id: Ibfa0535fa09af569f55aa1e6b8d5ff6adb720eb3
* libbinder: use base::GetThreadId instead of gettidAndrei Homescu2022-05-171-8/+4
| | | | | | | | | RpcSession uses gettid() to identify the current thread which is less portable than GetThreadId(). Test: atest binderRpcTest Bug: 224644083 Change-Id: I0d6020ef41af85c20bb58b89598812f2e790a38b
* libbinder: add TEMP_FAILURE_RETRY header to RPC codeAndrei Homescu2022-05-171-0/+1
| | | | | | | | | | | | Binder RPC code uses the TEMP_FAILURE_RETRY macro which is defined by the C library on Linux but not on other operating systems. The utils/Compat.h header defines that macro if not available. This change includes that header into RPC code. Test: m Bug: 224644083 Change-Id: I2637e5260e258f3b2dfeb99e8ea7187c079550f7
* Fix RpcSession::setupPreconnectedClientFrederick Mayle2022-05-121-8/+4
| | | | | | | | If you requested N connections, you'd get N connection objects using the same socket. Also, some error cases would leak sockets. Test: CLANG_ANALYZER_CHECKS=1 m tidy-frameworks-native-libs-binder Change-Id: I46528f952fdfc88d4e49b93499dbfbb39117b069
* libbinder: RPC clarify thread exhaustion logSteven Moreland2022-03-101-4/+10
| | | | | | | | | | | | | This log used the old 'client' 'server' terminology which in this context was disambiguated to 'incoming' and 'outcoming' threads, and it also now says what to do when threads are exhausted. Note: as you can see from this log, RpcServer still needs a way to limit the number of outgoing connections that it will create. Fixes: 220177986 Test: binderRpcTest Change-Id: Ib4c6bf654acd4a33d054d134ed578b40a976c314
* Fix or suppress tidy warnings-as-errors.Jiyong Park2022-03-091-2/+7
| | | | | | | | | | | | | Use std::map instead of KeyedVector (deprecated) in order to avoid unnecessary (and implicit) initialization of the value type. KeyedVector does it even when only the key is neeed (e.g. indexOfKey). std::map doesn't have such a problem. Bug: 222775179 Test: unset WITH_TIDY; CLANG_ANALYZER_CHECKS=1 make -k tidy-frameworks-native-libs-binder Change-Id: I548fc96a34bac9c7135e206983150948dbca57d4
* binder: Eliminate a data copy in RPC transport operationsAndrei Homescu2021-12-231-3/+5
| | | | | | | | | | Switch RpcTransportRaw to use sendmsg() and recvmsg() over iovecs to send data from multiple buffers to avoid having to copy all data into a single large buffer. Bug: 202878542 Test: atest binderRpcTest Change-Id: I8ba7fa815040555503160ae41888a0b0efe9e5d2
* Merge "binder: recovery variant does not use libandroid_runtime_vm_headers"Yifan Hong2021-11-021-3/+10
|\
| * binder: recovery variant does not use libandroid_runtime_vm_headersYifan Hong2021-11-011-3/+10
| | | | | | | | | | | | | | There's no Android Runtime in recovery anyways. Test: builds Change-Id: Iff202493241932ceb92988580150d6338058bc94
* | libbinder: RPC more nodiscard w/ fixSteven Moreland2021-10-251-1/+2
| | | | | | | | | | | | | | | | Another forgotten error. Bug: 167966510 Test: binderRpcTest Change-Id: I48adcf428c8ce68fdc5b49d7a0314d043e78e76d
* | libbinder: support server-specific sessionSteven Moreland2021-10-201-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When multiple clients connect to a server, we need a way to tell these clients apart. Having a per-client root object is the easiest way to do this (the alternative, using getCalling* like is used in binder, isn't so great because it requires global/thread local place, but given that many RpcSession objects can be created, and these can also be used in conjunction with kernel binder, it is complicated figuring out exactly where to call getCalling*). Bug: 199259751 Test: binderRpcTest Change-Id: I5727db618b5ea138bfa19e75ed915f6a6991518e
* | binder: RpcSession limit outgoing threadsYifan Hong2021-10-111-1/+24
|/ | | | | | | | | | | | | Similar to the number of incoming threads, the number of outgoing threads can be limited via RpcSession::setMaxOutgoingThreads(). If set, only min(maxOutgoingThreads, remoteMaxThreads) outgoing threads are instantiated. Test: binderRpcTest Bug: 194225767 Change-Id: I15686bae4317d0ced5af999f3a3d21f9a03037e1
* binder: RpcSession::*MaxThreads -> *MaxIncomingThreadsYifan Hong2021-10-081-9/+9
| | | | | | | | | We'll add a separate number for outgoing threads Bug: 194225767 Test: pass Change-Id: I7bf178c098adc6359582792a2f1ca1248a336b9f
* libbinder: RPC mThreadState -> mConnectionsSteven Moreland2021-10-041-40/+37
| | | | | | | | | Disambiguate name from 'thread state' meaning 'thread local'. This also allows simplification of other names here. Bug: N/A Test: binderRpcTest Change-Id: Ifd2fb5393a945c5d8a0f7bfd8b459843b1311b54
* libbinder: RPC allow RpcSession to be reusableSteven Moreland2021-10-011-37/+68
| | | | | | | | | | | | | | | | | | | | | | Previously, there were two ways setup could fail: - very quickly (e.g. cannot create fd to poll) - after some delay (e.g. second connectoin messed up) In either case, 'false' is returned from setup* funtions. However, in the second case, if setup* is called again, then it would result in an abort. When connections fail for unrelated reasons, this sometimes causes aborts in existing tests. Two alternatives considered: - switch to factory-type setup, this seems a bit heavy, chiefly because typically, only one RpcSession is needed, so it is annoying to have to create a factory and an object. - disallow setup* from being called multiple times - this breaks some of our tests, and it adds work to clients. Bug: 200737956 Test: manual Change-Id: Ia6a69a7d2ca6c6835844cd9a90c7d24646a83526