binder.h 9.4 KB

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