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