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