blob: 7915fc26851d5803be69cd8f0d9979286df5e36c [file] [log] [blame]
Mike Lockwood94afecf2012-10-24 10:45:23 -07001/* 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
10struct binder_state;
11
Mike Lockwood94afecf2012-10-24 10:45:23 -070012struct binder_io
13{
14 char *data; /* pointer to read/write from */
Arve Hjønnevåg399b6c32014-01-28 21:25:12 -080015 binder_size_t *offs; /* array of offsets */
Serban Constantinescu9b738bb2014-01-10 15:48:29 +000016 size_t data_avail; /* bytes available in data buffer */
17 size_t offs_avail; /* entries available in offsets array */
Mike Lockwood94afecf2012-10-24 10:45:23 -070018
19 char *data0; /* start of data buffer */
Arve Hjønnevåg399b6c32014-01-28 21:25:12 -080020 binder_size_t *offs0; /* start of offsets buffer */
Mike Lockwood94afecf2012-10-24 10:45:23 -070021 uint32_t flags;
22 uint32_t unused;
23};
24
25struct binder_death {
26 void (*func)(struct binder_state *bs, void *ptr);
27 void *ptr;
Serban Constantinescu9b738bb2014-01-10 15:48:29 +000028};
Mike Lockwood94afecf2012-10-24 10:45:23 -070029
Serban Constantinescu5fb1b882014-01-30 14:07:34 +000030/* the one magic handle */
31#define BINDER_SERVICE_MANAGER 0U
Mike Lockwood94afecf2012-10-24 10:45:23 -070032
33#define SVC_MGR_NAME "android.os.IServiceManager"
34
35enum {
Arve Hjønnevåge5245cb2014-01-28 21:35:03 -080036 /* Must match definitions in IBinder.h and IServiceManager.h */
37 PING_TRANSACTION = B_PACK_CHARS('_','P','N','G'),
Mike Lockwood94afecf2012-10-24 10:45:23 -070038 SVC_MGR_GET_SERVICE = 1,
39 SVC_MGR_CHECK_SERVICE,
40 SVC_MGR_ADD_SERVICE,
41 SVC_MGR_LIST_SERVICES,
42};
43
44typedef int (*binder_handler)(struct binder_state *bs,
Serban Constantinescubcf38882014-01-10 13:56:27 +000045 struct binder_transaction_data *txn,
Mike Lockwood94afecf2012-10-24 10:45:23 -070046 struct binder_io *msg,
47 struct binder_io *reply);
48
Serban Constantinescu9b738bb2014-01-10 15:48:29 +000049struct binder_state *binder_open(size_t mapsize);
Mike Lockwood94afecf2012-10-24 10:45:23 -070050void binder_close(struct binder_state *bs);
51
52/* initiate a blocking binder call
53 * - returns zero on success
54 */
55int binder_call(struct binder_state *bs,
56 struct binder_io *msg, struct binder_io *reply,
Serban Constantinescu5fb1b882014-01-30 14:07:34 +000057 uint32_t target, uint32_t code);
Mike Lockwood94afecf2012-10-24 10:45:23 -070058
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 */
64void binder_done(struct binder_state *bs,
65 struct binder_io *msg, struct binder_io *reply);
66
67/* manipulate strong references */
Serban Constantinescu5fb1b882014-01-30 14:07:34 +000068void binder_acquire(struct binder_state *bs, uint32_t target);
69void binder_release(struct binder_state *bs, uint32_t target);
Mike Lockwood94afecf2012-10-24 10:45:23 -070070
Serban Constantinescu5fb1b882014-01-30 14:07:34 +000071void binder_link_to_death(struct binder_state *bs, uint32_t target, struct binder_death *death);
Mike Lockwood94afecf2012-10-24 10:45:23 -070072
73void binder_loop(struct binder_state *bs, binder_handler func);
74
75int 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 */
81void bio_init(struct binder_io *bio, void *data,
Serban Constantinescu9b738bb2014-01-10 15:48:29 +000082 size_t maxdata, size_t maxobjects);
Mike Lockwood94afecf2012-10-24 10:45:23 -070083
84void bio_put_obj(struct binder_io *bio, void *ptr);
Serban Constantinescu5fb1b882014-01-30 14:07:34 +000085void bio_put_ref(struct binder_io *bio, uint32_t handle);
Mike Lockwood94afecf2012-10-24 10:45:23 -070086void bio_put_uint32(struct binder_io *bio, uint32_t n);
87void bio_put_string16(struct binder_io *bio, const uint16_t *str);
88void bio_put_string16_x(struct binder_io *bio, const char *_str);
89
90uint32_t bio_get_uint32(struct binder_io *bio);
Serban Constantinescu9b738bb2014-01-10 15:48:29 +000091uint16_t *bio_get_string16(struct binder_io *bio, size_t *sz);
Serban Constantinescu5fb1b882014-01-30 14:07:34 +000092uint32_t bio_get_ref(struct binder_io *bio);
Mike Lockwood94afecf2012-10-24 10:45:23 -070093
94#endif