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/types.h> 24 #include <linux/ioctl.h> 25 26 #define B_PACK_CHARS(c1, c2, c3, c4) \ 27 ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4)) 28 #define B_TYPE_LARGE 0x85 29 30 enum { 31 BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE), 32 BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE), 33 BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE), 34 BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE), 35 BINDER_TYPE_FD = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE), 36 BINDER_TYPE_FDA = B_PACK_CHARS('f', 'd', 'a', B_TYPE_LARGE), 37 BINDER_TYPE_PTR = B_PACK_CHARS('p', 't', '*', B_TYPE_LARGE), 38 }; 39 40 enum { 41 FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff, 42 FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100, 43 }; 44 45 #ifdef BINDER_IPC_32BIT 46 typedef __u32 binder_size_t; 47 typedef __u32 binder_uintptr_t; 48 #else 49 typedef __u64 binder_size_t; 50 typedef __u64 binder_uintptr_t; 51 #endif 52 53 /** 54 * struct binder_object_header - header shared by all binder metadata objects. 55 * @type: type of the object 56 */ 57 struct binder_object_header { 58 __u32 type; 59 }; 60 61 /* 62 * This is the flattened representation of a Binder object for transfer 63 * between processes. The 'offsets' supplied as part of a binder transaction 64 * contains offsets into the data where these structures occur. The Binder 65 * driver takes care of re-writing the structure type and data as it moves 66 * between processes. 67 */ 68 struct flat_binder_object { 69 struct binder_object_header hdr; 70 __u32 flags; 71 72 /* 8 bytes of data. */ 73 union { 74 binder_uintptr_t binder; /* local object */ 75 __u32 handle; /* remote object */ 76 }; 77 78 /* extra data associated with local object */ 79 binder_uintptr_t cookie; 80 }; 81 82 /** 83 * struct binder_fd_object - describes a filedescriptor to be fixed up. 84 * @hdr: common header structure 85 * @pad_flags: padding to remain compatible with old userspace code 86 * @pad_binder: padding to remain compatible with old userspace code 87 * @fd: file descriptor 88 * @cookie: opaque data, used by user-space 89 */ 90 struct binder_fd_object { 91 struct binder_object_header hdr; 92 __u32 pad_flags; 93 union { 94 binder_uintptr_t pad_binder; 95 __u32 fd; 96 }; 97 98 binder_uintptr_t cookie; 99 }; 100 101 /* struct binder_buffer_object - object describing a userspace buffer 102 * @hdr: common header structure 103 * @flags: one or more BINDER_BUFFER_* flags 104 * @buffer: address of the buffer 105 * @length: length of the buffer 106 * @parent: index in offset array pointing to parent buffer 107 * @parent_offset: offset in @parent pointing to this buffer 108 * 109 * A binder_buffer object represents an object that the 110 * binder kernel driver can copy verbatim to the target 111 * address space. A buffer itself may be pointed to from 112 * within another buffer, meaning that the pointer inside 113 * that other buffer needs to be fixed up as well. This 114 * can be done by setting the BINDER_BUFFER_FLAG_HAS_PARENT 115 * flag in @flags, by setting @parent buffer to the index 116 * in the offset array pointing to the parent binder_buffer_object, 117 * and by setting @parent_offset to the offset in the parent buffer 118 * at which the pointer to this buffer is located. 119 */ 120 struct binder_buffer_object { 121 struct binder_object_header hdr; 122 __u32 flags; 123 binder_uintptr_t buffer; 124 binder_size_t length; 125 binder_size_t parent; 126 binder_size_t parent_offset; 127 }; 128 129 enum { 130 BINDER_BUFFER_FLAG_HAS_PARENT = 0x01, 131 }; 132 133 /* struct binder_fd_array_object - object describing an array of fds in a buffer 134 * @hdr: common header structure 135 * @pad: padding to ensure correct alignment 136 * @num_fds: number of file descriptors in the buffer 137 * @parent: index in offset array to buffer holding the fd array 138 * @parent_offset: start offset of fd array in the buffer 139 * 140 * A binder_fd_array object represents an array of file 141 * descriptors embedded in a binder_buffer_object. It is 142 * different from a regular binder_buffer_object because it 143 * describes a list of file descriptors to fix up, not an opaque 144 * blob of memory, and hence the kernel needs to treat it differently. 145 * 146 * An example of how this would be used is with Android's 147 * native_handle_t object, which is a struct with a list of integers 148 * and a list of file descriptors. The native_handle_t struct itself 149 * will be represented by a struct binder_buffer_objct, whereas the 150 * embedded list of file descriptors is represented by a 151 * struct binder_fd_array_object with that binder_buffer_object as 152 * a parent. 153 */ 154 struct binder_fd_array_object { 155 struct binder_object_header hdr; 156 __u32 pad; 157 binder_size_t num_fds; 158 binder_size_t parent; 159 binder_size_t parent_offset; 160 }; 161 162 /* 163 * On 64-bit platforms where user code may run in 32-bits the driver must 164 * translate the buffer (and local binder) addresses appropriately. 165 */ 166 167 struct binder_write_read { 168 binder_size_t write_size; /* bytes to write */ 169 binder_size_t write_consumed; /* bytes consumed by driver */ 170 binder_uintptr_t write_buffer; 171 binder_size_t read_size; /* bytes to read */ 172 binder_size_t read_consumed; /* bytes consumed by driver */ 173 binder_uintptr_t read_buffer; 174 }; 175 176 /* Use with BINDER_VERSION, driver fills in fields. */ 177 struct binder_version { 178 /* driver protocol version -- increment with incompatible change */ 179 __s32 protocol_version; 180 }; 181 182 /* This is the current protocol version. */ 183 #ifdef BINDER_IPC_32BIT 184 #define BINDER_CURRENT_PROTOCOL_VERSION 7 185 #else 186 #define BINDER_CURRENT_PROTOCOL_VERSION 8 187 #endif 188 189 /* 190 * Use with BINDER_GET_NODE_DEBUG_INFO, driver reads ptr, writes to all fields. 191 * Set ptr to NULL for the first call to get the info for the first node, and 192 * then repeat the call passing the previously returned value to get the next 193 * nodes. ptr will be 0 when there are no more nodes. 194 */ 195 struct binder_node_debug_info { 196 binder_uintptr_t ptr; 197 binder_uintptr_t cookie; 198 __u32 has_strong_ref; 199 __u32 has_weak_ref; 200 }; 201 202 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read) 203 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64) 204 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32) 205 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32) 206 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32) 207 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32) 208 #define BINDER_VERSION _IOWR('b', 9, struct binder_version) 209 #define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info) 210 211 /* 212 * NOTE: Two special error codes you should check for when calling 213 * in to the driver are: 214 * 215 * EINTR -- The operation has been interupted. This should be 216 * handled by retrying the ioctl() until a different error code 217 * is returned. 218 * 219 * ECONNREFUSED -- The driver is no longer accepting operations 220 * from your process. That is, the process is being destroyed. 221 * You should handle this by exiting from your process. Note 222 * that once this error code is returned, all further calls to 223 * the driver from any thread will return this same code. 224 */ 225 226 enum transaction_flags { 227 TF_ONE_WAY = 0x01, /* this is a one-way call: async, no return */ 228 TF_ROOT_OBJECT = 0x04, /* contents are the component's root object */ 229 TF_STATUS_CODE = 0x08, /* contents are a 32-bit status code */ 230 TF_ACCEPT_FDS = 0x10, /* allow replies with file descriptors */ 231 }; 232 233 struct binder_transaction_data { 234 /* The first two are only used for bcTRANSACTION and brTRANSACTION, 235 * identifying the target and contents of the transaction. 236 */ 237 union { 238 /* target descriptor of command transaction */ 239 __u32 handle; 240 /* target descriptor of return transaction */ 241 binder_uintptr_t ptr; 242 } target; 243 binder_uintptr_t cookie; /* target object cookie */ 244 __u32 code; /* transaction command */ 245 246 /* General information about the transaction. */ 247 __u32 flags; 248 pid_t sender_pid; 249 uid_t sender_euid; 250 binder_size_t data_size; /* number of bytes of data */ 251 binder_size_t offsets_size; /* number of bytes of offsets */ 252 253 /* If this transaction is inline, the data immediately 254 * follows here; otherwise, it ends with a pointer to 255 * the data buffer. 256 */ 257 union { 258 struct { 259 /* transaction data */ 260 binder_uintptr_t buffer; 261 /* offsets from buffer to flat_binder_object structs */ 262 binder_uintptr_t offsets; 263 } ptr; 264 __u8 buf[8]; 265 } data; 266 }; 267 268 struct binder_transaction_data_sg { 269 struct binder_transaction_data transaction_data; 270 binder_size_t buffers_size; 271 }; 272 273 struct binder_ptr_cookie { 274 binder_uintptr_t ptr; 275 binder_uintptr_t cookie; 276 }; 277 278 struct binder_handle_cookie { 279 __u32 handle; 280 binder_uintptr_t cookie; 281 } __packed; 282 283 struct binder_pri_desc { 284 __s32 priority; 285 __u32 desc; 286 }; 287 288 struct binder_pri_ptr_cookie { 289 __s32 priority; 290 binder_uintptr_t ptr; 291 binder_uintptr_t cookie; 292 }; 293 294 enum binder_driver_return_protocol { 295 BR_ERROR = _IOR('r', 0, __s32), 296 /* 297 * int: error code 298 */ 299 300 BR_OK = _IO('r', 1), 301 /* No parameters! */ 302 303 BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data), 304 BR_REPLY = _IOR('r', 3, struct binder_transaction_data), 305 /* 306 * binder_transaction_data: the received command. 307 */ 308 309 BR_ACQUIRE_RESULT = _IOR('r', 4, __s32), 310 /* 311 * not currently supported 312 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful. 313 * Else the remote object has acquired a primary reference. 314 */ 315 316 BR_DEAD_REPLY = _IO('r', 5), 317 /* 318 * The target of the last transaction (either a bcTRANSACTION or 319 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters. 320 */ 321 322 BR_TRANSACTION_COMPLETE = _IO('r', 6), 323 /* 324 * No parameters... always refers to the last transaction requested 325 * (including replies). Note that this will be sent even for 326 * asynchronous transactions. 327 */ 328 329 BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie), 330 BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie), 331 BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie), 332 BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie), 333 /* 334 * void *: ptr to binder 335 * void *: cookie for binder 336 */ 337 338 BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie), 339 /* 340 * not currently supported 341 * int: priority 342 * void *: ptr to binder 343 * void *: cookie for binder 344 */ 345 346 BR_NOOP = _IO('r', 12), 347 /* 348 * No parameters. Do nothing and examine the next command. It exists 349 * primarily so that we can replace it with a BR_SPAWN_LOOPER command. 350 */ 351 352 BR_SPAWN_LOOPER = _IO('r', 13), 353 /* 354 * No parameters. The driver has determined that a process has no 355 * threads waiting to service incoming transactions. When a process 356 * receives this command, it must spawn a new service thread and 357 * register it via bcENTER_LOOPER. 358 */ 359 360 BR_FINISHED = _IO('r', 14), 361 /* 362 * not currently supported 363 * stop threadpool thread 364 */ 365 366 BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t), 367 /* 368 * void *: cookie 369 */ 370 BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t), 371 /* 372 * void *: cookie 373 */ 374 375 BR_FAILED_REPLY = _IO('r', 17), 376 /* 377 * The the last transaction (either a bcTRANSACTION or 378 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters. 379 */ 380 }; 381 382 enum binder_driver_command_protocol { 383 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data), 384 BC_REPLY = _IOW('c', 1, struct binder_transaction_data), 385 /* 386 * binder_transaction_data: the sent command. 387 */ 388 389 BC_ACQUIRE_RESULT = _IOW('c', 2, __s32), 390 /* 391 * not currently supported 392 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful. 393 * Else you have acquired a primary reference on the object. 394 */ 395 396 BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t), 397 /* 398 * void *: ptr to transaction data received on a read 399 */ 400 401 BC_INCREFS = _IOW('c', 4, __u32), 402 BC_ACQUIRE = _IOW('c', 5, __u32), 403 BC_RELEASE = _IOW('c', 6, __u32), 404 BC_DECREFS = _IOW('c', 7, __u32), 405 /* 406 * int: descriptor 407 */ 408 409 BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie), 410 BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie), 411 /* 412 * void *: ptr to binder 413 * void *: cookie for binder 414 */ 415 416 BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc), 417 /* 418 * not currently supported 419 * int: priority 420 * int: descriptor 421 */ 422 423 BC_REGISTER_LOOPER = _IO('c', 11), 424 /* 425 * No parameters. 426 * Register a spawned looper thread with the device. 427 */ 428 429 BC_ENTER_LOOPER = _IO('c', 12), 430 BC_EXIT_LOOPER = _IO('c', 13), 431 /* 432 * No parameters. 433 * These two commands are sent as an application-level thread 434 * enters and exits the binder loop, respectively. They are 435 * used so the binder can have an accurate count of the number 436 * of looping threads it has available. 437 */ 438 439 BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, 440 struct binder_handle_cookie), 441 /* 442 * int: handle 443 * void *: cookie 444 */ 445 446 BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, 447 struct binder_handle_cookie), 448 /* 449 * int: handle 450 * void *: cookie 451 */ 452 453 BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t), 454 /* 455 * void *: cookie 456 */ 457 458 BC_TRANSACTION_SG = _IOW('c', 17, struct binder_transaction_data_sg), 459 BC_REPLY_SG = _IOW('c', 18, struct binder_transaction_data_sg), 460 /* 461 * binder_transaction_data_sg: the sent command. 462 */ 463 }; 464 465 #endif /* _UAPI_LINUX_BINDER_H */ 466 467