1 /* 2 * Copyright (c) 2021 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 #ifndef _UAPI_LINUX_BINDER_H 17 #define _UAPI_LINUX_BINDER_H 18 19 #include <stdint.h> 20 #include <sys/types.h> 21 #include <sys/ioctl.h> 22 #include <linux/types.h> 23 24 #define B_PACK_CHARS(c1, c2, c3, c4) ((((c1) << 24)) | (((c2) << 16)) | (((c3) << 8)) | (c4)) 25 #define B_TYPE_LARGE 0x85 26 27 #if INTPTR_MAX == INT32_MAX 28 #define BINDER_IPC_32BIT 29 #elif INTPTR_MAX == INT64_MAX 30 #ifdef BINDER_IPC_32BIT 31 #undef BINDER_IPC_32BIT 32 #endif 33 #else 34 #error "Environment not 32 or 64 bit system." 35 #endif 36 37 enum { 38 BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE), 39 BINDER_TYPE_REMOTE_BINDER = B_PACK_CHARS('r', 'b', '*', B_TYPE_LARGE), 40 BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE), 41 BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE), 42 BINDER_TYPE_REMOTE_HANDLE = B_PACK_CHARS('r', 'h', '*', B_TYPE_LARGE), 43 BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE), 44 BINDER_TYPE_FD = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE), 45 BINDER_TYPE_FDA = B_PACK_CHARS('f', 'd', 'a', B_TYPE_LARGE), 46 BINDER_TYPE_PTR = B_PACK_CHARS('p', 't', '*', B_TYPE_LARGE), 47 }; 48 49 enum { 50 FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff, 51 FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100, 52 }; 53 54 #ifdef BINDER_IPC_32BIT 55 typedef __u32 binder_size_t; 56 typedef __u32 binder_uintptr_t; 57 #else 58 typedef __u64 binder_size_t; 59 typedef __u64 binder_uintptr_t; 60 #endif 61 struct binder_object_header { 62 __u32 type; 63 }; 64 65 struct flat_binder_object { 66 __u32 type; 67 __u32 flags; 68 union { 69 binder_uintptr_t binder; 70 __u32 handle; 71 }; 72 binder_uintptr_t cookie; 73 }; 74 75 struct binder_fd_object { 76 struct binder_object_header hdr; 77 __u32 pad_flags; 78 union { 79 binder_uintptr_t pad_binder; 80 __u32 fd; 81 }; 82 binder_uintptr_t cookie; 83 }; 84 85 struct binder_buffer_object { 86 struct binder_object_header hdr; 87 __u32 flags; 88 binder_uintptr_t buffer; 89 binder_size_t length; 90 binder_size_t parent; 91 binder_size_t parent_offset; 92 }; 93 94 enum { 95 BINDER_BUFFER_FLAG_HAS_PARENT = 0x01, 96 }; 97 98 struct binder_fd_array_object { 99 struct binder_object_header hdr; 100 __u32 pad; 101 binder_size_t num_fds; 102 binder_size_t parent; 103 binder_size_t parent_offset; 104 }; 105 106 struct binder_write_read { 107 binder_size_t write_size; 108 binder_size_t write_consumed; 109 binder_uintptr_t write_buffer; 110 binder_size_t read_size; 111 binder_size_t read_consumed; 112 binder_uintptr_t read_buffer; 113 }; 114 115 struct binder_version { 116 __s32 protocol_version; 117 }; 118 119 #ifdef BINDER_IPC_32BIT 120 #define BINDER_CURRENT_PROTOCOL_VERSION 7 121 #else 122 #define BINDER_CURRENT_PROTOCOL_VERSION 8 123 #endif 124 struct binder_node_debug_info { 125 binder_uintptr_t ptr; 126 binder_uintptr_t cookie; 127 __u32 has_strong_ref; 128 __u32 has_weak_ref; 129 }; 130 131 struct binder_ptr_count { 132 binder_uintptr_t ptr; 133 uint32_t count; 134 }; 135 136 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read) 137 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64) 138 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32) 139 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32) 140 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32) 141 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32) 142 #define BINDER_VERSION _IOWR('b', 9, struct binder_version) 143 #define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info) 144 #define BINDER_GET_NODE_REFCOUNT _IOWR('b', 17, struct binder_ptr_count) 145 146 enum transaction_flags { 147 TF_ONE_WAY = 0x01, 148 TF_ROOT_OBJECT = 0x04, 149 TF_STATUS_CODE = 0x08, 150 TF_ACCEPT_FDS = 0x10, 151 }; 152 153 struct binder_transaction_data { 154 union { 155 __u32 handle; 156 binder_uintptr_t ptr; 157 } target; 158 binder_uintptr_t cookie; 159 160 __u32 code; 161 __u32 flags; 162 pid_t sender_pid; 163 uid_t sender_euid; 164 binder_size_t data_size; 165 binder_size_t offsets_size; 166 union { 167 struct { 168 binder_uintptr_t buffer; 169 binder_uintptr_t offsets; 170 } ptr; 171 __u8 buf[8]; 172 } data; 173 }; 174 175 struct binder_transaction_data_sg { 176 struct binder_transaction_data transaction_data; 177 binder_size_t buffers_size; 178 }; 179 180 struct binder_ptr_cookie { 181 binder_uintptr_t ptr; 182 binder_uintptr_t cookie; 183 }; 184 185 struct binder_handle_cookie { 186 __u32 handle; 187 binder_uintptr_t cookie; 188 }__attribute__((__packed__)); 189 struct binder_pri_desc { 190 __s32 priority; 191 __u32 desc; 192 }; 193 194 struct binder_pri_ptr_cookie { 195 __s32 priority; 196 binder_uintptr_t ptr; 197 binder_uintptr_t cookie; 198 }; 199 200 enum binder_driver_return_protocol { 201 BR_ERROR = _IOR('r', 0, __s32), 202 BR_OK = _IO('r', 1), 203 BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data), 204 BR_REPLY = _IOR('r', 3, struct binder_transaction_data), 205 BR_ACQUIRE_RESULT = _IOR('r', 4, __s32), 206 BR_DEAD_REPLY = _IO('r', 5), 207 BR_TRANSACTION_COMPLETE = _IO('r', 6), 208 BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie), 209 BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie), 210 BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie), 211 BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie), 212 BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie), 213 BR_NOOP = _IO('r', 12), 214 BR_SPAWN_LOOPER = _IO('r', 13), 215 BR_FINISHED = _IO('r', 14), 216 BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t), 217 BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t), 218 BR_FAILED_REPLY = _IO('r', 17), 219 BR_RELEASE_NODE = _IO('r', 18), 220 }; 221 222 enum binder_driver_command_protocol { 223 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data), 224 BC_REPLY = _IOW('c', 1, struct binder_transaction_data), 225 BC_ACQUIRE_RESULT = _IOW('c', 2, __s32), 226 BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t), 227 BC_INCREFS = _IOW('c', 4, __u32), 228 BC_ACQUIRE = _IOW('c', 5, __u32), 229 BC_RELEASE = _IOW('c', 6, __u32), 230 BC_DECREFS = _IOW('c', 7, __u32), 231 BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie), 232 BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie), 233 BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc), 234 BC_REGISTER_LOOPER = _IO('c', 11), 235 BC_ENTER_LOOPER = _IO('c', 12), 236 BC_EXIT_LOOPER = _IO('c', 13), 237 BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_handle_cookie), 238 BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_handle_cookie), 239 BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t), 240 BC_TRANSACTION_SG = _IOW('c', 17, struct binder_transaction_data_sg), 241 BC_REPLY_SG = _IOW('c', 18, struct binder_transaction_data_sg), 242 BC_RELEASE_NODE = _IOW('c', 19, binder_uintptr_t), 243 }; 244 245 #endif 246