binder.h 10 KB

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