summaryrefslogtreecommitdiff
path: root/libs/binder/RpcServer.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Binder unique_fdTomasz Wasilczyk2023-11-171-6/+6
| | | | | | 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-4/+5
| | | | | | | | 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: 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-5/+4
| | | | | | | | | | | | 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-4/+5
| | | | | | Bug: 302723053 Test: mma Change-Id: I27226885b8b5e771d675ba2d83d0a2e14551d13e
* Merge "RPC binder: set TCP_NDELAY" into mainKeith Mok2023-10-171-0/+12
|\
| * RPC binder: set TCP_NDELAYKeith Mok2023-10-131-0/+12
| | | | | | | | | | | | | | | | | | | | | | System by default cache TCP data trying to pack more data before sending out to the wire, this cause delay in rpc communication. Currently we set TCP_NDELAY in RpcSession, but not in RpcServer. This CL add TCP_NDELAY to RpcServer also. Bug: 304823925 Test: manual Change-Id: I8bfda370a78eff9b8e0ab75e6bc2fd0a5ba743ed
* | Merge "Binder: Split OS to Android and Unix part, abstract GetThreadId out" ↵Tomasz Wasilczyk2023-10-161-4/+4
|\ \ | | | | | | | | | into main
| * | Binder: Split OS to Android and Unix part, abstract GetThreadId outTomasz Wasilczyk2023-10-161-4/+4
| |/ | | | | | | | | | | | | Bug: 302723053 Test: mma in binder folder Test: aosp/2616196 Change-Id: I73df8fc453df0edf496960853cb0004f1c3a6a43
* / Copy HexString to libbinderTomasz Wasilczyk2023-10-121-7/+5
|/ | | | | | Bug: 302723053 Test: mma Change-Id: I5c7a71a91b7dc95bfa0cd653eabe554bdd3f7812
* RPC binder: expose session to per-client rootsSteven Moreland2023-05-241-2/+3
| | | | | | Bug: 274156888 Test: N/A Change-Id: Iad721ebea7ddd461ed41f2ba1fc08849309f7611
* Merge "libbinder: RpcServer protocol version error"Steven Moreland2023-05-151-1/+6
|\
| * libbinder: RpcServer protocol version errorSteven Moreland2023-05-121-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | 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 "Fix the Nullable pointer is dereferenced issue"Zijun Zhao2023-05-121-0/+1
|\ \
| * | Fix the Nullable pointer is dereferenced issuezijunzhao2023-05-111-0/+1
| |/ | | | | | | | | | | | | | | | | | | | | The member ai_addr is allowed to be null, which will cause dereferencing nullptr issue here. See https://android-build.corp.google.com/artifact/pending/P54712024/aosp_arm64-userdebug/latest/view/logs%2Fbuild.log for more details Bug: None Test: mm Change-Id: Ie1e8ec56bbd1edee0456c26d0d29775bc7abbbb5
* / Fix publishing RPC Server on the same address/port after a short timeTomasz Wasilczyk2023-05-111-0/+16
|/ | | | | | | Bug: 274786956 Test: atest libsdvrpc_test_cpp Change-Id: I58b0b99b5e3ab8c9659eed0eba9ff689000b84ac
* libbinder: RpcServer +info on socket create failSteven Moreland2023-04-101-1/+1
| | | | | | Bug: 268131636 Test: binderRpcTest Change-Id: I3466a6fa068e400843bc006a370da7f53771f95c
* Clarify RpcServer shutdown error for corner caseDevin Moore2023-03-221-1/+2
| | | | | | | | If the service tries to shutdown before join(), we end up in this case. Test: none Bug: none Change-Id: I0d2f59b0d398ce3a18b522d7830417220b1a5145
* rpc_binder: Properly shut down on socketpair() EOFDavid Brazdil2022-12-201-3/+10
| | | | | | | | | | | | | | FdTrigger::triggerablePoll returns OK on POLLIN (higher priority) and DEAD_OBJECT on POLLHUP (lower priority). Unlike INET or vsock, socketpair() sockets trigger POLLIN|POLLHUP on EOF and EOF is detected by recvmsg() returning zero bytes. Adjust the server accept loop to take this into account and correctly break out of the loop. Bug: 250685929 Test: cleanly shut down UDS bootstrap RpcServer Change-Id: I56d6a67373f16b5b1bdc167de94a7252bedca8e2
* rpc_binder: Prevent RpcServer shutdown deadlockDavid Brazdil2022-12-191-1/+2
| | | | | | | | | | | | | | | | | RpcServer::~RpcServer invokes shutdown() to trigger exit from all join and session threads. The function waits for the number of connections to drop down to zero, but this depends on RpcSession promoting a wp<RpcServer> to sp<RpcServer>. Since this is happening during the destructor, when the refcount is zero, this pointer promotion fails. As a result, the list of connections may not be fully cleared and the thread calling shutdown() will deadlock. Fix this by forcing users to call shutdown() earlier and panicing otherwise. Bug: 263168076 Test: cleanly shutdown RpcServer with many connections Change-Id: Ia67a4a839419aafb1bd47fb93ed2e76d56b107c2
* rpc_binder: Specify CID for vsock RpcServerDavid Brazdil2022-12-141-6/+15
| | | | | | | | | | | | | | | | | | | | | | | Currently RpcServer only allows to start a server listening for connections from VMHOST_CID_ANY. This is not always desirable as clients may want to listen only for connections from specific CIDs, eg. only the host or only local. This can be partially solved by setting the bind CID of the virtual socket. The server can bind to VMADDR_CID_LOCAL for local interface only. VMADDR_CID_ANY same as its own CID will bind to the remote interface and accept connections from all clients. To this end, add a callback for filtering accepted connections in RpcServer. This may already be possible with per-session root object. However, the root object is selected very late, after initial negotiation with the client. For both performance and safety, add the callback immediately after accept() to reject the connection as early as possible. Bug: 245727626 Test: atest binderRpcTest Change-Id: I5b3e6fd5119c77ef8c5c4fbbfead9892c5de1a07
* Merge "[rpc_binder] Use unique_fd directly for socket in raw socket setup"Alice Wang2022-11-171-3/+2
|\
| * [rpc_binder] Use unique_fd directly for socket in raw socket setupAlice Wang2022-11-161-3/+2
| | | | | | | | | | | | Test: atest binderRpcTest Bug: 222479468 Change-Id: Ie4d4cfe6ff85e91c2218eef76bd46b7b1f8d1167
* | [rpc_binder] Reuse raw socket setup method in vsock/uds sockets setupAlice Wang2022-11-161-23/+6
|/ | | | | | Test: atest binderRpcTest Bug: 222479468 Change-Id: I4cf89f1543898279fe041f89f272eddccf29e763
* [rpc_binder] Adjust return when raw socket is not set upAlice Wang2022-11-151-5/+2
| | | | | | | | | | | | This cl adjusts the return in RpcServer::setupRawSocketServer() when the socket_fd is not set up. Prior to this cl, errno is returned. This can be confusing as errno is not always set up in this case. The current CL fixed this and logged more clear information. Test: atest binderRpcTest Bug: 222479468 Change-Id: Ic9718cbf3cf08befe4044e7f5f021b915b4c4c41
* [rpc_binder] Implement RPC binder over init-managed Unix domain socketAlice Wang2022-11-101-0/+23
| | | | | | | | | | | This implements an RPC binder over init-managed Unix domain sockets. The cl adds binder tests and the new API is also used for vm_payload_service inside Microdroid. A previous cl aosp/2229557 sets up the binder over anonymous Unix sockets. Test: atest MicrodroidTests ComposHostTestCases Bug: 222479468 Change-Id: I0c7c38f4792c4536f5f88eb7e035091505f782f7
* RpcBinder: Add AF_UNIX socketpair transportDavid Brazdil2022-10-071-11/+61
| | | | | | | | | | | | | | | | | | | 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/+10
| | | | | | | | | | | | 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-3/+3
| | | | | | | Test: m Test: m libbinder binderRpcTest Bug: 218518615 Change-Id: I822bdb751f68c83e1b10c5fd16c9d8439646b771
* Merge "libbinder : Adding new type TransportFd"Pawan Wagh2022-08-261-19/+19
|\
| * libbinder : Adding new type TransportFdPawan2022-08-261-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: build on TrustyAndrei Homescu2022-07-141-6/+9
| | | | | | | | | | | | | | Adds a new trusty/ subdirectory containing all the files needed to build Binder RPC on Trusty, including: * A RpcServerTrusty class used to create Trusty Binder services * The underlying RpcTransportTipcTrusty transport that interfaces between libbinder and TIPC * Trusty implementations of some OS-specific functionality, like logging * Make-based build file for libbinder in the Trusty build system Bug: 224644083 Test: build Trusty Change-Id: I25b97736d41489d20c2dd266e8e110764215378c
* Merge "libbinder: Fix out-of-bounds abort in RpcServer"Treehugger Robot2022-07-081-1/+3
|\
| * libbinder: Fix out-of-bounds abort in RpcServerFrederick Mayle2022-07-081-1/+3
| | | | | | | | | | | | Bug: 237639446 Test: atest binderRpcTest Change-Id: Ic35a75fe2b218ef024c6e5e33901813a454243d6
* | 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-26/+42
| | | | | | | | | | 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
* libbinder: Stricter protocol and code for receiving FDsFrederick Mayle2022-06-301-2/+2
| | | | | | | | | | | | | | | | | This is a slight change the to wire protocol. Now out-of-band FDs must be sent along with the command header bytes. The code changes exploit that by only using the more complex `recvmsg` call when reading the command header. Additionally, we explicitly pass around the list of FDs so that there is no risk of accumulating them. The same (somewhat ugly) vector type is used everywhere now so that there is only one allocation to capture the FDs and pass them to the `Parcel` object. Test: binderRpcTest Bug: 185909244 Change-Id: I1f55995ca82338ab9716fb2246c954ac8b16cfe5
* binder: Add FD support to RPC BinderFrederick Mayle2022-06-291-3/+22
| | | | | | Bug: 185909244 Test: TH Change-Id: Ic4fc1b1edfe9d69984e785553cd1aaca97a07da3
* libbinder: clear RpcTransportCtx for new sessions in RpcServerAndrei Homescu2022-06-101-1/+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
* libbinder: switch sockaddr to byte array in RpcServerAndrei Homescu2022-06-091-9/+9
| | | | | | | | | | | A few methods in RpcServer.cpp take a sockaddr or sockaddr_storage parameter. To support operating systems without sockets, e.g. Trusty, this switches those types to void* and std::array<uint8_t, 128>, respectively. Test: atest binderRpcTest Bug: 224644083 Change-Id: I9773a4cf0aedd5ebec22a10cea5b1593067632c5
* Use android::base::function_ref isntead of std::functionDevin Moore2022-06-061-4/+6
| | | | | | | | This removes an allocation from the binder RPC calls. Test: atest binderAllocationLimits Bug: 230625474 Change-Id: I70ebb4e320323149c3c66809f1077cbf332c07ef
* libbinder: move session ID RNG code to Utils.cppAndrei Homescu2022-05-171-5/+4
| | | | | | | | | | This moves the code that reads from /dev/urandom from RpcServer.cpp into Utils.cpp so other operating systems can provide their own implementations by replacing Utils.cpp. Test: atest binderRpcTest Bug: 224644083 Change-Id: I2923b25537c07060b830b0d8378df8c969bbd02f
* 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
* binder: Eliminate a data copy in RPC transport operationsAndrei Homescu2021-12-231-6/+7
| | | | | | | | | | 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
* libbinder: RPC - remove 'agreed experimental'Steven Moreland2021-10-211-12/+0
| | | | | | | | | | | Where this can be used is still limited by sepolicy, but now that we have examples for how to version the wire protocol, tests, fuzzer entries, and most performance analysis is done, we can avoid this function name. Bug: 167966510 Test: N/A Change-Id: Ibda9a656f1b96be7d38c4684cab787e411297a24
* libbinder: support server-specific sessionSteven Moreland2021-10-201-5/+33
| | | | | | | | | | | | | | 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::*MaxThreads -> *MaxIncomingThreadsYifan Hong2021-10-081-1/+1
| | | | | | | | | We'll add a separate number for outgoing threads Bug: 194225767 Test: pass Change-Id: I7bf178c098adc6359582792a2f1ca1248a336b9f