blob: 5539933b3491b6ec98353c560a957ab9ad3f5544 [file] [log] [blame]
Colin Crossa3e9ddb2014-02-17 13:58:33 -08001/*
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
Greg Kroah-Hartmanbc2d62a2014-10-16 15:22:30 +020023#include <linux/types.h>
Colin Crossa3e9ddb2014-02-17 13:58:33 -080024#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
30enum {
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),
Martijn Coenene3e0f4802016-10-18 13:58:55 +020036 BINDER_TYPE_FDA = B_PACK_CHARS('f', 'd', 'a', B_TYPE_LARGE),
Martijn Coenen5a6da532016-09-30 14:10:07 +020037 BINDER_TYPE_PTR = B_PACK_CHARS('p', 't', '*', B_TYPE_LARGE),
Colin Crossa3e9ddb2014-02-17 13:58:33 -080038};
39
Martijn Coenen6aac9792017-06-07 09:29:14 -070040/**
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 */
45enum 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 */
52enum 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 */
Colin Crossa3e9ddb2014-02-17 13:58:33 -080064 FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
Martijn Coenen6aac9792017-06-07 09:29:14 -070065 /**
66 * @FLAT_BINDER_FLAG_ACCEPTS_FDS: whether the node accepts fds.
67 */
Colin Crossa3e9ddb2014-02-17 13:58:33 -080068 FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
Martijn Coenen6aac9792017-06-07 09:29:14 -070069 /**
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,
Martijn Coenenc46810c2017-06-23 10:13:43 -070082
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,
Colin Crossa3e9ddb2014-02-17 13:58:33 -080090};
91
Arve Hjønnevågda498892014-02-21 14:40:26 -080092#ifdef BINDER_IPC_32BIT
93typedef __u32 binder_size_t;
94typedef __u32 binder_uintptr_t;
95#else
96typedef __u64 binder_size_t;
97typedef __u64 binder_uintptr_t;
98#endif
99
Martijn Coenen00c80372016-07-13 12:06:49 +0200100/**
101 * struct binder_object_header - header shared by all binder metadata objects.
102 * @type: type of the object
103 */
104struct binder_object_header {
105 __u32 type;
106};
107
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800108/*
109 * This is the flattened representation of a Binder object for transfer
110 * between processes. The 'offsets' supplied as part of a binder transaction
111 * contains offsets into the data where these structures occur. The Binder
112 * driver takes care of re-writing the structure type and data as it moves
113 * between processes.
114 */
115struct flat_binder_object {
Martijn Coenen00c80372016-07-13 12:06:49 +0200116 struct binder_object_header hdr;
117 __u32 flags;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800118
119 /* 8 bytes of data. */
120 union {
Arve Hjønnevågda498892014-02-21 14:40:26 -0800121 binder_uintptr_t binder; /* local object */
122 __u32 handle; /* remote object */
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800123 };
124
125 /* extra data associated with local object */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800126 binder_uintptr_t cookie;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800127};
128
Martijn Coenen00c80372016-07-13 12:06:49 +0200129/**
130 * struct binder_fd_object - describes a filedescriptor to be fixed up.
131 * @hdr: common header structure
132 * @pad_flags: padding to remain compatible with old userspace code
133 * @pad_binder: padding to remain compatible with old userspace code
134 * @fd: file descriptor
135 * @cookie: opaque data, used by user-space
136 */
137struct binder_fd_object {
138 struct binder_object_header hdr;
139 __u32 pad_flags;
140 union {
141 binder_uintptr_t pad_binder;
142 __u32 fd;
143 };
144
145 binder_uintptr_t cookie;
146};
Martijn Coenen5a6da532016-09-30 14:10:07 +0200147
148/* struct binder_buffer_object - object describing a userspace buffer
149 * @hdr: common header structure
150 * @flags: one or more BINDER_BUFFER_* flags
151 * @buffer: address of the buffer
152 * @length: length of the buffer
153 * @parent: index in offset array pointing to parent buffer
154 * @parent_offset: offset in @parent pointing to this buffer
155 *
156 * A binder_buffer object represents an object that the
157 * binder kernel driver can copy verbatim to the target
158 * address space. A buffer itself may be pointed to from
159 * within another buffer, meaning that the pointer inside
160 * that other buffer needs to be fixed up as well. This
161 * can be done by setting the BINDER_BUFFER_FLAG_HAS_PARENT
162 * flag in @flags, by setting @parent buffer to the index
163 * in the offset array pointing to the parent binder_buffer_object,
164 * and by setting @parent_offset to the offset in the parent buffer
165 * at which the pointer to this buffer is located.
166 */
167struct binder_buffer_object {
168 struct binder_object_header hdr;
169 __u32 flags;
170 binder_uintptr_t buffer;
171 binder_size_t length;
172 binder_size_t parent;
173 binder_size_t parent_offset;
174};
175
176enum {
177 BINDER_BUFFER_FLAG_HAS_PARENT = 0x01,
178};
179
Martijn Coenene3e0f4802016-10-18 13:58:55 +0200180/* struct binder_fd_array_object - object describing an array of fds in a buffer
181 * @hdr: common header structure
Martijn Coenen8b451dc2017-03-07 15:54:56 +0100182 * @pad: padding to ensure correct alignment
Martijn Coenene3e0f4802016-10-18 13:58:55 +0200183 * @num_fds: number of file descriptors in the buffer
184 * @parent: index in offset array to buffer holding the fd array
185 * @parent_offset: start offset of fd array in the buffer
186 *
187 * A binder_fd_array object represents an array of file
188 * descriptors embedded in a binder_buffer_object. It is
189 * different from a regular binder_buffer_object because it
190 * describes a list of file descriptors to fix up, not an opaque
191 * blob of memory, and hence the kernel needs to treat it differently.
192 *
193 * An example of how this would be used is with Android's
194 * native_handle_t object, which is a struct with a list of integers
195 * and a list of file descriptors. The native_handle_t struct itself
196 * will be represented by a struct binder_buffer_objct, whereas the
197 * embedded list of file descriptors is represented by a
198 * struct binder_fd_array_object with that binder_buffer_object as
199 * a parent.
200 */
201struct binder_fd_array_object {
202 struct binder_object_header hdr;
Martijn Coenen8b451dc2017-03-07 15:54:56 +0100203 __u32 pad;
Martijn Coenene3e0f4802016-10-18 13:58:55 +0200204 binder_size_t num_fds;
205 binder_size_t parent;
206 binder_size_t parent_offset;
207};
208
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800209/*
210 * On 64-bit platforms where user code may run in 32-bits the driver must
211 * translate the buffer (and local binder) addresses appropriately.
212 */
213
214struct binder_write_read {
Arve Hjønnevågda498892014-02-21 14:40:26 -0800215 binder_size_t write_size; /* bytes to write */
216 binder_size_t write_consumed; /* bytes consumed by driver */
217 binder_uintptr_t write_buffer;
218 binder_size_t read_size; /* bytes to read */
219 binder_size_t read_consumed; /* bytes consumed by driver */
220 binder_uintptr_t read_buffer;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800221};
222
223/* Use with BINDER_VERSION, driver fills in fields. */
224struct binder_version {
225 /* driver protocol version -- increment with incompatible change */
226 __s32 protocol_version;
227};
228
229/* This is the current protocol version. */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800230#ifdef BINDER_IPC_32BIT
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800231#define BINDER_CURRENT_PROTOCOL_VERSION 7
Arve Hjønnevågda498892014-02-21 14:40:26 -0800232#else
233#define BINDER_CURRENT_PROTOCOL_VERSION 8
234#endif
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800235
Colin Cross833babb32017-06-20 13:54:44 -0700236/*
237 * Use with BINDER_GET_NODE_DEBUG_INFO, driver reads ptr, writes to all fields.
238 * Set ptr to NULL for the first call to get the info for the first node, and
239 * then repeat the call passing the previously returned value to get the next
240 * nodes. ptr will be 0 when there are no more nodes.
241 */
242struct binder_node_debug_info {
243 binder_uintptr_t ptr;
244 binder_uintptr_t cookie;
245 __u32 has_strong_ref;
246 __u32 has_weak_ref;
247};
248
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800249#define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
250#define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
251#define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
252#define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
253#define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
254#define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
255#define BINDER_VERSION _IOWR('b', 9, struct binder_version)
Colin Cross833babb32017-06-20 13:54:44 -0700256#define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info)
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800257
258/*
259 * NOTE: Two special error codes you should check for when calling
260 * in to the driver are:
261 *
262 * EINTR -- The operation has been interupted. This should be
263 * handled by retrying the ioctl() until a different error code
264 * is returned.
265 *
266 * ECONNREFUSED -- The driver is no longer accepting operations
267 * from your process. That is, the process is being destroyed.
268 * You should handle this by exiting from your process. Note
269 * that once this error code is returned, all further calls to
270 * the driver from any thread will return this same code.
271 */
272
273enum transaction_flags {
274 TF_ONE_WAY = 0x01, /* this is a one-way call: async, no return */
275 TF_ROOT_OBJECT = 0x04, /* contents are the component's root object */
276 TF_STATUS_CODE = 0x08, /* contents are a 32-bit status code */
277 TF_ACCEPT_FDS = 0x10, /* allow replies with file descriptors */
278};
279
280struct binder_transaction_data {
281 /* The first two are only used for bcTRANSACTION and brTRANSACTION,
282 * identifying the target and contents of the transaction.
283 */
284 union {
Arve Hjønnevågda498892014-02-21 14:40:26 -0800285 /* target descriptor of command transaction */
286 __u32 handle;
287 /* target descriptor of return transaction */
288 binder_uintptr_t ptr;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800289 } target;
Arve Hjønnevågda498892014-02-21 14:40:26 -0800290 binder_uintptr_t cookie; /* target object cookie */
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800291 __u32 code; /* transaction command */
292
293 /* General information about the transaction. */
294 __u32 flags;
295 pid_t sender_pid;
296 uid_t sender_euid;
Arve Hjønnevågda498892014-02-21 14:40:26 -0800297 binder_size_t data_size; /* number of bytes of data */
298 binder_size_t offsets_size; /* number of bytes of offsets */
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800299
300 /* If this transaction is inline, the data immediately
301 * follows here; otherwise, it ends with a pointer to
302 * the data buffer.
303 */
304 union {
305 struct {
306 /* transaction data */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800307 binder_uintptr_t buffer;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800308 /* offsets from buffer to flat_binder_object structs */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800309 binder_uintptr_t offsets;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800310 } ptr;
311 __u8 buf[8];
312 } data;
313};
314
Martijn Coenen5a6da532016-09-30 14:10:07 +0200315struct binder_transaction_data_sg {
316 struct binder_transaction_data transaction_data;
317 binder_size_t buffers_size;
318};
319
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800320struct binder_ptr_cookie {
Arve Hjønnevågda498892014-02-21 14:40:26 -0800321 binder_uintptr_t ptr;
322 binder_uintptr_t cookie;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800323};
324
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800325struct binder_handle_cookie {
326 __u32 handle;
Arve Hjønnevågda498892014-02-21 14:40:26 -0800327 binder_uintptr_t cookie;
Purnendu Kapadia2fd29142014-08-15 18:20:30 +0100328} __packed;
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800329
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800330struct binder_pri_desc {
331 __s32 priority;
332 __u32 desc;
333};
334
335struct binder_pri_ptr_cookie {
336 __s32 priority;
Arve Hjønnevågda498892014-02-21 14:40:26 -0800337 binder_uintptr_t ptr;
338 binder_uintptr_t cookie;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800339};
340
341enum binder_driver_return_protocol {
342 BR_ERROR = _IOR('r', 0, __s32),
343 /*
344 * int: error code
345 */
346
347 BR_OK = _IO('r', 1),
348 /* No parameters! */
349
350 BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
351 BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
352 /*
353 * binder_transaction_data: the received command.
354 */
355
356 BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
357 /*
358 * not currently supported
359 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
360 * Else the remote object has acquired a primary reference.
361 */
362
363 BR_DEAD_REPLY = _IO('r', 5),
364 /*
365 * The target of the last transaction (either a bcTRANSACTION or
366 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters.
367 */
368
369 BR_TRANSACTION_COMPLETE = _IO('r', 6),
370 /*
371 * No parameters... always refers to the last transaction requested
372 * (including replies). Note that this will be sent even for
373 * asynchronous transactions.
374 */
375
376 BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
377 BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
378 BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
379 BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
380 /*
381 * void *: ptr to binder
382 * void *: cookie for binder
383 */
384
385 BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
386 /*
387 * not currently supported
388 * int: priority
389 * void *: ptr to binder
390 * void *: cookie for binder
391 */
392
393 BR_NOOP = _IO('r', 12),
394 /*
395 * No parameters. Do nothing and examine the next command. It exists
396 * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
397 */
398
399 BR_SPAWN_LOOPER = _IO('r', 13),
400 /*
401 * No parameters. The driver has determined that a process has no
402 * threads waiting to service incoming transactions. When a process
403 * receives this command, it must spawn a new service thread and
404 * register it via bcENTER_LOOPER.
405 */
406
407 BR_FINISHED = _IO('r', 14),
408 /*
409 * not currently supported
410 * stop threadpool thread
411 */
412
Arve Hjønnevågda498892014-02-21 14:40:26 -0800413 BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800414 /*
415 * void *: cookie
416 */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800417 BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800418 /*
419 * void *: cookie
420 */
421
422 BR_FAILED_REPLY = _IO('r', 17),
423 /*
424 * The the last transaction (either a bcTRANSACTION or
425 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters.
426 */
427};
428
429enum binder_driver_command_protocol {
430 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
431 BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
432 /*
433 * binder_transaction_data: the sent command.
434 */
435
436 BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
437 /*
438 * not currently supported
439 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful.
440 * Else you have acquired a primary reference on the object.
441 */
442
Arve Hjønnevågda498892014-02-21 14:40:26 -0800443 BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800444 /*
445 * void *: ptr to transaction data received on a read
446 */
447
448 BC_INCREFS = _IOW('c', 4, __u32),
449 BC_ACQUIRE = _IOW('c', 5, __u32),
450 BC_RELEASE = _IOW('c', 6, __u32),
451 BC_DECREFS = _IOW('c', 7, __u32),
452 /*
453 * int: descriptor
454 */
455
456 BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
457 BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
458 /*
459 * void *: ptr to binder
460 * void *: cookie for binder
461 */
462
463 BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
464 /*
465 * not currently supported
466 * int: priority
467 * int: descriptor
468 */
469
470 BC_REGISTER_LOOPER = _IO('c', 11),
471 /*
472 * No parameters.
473 * Register a spawned looper thread with the device.
474 */
475
476 BC_ENTER_LOOPER = _IO('c', 12),
477 BC_EXIT_LOOPER = _IO('c', 13),
478 /*
479 * No parameters.
480 * These two commands are sent as an application-level thread
481 * enters and exits the binder loop, respectively. They are
482 * used so the binder can have an accurate count of the number
483 * of looping threads it has available.
484 */
485
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800486 BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14,
487 struct binder_handle_cookie),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800488 /*
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800489 * int: handle
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800490 * void *: cookie
491 */
492
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800493 BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15,
494 struct binder_handle_cookie),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800495 /*
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800496 * int: handle
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800497 * void *: cookie
498 */
499
Arve Hjønnevågda498892014-02-21 14:40:26 -0800500 BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800501 /*
502 * void *: cookie
503 */
Martijn Coenen5a6da532016-09-30 14:10:07 +0200504
505 BC_TRANSACTION_SG = _IOW('c', 17, struct binder_transaction_data_sg),
506 BC_REPLY_SG = _IOW('c', 18, struct binder_transaction_data_sg),
507 /*
508 * binder_transaction_data_sg: the sent command.
509 */
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800510};
511
512#endif /* _UAPI_LINUX_BINDER_H */
513