• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ioctl.h>
24 
25 #define B_PACK_CHARS(c1, c2, c3, c4) \
26 	((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
27 #define B_TYPE_LARGE 0x85
28 
29 enum {
30 	BINDER_TYPE_BINDER	= B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
31 	BINDER_TYPE_WEAK_BINDER	= B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
32 	BINDER_TYPE_HANDLE	= B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE),
33 	BINDER_TYPE_WEAK_HANDLE	= B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE),
34 	BINDER_TYPE_FD		= B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE),
35 };
36 
37 enum {
38 	FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
39 	FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
40 };
41 
42 #ifdef BINDER_IPC_32BIT
43 typedef __u32 binder_size_t;
44 typedef __u32 binder_uintptr_t;
45 #else
46 typedef __u64 binder_size_t;
47 typedef __u64 binder_uintptr_t;
48 #endif
49 
50 /*
51  * This is the flattened representation of a Binder object for transfer
52  * between processes.  The 'offsets' supplied as part of a binder transaction
53  * contains offsets into the data where these structures occur.  The Binder
54  * driver takes care of re-writing the structure type and data as it moves
55  * between processes.
56  */
57 struct flat_binder_object {
58 	/* 8 bytes for large_flat_header. */
59 	__u32	type;
60 	__u32	flags;
61 
62 	/* 8 bytes of data. */
63 	union {
64 		binder_uintptr_t	binder;	/* local object */
65 		__u32			handle;	/* remote object */
66 	};
67 
68 	/* extra data associated with local object */
69 	binder_uintptr_t	cookie;
70 };
71 
72 /*
73  * On 64-bit platforms where user code may run in 32-bits the driver must
74  * translate the buffer (and local binder) addresses appropriately.
75  */
76 
77 struct binder_write_read {
78 	binder_size_t		write_size;	/* bytes to write */
79 	binder_size_t		write_consumed;	/* bytes consumed by driver */
80 	binder_uintptr_t	write_buffer;
81 	binder_size_t		read_size;	/* bytes to read */
82 	binder_size_t		read_consumed;	/* bytes consumed by driver */
83 	binder_uintptr_t	read_buffer;
84 };
85 
86 /* Use with BINDER_VERSION, driver fills in fields. */
87 struct binder_version {
88 	/* driver protocol version -- increment with incompatible change */
89 	__s32	protocol_version;
90 };
91 
92 /* This is the current protocol version. */
93 #ifdef BINDER_IPC_32BIT
94 #define BINDER_CURRENT_PROTOCOL_VERSION 7
95 #else
96 #define BINDER_CURRENT_PROTOCOL_VERSION 8
97 #endif
98 
99 #define BINDER_WRITE_READ		_IOWR('b', 1, struct binder_write_read)
100 #define	BINDER_SET_IDLE_TIMEOUT		_IOW('b', 3, __s64)
101 #define	BINDER_SET_MAX_THREADS		_IOW('b', 5, __u32)
102 #define	BINDER_SET_IDLE_PRIORITY	_IOW('b', 6, __s32)
103 #define	BINDER_SET_CONTEXT_MGR		_IOW('b', 7, __s32)
104 #define	BINDER_THREAD_EXIT		_IOW('b', 8, __s32)
105 #define BINDER_VERSION			_IOWR('b', 9, struct binder_version)
106 
107 /*
108  * NOTE: Two special error codes you should check for when calling
109  * in to the driver are:
110  *
111  * EINTR -- The operation has been interupted.  This should be
112  * handled by retrying the ioctl() until a different error code
113  * is returned.
114  *
115  * ECONNREFUSED -- The driver is no longer accepting operations
116  * from your process.  That is, the process is being destroyed.
117  * You should handle this by exiting from your process.  Note
118  * that once this error code is returned, all further calls to
119  * the driver from any thread will return this same code.
120  */
121 
122 enum transaction_flags {
123 	TF_ONE_WAY	= 0x01,	/* this is a one-way call: async, no return */
124 	TF_ROOT_OBJECT	= 0x04,	/* contents are the component's root object */
125 	TF_STATUS_CODE	= 0x08,	/* contents are a 32-bit status code */
126 	TF_ACCEPT_FDS	= 0x10,	/* allow replies with file descriptors */
127 };
128 
129 struct binder_transaction_data {
130 	/* The first two are only used for bcTRANSACTION and brTRANSACTION,
131 	 * identifying the target and contents of the transaction.
132 	 */
133 	union {
134 		__u32	handle;	/* target descriptor of command transaction */
135 		binder_uintptr_t ptr;	/* target descriptor of return transaction */
136 	} target;
137 	binder_uintptr_t	cookie;	/* target object cookie */
138 	__u32		code;		/* transaction command */
139 
140 	/* General information about the transaction. */
141 	__u32		flags;
142 	pid_t		sender_pid;
143 	uid_t		sender_euid;
144 	binder_size_t	data_size;	/* number of bytes of data */
145 	binder_size_t	offsets_size;	/* number of bytes of offsets */
146 
147 	/* If this transaction is inline, the data immediately
148 	 * follows here; otherwise, it ends with a pointer to
149 	 * the data buffer.
150 	 */
151 	union {
152 		struct {
153 			/* transaction data */
154 			binder_uintptr_t	buffer;
155 			/* offsets from buffer to flat_binder_object structs */
156 			binder_uintptr_t	offsets;
157 		} ptr;
158 		__u8	buf[8];
159 	} data;
160 };
161 
162 struct binder_ptr_cookie {
163 	binder_uintptr_t ptr;
164 	binder_uintptr_t cookie;
165 };
166 
167 struct binder_handle_cookie {
168 	__u32 handle;
169 	binder_uintptr_t cookie;
170 } __attribute__((packed));
171 
172 struct binder_pri_desc {
173 	__s32 priority;
174 	__u32 desc;
175 };
176 
177 struct binder_pri_ptr_cookie {
178 	__s32 priority;
179 	binder_uintptr_t ptr;
180 	binder_uintptr_t cookie;
181 };
182 
183 enum binder_driver_return_protocol {
184 	BR_ERROR = _IOR('r', 0, __s32),
185 	/*
186 	 * int: error code
187 	 */
188 
189 	BR_OK = _IO('r', 1),
190 	/* No parameters! */
191 
192 	BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
193 	BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
194 	/*
195 	 * binder_transaction_data: the received command.
196 	 */
197 
198 	BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
199 	/*
200 	 * not currently supported
201 	 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
202 	 * Else the remote object has acquired a primary reference.
203 	 */
204 
205 	BR_DEAD_REPLY = _IO('r', 5),
206 	/*
207 	 * The target of the last transaction (either a bcTRANSACTION or
208 	 * a bcATTEMPT_ACQUIRE) is no longer with us.  No parameters.
209 	 */
210 
211 	BR_TRANSACTION_COMPLETE = _IO('r', 6),
212 	/*
213 	 * No parameters... always refers to the last transaction requested
214 	 * (including replies).  Note that this will be sent even for
215 	 * asynchronous transactions.
216 	 */
217 
218 	BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
219 	BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
220 	BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
221 	BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
222 	/*
223 	 * void *:	ptr to binder
224 	 * void *: cookie for binder
225 	 */
226 
227 	BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
228 	/*
229 	 * not currently supported
230 	 * int:	priority
231 	 * void *: ptr to binder
232 	 * void *: cookie for binder
233 	 */
234 
235 	BR_NOOP = _IO('r', 12),
236 	/*
237 	 * No parameters.  Do nothing and examine the next command.  It exists
238 	 * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
239 	 */
240 
241 	BR_SPAWN_LOOPER = _IO('r', 13),
242 	/*
243 	 * No parameters.  The driver has determined that a process has no
244 	 * threads waiting to service incoming transactions.  When a process
245 	 * receives this command, it must spawn a new service thread and
246 	 * register it via bcENTER_LOOPER.
247 	 */
248 
249 	BR_FINISHED = _IO('r', 14),
250 	/*
251 	 * not currently supported
252 	 * stop threadpool thread
253 	 */
254 
255 	BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
256 	/*
257 	 * void *: cookie
258 	 */
259 	BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
260 	/*
261 	 * void *: cookie
262 	 */
263 
264 	BR_FAILED_REPLY = _IO('r', 17),
265 	/*
266 	 * The the last transaction (either a bcTRANSACTION or
267 	 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory).  No parameters.
268 	 */
269 };
270 
271 enum binder_driver_command_protocol {
272 	BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
273 	BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
274 	/*
275 	 * binder_transaction_data: the sent command.
276 	 */
277 
278 	BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
279 	/*
280 	 * not currently supported
281 	 * int:  0 if the last BR_ATTEMPT_ACQUIRE was not successful.
282 	 * Else you have acquired a primary reference on the object.
283 	 */
284 
285 	BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
286 	/*
287 	 * void *: ptr to transaction data received on a read
288 	 */
289 
290 	BC_INCREFS = _IOW('c', 4, __u32),
291 	BC_ACQUIRE = _IOW('c', 5, __u32),
292 	BC_RELEASE = _IOW('c', 6, __u32),
293 	BC_DECREFS = _IOW('c', 7, __u32),
294 	/*
295 	 * int:	descriptor
296 	 */
297 
298 	BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
299 	BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
300 	/*
301 	 * void *: ptr to binder
302 	 * void *: cookie for binder
303 	 */
304 
305 	BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
306 	/*
307 	 * not currently supported
308 	 * int: priority
309 	 * int: descriptor
310 	 */
311 
312 	BC_REGISTER_LOOPER = _IO('c', 11),
313 	/*
314 	 * No parameters.
315 	 * Register a spawned looper thread with the device.
316 	 */
317 
318 	BC_ENTER_LOOPER = _IO('c', 12),
319 	BC_EXIT_LOOPER = _IO('c', 13),
320 	/*
321 	 * No parameters.
322 	 * These two commands are sent as an application-level thread
323 	 * enters and exits the binder loop, respectively.  They are
324 	 * used so the binder can have an accurate count of the number
325 	 * of looping threads it has available.
326 	 */
327 
328 	BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_handle_cookie),
329 	/*
330 	 * int: handle
331 	 * void *: cookie
332 	 */
333 
334 	BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_handle_cookie),
335 	/*
336 	 * int: handle
337 	 * void *: cookie
338 	 */
339 
340 	BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
341 	/*
342 	 * void *: cookie
343 	 */
344 };
345 
346 #endif /* _UAPI_LINUX_BINDER_H */
347 
348