Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 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_object |
| 13 | { |
| 14 | uint32_t type; |
| 15 | uint32_t flags; |
| 16 | void *pointer; |
| 17 | void *cookie; |
| 18 | }; |
| 19 | |
| 20 | struct binder_txn |
| 21 | { |
| 22 | void *target; |
| 23 | void *cookie; |
| 24 | uint32_t code; |
| 25 | uint32_t flags; |
| 26 | |
| 27 | uint32_t sender_pid; |
| 28 | uint32_t sender_euid; |
| 29 | |
| 30 | uint32_t data_size; |
| 31 | uint32_t offs_size; |
| 32 | void *data; |
| 33 | void *offs; |
| 34 | }; |
| 35 | |
| 36 | struct binder_io |
| 37 | { |
| 38 | char *data; /* pointer to read/write from */ |
| 39 | uint32_t *offs; /* array of offsets */ |
| 40 | uint32_t data_avail; /* bytes available in data buffer */ |
| 41 | uint32_t offs_avail; /* entries available in offsets array */ |
| 42 | |
| 43 | char *data0; /* start of data buffer */ |
| 44 | uint32_t *offs0; /* start of offsets buffer */ |
| 45 | uint32_t flags; |
| 46 | uint32_t unused; |
| 47 | }; |
| 48 | |
| 49 | struct binder_death { |
| 50 | void (*func)(struct binder_state *bs, void *ptr); |
| 51 | void *ptr; |
| 52 | }; |
| 53 | |
| 54 | /* the one magic object */ |
| 55 | #define BINDER_SERVICE_MANAGER ((void*) 0) |
| 56 | |
| 57 | #define SVC_MGR_NAME "android.os.IServiceManager" |
| 58 | |
| 59 | enum { |
| 60 | SVC_MGR_GET_SERVICE = 1, |
| 61 | SVC_MGR_CHECK_SERVICE, |
| 62 | SVC_MGR_ADD_SERVICE, |
| 63 | SVC_MGR_LIST_SERVICES, |
| 64 | }; |
| 65 | |
| 66 | typedef int (*binder_handler)(struct binder_state *bs, |
| 67 | struct binder_txn *txn, |
| 68 | struct binder_io *msg, |
| 69 | struct binder_io *reply); |
| 70 | |
| 71 | struct binder_state *binder_open(unsigned mapsize); |
| 72 | void binder_close(struct binder_state *bs); |
| 73 | |
| 74 | /* initiate a blocking binder call |
| 75 | * - returns zero on success |
| 76 | */ |
| 77 | int binder_call(struct binder_state *bs, |
| 78 | struct binder_io *msg, struct binder_io *reply, |
| 79 | void *target, uint32_t code); |
| 80 | |
| 81 | /* release any state associate with the binder_io |
| 82 | * - call once any necessary data has been extracted from the |
| 83 | * binder_io after binder_call() returns |
| 84 | * - can safely be called even if binder_call() fails |
| 85 | */ |
| 86 | void binder_done(struct binder_state *bs, |
| 87 | struct binder_io *msg, struct binder_io *reply); |
| 88 | |
| 89 | /* manipulate strong references */ |
| 90 | void binder_acquire(struct binder_state *bs, void *ptr); |
| 91 | void binder_release(struct binder_state *bs, void *ptr); |
| 92 | |
| 93 | void binder_link_to_death(struct binder_state *bs, void *ptr, struct binder_death *death); |
| 94 | |
| 95 | void binder_loop(struct binder_state *bs, binder_handler func); |
| 96 | |
| 97 | int binder_become_context_manager(struct binder_state *bs); |
| 98 | |
| 99 | /* allocate a binder_io, providing a stack-allocated working |
| 100 | * buffer, size of the working buffer, and how many object |
| 101 | * offset entries to reserve from the buffer |
| 102 | */ |
| 103 | void bio_init(struct binder_io *bio, void *data, |
| 104 | uint32_t maxdata, uint32_t maxobjects); |
| 105 | |
| 106 | void bio_destroy(struct binder_io *bio); |
| 107 | |
| 108 | void bio_put_obj(struct binder_io *bio, void *ptr); |
| 109 | void bio_put_ref(struct binder_io *bio, void *ptr); |
| 110 | void bio_put_uint32(struct binder_io *bio, uint32_t n); |
| 111 | void bio_put_string16(struct binder_io *bio, const uint16_t *str); |
| 112 | void bio_put_string16_x(struct binder_io *bio, const char *_str); |
| 113 | |
| 114 | uint32_t bio_get_uint32(struct binder_io *bio); |
| 115 | uint16_t *bio_get_string16(struct binder_io *bio, uint32_t *sz); |
| 116 | void *bio_get_obj(struct binder_io *bio); |
| 117 | void *bio_get_ref(struct binder_io *bio); |
| 118 | |
| 119 | #endif |