1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 //! Safe Rust interface to OHOS IPC/RPC 17 18 mod ipc_binding; 19 mod errors; 20 mod ipc; 21 mod parcel; 22 mod process; 23 mod ashmem; 24 25 // Export types of this crate 26 pub use crate::errors::{IpcResult, status_result, IpcStatusCode, parse_status_code}; 27 pub use crate::ipc::{ 28 IRemoteBroker, IRemoteObj, IRemoteStub, FromRemoteObj, RemoteObjRef, 29 remote_obj::RemoteObj, remote_obj::death_recipient::DeathRecipient, 30 remote_stub::RemoteStub, 31 }; 32 pub use crate::parcel::{ 33 MsgParcel, BorrowedMsgParcel, IMsgParcel, RawData, 34 parcelable::{Serialize, Deserialize, SerOption, DeOption}, 35 }; 36 pub use crate::parcel::parcelable::{SerArray, DeArray}; 37 pub use crate::parcel::types::{ 38 interface_token::InterfaceToken, file_desc::FileDesc, 39 string16::String16 40 }; 41 pub use crate::ashmem::{ 42 Ashmem, PROT_NONE, PROT_READ, PROT_WRITE, PROT_EXEC, 43 }; 44 pub use crate::process::{ 45 get_context_object, add_service, get_service, join_work_thread, stop_work_thread, 46 get_calling_uid, get_calling_token_id, get_first_token_id, get_self_token_id, 47 get_calling_pid, set_max_work_thread, is_local_calling, set_calling_identity, 48 get_local_device_id, get_calling_device_id, reset_calling_identity, 49 }; 50 51 /// First request code available for user IPC request(inclusive) 52 pub const FIRST_CALL_TRANSACTION: isize = 0x00000001; 53 /// Last request code available for user IPC request(inclusive) 54 pub const LAST_CALL_TRANSACTION: isize = 0x00ffffff; 55 56 /// Trait for transparent Rust wrappers around native raw pointer types. 57 /// 58 /// # Safety 59 /// 60 /// The pointer return by this trait's methods should be immediately passed to 61 /// native and not stored by Rust. The pointer is valid only as long as the 62 /// underlying native object is alive, so users must be careful to take this into 63 /// account, as Rust cannot enforce this. 64 /// 65 /// For this trait to be a correct implementation, `T` must be a valid native 66 /// type. Since we cannot constrain this via the type system, this trait is 67 /// marked as unsafe. 68 pub unsafe trait AsRawPtr<T> { 69 /// Return a pointer to the native version of `self` as_raw(&self) -> *const T70 fn as_raw(&self) -> *const T; 71 72 /// Return a mutable pointer to the native version of `self` as_mut_raw(&mut self) -> *mut T73 fn as_mut_raw(&mut self) -> *mut T; 74 }