binder.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright 2008 The Android Open Source Project
  2. */
  3. #ifndef _BINDER_H_
  4. #define _BINDER_H_
  5. #include <linux/android/binder.h>
  6. #include <sys/ioctl.h>
  7. struct binder_state;
  8. struct binder_io
  9. {
  10. char *data; /* pointer to read/write from */
  11. binder_size_t *offs; /* array of offsets */
  12. size_t data_avail; /* bytes available in data buffer */
  13. size_t offs_avail; /* entries available in offsets array */
  14. char *data0; /* start of data buffer */
  15. binder_size_t *offs0; /* start of offsets buffer */
  16. uint32_t flags;
  17. uint32_t unused;
  18. };
  19. struct binder_death {
  20. void (*func)(struct binder_state *bs, void *ptr);
  21. void *ptr;
  22. };
  23. /* the one magic handle */
  24. #define BINDER_SERVICE_MANAGER 0U
  25. #define SVC_MGR_NAME "android.os.IServiceManager"
  26. enum {
  27. /* Must match definitions in IBinder.h and IServiceManager.h */
  28. PING_TRANSACTION = B_PACK_CHARS('_','P','N','G'),
  29. SVC_MGR_GET_SERVICE = 1,
  30. SVC_MGR_CHECK_SERVICE,
  31. SVC_MGR_ADD_SERVICE,
  32. SVC_MGR_LIST_SERVICES,
  33. };
  34. typedef int (*binder_handler)(struct binder_state *bs,
  35. struct binder_transaction_data_secctx *txn,
  36. struct binder_io *msg,
  37. struct binder_io *reply);
  38. struct binder_state *binder_open(const char* driver, size_t mapsize);
  39. void binder_close(struct binder_state *bs);
  40. /* initiate a blocking binder call
  41. * - returns zero on success
  42. */
  43. int binder_call(struct binder_state *bs,
  44. struct binder_io *msg, struct binder_io *reply,
  45. uint32_t target, uint32_t code);
  46. /* release any state associate with the binder_io
  47. * - call once any necessary data has been extracted from the
  48. * binder_io after binder_call() returns
  49. * - can safely be called even if binder_call() fails
  50. */
  51. void binder_done(struct binder_state *bs,
  52. struct binder_io *msg, struct binder_io *reply);
  53. /* manipulate strong references */
  54. void binder_acquire(struct binder_state *bs, uint32_t target);
  55. void binder_release(struct binder_state *bs, uint32_t target);
  56. void binder_link_to_death(struct binder_state *bs, uint32_t target, struct binder_death *death);
  57. void binder_loop(struct binder_state *bs, binder_handler func);
  58. int binder_become_context_manager(struct binder_state *bs);
  59. /* allocate a binder_io, providing a stack-allocated working
  60. * buffer, size of the working buffer, and how many object
  61. * offset entries to reserve from the buffer
  62. */
  63. void bio_init(struct binder_io *bio, void *data,
  64. size_t maxdata, size_t maxobjects);
  65. void bio_put_obj(struct binder_io *bio, void *ptr);
  66. void bio_put_ref(struct binder_io *bio, uint32_t handle);
  67. void bio_put_uint32(struct binder_io *bio, uint32_t n);
  68. void bio_put_string16(struct binder_io *bio, const uint16_t *str);
  69. void bio_put_string16_x(struct binder_io *bio, const char *_str);
  70. uint32_t bio_get_uint32(struct binder_io *bio);
  71. uint16_t *bio_get_string16(struct binder_io *bio, size_t *sz);
  72. uint32_t bio_get_ref(struct binder_io *bio);
  73. #endif