ServiceManager: Generic Fixes
This patch fixes some of the ServiceManager issues. The following patches
of the series add fixes to the ABI.
Change-Id: Ib479234c8704e12592f1b149ddec67881bc50230
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
diff --git a/cmds/servicemanager/binder.c b/cmds/servicemanager/binder.c
index 7fdd841..d953981 100644
--- a/cmds/servicemanager/binder.c
+++ b/cmds/servicemanager/binder.c
@@ -20,14 +20,14 @@
void bio_init_from_txn(struct binder_io *io, struct binder_transaction_data *txn);
#if TRACE
-void hexdump(void *_data, unsigned len)
+void hexdump(void *_data, size_t len)
{
unsigned char *data = _data;
- unsigned count;
+ size_t count;
for (count = 0; count < len; count++) {
if ((count & 15) == 0)
- fprintf(stderr,"%04x:", count);
+ fprintf(stderr,"%04zu:", count);
fprintf(stderr," %02x %c", *data,
(*data < 32) || (*data > 126) ? '.' : *data);
data++;
@@ -41,8 +41,8 @@
void binder_dump_txn(struct binder_transaction_data *txn)
{
struct flat_binder_object *obj;
- unsigned *offs = txn->data.ptr.offsets;
- unsigned count = txn->offsets_size / 4;
+ size_t *offs = txn->data.ptr.offsets;
+ size_t count = txn->offsets_size / sizeof(size_t);
fprintf(stderr," target %p cookie %p code %08x flags %08x\n",
txn->target.ptr, txn->cookie, txn->code, txn->flags);
@@ -88,10 +88,10 @@
{
int fd;
void *mapped;
- unsigned mapsize;
+ size_t mapsize;
};
-struct binder_state *binder_open(unsigned mapsize)
+struct binder_state *binder_open(size_t mapsize)
{
struct binder_state *bs;
struct binder_version vers;
@@ -99,7 +99,7 @@
bs = malloc(sizeof(*bs));
if (!bs) {
errno = ENOMEM;
- return 0;
+ return NULL;
}
bs->fd = open("/dev/binder", O_RDWR);
@@ -129,7 +129,7 @@
close(bs->fd);
fail_open:
free(bs);
- return 0;
+ return NULL;
}
void binder_close(struct binder_state *bs)
@@ -144,7 +144,7 @@
return ioctl(bs->fd, BINDER_SET_CONTEXT_MGR, 0);
}
-int binder_write(struct binder_state *bs, void *data, unsigned len)
+int binder_write(struct binder_state *bs, void *data, size_t len)
{
struct binder_write_read bwr;
int res;
@@ -164,7 +164,7 @@
void binder_send_reply(struct binder_state *bs,
struct binder_io *reply,
- void *buffer_to_free,
+ const void *buffer_to_free,
int status)
{
struct {
@@ -334,7 +334,7 @@
bwr.write_size = sizeof(writebuf);
bwr.write_consumed = 0;
bwr.write_buffer = (unsigned) &writebuf;
-
+
hexdump(msg->data0, msg->data - msg->data0);
for (;;) {
bwr.read_size = sizeof(readbuf);
@@ -368,7 +368,7 @@
bwr.write_size = 0;
bwr.write_consumed = 0;
bwr.write_buffer = 0;
-
+
readbuf[0] = BC_ENTER_LOOPER;
binder_write(bs, readbuf, sizeof(unsigned));
@@ -406,9 +406,9 @@
}
void bio_init(struct binder_io *bio, void *data,
- uint32_t maxdata, uint32_t maxoffs)
+ size_t maxdata, size_t maxoffs)
{
- uint32_t n = maxoffs * sizeof(uint32_t);
+ size_t n = maxoffs * sizeof(size_t);
if (n > maxdata) {
bio->flags = BIO_F_OVERFLOW;
@@ -429,7 +429,7 @@
size = (size + 3) & (~3);
if (size > bio->data_avail) {
bio->flags |= BIO_F_OVERFLOW;
- return 0;
+ return NULL;
} else {
void *ptr = bio->data;
bio->data += size;
@@ -456,7 +456,7 @@
struct flat_binder_object *obj;
obj = bio_alloc(bio, sizeof(*obj));
-
+
if (obj && bio->offs_avail) {
bio->offs_avail--;
*bio->offs++ = ((char*) obj) - ((char*) bio->data0);
@@ -464,7 +464,7 @@
}
bio->flags |= BIO_F_OVERFLOW;
- return 0;
+ return NULL;
}
void bio_put_uint32(struct binder_io *bio, uint32_t n)
@@ -508,7 +508,7 @@
void bio_put_string16(struct binder_io *bio, const uint16_t *str)
{
- uint32_t len;
+ size_t len;
uint16_t *ptr;
if (!str) {
@@ -524,7 +524,8 @@
return;
}
- bio_put_uint32(bio, len);
+ /* Note: The payload will carry 32bit size instead of size_t */
+ bio_put_uint32(bio, (uint32_t) len);
len = (len + 1) * sizeof(uint16_t);
ptr = bio_alloc(bio, len);
if (ptr)
@@ -534,7 +535,7 @@
void bio_put_string16_x(struct binder_io *bio, const char *_str)
{
unsigned char *str = (unsigned char*) _str;
- uint32_t len;
+ size_t len;
uint16_t *ptr;
if (!str) {
@@ -549,6 +550,7 @@
return;
}
+ /* Note: The payload will carry 32bit size instead of size_t */
bio_put_uint32(bio, len);
ptr = bio_alloc(bio, (len + 1) * sizeof(uint16_t));
if (!ptr)
@@ -559,14 +561,14 @@
*ptr++ = 0;
}
-static void *bio_get(struct binder_io *bio, uint32_t size)
+static void *bio_get(struct binder_io *bio, size_t size)
{
size = (size + 3) & (~3);
if (bio->data_avail < size){
bio->data_avail = 0;
bio->flags |= BIO_F_OVERFLOW;
- return 0;
+ return NULL;
} else {
void *ptr = bio->data;
bio->data += size;
@@ -581,10 +583,12 @@
return ptr ? *ptr : 0;
}
-uint16_t *bio_get_string16(struct binder_io *bio, unsigned *sz)
+uint16_t *bio_get_string16(struct binder_io *bio, size_t *sz)
{
- unsigned len;
- len = bio_get_uint32(bio);
+ size_t len;
+
+ /* Note: The payload will carry 32bit size instead of size_t */
+ len = (size_t) bio_get_uint32(bio);
if (sz)
*sz = len;
return bio_get(bio, (len + 1) * sizeof(uint16_t));
@@ -592,8 +596,8 @@
static struct flat_binder_object *_bio_get_obj(struct binder_io *bio)
{
- unsigned n;
- unsigned off = bio->data - bio->data0;
+ size_t n;
+ size_t off = bio->data - bio->data0;
/* TODO: be smarter about this? */
for (n = 0; n < bio->offs_avail; n++) {
@@ -603,7 +607,7 @@
bio->data_avail = 0;
bio->flags |= BIO_F_OVERFLOW;
- return 0;
+ return NULL;
}
void *bio_get_ref(struct binder_io *bio)