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_object
1394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood{
1494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t type;
1594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t flags;
1694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void *pointer;
1794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void *cookie;
1894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood};
1994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
2094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodstruct binder_txn
2194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood{
2294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void *target;
2394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void *cookie;
2494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t code;
2594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t flags;
2694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
2794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t sender_pid;
2894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t sender_euid;
2994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
3094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t data_size;
3194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t offs_size;
3294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void *data;
3394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void *offs;
3494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood};
3594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
3694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodstruct binder_io
3794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood{
3894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    char *data;            /* pointer to read/write from */
3994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t *offs;        /* array of offsets */
4094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t data_avail;   /* bytes available in data buffer */
4194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t offs_avail;   /* entries available in offsets array */
4294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
4394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    char *data0;           /* start of data buffer */
4494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t *offs0;       /* start of offsets buffer */
4594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t flags;
4694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    uint32_t unused;
4794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood};
4894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
4994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodstruct binder_death {
5094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void (*func)(struct binder_state *bs, void *ptr);
5194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    void *ptr;
5294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood};
5394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* the one magic object */
5594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define BINDER_SERVICE_MANAGER ((void*) 0)
5694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#define SVC_MGR_NAME "android.os.IServiceManager"
5894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
5994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodenum {
6094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    SVC_MGR_GET_SERVICE = 1,
6194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    SVC_MGR_CHECK_SERVICE,
6294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    SVC_MGR_ADD_SERVICE,
6394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood    SVC_MGR_LIST_SERVICES,
6494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood};
6594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
6694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodtypedef int (*binder_handler)(struct binder_state *bs,
6794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                              struct binder_txn *txn,
6894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                              struct binder_io *msg,
6994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                              struct binder_io *reply);
7094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodstruct binder_state *binder_open(unsigned mapsize);
7294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_close(struct binder_state *bs);
7394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
7494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* initiate a blocking binder call
7594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * - returns zero on success
7694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood */
7794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint binder_call(struct binder_state *bs,
7894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                struct binder_io *msg, struct binder_io *reply,
7994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                void *target, uint32_t code);
8094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
8194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* release any state associate with the binder_io
8294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * - call once any necessary data has been extracted from the
8394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood *   binder_io after binder_call() returns
8494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * - can safely be called even if binder_call() fails
8594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood */
8694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_done(struct binder_state *bs,
8794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood                 struct binder_io *msg, struct binder_io *reply);
8894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
8994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* manipulate strong references */
9094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_acquire(struct binder_state *bs, void *ptr);
9194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_release(struct binder_state *bs, void *ptr);
9294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
9394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_link_to_death(struct binder_state *bs, void *ptr, struct binder_death *death);
9494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
9594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid binder_loop(struct binder_state *bs, binder_handler func);
9694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
9794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodint binder_become_context_manager(struct binder_state *bs);
9894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
9994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood/* allocate a binder_io, providing a stack-allocated working
10094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * buffer, size of the working buffer, and how many object
10194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood * offset entries to reserve from the buffer
10294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood */
10394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_init(struct binder_io *bio, void *data,
10494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood           uint32_t maxdata, uint32_t maxobjects);
10594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
10694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_destroy(struct binder_io *bio);
10794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
10894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_obj(struct binder_io *bio, void *ptr);
10994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_ref(struct binder_io *bio, void *ptr);
11094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_uint32(struct binder_io *bio, uint32_t n);
11194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_string16(struct binder_io *bio, const uint16_t *str);
11294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid bio_put_string16_x(struct binder_io *bio, const char *_str);
11394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
11494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwooduint32_t bio_get_uint32(struct binder_io *bio);
11594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwooduint16_t *bio_get_string16(struct binder_io *bio, uint32_t *sz);
11694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid *bio_get_obj(struct binder_io *bio);
11794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodvoid *bio_get_ref(struct binder_io *bio);
11894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood
11994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#endif
120