2 * Copyright (C) 2008 Google, Inc.
4 * Based on, but no longer compatible with, the original
5 * OpenBinder.org binder driver interface, which is:
7 * Copyright (c) 2005 Palmsource, Inc.
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.
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.
20 #ifndef _UAPI_LINUX_BINDER_H
21 #define _UAPI_LINUX_BINDER_H
23 #include <linux/types.h>
24 #include <linux/ioctl.h>
26 #define B_PACK_CHARS(c1, c2, c3, c4) \
27 ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
28 #define B_TYPE_LARGE 0x85
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
),
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.
45 enum flat_binder_object_shifts
{
46 FLAT_BINDER_FLAG_SCHED_POLICY_SHIFT
= 9,
50 * enum flat_binder_object_flags - flags for use in flat_binder_object.flags
52 enum flat_binder_object_flags
{
54 * @FLAT_BINDER_FLAG_PRIORITY_MASK: bit-mask for min scheduler priority
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.
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]
64 FLAT_BINDER_FLAG_PRIORITY_MASK
= 0xff,
66 * @FLAT_BINDER_FLAG_ACCEPTS_FDS: whether the node accepts fds.
68 FLAT_BINDER_FLAG_ACCEPTS_FDS
= 0x100,
70 * @FLAT_BINDER_FLAG_SCHED_POLICY_MASK: bit-mask for scheduling policy
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:
80 FLAT_BINDER_FLAG_SCHED_POLICY_MASK
=
81 3U << FLAT_BINDER_FLAG_SCHED_POLICY_SHIFT
,
84 * @FLAT_BINDER_FLAG_INHERIT_RT: whether the node inherits RT policy
86 * Only when set, calls into this node will inherit a real-time
87 * scheduling policy from the caller (for synchronous transactions).
89 FLAT_BINDER_FLAG_INHERIT_RT
= 0x800,
91 * @FLAT_BINDER_FLAG_TXN_SECURITY_CTX: request security contexts
93 * Only when set, causes senders to include their security
96 FLAT_BINDER_FLAG_TXN_SECURITY_CTX
= 0x1000,
99 #ifdef BINDER_IPC_32BIT
100 typedef __u32 binder_size_t
;
101 typedef __u32 binder_uintptr_t
;
103 typedef __u64 binder_size_t
;
104 typedef __u64 binder_uintptr_t
;
108 * struct binder_object_header - header shared by all binder metadata objects.
109 * @type: type of the object
111 struct binder_object_header
{
116 * This is the flattened representation of a Binder object for transfer
117 * between processes. The 'offsets' supplied as part of a binder transaction
118 * contains offsets into the data where these structures occur. The Binder
119 * driver takes care of re-writing the structure type and data as it moves
122 struct flat_binder_object
{
123 struct binder_object_header hdr
;
126 /* 8 bytes of data. */
128 binder_uintptr_t binder
; /* local object */
129 __u32 handle
; /* remote object */
132 /* extra data associated with local object */
133 binder_uintptr_t cookie
;
137 * struct binder_fd_object - describes a filedescriptor to be fixed up.
138 * @hdr: common header structure
139 * @pad_flags: padding to remain compatible with old userspace code
140 * @pad_binder: padding to remain compatible with old userspace code
141 * @fd: file descriptor
142 * @cookie: opaque data, used by user-space
144 struct binder_fd_object
{
145 struct binder_object_header hdr
;
148 binder_uintptr_t pad_binder
;
152 binder_uintptr_t cookie
;
155 /* struct binder_buffer_object - object describing a userspace buffer
156 * @hdr: common header structure
157 * @flags: one or more BINDER_BUFFER_* flags
158 * @buffer: address of the buffer
159 * @length: length of the buffer
160 * @parent: index in offset array pointing to parent buffer
161 * @parent_offset: offset in @parent pointing to this buffer
163 * A binder_buffer object represents an object that the
164 * binder kernel driver can copy verbatim to the target
165 * address space. A buffer itself may be pointed to from
166 * within another buffer, meaning that the pointer inside
167 * that other buffer needs to be fixed up as well. This
168 * can be done by setting the BINDER_BUFFER_FLAG_HAS_PARENT
169 * flag in @flags, by setting @parent buffer to the index
170 * in the offset array pointing to the parent binder_buffer_object,
171 * and by setting @parent_offset to the offset in the parent buffer
172 * at which the pointer to this buffer is located.
174 struct binder_buffer_object
{
175 struct binder_object_header hdr
;
177 binder_uintptr_t buffer
;
178 binder_size_t length
;
179 binder_size_t parent
;
180 binder_size_t parent_offset
;
184 BINDER_BUFFER_FLAG_HAS_PARENT
= 0x01,
187 /* struct binder_fd_array_object - object describing an array of fds in a buffer
188 * @hdr: common header structure
189 * @pad: padding to ensure correct alignment
190 * @num_fds: number of file descriptors in the buffer
191 * @parent: index in offset array to buffer holding the fd array
192 * @parent_offset: start offset of fd array in the buffer
194 * A binder_fd_array object represents an array of file
195 * descriptors embedded in a binder_buffer_object. It is
196 * different from a regular binder_buffer_object because it
197 * describes a list of file descriptors to fix up, not an opaque
198 * blob of memory, and hence the kernel needs to treat it differently.
200 * An example of how this would be used is with Android's
201 * native_handle_t object, which is a struct with a list of integers
202 * and a list of file descriptors. The native_handle_t struct itself
203 * will be represented by a struct binder_buffer_objct, whereas the
204 * embedded list of file descriptors is represented by a
205 * struct binder_fd_array_object with that binder_buffer_object as
208 struct binder_fd_array_object
{
209 struct binder_object_header hdr
;
211 binder_size_t num_fds
;
212 binder_size_t parent
;
213 binder_size_t parent_offset
;
217 * On 64-bit platforms where user code may run in 32-bits the driver must
218 * translate the buffer (and local binder) addresses appropriately.
221 struct binder_write_read
{
222 binder_size_t write_size
; /* bytes to write */
223 binder_size_t write_consumed
; /* bytes consumed by driver */
224 binder_uintptr_t write_buffer
;
225 binder_size_t read_size
; /* bytes to read */
226 binder_size_t read_consumed
; /* bytes consumed by driver */
227 binder_uintptr_t read_buffer
;
230 /* Use with BINDER_VERSION, driver fills in fields. */
231 struct binder_version
{
232 /* driver protocol version -- increment with incompatible change */
233 __s32 protocol_version
;
236 /* This is the current protocol version. */
237 #ifdef BINDER_IPC_32BIT
238 #define BINDER_CURRENT_PROTOCOL_VERSION 7
240 #define BINDER_CURRENT_PROTOCOL_VERSION 8
244 * Use with BINDER_GET_NODE_DEBUG_INFO, driver reads ptr, writes to all fields.
245 * Set ptr to NULL for the first call to get the info for the first node, and
246 * then repeat the call passing the previously returned value to get the next
247 * nodes. ptr will be 0 when there are no more nodes.
249 struct binder_node_debug_info
{
250 binder_uintptr_t ptr
;
251 binder_uintptr_t cookie
;
252 __u32 has_strong_ref
;
256 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
257 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
258 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
259 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
260 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
261 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
262 #define BINDER_VERSION _IOWR('b', 9, struct binder_version)
263 #define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info)
264 #define BINDER_SET_CONTEXT_MGR_EXT _IOW('b', 13, struct flat_binder_object)
266 * NOTE: Two special error codes you should check for when calling
267 * in to the driver are:
269 * EINTR -- The operation has been interupted. This should be
270 * handled by retrying the ioctl() until a different error code
273 * ECONNREFUSED -- The driver is no longer accepting operations
274 * from your process. That is, the process is being destroyed.
275 * You should handle this by exiting from your process. Note
276 * that once this error code is returned, all further calls to
277 * the driver from any thread will return this same code.
280 enum transaction_flags
{
281 TF_ONE_WAY
= 0x01, /* this is a one-way call: async, no return */
282 TF_ROOT_OBJECT
= 0x04, /* contents are the component's root object */
283 TF_STATUS_CODE
= 0x08, /* contents are a 32-bit status code */
284 TF_ACCEPT_FDS
= 0x10, /* allow replies with file descriptors */
287 struct binder_transaction_data
{
288 /* The first two are only used for bcTRANSACTION and brTRANSACTION,
289 * identifying the target and contents of the transaction.
292 /* target descriptor of command transaction */
294 /* target descriptor of return transaction */
295 binder_uintptr_t ptr
;
297 binder_uintptr_t cookie
; /* target object cookie */
298 __u32 code
; /* transaction command */
300 /* General information about the transaction. */
304 binder_size_t data_size
; /* number of bytes of data */
305 binder_size_t offsets_size
; /* number of bytes of offsets */
307 /* If this transaction is inline, the data immediately
308 * follows here; otherwise, it ends with a pointer to
313 /* transaction data */
314 binder_uintptr_t buffer
;
315 /* offsets from buffer to flat_binder_object structs */
316 binder_uintptr_t offsets
;
321 struct binder_transaction_data_secctx
{
322 struct binder_transaction_data transaction_data
;
323 binder_uintptr_t secctx
;
327 struct binder_transaction_data_sg
{
328 struct binder_transaction_data transaction_data
;
329 binder_size_t buffers_size
;
332 struct binder_ptr_cookie
{
333 binder_uintptr_t ptr
;
334 binder_uintptr_t cookie
;
337 struct binder_handle_cookie
{
339 binder_uintptr_t cookie
;
342 struct binder_pri_desc
{
347 struct binder_pri_ptr_cookie
{
349 binder_uintptr_t ptr
;
350 binder_uintptr_t cookie
;
353 enum binder_driver_return_protocol
{
354 BR_ERROR
= _IOR('r', 0, __s32
),
361 BR_TRANSACTION_SEC_CTX
= _IOR('r', 2,
362 struct binder_transaction_data_secctx
),
364 * binder_transaction_data_secctx: the received command.
366 BR_TRANSACTION
= _IOR('r', 2, struct binder_transaction_data
),
367 BR_REPLY
= _IOR('r', 3, struct binder_transaction_data
),
369 * binder_transaction_data: the received command.
372 BR_ACQUIRE_RESULT
= _IOR('r', 4, __s32
),
374 * not currently supported
375 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
376 * Else the remote object has acquired a primary reference.
379 BR_DEAD_REPLY
= _IO('r', 5),
381 * The target of the last transaction (either a bcTRANSACTION or
382 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters.
385 BR_TRANSACTION_COMPLETE
= _IO('r', 6),
387 * No parameters... always refers to the last transaction requested
388 * (including replies). Note that this will be sent even for
389 * asynchronous transactions.
392 BR_INCREFS
= _IOR('r', 7, struct binder_ptr_cookie
),
393 BR_ACQUIRE
= _IOR('r', 8, struct binder_ptr_cookie
),
394 BR_RELEASE
= _IOR('r', 9, struct binder_ptr_cookie
),
395 BR_DECREFS
= _IOR('r', 10, struct binder_ptr_cookie
),
397 * void *: ptr to binder
398 * void *: cookie for binder
401 BR_ATTEMPT_ACQUIRE
= _IOR('r', 11, struct binder_pri_ptr_cookie
),
403 * not currently supported
405 * void *: ptr to binder
406 * void *: cookie for binder
409 BR_NOOP
= _IO('r', 12),
411 * No parameters. Do nothing and examine the next command. It exists
412 * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
415 BR_SPAWN_LOOPER
= _IO('r', 13),
417 * No parameters. The driver has determined that a process has no
418 * threads waiting to service incoming transactions. When a process
419 * receives this command, it must spawn a new service thread and
420 * register it via bcENTER_LOOPER.
423 BR_FINISHED
= _IO('r', 14),
425 * not currently supported
426 * stop threadpool thread
429 BR_DEAD_BINDER
= _IOR('r', 15, binder_uintptr_t
),
433 BR_CLEAR_DEATH_NOTIFICATION_DONE
= _IOR('r', 16, binder_uintptr_t
),
438 BR_FAILED_REPLY
= _IO('r', 17),
440 * The the last transaction (either a bcTRANSACTION or
441 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters.
445 enum binder_driver_command_protocol
{
446 BC_TRANSACTION
= _IOW('c', 0, struct binder_transaction_data
),
447 BC_REPLY
= _IOW('c', 1, struct binder_transaction_data
),
449 * binder_transaction_data: the sent command.
452 BC_ACQUIRE_RESULT
= _IOW('c', 2, __s32
),
454 * not currently supported
455 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful.
456 * Else you have acquired a primary reference on the object.
459 BC_FREE_BUFFER
= _IOW('c', 3, binder_uintptr_t
),
461 * void *: ptr to transaction data received on a read
464 BC_INCREFS
= _IOW('c', 4, __u32
),
465 BC_ACQUIRE
= _IOW('c', 5, __u32
),
466 BC_RELEASE
= _IOW('c', 6, __u32
),
467 BC_DECREFS
= _IOW('c', 7, __u32
),
472 BC_INCREFS_DONE
= _IOW('c', 8, struct binder_ptr_cookie
),
473 BC_ACQUIRE_DONE
= _IOW('c', 9, struct binder_ptr_cookie
),
475 * void *: ptr to binder
476 * void *: cookie for binder
479 BC_ATTEMPT_ACQUIRE
= _IOW('c', 10, struct binder_pri_desc
),
481 * not currently supported
486 BC_REGISTER_LOOPER
= _IO('c', 11),
489 * Register a spawned looper thread with the device.
492 BC_ENTER_LOOPER
= _IO('c', 12),
493 BC_EXIT_LOOPER
= _IO('c', 13),
496 * These two commands are sent as an application-level thread
497 * enters and exits the binder loop, respectively. They are
498 * used so the binder can have an accurate count of the number
499 * of looping threads it has available.
502 BC_REQUEST_DEATH_NOTIFICATION
= _IOW('c', 14,
503 struct binder_handle_cookie
),
509 BC_CLEAR_DEATH_NOTIFICATION
= _IOW('c', 15,
510 struct binder_handle_cookie
),
516 BC_DEAD_BINDER_DONE
= _IOW('c', 16, binder_uintptr_t
),
521 BC_TRANSACTION_SG
= _IOW('c', 17, struct binder_transaction_data_sg
),
522 BC_REPLY_SG
= _IOW('c', 18, struct binder_transaction_data_sg
),
524 * binder_transaction_data_sg: the sent command.
528 #endif /* _UAPI_LINUX_BINDER_H */