blob: 026558ac254d34879bd356f51a77c4c6c372d9fc [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,
Colin Crossa3e9ddb2014-02-17 13:58:33 -080082};
83
Arve Hjønnevågda498892014-02-21 14:40:26 -080084#ifdef BINDER_IPC_32BIT
85typedef __u32 binder_size_t;
86typedef __u32 binder_uintptr_t;
87#else
88typedef __u64 binder_size_t;
89typedef __u64 binder_uintptr_t;
90#endif
91
Martijn Coenen00c80372016-07-13 12:06:49 +020092/**
93 * struct binder_object_header - header shared by all binder metadata objects.
94 * @type: type of the object
95 */
96struct binder_object_header {
97 __u32 type;
98};
99
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800100/*
101 * This is the flattened representation of a Binder object for transfer
102 * between processes. The 'offsets' supplied as part of a binder transaction
103 * contains offsets into the data where these structures occur. The Binder
104 * driver takes care of re-writing the structure type and data as it moves
105 * between processes.
106 */
107struct flat_binder_object {
Martijn Coenen00c80372016-07-13 12:06:49 +0200108 struct binder_object_header hdr;
109 __u32 flags;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800110
111 /* 8 bytes of data. */
112 union {
Arve Hjønnevågda498892014-02-21 14:40:26 -0800113 binder_uintptr_t binder; /* local object */
114 __u32 handle; /* remote object */
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800115 };
116
117 /* extra data associated with local object */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800118 binder_uintptr_t cookie;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800119};
120
Martijn Coenen00c80372016-07-13 12:06:49 +0200121/**
122 * struct binder_fd_object - describes a filedescriptor to be fixed up.
123 * @hdr: common header structure
124 * @pad_flags: padding to remain compatible with old userspace code
125 * @pad_binder: padding to remain compatible with old userspace code
126 * @fd: file descriptor
127 * @cookie: opaque data, used by user-space
128 */
129struct binder_fd_object {
130 struct binder_object_header hdr;
131 __u32 pad_flags;
132 union {
133 binder_uintptr_t pad_binder;
134 __u32 fd;
135 };
136
137 binder_uintptr_t cookie;
138};
Martijn Coenen5a6da532016-09-30 14:10:07 +0200139
140/* struct binder_buffer_object - object describing a userspace buffer
141 * @hdr: common header structure
142 * @flags: one or more BINDER_BUFFER_* flags
143 * @buffer: address of the buffer
144 * @length: length of the buffer
145 * @parent: index in offset array pointing to parent buffer
146 * @parent_offset: offset in @parent pointing to this buffer
147 *
148 * A binder_buffer object represents an object that the
149 * binder kernel driver can copy verbatim to the target
150 * address space. A buffer itself may be pointed to from
151 * within another buffer, meaning that the pointer inside
152 * that other buffer needs to be fixed up as well. This
153 * can be done by setting the BINDER_BUFFER_FLAG_HAS_PARENT
154 * flag in @flags, by setting @parent buffer to the index
155 * in the offset array pointing to the parent binder_buffer_object,
156 * and by setting @parent_offset to the offset in the parent buffer
157 * at which the pointer to this buffer is located.
158 */
159struct binder_buffer_object {
160 struct binder_object_header hdr;
161 __u32 flags;
162 binder_uintptr_t buffer;
163 binder_size_t length;
164 binder_size_t parent;
165 binder_size_t parent_offset;
166};
167
168enum {
169 BINDER_BUFFER_FLAG_HAS_PARENT = 0x01,
170};
171
Martijn Coenene3e0f4802016-10-18 13:58:55 +0200172/* struct binder_fd_array_object - object describing an array of fds in a buffer
173 * @hdr: common header structure
Martijn Coenen8b451dc2017-03-07 15:54:56 +0100174 * @pad: padding to ensure correct alignment
Martijn Coenene3e0f4802016-10-18 13:58:55 +0200175 * @num_fds: number of file descriptors in the buffer
176 * @parent: index in offset array to buffer holding the fd array
177 * @parent_offset: start offset of fd array in the buffer
178 *
179 * A binder_fd_array object represents an array of file
180 * descriptors embedded in a binder_buffer_object. It is
181 * different from a regular binder_buffer_object because it
182 * describes a list of file descriptors to fix up, not an opaque
183 * blob of memory, and hence the kernel needs to treat it differently.
184 *
185 * An example of how this would be used is with Android's
186 * native_handle_t object, which is a struct with a list of integers
187 * and a list of file descriptors. The native_handle_t struct itself
188 * will be represented by a struct binder_buffer_objct, whereas the
189 * embedded list of file descriptors is represented by a
190 * struct binder_fd_array_object with that binder_buffer_object as
191 * a parent.
192 */
193struct binder_fd_array_object {
194 struct binder_object_header hdr;
Martijn Coenen8b451dc2017-03-07 15:54:56 +0100195 __u32 pad;
Martijn Coenene3e0f4802016-10-18 13:58:55 +0200196 binder_size_t num_fds;
197 binder_size_t parent;
198 binder_size_t parent_offset;
199};
200
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800201/*
202 * On 64-bit platforms where user code may run in 32-bits the driver must
203 * translate the buffer (and local binder) addresses appropriately.
204 */
205
206struct binder_write_read {
Arve Hjønnevågda498892014-02-21 14:40:26 -0800207 binder_size_t write_size; /* bytes to write */
208 binder_size_t write_consumed; /* bytes consumed by driver */
209 binder_uintptr_t write_buffer;
210 binder_size_t read_size; /* bytes to read */
211 binder_size_t read_consumed; /* bytes consumed by driver */
212 binder_uintptr_t read_buffer;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800213};
214
215/* Use with BINDER_VERSION, driver fills in fields. */
216struct binder_version {
217 /* driver protocol version -- increment with incompatible change */
218 __s32 protocol_version;
219};
220
221/* This is the current protocol version. */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800222#ifdef BINDER_IPC_32BIT
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800223#define BINDER_CURRENT_PROTOCOL_VERSION 7
Arve Hjønnevågda498892014-02-21 14:40:26 -0800224#else
225#define BINDER_CURRENT_PROTOCOL_VERSION 8
226#endif
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800227
228#define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
229#define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
230#define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
231#define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
232#define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
233#define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
234#define BINDER_VERSION _IOWR('b', 9, struct binder_version)
235
236/*
237 * NOTE: Two special error codes you should check for when calling
238 * in to the driver are:
239 *
240 * EINTR -- The operation has been interupted. This should be
241 * handled by retrying the ioctl() until a different error code
242 * is returned.
243 *
244 * ECONNREFUSED -- The driver is no longer accepting operations
245 * from your process. That is, the process is being destroyed.
246 * You should handle this by exiting from your process. Note
247 * that once this error code is returned, all further calls to
248 * the driver from any thread will return this same code.
249 */
250
251enum transaction_flags {
252 TF_ONE_WAY = 0x01, /* this is a one-way call: async, no return */
253 TF_ROOT_OBJECT = 0x04, /* contents are the component's root object */
254 TF_STATUS_CODE = 0x08, /* contents are a 32-bit status code */
255 TF_ACCEPT_FDS = 0x10, /* allow replies with file descriptors */
256};
257
258struct binder_transaction_data {
259 /* The first two are only used for bcTRANSACTION and brTRANSACTION,
260 * identifying the target and contents of the transaction.
261 */
262 union {
Arve Hjønnevågda498892014-02-21 14:40:26 -0800263 /* target descriptor of command transaction */
264 __u32 handle;
265 /* target descriptor of return transaction */
266 binder_uintptr_t ptr;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800267 } target;
Arve Hjønnevågda498892014-02-21 14:40:26 -0800268 binder_uintptr_t cookie; /* target object cookie */
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800269 __u32 code; /* transaction command */
270
271 /* General information about the transaction. */
272 __u32 flags;
273 pid_t sender_pid;
274 uid_t sender_euid;
Arve Hjønnevågda498892014-02-21 14:40:26 -0800275 binder_size_t data_size; /* number of bytes of data */
276 binder_size_t offsets_size; /* number of bytes of offsets */
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800277
278 /* If this transaction is inline, the data immediately
279 * follows here; otherwise, it ends with a pointer to
280 * the data buffer.
281 */
282 union {
283 struct {
284 /* transaction data */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800285 binder_uintptr_t buffer;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800286 /* offsets from buffer to flat_binder_object structs */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800287 binder_uintptr_t offsets;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800288 } ptr;
289 __u8 buf[8];
290 } data;
291};
292
Martijn Coenen5a6da532016-09-30 14:10:07 +0200293struct binder_transaction_data_sg {
294 struct binder_transaction_data transaction_data;
295 binder_size_t buffers_size;
296};
297
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800298struct binder_ptr_cookie {
Arve Hjønnevågda498892014-02-21 14:40:26 -0800299 binder_uintptr_t ptr;
300 binder_uintptr_t cookie;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800301};
302
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800303struct binder_handle_cookie {
304 __u32 handle;
Arve Hjønnevågda498892014-02-21 14:40:26 -0800305 binder_uintptr_t cookie;
Purnendu Kapadia2fd29142014-08-15 18:20:30 +0100306} __packed;
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800307
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800308struct binder_pri_desc {
309 __s32 priority;
310 __u32 desc;
311};
312
313struct binder_pri_ptr_cookie {
314 __s32 priority;
Arve Hjønnevågda498892014-02-21 14:40:26 -0800315 binder_uintptr_t ptr;
316 binder_uintptr_t cookie;
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800317};
318
319enum binder_driver_return_protocol {
320 BR_ERROR = _IOR('r', 0, __s32),
321 /*
322 * int: error code
323 */
324
325 BR_OK = _IO('r', 1),
326 /* No parameters! */
327
328 BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
329 BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
330 /*
331 * binder_transaction_data: the received command.
332 */
333
334 BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
335 /*
336 * not currently supported
337 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
338 * Else the remote object has acquired a primary reference.
339 */
340
341 BR_DEAD_REPLY = _IO('r', 5),
342 /*
343 * The target of the last transaction (either a bcTRANSACTION or
344 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters.
345 */
346
347 BR_TRANSACTION_COMPLETE = _IO('r', 6),
348 /*
349 * No parameters... always refers to the last transaction requested
350 * (including replies). Note that this will be sent even for
351 * asynchronous transactions.
352 */
353
354 BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
355 BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
356 BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
357 BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
358 /*
359 * void *: ptr to binder
360 * void *: cookie for binder
361 */
362
363 BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
364 /*
365 * not currently supported
366 * int: priority
367 * void *: ptr to binder
368 * void *: cookie for binder
369 */
370
371 BR_NOOP = _IO('r', 12),
372 /*
373 * No parameters. Do nothing and examine the next command. It exists
374 * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
375 */
376
377 BR_SPAWN_LOOPER = _IO('r', 13),
378 /*
379 * No parameters. The driver has determined that a process has no
380 * threads waiting to service incoming transactions. When a process
381 * receives this command, it must spawn a new service thread and
382 * register it via bcENTER_LOOPER.
383 */
384
385 BR_FINISHED = _IO('r', 14),
386 /*
387 * not currently supported
388 * stop threadpool thread
389 */
390
Arve Hjønnevågda498892014-02-21 14:40:26 -0800391 BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800392 /*
393 * void *: cookie
394 */
Arve Hjønnevågda498892014-02-21 14:40:26 -0800395 BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800396 /*
397 * void *: cookie
398 */
399
400 BR_FAILED_REPLY = _IO('r', 17),
401 /*
402 * The the last transaction (either a bcTRANSACTION or
403 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters.
404 */
405};
406
407enum binder_driver_command_protocol {
408 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
409 BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
410 /*
411 * binder_transaction_data: the sent command.
412 */
413
414 BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
415 /*
416 * not currently supported
417 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful.
418 * Else you have acquired a primary reference on the object.
419 */
420
Arve Hjønnevågda498892014-02-21 14:40:26 -0800421 BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800422 /*
423 * void *: ptr to transaction data received on a read
424 */
425
426 BC_INCREFS = _IOW('c', 4, __u32),
427 BC_ACQUIRE = _IOW('c', 5, __u32),
428 BC_RELEASE = _IOW('c', 6, __u32),
429 BC_DECREFS = _IOW('c', 7, __u32),
430 /*
431 * int: descriptor
432 */
433
434 BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
435 BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
436 /*
437 * void *: ptr to binder
438 * void *: cookie for binder
439 */
440
441 BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
442 /*
443 * not currently supported
444 * int: priority
445 * int: descriptor
446 */
447
448 BC_REGISTER_LOOPER = _IO('c', 11),
449 /*
450 * No parameters.
451 * Register a spawned looper thread with the device.
452 */
453
454 BC_ENTER_LOOPER = _IO('c', 12),
455 BC_EXIT_LOOPER = _IO('c', 13),
456 /*
457 * No parameters.
458 * These two commands are sent as an application-level thread
459 * enters and exits the binder loop, respectively. They are
460 * used so the binder can have an accurate count of the number
461 * of looping threads it has available.
462 */
463
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800464 BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14,
465 struct binder_handle_cookie),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800466 /*
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800467 * int: handle
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800468 * void *: cookie
469 */
470
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800471 BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15,
472 struct binder_handle_cookie),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800473 /*
Serban Constantinescudf24a2e2014-02-21 14:40:25 -0800474 * int: handle
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800475 * void *: cookie
476 */
477
Arve Hjønnevågda498892014-02-21 14:40:26 -0800478 BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800479 /*
480 * void *: cookie
481 */
Martijn Coenen5a6da532016-09-30 14:10:07 +0200482
483 BC_TRANSACTION_SG = _IOW('c', 17, struct binder_transaction_data_sg),
484 BC_REPLY_SG = _IOW('c', 18, struct binder_transaction_data_sg),
485 /*
486 * binder_transaction_data_sg: the sent command.
487 */
Colin Crossa3e9ddb2014-02-17 13:58:33 -0800488};
489
490#endif /* _UAPI_LINUX_BINDER_H */
491