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 | |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 12 | struct binder_io |
| 13 | { |
| 14 | char *data; /* pointer to read/write from */ |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame^] | 15 | 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 */ |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 18 | |
| 19 | char *data0; /* start of data buffer */ |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame^] | 20 | size_t *offs0; /* start of offsets buffer */ |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 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; |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame^] | 28 | }; |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 29 | |
| 30 | /* the one magic object */ |
| 31 | #define BINDER_SERVICE_MANAGER ((void*) 0) |
| 32 | |
| 33 | #define SVC_MGR_NAME "android.os.IServiceManager" |
| 34 | |
| 35 | enum { |
| 36 | SVC_MGR_GET_SERVICE = 1, |
| 37 | SVC_MGR_CHECK_SERVICE, |
| 38 | SVC_MGR_ADD_SERVICE, |
| 39 | SVC_MGR_LIST_SERVICES, |
| 40 | }; |
| 41 | |
| 42 | typedef int (*binder_handler)(struct binder_state *bs, |
Serban Constantinescu | bcf3888 | 2014-01-10 13:56:27 +0000 | [diff] [blame] | 43 | struct binder_transaction_data *txn, |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 44 | struct binder_io *msg, |
| 45 | struct binder_io *reply); |
| 46 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame^] | 47 | struct binder_state *binder_open(size_t mapsize); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 48 | void binder_close(struct binder_state *bs); |
| 49 | |
| 50 | /* initiate a blocking binder call |
| 51 | * - returns zero on success |
| 52 | */ |
| 53 | int binder_call(struct binder_state *bs, |
| 54 | struct binder_io *msg, struct binder_io *reply, |
| 55 | void *target, uint32_t code); |
| 56 | |
| 57 | /* release any state associate with the binder_io |
| 58 | * - call once any necessary data has been extracted from the |
| 59 | * binder_io after binder_call() returns |
| 60 | * - can safely be called even if binder_call() fails |
| 61 | */ |
| 62 | void binder_done(struct binder_state *bs, |
| 63 | struct binder_io *msg, struct binder_io *reply); |
| 64 | |
| 65 | /* manipulate strong references */ |
| 66 | void binder_acquire(struct binder_state *bs, void *ptr); |
| 67 | void binder_release(struct binder_state *bs, void *ptr); |
| 68 | |
| 69 | void binder_link_to_death(struct binder_state *bs, void *ptr, struct binder_death *death); |
| 70 | |
| 71 | void binder_loop(struct binder_state *bs, binder_handler func); |
| 72 | |
| 73 | int binder_become_context_manager(struct binder_state *bs); |
| 74 | |
| 75 | /* allocate a binder_io, providing a stack-allocated working |
| 76 | * buffer, size of the working buffer, and how many object |
| 77 | * offset entries to reserve from the buffer |
| 78 | */ |
| 79 | void bio_init(struct binder_io *bio, void *data, |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame^] | 80 | size_t maxdata, size_t maxobjects); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 81 | |
| 82 | void bio_put_obj(struct binder_io *bio, void *ptr); |
| 83 | void bio_put_ref(struct binder_io *bio, void *ptr); |
| 84 | void bio_put_uint32(struct binder_io *bio, uint32_t n); |
| 85 | void bio_put_string16(struct binder_io *bio, const uint16_t *str); |
| 86 | void bio_put_string16_x(struct binder_io *bio, const char *_str); |
| 87 | |
| 88 | uint32_t bio_get_uint32(struct binder_io *bio); |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame^] | 89 | uint16_t *bio_get_string16(struct binder_io *bio, size_t *sz); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 90 | void *bio_get_ref(struct binder_io *bio); |
| 91 | |
| 92 | #endif |