1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * Copyright (C) 2008 Google, Inc.
5 * Based on, but no longer compatible with, the original
6 * OpenBinder.org binder driver interface, which is:
8 * Copyright (c) 2005 Palmsource, Inc.
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
21 #ifndef _UAPI_LINUX_BINDER_H
22 #define _UAPI_LINUX_BINDER_H
24 #include <linux/types.h>
25 #include <linux/ioctl.h>
27 #define B_PACK_CHARS(c1, c2, c3, c4) \
28 ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
29 #define B_TYPE_LARGE 0x85
32 BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
33 BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
34 BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE),
35 BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', 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),
42 FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
43 FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
46 * @FLAT_BINDER_FLAG_TXN_SECURITY_CTX: request security contexts
48 * Only when set, causes senders to include their security
51 FLAT_BINDER_FLAG_TXN_SECURITY_CTX = 0x1000,
54 #ifdef BINDER_IPC_32BIT
55 typedef __u32 binder_size_t;
56 typedef __u32 binder_uintptr_t;
58 typedef __u64 binder_size_t;
59 typedef __u64 binder_uintptr_t;
63 * struct binder_object_header - header shared by all binder metadata objects.
64 * @type: type of the object
66 struct binder_object_header {
71 * This is the flattened representation of a Binder object for transfer
72 * between processes. The 'offsets' supplied as part of a binder transaction
73 * contains offsets into the data where these structures occur. The Binder
74 * driver takes care of re-writing the structure type and data as it moves
77 struct flat_binder_object {
78 struct binder_object_header hdr;
81 /* 8 bytes of data. */
83 binder_uintptr_t binder; /* local object */
84 __u32 handle; /* remote object */
87 /* extra data associated with local object */
88 binder_uintptr_t cookie;
92 * struct binder_fd_object - describes a filedescriptor to be fixed up.
93 * @hdr: common header structure
94 * @pad_flags: padding to remain compatible with old userspace code
95 * @pad_binder: padding to remain compatible with old userspace code
96 * @fd: file descriptor
97 * @cookie: opaque data, used by user-space
99 struct binder_fd_object {
100 struct binder_object_header hdr;
103 binder_uintptr_t pad_binder;
107 binder_uintptr_t cookie;
110 /* struct binder_buffer_object - object describing a userspace buffer
111 * @hdr: common header structure
112 * @flags: one or more BINDER_BUFFER_* flags
113 * @buffer: address of the buffer
114 * @length: length of the buffer
115 * @parent: index in offset array pointing to parent buffer
116 * @parent_offset: offset in @parent pointing to this buffer
118 * A binder_buffer object represents an object that the
119 * binder kernel driver can copy verbatim to the target
120 * address space. A buffer itself may be pointed to from
121 * within another buffer, meaning that the pointer inside
122 * that other buffer needs to be fixed up as well. This
123 * can be done by setting the BINDER_BUFFER_FLAG_HAS_PARENT
124 * flag in @flags, by setting @parent buffer to the index
125 * in the offset array pointing to the parent binder_buffer_object,
126 * and by setting @parent_offset to the offset in the parent buffer
127 * at which the pointer to this buffer is located.
129 struct binder_buffer_object {
130 struct binder_object_header hdr;
132 binder_uintptr_t buffer;
133 binder_size_t length;
134 binder_size_t parent;
135 binder_size_t parent_offset;
139 BINDER_BUFFER_FLAG_HAS_PARENT = 0x01,
142 /* struct binder_fd_array_object - object describing an array of fds in a buffer
143 * @hdr: common header structure
144 * @pad: padding to ensure correct alignment
145 * @num_fds: number of file descriptors in the buffer
146 * @parent: index in offset array to buffer holding the fd array
147 * @parent_offset: start offset of fd array in the buffer
149 * A binder_fd_array object represents an array of file
150 * descriptors embedded in a binder_buffer_object. It is
151 * different from a regular binder_buffer_object because it
152 * describes a list of file descriptors to fix up, not an opaque
153 * blob of memory, and hence the kernel needs to treat it differently.
155 * An example of how this would be used is with Android's
156 * native_handle_t object, which is a struct with a list of integers
157 * and a list of file descriptors. The native_handle_t struct itself
158 * will be represented by a struct binder_buffer_objct, whereas the
159 * embedded list of file descriptors is represented by a
160 * struct binder_fd_array_object with that binder_buffer_object as
163 struct binder_fd_array_object {
164 struct binder_object_header hdr;
166 binder_size_t num_fds;
167 binder_size_t parent;
168 binder_size_t parent_offset;
172 * On 64-bit platforms where user code may run in 32-bits the driver must
173 * translate the buffer (and local binder) addresses appropriately.
176 struct binder_write_read {
177 binder_size_t write_size; /* bytes to write */
178 binder_size_t write_consumed; /* bytes consumed by driver */
179 binder_uintptr_t write_buffer;
180 binder_size_t read_size; /* bytes to read */
181 binder_size_t read_consumed; /* bytes consumed by driver */
182 binder_uintptr_t read_buffer;
185 /* Use with BINDER_VERSION, driver fills in fields. */
186 struct binder_version {
187 /* driver protocol version -- increment with incompatible change */
188 __s32 protocol_version;
191 /* This is the current protocol version. */
192 #ifdef BINDER_IPC_32BIT
193 #define BINDER_CURRENT_PROTOCOL_VERSION 7
195 #define BINDER_CURRENT_PROTOCOL_VERSION 8
199 * Use with BINDER_GET_NODE_DEBUG_INFO, driver reads ptr, writes to all fields.
200 * Set ptr to NULL for the first call to get the info for the first node, and
201 * then repeat the call passing the previously returned value to get the next
202 * nodes. ptr will be 0 when there are no more nodes.
204 struct binder_node_debug_info {
205 binder_uintptr_t ptr;
206 binder_uintptr_t cookie;
207 __u32 has_strong_ref;
211 struct binder_node_info_for_ref {
220 struct binder_freeze_info {
226 struct binder_frozen_status_info {
229 /* process received sync transactions since last frozen
230 * bit 0: received sync transaction after being frozen
231 * bit 1: new pending sync transaction during freezing
235 /* process received async transactions since last frozen */
239 /* struct binder_extened_error - extended error information
240 * @id: identifier for the failed operation
241 * @command: command as defined by binder_driver_return_protocol
242 * @param: parameter holding a negative errno value
244 * Used with BINDER_GET_EXTENDED_ERROR. This extends the error information
245 * returned by the driver upon a failed operation. Userspace can pull this
246 * data to properly handle specific error scenarios.
248 struct binder_extended_error {
254 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
255 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
256 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
257 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
258 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
259 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
260 #define BINDER_VERSION _IOWR('b', 9, struct binder_version)
261 #define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info)
262 #define BINDER_GET_NODE_INFO_FOR_REF _IOWR('b', 12, struct binder_node_info_for_ref)
263 #define BINDER_SET_CONTEXT_MGR_EXT _IOW('b', 13, struct flat_binder_object)
264 #define BINDER_FREEZE _IOW('b', 14, struct binder_freeze_info)
265 #define BINDER_GET_FROZEN_INFO _IOWR('b', 15, struct binder_frozen_status_info)
266 #define BINDER_ENABLE_ONEWAY_SPAM_DETECTION _IOW('b', 16, __u32)
267 #define BINDER_GET_EXTENDED_ERROR _IOWR('b', 17, struct binder_extended_error)
270 * NOTE: Two special error codes you should check for when calling
271 * in to the driver are:
273 * EINTR -- The operation has been interupted. This should be
274 * handled by retrying the ioctl() until a different error code
277 * ECONNREFUSED -- The driver is no longer accepting operations
278 * from your process. That is, the process is being destroyed.
279 * You should handle this by exiting from your process. Note
280 * that once this error code is returned, all further calls to
281 * the driver from any thread will return this same code.
284 enum transaction_flags {
285 TF_ONE_WAY = 0x01, /* this is a one-way call: async, no return */
286 TF_ROOT_OBJECT = 0x04, /* contents are the component's root object */
287 TF_STATUS_CODE = 0x08, /* contents are a 32-bit status code */
288 TF_ACCEPT_FDS = 0x10, /* allow replies with file descriptors */
289 TF_CLEAR_BUF = 0x20, /* clear buffer on txn complete */
292 struct binder_transaction_data {
293 /* The first two are only used for bcTRANSACTION and brTRANSACTION,
294 * identifying the target and contents of the transaction.
297 /* target descriptor of command transaction */
299 /* target descriptor of return transaction */
300 binder_uintptr_t ptr;
302 binder_uintptr_t cookie; /* target object cookie */
303 __u32 code; /* transaction command */
305 /* General information about the transaction. */
307 __kernel_pid_t sender_pid;
308 __kernel_uid32_t sender_euid;
309 binder_size_t data_size; /* number of bytes of data */
310 binder_size_t offsets_size; /* number of bytes of offsets */
312 /* If this transaction is inline, the data immediately
313 * follows here; otherwise, it ends with a pointer to
318 /* transaction data */
319 binder_uintptr_t buffer;
320 /* offsets from buffer to flat_binder_object structs */
321 binder_uintptr_t offsets;
327 struct binder_transaction_data_secctx {
328 struct binder_transaction_data transaction_data;
329 binder_uintptr_t secctx;
332 struct binder_transaction_data_sg {
333 struct binder_transaction_data transaction_data;
334 binder_size_t buffers_size;
337 struct binder_ptr_cookie {
338 binder_uintptr_t ptr;
339 binder_uintptr_t cookie;
342 struct binder_handle_cookie {
344 binder_uintptr_t cookie;
347 struct binder_pri_desc {
352 struct binder_pri_ptr_cookie {
354 binder_uintptr_t ptr;
355 binder_uintptr_t cookie;
358 enum binder_driver_return_protocol {
359 BR_ERROR = _IOR('r', 0, __s32),
367 BR_TRANSACTION_SEC_CTX = _IOR('r', 2,
368 struct binder_transaction_data_secctx),
370 * binder_transaction_data_secctx: the received command.
372 BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
373 BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
375 * binder_transaction_data: the received command.
378 BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
380 * not currently supported
381 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
382 * Else the remote object has acquired a primary reference.
385 BR_DEAD_REPLY = _IO('r', 5),
387 * The target of the last transaction (either a bcTRANSACTION or
388 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters.
391 BR_TRANSACTION_COMPLETE = _IO('r', 6),
393 * No parameters... always refers to the last transaction requested
394 * (including replies). Note that this will be sent even for
395 * asynchronous transactions.
398 BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
399 BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
400 BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
401 BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
403 * void *: ptr to binder
404 * void *: cookie for binder
407 BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
409 * not currently supported
411 * void *: ptr to binder
412 * void *: cookie for binder
415 BR_NOOP = _IO('r', 12),
417 * No parameters. Do nothing and examine the next command. It exists
418 * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
421 BR_SPAWN_LOOPER = _IO('r', 13),
423 * No parameters. The driver has determined that a process has no
424 * threads waiting to service incoming transactions. When a process
425 * receives this command, it must spawn a new service thread and
426 * register it via bcENTER_LOOPER.
429 BR_FINISHED = _IO('r', 14),
431 * not currently supported
432 * stop threadpool thread
435 BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
439 BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
444 BR_FAILED_REPLY = _IO('r', 17),
446 * The last transaction (either a bcTRANSACTION or
447 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters.
450 BR_FROZEN_REPLY = _IO('r', 18),
452 * The target of the last transaction (either a bcTRANSACTION or
453 * a bcATTEMPT_ACQUIRE) is frozen. No parameters.
456 BR_ONEWAY_SPAM_SUSPECT = _IO('r', 19),
458 * Current process sent too many oneway calls to target, and the last
459 * asynchronous transaction makes the allocated async buffer size exceed
460 * detection threshold. No parameters.
464 enum binder_driver_command_protocol {
465 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
466 BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
468 * binder_transaction_data: the sent command.
471 BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
473 * not currently supported
474 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful.
475 * Else you have acquired a primary reference on the object.
478 BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
480 * void *: ptr to transaction data received on a read
483 BC_INCREFS = _IOW('c', 4, __u32),
484 BC_ACQUIRE = _IOW('c', 5, __u32),
485 BC_RELEASE = _IOW('c', 6, __u32),
486 BC_DECREFS = _IOW('c', 7, __u32),
491 BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
492 BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
494 * void *: ptr to binder
495 * void *: cookie for binder
498 BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
500 * not currently supported
505 BC_REGISTER_LOOPER = _IO('c', 11),
508 * Register a spawned looper thread with the device.
511 BC_ENTER_LOOPER = _IO('c', 12),
512 BC_EXIT_LOOPER = _IO('c', 13),
515 * These two commands are sent as an application-level thread
516 * enters and exits the binder loop, respectively. They are
517 * used so the binder can have an accurate count of the number
518 * of looping threads it has available.
521 BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14,
522 struct binder_handle_cookie),
528 BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15,
529 struct binder_handle_cookie),
535 BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
540 BC_TRANSACTION_SG = _IOW('c', 17, struct binder_transaction_data_sg),
541 BC_REPLY_SG = _IOW('c', 18, struct binder_transaction_data_sg),
543 * binder_transaction_data_sg: the sent command.
547 #endif /* _UAPI_LINUX_BINDER_H */