binder.h 8.9 KB

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