Loading libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp +6 −7 Original line number Diff line number Diff line Loading @@ -24,20 +24,20 @@ struct AIBinder; // Starts an RPC server on a given port and a given root IBinder object. // This function sets up the server and joins before returning. bool RunRpcServer(AIBinder* service, unsigned int port); bool RunVsockRpcServer(AIBinder* service, unsigned int port); // Starts an RPC server on a given port and a given root IBinder object. // This function sets up the server, calls readyCallback with a given param, and // then joins before returning. bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param); bool RunVsockRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param); // Starts an RPC server on a given port and a given root IBinder factory. // RunRpcServerWithFactory acts like RunRpcServerCallback, but instead of // RunVsockRpcServerWithFactory acts like RunVsockRpcServerCallback, but instead of // assigning single root IBinder object to all connections, factory is called // whenever a client connects, making it possible to assign unique IBinder // object to each client. bool RunRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* context), bool RunVsockRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* context), void* factoryContext, unsigned int port); AIBinder* RpcClient(unsigned int cid, unsigned int port); Loading @@ -50,5 +50,4 @@ AIBinder* RpcClient(unsigned int cid, unsigned int port); // param will be passed to requestFd. Callers can use param to pass contexts to // the requestFd function. AIBinder* RpcPreconnectedClient(int (*requestFd)(void* param), void* param); } libs/binder/libbinder_rpc_unstable.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ using android::base::unique_fd; extern "C" { bool RunRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* context), bool RunVsockRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* context), void* factoryContext, unsigned int port) { auto server = RpcServer::make(); if (status_t status = server->setupVsockServer(port); status != OK) { Loading @@ -52,8 +52,8 @@ bool RunRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* contex return true; } bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param) { bool RunVsockRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param) { auto server = RpcServer::make(); if (status_t status = server->setupVsockServer(port); status != OK) { LOG(ERROR) << "Failed to set up vsock server with port " << port Loading @@ -70,8 +70,8 @@ bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCall return true; } bool RunRpcServer(AIBinder* service, unsigned int port) { return RunRpcServerCallback(service, port, nullptr, nullptr); bool RunVsockRpcServer(AIBinder* service, unsigned int port) { return RunVsockRpcServerCallback(service, port, nullptr, nullptr); } AIBinder* RpcClient(unsigned int cid, unsigned int port) { Loading libs/binder/libbinder_rpc_unstable.map.txt +2 −2 Original line number Diff line number Diff line LIBBINDER_RPC_UNSTABLE_SHIM { # platform-only global: RunRpcServer; RunRpcServerCallback; RunVsockRpcServer; RunVsockRpcServerCallback; RpcClient; RpcPreconnectedClient; local: Loading libs/binder/rust/rpcbinder/src/lib.rs +1 −1 Original line number Diff line number Diff line Loading @@ -23,4 +23,4 @@ pub use client::{ get_preconnected_rpc_interface, get_preconnected_rpc_service, get_vsock_rpc_interface, get_vsock_rpc_service, }; pub use server::{run_rpc_server, run_rpc_server_with_factory}; pub use server::{run_vsock_rpc_server, run_vsock_rpc_server_with_factory}; libs/binder/rust/rpcbinder/src/server.rs +13 −9 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ use std::{os::raw, ptr::null_mut}; /// The current thread is joined to the binder thread pool to handle incoming messages. /// /// Returns true if the server has shutdown normally, false if it failed in some way. pub fn run_rpc_server<F>(service: SpIBinder, port: u32, on_ready: F) -> bool pub fn run_vsock_rpc_server<F>(service: SpIBinder, port: u32, on_ready: F) -> bool where F: FnOnce(), { Loading @@ -52,10 +52,10 @@ where // SAFETY: Service ownership is transferring to the server and won't be valid afterward. // Plus the binder objects are threadsafe. // RunRpcServerCallback does not retain a reference to `ready_callback` or `param`; it only // RunVsockRpcServerCallback does not retain a reference to `ready_callback` or `param`; it only // uses them before it returns, which is during the lifetime of `self`. unsafe { binder_rpc_unstable_bindgen::RunRpcServerCallback( binder_rpc_unstable_bindgen::RunVsockRpcServerCallback( service, port, Some(Self::ready_callback), Loading @@ -69,7 +69,7 @@ where } unsafe extern "C" fn ready_callback(param: *mut raw::c_void) { // SAFETY: This is only ever called by `RunRpcServerCallback`, within the lifetime of the // SAFETY: This is only ever called by `RunVsockRpcServerCallback`, within the lifetime of the // `ReadyNotifier`, with `param` taking the value returned by `as_void_ptr` (so a properly // aligned non-null pointer to an initialized instance). let ready_notifier = param as *mut Self; Loading @@ -91,7 +91,7 @@ type RpcServerFactoryRef<'a> = &'a mut (dyn FnMut(u32) -> Option<SpIBinder> + Se /// The current thread is joined to the binder thread pool to handle incoming messages. /// /// Returns true if the server has shutdown normally, false if it failed in some way. pub fn run_rpc_server_with_factory( pub fn run_vsock_rpc_server_with_factory( port: u32, mut factory: impl FnMut(u32) -> Option<SpIBinder> + Send + Sync, ) -> bool { Loading @@ -100,18 +100,22 @@ pub fn run_rpc_server_with_factory( let mut factory_ref: RpcServerFactoryRef = &mut factory; let context = &mut factory_ref as *mut RpcServerFactoryRef as *mut raw::c_void; // SAFETY: `factory_wrapper` is only ever called by `RunRpcServerWithFactory`, with context // SAFETY: `factory_wrapper` is only ever called by `RunVsockRpcServerWithFactory`, with context // taking the pointer value above (so a properly aligned non-null pointer to an initialized // `RpcServerFactoryRef`), within the lifetime of `factory_ref` (i.e. no more calls will be made // after `RunRpcServerWithFactory` returns). // after `RunVsockRpcServerWithFactory` returns). unsafe { binder_rpc_unstable_bindgen::RunRpcServerWithFactory(Some(factory_wrapper), context, port) binder_rpc_unstable_bindgen::RunVsockRpcServerWithFactory( Some(factory_wrapper), context, port, ) } } unsafe extern "C" fn factory_wrapper(cid: u32, context: *mut raw::c_void) -> *mut AIBinder { // SAFETY: `context` was created from an `&mut RpcServerFactoryRef` by // `run_rpc_server_with_factory`, and we are still within the lifetime of the value it is // `run_vsock_rpc_server_with_factory`, and we are still within the lifetime of the value it is // pointing to. let factory_ptr = context as *mut RpcServerFactoryRef; let factory = factory_ptr.as_mut().unwrap(); Loading Loading
libs/binder/include_rpc_unstable/binder_rpc_unstable.hpp +6 −7 Original line number Diff line number Diff line Loading @@ -24,20 +24,20 @@ struct AIBinder; // Starts an RPC server on a given port and a given root IBinder object. // This function sets up the server and joins before returning. bool RunRpcServer(AIBinder* service, unsigned int port); bool RunVsockRpcServer(AIBinder* service, unsigned int port); // Starts an RPC server on a given port and a given root IBinder object. // This function sets up the server, calls readyCallback with a given param, and // then joins before returning. bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param); bool RunVsockRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param); // Starts an RPC server on a given port and a given root IBinder factory. // RunRpcServerWithFactory acts like RunRpcServerCallback, but instead of // RunVsockRpcServerWithFactory acts like RunVsockRpcServerCallback, but instead of // assigning single root IBinder object to all connections, factory is called // whenever a client connects, making it possible to assign unique IBinder // object to each client. bool RunRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* context), bool RunVsockRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* context), void* factoryContext, unsigned int port); AIBinder* RpcClient(unsigned int cid, unsigned int port); Loading @@ -50,5 +50,4 @@ AIBinder* RpcClient(unsigned int cid, unsigned int port); // param will be passed to requestFd. Callers can use param to pass contexts to // the requestFd function. AIBinder* RpcPreconnectedClient(int (*requestFd)(void* param), void* param); }
libs/binder/libbinder_rpc_unstable.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ using android::base::unique_fd; extern "C" { bool RunRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* context), bool RunVsockRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* context), void* factoryContext, unsigned int port) { auto server = RpcServer::make(); if (status_t status = server->setupVsockServer(port); status != OK) { Loading @@ -52,8 +52,8 @@ bool RunRpcServerWithFactory(AIBinder* (*factory)(unsigned int cid, void* contex return true; } bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param) { bool RunVsockRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCallback)(void* param), void* param) { auto server = RpcServer::make(); if (status_t status = server->setupVsockServer(port); status != OK) { LOG(ERROR) << "Failed to set up vsock server with port " << port Loading @@ -70,8 +70,8 @@ bool RunRpcServerCallback(AIBinder* service, unsigned int port, void (*readyCall return true; } bool RunRpcServer(AIBinder* service, unsigned int port) { return RunRpcServerCallback(service, port, nullptr, nullptr); bool RunVsockRpcServer(AIBinder* service, unsigned int port) { return RunVsockRpcServerCallback(service, port, nullptr, nullptr); } AIBinder* RpcClient(unsigned int cid, unsigned int port) { Loading
libs/binder/libbinder_rpc_unstable.map.txt +2 −2 Original line number Diff line number Diff line LIBBINDER_RPC_UNSTABLE_SHIM { # platform-only global: RunRpcServer; RunRpcServerCallback; RunVsockRpcServer; RunVsockRpcServerCallback; RpcClient; RpcPreconnectedClient; local: Loading
libs/binder/rust/rpcbinder/src/lib.rs +1 −1 Original line number Diff line number Diff line Loading @@ -23,4 +23,4 @@ pub use client::{ get_preconnected_rpc_interface, get_preconnected_rpc_service, get_vsock_rpc_interface, get_vsock_rpc_service, }; pub use server::{run_rpc_server, run_rpc_server_with_factory}; pub use server::{run_vsock_rpc_server, run_vsock_rpc_server_with_factory};
libs/binder/rust/rpcbinder/src/server.rs +13 −9 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ use std::{os::raw, ptr::null_mut}; /// The current thread is joined to the binder thread pool to handle incoming messages. /// /// Returns true if the server has shutdown normally, false if it failed in some way. pub fn run_rpc_server<F>(service: SpIBinder, port: u32, on_ready: F) -> bool pub fn run_vsock_rpc_server<F>(service: SpIBinder, port: u32, on_ready: F) -> bool where F: FnOnce(), { Loading @@ -52,10 +52,10 @@ where // SAFETY: Service ownership is transferring to the server and won't be valid afterward. // Plus the binder objects are threadsafe. // RunRpcServerCallback does not retain a reference to `ready_callback` or `param`; it only // RunVsockRpcServerCallback does not retain a reference to `ready_callback` or `param`; it only // uses them before it returns, which is during the lifetime of `self`. unsafe { binder_rpc_unstable_bindgen::RunRpcServerCallback( binder_rpc_unstable_bindgen::RunVsockRpcServerCallback( service, port, Some(Self::ready_callback), Loading @@ -69,7 +69,7 @@ where } unsafe extern "C" fn ready_callback(param: *mut raw::c_void) { // SAFETY: This is only ever called by `RunRpcServerCallback`, within the lifetime of the // SAFETY: This is only ever called by `RunVsockRpcServerCallback`, within the lifetime of the // `ReadyNotifier`, with `param` taking the value returned by `as_void_ptr` (so a properly // aligned non-null pointer to an initialized instance). let ready_notifier = param as *mut Self; Loading @@ -91,7 +91,7 @@ type RpcServerFactoryRef<'a> = &'a mut (dyn FnMut(u32) -> Option<SpIBinder> + Se /// The current thread is joined to the binder thread pool to handle incoming messages. /// /// Returns true if the server has shutdown normally, false if it failed in some way. pub fn run_rpc_server_with_factory( pub fn run_vsock_rpc_server_with_factory( port: u32, mut factory: impl FnMut(u32) -> Option<SpIBinder> + Send + Sync, ) -> bool { Loading @@ -100,18 +100,22 @@ pub fn run_rpc_server_with_factory( let mut factory_ref: RpcServerFactoryRef = &mut factory; let context = &mut factory_ref as *mut RpcServerFactoryRef as *mut raw::c_void; // SAFETY: `factory_wrapper` is only ever called by `RunRpcServerWithFactory`, with context // SAFETY: `factory_wrapper` is only ever called by `RunVsockRpcServerWithFactory`, with context // taking the pointer value above (so a properly aligned non-null pointer to an initialized // `RpcServerFactoryRef`), within the lifetime of `factory_ref` (i.e. no more calls will be made // after `RunRpcServerWithFactory` returns). // after `RunVsockRpcServerWithFactory` returns). unsafe { binder_rpc_unstable_bindgen::RunRpcServerWithFactory(Some(factory_wrapper), context, port) binder_rpc_unstable_bindgen::RunVsockRpcServerWithFactory( Some(factory_wrapper), context, port, ) } } unsafe extern "C" fn factory_wrapper(cid: u32, context: *mut raw::c_void) -> *mut AIBinder { // SAFETY: `context` was created from an `&mut RpcServerFactoryRef` by // `run_rpc_server_with_factory`, and we are still within the lifetime of the value it is // `run_vsock_rpc_server_with_factory`, and we are still within the lifetime of the value it is // pointing to. let factory_ptr = context as *mut RpcServerFactoryRef; let factory = factory_ptr.as_mut().unwrap(); Loading