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> |
Christopher Ferris | 0170cd0 | 2016-07-18 16:57:34 -0700 | [diff] [blame] | 8 | #include <linux/android/binder.h> |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 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 */ |
Arve Hjønnevåg | 399b6c3 | 2014-01-28 21:25:12 -0800 | [diff] [blame] | 15 | binder_size_t *offs; /* array of offsets */ |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 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 */ |
Arve Hjønnevåg | 399b6c3 | 2014-01-28 21:25:12 -0800 | [diff] [blame] | 20 | binder_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 | |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 30 | /* the one magic handle */ |
| 31 | #define BINDER_SERVICE_MANAGER 0U |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 32 | |
| 33 | #define SVC_MGR_NAME "android.os.IServiceManager" |
| 34 | |
| 35 | enum { |
Arve Hjønnevåg | e5245cb | 2014-01-28 21:35:03 -0800 | [diff] [blame] | 36 | /* Must match definitions in IBinder.h and IServiceManager.h */ |
| 37 | PING_TRANSACTION = B_PACK_CHARS('_','P','N','G'), |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 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, |
Serban Constantinescu | bcf3888 | 2014-01-10 13:56:27 +0000 | [diff] [blame] | 45 | struct binder_transaction_data *txn, |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 46 | struct binder_io *msg, |
| 47 | struct binder_io *reply); |
| 48 | |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 49 | struct binder_state *binder_open(size_t mapsize); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 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, |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 57 | uint32_t target, uint32_t code); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 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 */ |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 68 | void binder_acquire(struct binder_state *bs, uint32_t target); |
| 69 | void binder_release(struct binder_state *bs, uint32_t target); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 70 | |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 71 | void binder_link_to_death(struct binder_state *bs, uint32_t target, struct binder_death *death); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 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, |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 82 | size_t maxdata, size_t maxobjects); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 83 | |
| 84 | void bio_put_obj(struct binder_io *bio, void *ptr); |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 85 | void bio_put_ref(struct binder_io *bio, uint32_t handle); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 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); |
Serban Constantinescu | 9b738bb | 2014-01-10 15:48:29 +0000 | [diff] [blame] | 91 | uint16_t *bio_get_string16(struct binder_io *bio, size_t *sz); |
Serban Constantinescu | 5fb1b88 | 2014-01-30 14:07:34 +0000 | [diff] [blame] | 92 | uint32_t bio_get_ref(struct binder_io *bio); |
Mike Lockwood | 94afecf | 2012-10-24 10:45:23 -0700 | [diff] [blame] | 93 | |
| 94 | #endif |