binder.h revision 5fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bf
194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* Copyright 2008 The Android Open Source Project
294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood */
394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#ifndef _BINDER_H_
594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define _BINDER_H_
694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <sys/ioctl.h>
894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include <linux/binder.h>
994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
1094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodstruct binder_state;
1194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
1294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodstruct binder_io
1394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood{
1494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    char *data;            /* pointer to read/write from */
159b738bb4110926b85da65d36b2e6f1a50199ec4cSerban Constantinescu    size_t *offs;          /* array of offsets */
169b738bb4110926b85da65d36b2e6f1a50199ec4cSerban Constantinescu    size_t data_avail;     /* bytes available in data buffer */
179b738bb4110926b85da65d36b2e6f1a50199ec4cSerban Constantinescu    size_t offs_avail;     /* entries available in offsets array */
1894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
1994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    char *data0;           /* start of data buffer */
209b738bb4110926b85da65d36b2e6f1a50199ec4cSerban Constantinescu    size_t *offs0;         /* start of offsets buffer */
2194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t flags;
2294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t unused;
2394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood};
2494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
2594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodstruct binder_death {
2694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void (*func)(struct binder_state *bs, void *ptr);
2794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void *ptr;
289b738bb4110926b85da65d36b2e6f1a50199ec4cSerban Constantinescu};
2994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
305fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bfSerban Constantinescu/* the one magic handle */
315fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bfSerban Constantinescu#define BINDER_SERVICE_MANAGER  0U
3294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
3394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define SVC_MGR_NAME "android.os.IServiceManager"
3494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
3594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodenum {
3694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    SVC_MGR_GET_SERVICE = 1,
3794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    SVC_MGR_CHECK_SERVICE,
3894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    SVC_MGR_ADD_SERVICE,
3994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    SVC_MGR_LIST_SERVICES,
4094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood};
4194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
4294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodtypedef int (*binder_handler)(struct binder_state *bs,
43bcf38880c65297da58194eb0c0ce8d6e2bab7d94Serban Constantinescu                              struct binder_transaction_data *txn,
4494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                              struct binder_io *msg,
4594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                              struct binder_io *reply);
4694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
479b738bb4110926b85da65d36b2e6f1a50199ec4cSerban Constantinescustruct binder_state *binder_open(size_t mapsize);
4894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_close(struct binder_state *bs);
4994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* initiate a blocking binder call
5194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * - returns zero on success
5294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood */
5394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint binder_call(struct binder_state *bs,
5494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                struct binder_io *msg, struct binder_io *reply,
555fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bfSerban Constantinescu                uint32_t target, uint32_t code);
5694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* release any state associate with the binder_io
5894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * - call once any necessary data has been extracted from the
5994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood *   binder_io after binder_call() returns
6094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * - can safely be called even if binder_call() fails
6194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood */
6294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_done(struct binder_state *bs,
6394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                 struct binder_io *msg, struct binder_io *reply);
6494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
6594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* manipulate strong references */
665fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bfSerban Constantinescuvoid binder_acquire(struct binder_state *bs, uint32_t target);
675fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bfSerban Constantinescuvoid binder_release(struct binder_state *bs, uint32_t target);
6894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
695fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bfSerban Constantinescuvoid binder_link_to_death(struct binder_state *bs, uint32_t target, struct binder_death *death);
7094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_loop(struct binder_state *bs, binder_handler func);
7294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint binder_become_context_manager(struct binder_state *bs);
7494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* allocate a binder_io, providing a stack-allocated working
7694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * buffer, size of the working buffer, and how many object
7794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * offset entries to reserve from the buffer
7894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood */
7994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_init(struct binder_io *bio, void *data,
809b738bb4110926b85da65d36b2e6f1a50199ec4cSerban Constantinescu           size_t maxdata, size_t maxobjects);
8194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
8294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_obj(struct binder_io *bio, void *ptr);
835fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bfSerban Constantinescuvoid bio_put_ref(struct binder_io *bio, uint32_t handle);
8494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_uint32(struct binder_io *bio, uint32_t n);
8594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_string16(struct binder_io *bio, const uint16_t *str);
8694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_string16_x(struct binder_io *bio, const char *_str);
8794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
8894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwooduint32_t bio_get_uint32(struct binder_io *bio);
899b738bb4110926b85da65d36b2e6f1a50199ec4cSerban Constantinescuuint16_t *bio_get_string16(struct binder_io *bio, size_t *sz);
905fb1b8836aa5cf0f38b49bc7bfb8343b84fdf9bfSerban Constantinescuuint32_t bio_get_ref(struct binder_io *bio);
9194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
9294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#endif
93