1 /* 2 * Copyright (c) 2021-2023 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 /** 17 * @file flat_obj.h 18 * 19 * @brief Define types and structures for reading and writing object in parcel. 20 * 21 * Types are platform-sensitive. Structures is only used for checking the 22 * validity of data in parcel, not for saving and using of data. 23 */ 24 #ifndef UTILS_BASE_FLAT_OBJ_H 25 #define UTILS_BASE_FLAT_OBJ_H 26 27 #if defined(__APPLE__) || defined(_WIN32) 28 #include <cstdint> 29 #include <sys/types.h> 30 31 #ifdef BINDER_IPC_32BIT 32 typedef uint32_t binder_size_t; 33 typedef uint32_t binder_uintptr_t; 34 #else 35 typedef uint64_t binder_size_t; 36 typedef uint64_t binder_uintptr_t; 37 #endif 38 39 struct parcel_binder_object_header { 40 uint32_t type; 41 }; 42 struct parcel_flat_binder_object { 43 struct parcel_binder_object_header hdr; 44 uint32_t flags; 45 union { 46 binder_uintptr_t binder; 47 uint32_t handle; 48 }; 49 binder_uintptr_t cookie; 50 }; 51 #else // !_WIN32 52 #include <sys/types.h> 53 #include <linux/types.h> 54 55 #ifdef BINDER_IPC_32BIT 56 typedef __u32 binder_size_t; 57 typedef __u32 binder_uintptr_t; 58 #else 59 typedef __u64 binder_size_t; 60 typedef __u64 binder_uintptr_t; 61 #endif 62 63 struct parcel_binder_object_header { 64 __u32 type; 65 }; 66 struct parcel_flat_binder_object { 67 struct parcel_binder_object_header hdr; 68 __u32 flags; 69 union { 70 binder_uintptr_t binder; 71 __u32 handle; 72 }; 73 binder_uintptr_t cookie; 74 }; 75 #endif // _WIN32 76 77 #endif // UTILS_BASE_FLAT_OBJ_H 78