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