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