1 /* 2 * Copyright (C) 2008 Google, Inc. 3 * 4 * Based on, but no longer compatible with, the original 5 * OpenBinder.org binder driver interface, which is: 6 * 7 * Copyright (c) 2005 Palmsource, Inc. 8 * 9 * This software is licensed under the terms of the GNU General Public 10 * License version 2, as published by the Free Software Foundation, and 11 * may be copied, distributed, and modified under those terms. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 */ 19 20 #ifndef _UAPI_LINUX_BINDER_H 21 #define _UAPI_LINUX_BINDER_H 22 23 #include <linux/ioctl.h> 24 25 #define B_PACK_CHARS(c1, c2, c3, c4) \ 26 ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4)) 27 #define B_TYPE_LARGE 0x85 28 29 enum { 30 BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE), 31 BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE), 32 BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE), 33 BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE), 34 BINDER_TYPE_FD = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE), 35 }; 36 37 enum { 38 FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff, 39 FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100, 40 }; 41 42 #ifdef BINDER_IPC_32BIT 43 typedef __u32 binder_size_t; 44 typedef __u32 binder_uintptr_t; 45 #else 46 typedef __u64 binder_size_t; 47 typedef __u64 binder_uintptr_t; 48 #endif 49 50 /* 51 * This is the flattened representation of a Binder object for transfer 52 * between processes. The 'offsets' supplied as part of a binder transaction 53 * contains offsets into the data where these structures occur. The Binder 54 * driver takes care of re-writing the structure type and data as it moves 55 * between processes. 56 */ 57 struct flat_binder_object { 58 /* 8 bytes for large_flat_header. */ 59 __u32 type; 60 __u32 flags; 61 62 /* 8 bytes of data. */ 63 union { 64 binder_uintptr_t binder; /* local object */ 65 __u32 handle; /* remote object */ 66 }; 67 68 /* extra data associated with local object */ 69 binder_uintptr_t cookie; 70 }; 71 72 /* 73 * On 64-bit platforms where user code may run in 32-bits the driver must 74 * translate the buffer (and local binder) addresses appropriately. 75 */ 76 77 struct binder_write_read { 78 binder_size_t write_size; /* bytes to write */ 79 binder_size_t write_consumed; /* bytes consumed by driver */ 80 binder_uintptr_t write_buffer; 81 binder_size_t read_size; /* bytes to read */ 82 binder_size_t read_consumed; /* bytes consumed by driver */ 83 binder_uintptr_t read_buffer; 84 }; 85 86 /* Use with BINDER_VERSION, driver fills in fields. */ 87 struct binder_version { 88 /* driver protocol version -- increment with incompatible change */ 89 __s32 protocol_version; 90 }; 91 92 /* This is the current protocol version. */ 93 #ifdef BINDER_IPC_32BIT 94 #define BINDER_CURRENT_PROTOCOL_VERSION 7 95 #else 96 #define BINDER_CURRENT_PROTOCOL_VERSION 8 97 #endif 98 99 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read) 100 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64) 101 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32) 102 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32) 103 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32) 104 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32) 105 #define BINDER_VERSION _IOWR('b', 9, struct binder_version) 106 107 /* 108 * NOTE: Two special error codes you should check for when calling 109 * in to the driver are: 110 * 111 * EINTR -- The operation has been interupted. This should be 112 * handled by retrying the ioctl() until a different error code 113 * is returned. 114 * 115 * ECONNREFUSED -- The driver is no longer accepting operations 116 * from your process. That is, the process is being destroyed. 117 * You should handle this by exiting from your process. Note 118 * that once this error code is returned, all further calls to 119 * the driver from any thread will return this same code. 120 */ 121 122 enum transaction_flags { 123 TF_ONE_WAY = 0x01, /* this is a one-way call: async, no return */ 124 TF_ROOT_OBJECT = 0x04, /* contents are the component's root object */ 125 TF_STATUS_CODE = 0x08, /* contents are a 32-bit status code */ 126 TF_ACCEPT_FDS = 0x10, /* allow replies with file descriptors */ 127 }; 128 129 struct binder_transaction_data { 130 /* The first two are only used for bcTRANSACTION and brTRANSACTION, 131 * identifying the target and contents of the transaction. 132 */ 133 union { 134 /* target descriptor of command transaction */ 135 __u32 handle; 136 /* target descriptor of return transaction */ 137 binder_uintptr_t ptr; 138 } target; 139 binder_uintptr_t cookie; /* target object cookie */ 140 __u32 code; /* transaction command */ 141 142 /* General information about the transaction. */ 143 __u32 flags; 144 pid_t sender_pid; 145 uid_t sender_euid; 146 binder_size_t data_size; /* number of bytes of data */ 147 binder_size_t offsets_size; /* number of bytes of offsets */ 148 149 /* If this transaction is inline, the data immediately 150 * follows here; otherwise, it ends with a pointer to 151 * the data buffer. 152 */ 153 union { 154 struct { 155 /* transaction data */ 156 binder_uintptr_t buffer; 157 /* offsets from buffer to flat_binder_object structs */ 158 binder_uintptr_t offsets; 159 } ptr; 160 __u8 buf[8]; 161 } data; 162 }; 163 164 struct binder_ptr_cookie { 165 binder_uintptr_t ptr; 166 binder_uintptr_t cookie; 167 }; 168 169 struct binder_handle_cookie { 170 __u32 handle; 171 binder_uintptr_t cookie; 172 } __packed; 173 174 struct binder_pri_desc { 175 __s32 priority; 176 __u32 desc; 177 }; 178 179 struct binder_pri_ptr_cookie { 180 __s32 priority; 181 binder_uintptr_t ptr; 182 binder_uintptr_t cookie; 183 }; 184 185 enum binder_driver_return_protocol { 186 BR_ERROR = _IOR('r', 0, __s32), 187 /* 188 * int: error code 189 */ 190 191 BR_OK = _IO('r', 1), 192 /* No parameters! */ 193 194 BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data), 195 BR_REPLY = _IOR('r', 3, struct binder_transaction_data), 196 /* 197 * binder_transaction_data: the received command. 198 */ 199 200 BR_ACQUIRE_RESULT = _IOR('r', 4, __s32), 201 /* 202 * not currently supported 203 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful. 204 * Else the remote object has acquired a primary reference. 205 */ 206 207 BR_DEAD_REPLY = _IO('r', 5), 208 /* 209 * The target of the last transaction (either a bcTRANSACTION or 210 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters. 211 */ 212 213 BR_TRANSACTION_COMPLETE = _IO('r', 6), 214 /* 215 * No parameters... always refers to the last transaction requested 216 * (including replies). Note that this will be sent even for 217 * asynchronous transactions. 218 */ 219 220 BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie), 221 BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie), 222 BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie), 223 BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie), 224 /* 225 * void *: ptr to binder 226 * void *: cookie for binder 227 */ 228 229 BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie), 230 /* 231 * not currently supported 232 * int: priority 233 * void *: ptr to binder 234 * void *: cookie for binder 235 */ 236 237 BR_NOOP = _IO('r', 12), 238 /* 239 * No parameters. Do nothing and examine the next command. It exists 240 * primarily so that we can replace it with a BR_SPAWN_LOOPER command. 241 */ 242 243 BR_SPAWN_LOOPER = _IO('r', 13), 244 /* 245 * No parameters. The driver has determined that a process has no 246 * threads waiting to service incoming transactions. When a process 247 * receives this command, it must spawn a new service thread and 248 * register it via bcENTER_LOOPER. 249 */ 250 251 BR_FINISHED = _IO('r', 14), 252 /* 253 * not currently supported 254 * stop threadpool thread 255 */ 256 257 BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t), 258 /* 259 * void *: cookie 260 */ 261 BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t), 262 /* 263 * void *: cookie 264 */ 265 266 BR_FAILED_REPLY = _IO('r', 17), 267 /* 268 * The the last transaction (either a bcTRANSACTION or 269 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters. 270 */ 271 }; 272 273 enum binder_driver_command_protocol { 274 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data), 275 BC_REPLY = _IOW('c', 1, struct binder_transaction_data), 276 /* 277 * binder_transaction_data: the sent command. 278 */ 279 280 BC_ACQUIRE_RESULT = _IOW('c', 2, __s32), 281 /* 282 * not currently supported 283 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful. 284 * Else you have acquired a primary reference on the object. 285 */ 286 287 BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t), 288 /* 289 * void *: ptr to transaction data received on a read 290 */ 291 292 BC_INCREFS = _IOW('c', 4, __u32), 293 BC_ACQUIRE = _IOW('c', 5, __u32), 294 BC_RELEASE = _IOW('c', 6, __u32), 295 BC_DECREFS = _IOW('c', 7, __u32), 296 /* 297 * int: descriptor 298 */ 299 300 BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie), 301 BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie), 302 /* 303 * void *: ptr to binder 304 * void *: cookie for binder 305 */ 306 307 BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc), 308 /* 309 * not currently supported 310 * int: priority 311 * int: descriptor 312 */ 313 314 BC_REGISTER_LOOPER = _IO('c', 11), 315 /* 316 * No parameters. 317 * Register a spawned looper thread with the device. 318 */ 319 320 BC_ENTER_LOOPER = _IO('c', 12), 321 BC_EXIT_LOOPER = _IO('c', 13), 322 /* 323 * No parameters. 324 * These two commands are sent as an application-level thread 325 * enters and exits the binder loop, respectively. They are 326 * used so the binder can have an accurate count of the number 327 * of looping threads it has available. 328 */ 329 330 BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, 331 struct binder_handle_cookie), 332 /* 333 * int: handle 334 * void *: cookie 335 */ 336 337 BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, 338 struct binder_handle_cookie), 339 /* 340 * int: handle 341 * void *: cookie 342 */ 343 344 BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t), 345 /* 346 * void *: cookie 347 */ 348 }; 349 350 #endif /* _UAPI_LINUX_BINDER_H */ 351 352