binder.h revision 9b738bb4110926b85da65d36b2e6f1a50199ec4c
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
10struct binder_state;
11
12struct binder_io
13{
14    char *data;            /* pointer to read/write from */
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 */
18
19    char *data0;           /* start of data buffer */
20    size_t *offs0;         /* start of offsets buffer */
21    uint32_t flags;
22    uint32_t unused;
23};
24
25struct binder_death {
26    void (*func)(struct binder_state *bs, void *ptr);
27    void *ptr;
28};
29
30/* the one magic object */
31#define BINDER_SERVICE_MANAGER ((void*) 0)
32
33#define SVC_MGR_NAME "android.os.IServiceManager"
34
35enum {
36    SVC_MGR_GET_SERVICE = 1,
37    SVC_MGR_CHECK_SERVICE,
38    SVC_MGR_ADD_SERVICE,
39    SVC_MGR_LIST_SERVICES,
40};
41
42typedef int (*binder_handler)(struct binder_state *bs,
43                              struct binder_transaction_data *txn,
44                              struct binder_io *msg,
45                              struct binder_io *reply);
46
47struct binder_state *binder_open(size_t mapsize);
48void binder_close(struct binder_state *bs);
49
50/* initiate a blocking binder call
51 * - returns zero on success
52 */
53int 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 */
62void binder_done(struct binder_state *bs,
63                 struct binder_io *msg, struct binder_io *reply);
64
65/* manipulate strong references */
66void binder_acquire(struct binder_state *bs, void *ptr);
67void binder_release(struct binder_state *bs, void *ptr);
68
69void binder_link_to_death(struct binder_state *bs, void *ptr, struct binder_death *death);
70
71void binder_loop(struct binder_state *bs, binder_handler func);
72
73int 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 */
79void bio_init(struct binder_io *bio, void *data,
80           size_t maxdata, size_t maxobjects);
81
82void bio_put_obj(struct binder_io *bio, void *ptr);
83void bio_put_ref(struct binder_io *bio, void *ptr);
84void bio_put_uint32(struct binder_io *bio, uint32_t n);
85void bio_put_string16(struct binder_io *bio, const uint16_t *str);
86void bio_put_string16_x(struct binder_io *bio, const char *_str);
87
88uint32_t bio_get_uint32(struct binder_io *bio);
89uint16_t *bio_get_string16(struct binder_io *bio, size_t *sz);
90void *bio_get_ref(struct binder_io *bio);
91
92#endif
93