ServiceManager: Store handles in uint32_t instead of void *
This patch corrects the types used for storing handles. Change-Id: If9c10782345f1de9e12b4b3fd6be9e02e6b568cd Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
This commit is contained in:
parent
9b738bb411
commit
5fb1b8836a
@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
#include "binder.h"
|
#include "binder.h"
|
||||||
|
|
||||||
void *svcmgr_lookup(struct binder_state *bs, void *target, const char *name)
|
uint32_t svcmgr_lookup(struct binder_state *bs, uint32_t target, const char *name)
|
||||||
{
|
{
|
||||||
void *ptr;
|
uint32_t handle;
|
||||||
unsigned iodata[512/4];
|
unsigned iodata[512/4];
|
||||||
struct binder_io msg, reply;
|
struct binder_io msg, reply;
|
||||||
|
|
||||||
@ -21,17 +21,17 @@ void *svcmgr_lookup(struct binder_state *bs, void *target, const char *name)
|
|||||||
if (binder_call(bs, &msg, &reply, target, SVC_MGR_CHECK_SERVICE))
|
if (binder_call(bs, &msg, &reply, target, SVC_MGR_CHECK_SERVICE))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ptr = bio_get_ref(&reply);
|
handle = bio_get_ref(&reply);
|
||||||
|
|
||||||
if (ptr)
|
if (handle)
|
||||||
binder_acquire(bs, ptr);
|
binder_acquire(bs, handle);
|
||||||
|
|
||||||
binder_done(bs, &msg, &reply);
|
binder_done(bs, &msg, &reply);
|
||||||
|
|
||||||
return ptr;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
int svcmgr_publish(struct binder_state *bs, void *target, const char *name, void *ptr)
|
int svcmgr_publish(struct binder_state *bs, uint32_t target, const char *name, void *ptr)
|
||||||
{
|
{
|
||||||
unsigned status;
|
unsigned status;
|
||||||
unsigned iodata[512/4];
|
unsigned iodata[512/4];
|
||||||
@ -59,7 +59,8 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct binder_state *bs;
|
struct binder_state *bs;
|
||||||
void *svcmgr = BINDER_SERVICE_MANAGER;
|
uint32_t svcmgr = BINDER_SERVICE_MANAGER;
|
||||||
|
uint32_t handle;
|
||||||
|
|
||||||
bs = binder_open(128*1024);
|
bs = binder_open(128*1024);
|
||||||
if (!bs) {
|
if (!bs) {
|
||||||
@ -71,21 +72,20 @@ int main(int argc, char **argv)
|
|||||||
argv++;
|
argv++;
|
||||||
while (argc > 0) {
|
while (argc > 0) {
|
||||||
if (!strcmp(argv[0],"alt")) {
|
if (!strcmp(argv[0],"alt")) {
|
||||||
void *ptr = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr");
|
handle = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr");
|
||||||
if (!ptr) {
|
if (!handle) {
|
||||||
fprintf(stderr,"cannot find alt_svc_mgr\n");
|
fprintf(stderr,"cannot find alt_svc_mgr\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
svcmgr = ptr;
|
svcmgr = handle;
|
||||||
fprintf(stderr,"svcmgr is via %p\n", ptr);
|
fprintf(stderr,"svcmgr is via %x\n", handle);
|
||||||
} else if (!strcmp(argv[0],"lookup")) {
|
} else if (!strcmp(argv[0],"lookup")) {
|
||||||
void *ptr;
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr,"argument required\n");
|
fprintf(stderr,"argument required\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ptr = svcmgr_lookup(bs, svcmgr, argv[1]);
|
handle = svcmgr_lookup(bs, svcmgr, argv[1]);
|
||||||
fprintf(stderr,"lookup(%s) = %p\n", argv[1], ptr);
|
fprintf(stderr,"lookup(%s) = %x\n", argv[1], handle);
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
} else if (!strcmp(argv[0],"publish")) {
|
} else if (!strcmp(argv[0],"publish")) {
|
||||||
|
@ -279,27 +279,27 @@ int binder_parse(struct binder_state *bs, struct binder_io *bio,
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void binder_acquire(struct binder_state *bs, void *ptr)
|
void binder_acquire(struct binder_state *bs, uint32_t target)
|
||||||
{
|
{
|
||||||
uint32_t cmd[2];
|
uint32_t cmd[2];
|
||||||
cmd[0] = BC_ACQUIRE;
|
cmd[0] = BC_ACQUIRE;
|
||||||
cmd[1] = (uint32_t) ptr;
|
cmd[1] = target;
|
||||||
binder_write(bs, cmd, sizeof(cmd));
|
binder_write(bs, cmd, sizeof(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void binder_release(struct binder_state *bs, void *ptr)
|
void binder_release(struct binder_state *bs, uint32_t target)
|
||||||
{
|
{
|
||||||
uint32_t cmd[2];
|
uint32_t cmd[2];
|
||||||
cmd[0] = BC_RELEASE;
|
cmd[0] = BC_RELEASE;
|
||||||
cmd[1] = (uint32_t) ptr;
|
cmd[1] = target;
|
||||||
binder_write(bs, cmd, sizeof(cmd));
|
binder_write(bs, cmd, sizeof(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void binder_link_to_death(struct binder_state *bs, void *ptr, struct binder_death *death)
|
void binder_link_to_death(struct binder_state *bs, uint32_t target, struct binder_death *death)
|
||||||
{
|
{
|
||||||
uint32_t cmd[3];
|
uint32_t cmd[3];
|
||||||
cmd[0] = BC_REQUEST_DEATH_NOTIFICATION;
|
cmd[0] = BC_REQUEST_DEATH_NOTIFICATION;
|
||||||
cmd[1] = (uint32_t) ptr;
|
cmd[1] = (uint32_t) target;
|
||||||
cmd[2] = (uint32_t) death;
|
cmd[2] = (uint32_t) death;
|
||||||
binder_write(bs, cmd, sizeof(cmd));
|
binder_write(bs, cmd, sizeof(cmd));
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ void binder_link_to_death(struct binder_state *bs, void *ptr, struct binder_deat
|
|||||||
|
|
||||||
int binder_call(struct binder_state *bs,
|
int binder_call(struct binder_state *bs,
|
||||||
struct binder_io *msg, struct binder_io *reply,
|
struct binder_io *msg, struct binder_io *reply,
|
||||||
void *target, uint32_t code)
|
uint32_t target, uint32_t code)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
struct binder_write_read bwr;
|
struct binder_write_read bwr;
|
||||||
@ -488,11 +488,11 @@ void bio_put_obj(struct binder_io *bio, void *ptr)
|
|||||||
obj->cookie = 0;
|
obj->cookie = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bio_put_ref(struct binder_io *bio, void *ptr)
|
void bio_put_ref(struct binder_io *bio, uint32_t handle)
|
||||||
{
|
{
|
||||||
struct flat_binder_object *obj;
|
struct flat_binder_object *obj;
|
||||||
|
|
||||||
if (ptr)
|
if (handle)
|
||||||
obj = bio_alloc_obj(bio);
|
obj = bio_alloc_obj(bio);
|
||||||
else
|
else
|
||||||
obj = bio_alloc(bio, sizeof(*obj));
|
obj = bio_alloc(bio, sizeof(*obj));
|
||||||
@ -502,7 +502,7 @@ void bio_put_ref(struct binder_io *bio, void *ptr)
|
|||||||
|
|
||||||
obj->flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
|
obj->flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
|
||||||
obj->type = BINDER_TYPE_HANDLE;
|
obj->type = BINDER_TYPE_HANDLE;
|
||||||
obj->handle = ptr;
|
obj->handle = handle;
|
||||||
obj->cookie = 0;
|
obj->cookie = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,7 +610,7 @@ static struct flat_binder_object *_bio_get_obj(struct binder_io *bio)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *bio_get_ref(struct binder_io *bio)
|
uint32_t bio_get_ref(struct binder_io *bio)
|
||||||
{
|
{
|
||||||
struct flat_binder_object *obj;
|
struct flat_binder_object *obj;
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ struct binder_death {
|
|||||||
void *ptr;
|
void *ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* the one magic object */
|
/* the one magic handle */
|
||||||
#define BINDER_SERVICE_MANAGER ((void*) 0)
|
#define BINDER_SERVICE_MANAGER 0U
|
||||||
|
|
||||||
#define SVC_MGR_NAME "android.os.IServiceManager"
|
#define SVC_MGR_NAME "android.os.IServiceManager"
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ void binder_close(struct binder_state *bs);
|
|||||||
*/
|
*/
|
||||||
int binder_call(struct binder_state *bs,
|
int binder_call(struct binder_state *bs,
|
||||||
struct binder_io *msg, struct binder_io *reply,
|
struct binder_io *msg, struct binder_io *reply,
|
||||||
void *target, uint32_t code);
|
uint32_t target, uint32_t code);
|
||||||
|
|
||||||
/* release any state associate with the binder_io
|
/* release any state associate with the binder_io
|
||||||
* - call once any necessary data has been extracted from the
|
* - call once any necessary data has been extracted from the
|
||||||
@ -63,10 +63,10 @@ void binder_done(struct binder_state *bs,
|
|||||||
struct binder_io *msg, struct binder_io *reply);
|
struct binder_io *msg, struct binder_io *reply);
|
||||||
|
|
||||||
/* manipulate strong references */
|
/* manipulate strong references */
|
||||||
void binder_acquire(struct binder_state *bs, void *ptr);
|
void binder_acquire(struct binder_state *bs, uint32_t target);
|
||||||
void binder_release(struct binder_state *bs, void *ptr);
|
void binder_release(struct binder_state *bs, uint32_t target);
|
||||||
|
|
||||||
void binder_link_to_death(struct binder_state *bs, void *ptr, struct binder_death *death);
|
void binder_link_to_death(struct binder_state *bs, uint32_t target, struct binder_death *death);
|
||||||
|
|
||||||
void binder_loop(struct binder_state *bs, binder_handler func);
|
void binder_loop(struct binder_state *bs, binder_handler func);
|
||||||
|
|
||||||
@ -80,13 +80,13 @@ void bio_init(struct binder_io *bio, void *data,
|
|||||||
size_t maxdata, size_t maxobjects);
|
size_t maxdata, size_t maxobjects);
|
||||||
|
|
||||||
void bio_put_obj(struct binder_io *bio, void *ptr);
|
void bio_put_obj(struct binder_io *bio, void *ptr);
|
||||||
void bio_put_ref(struct binder_io *bio, void *ptr);
|
void bio_put_ref(struct binder_io *bio, uint32_t handle);
|
||||||
void bio_put_uint32(struct binder_io *bio, uint32_t n);
|
void bio_put_uint32(struct binder_io *bio, uint32_t n);
|
||||||
void bio_put_string16(struct binder_io *bio, const uint16_t *str);
|
void bio_put_string16(struct binder_io *bio, const uint16_t *str);
|
||||||
void bio_put_string16_x(struct binder_io *bio, const char *_str);
|
void bio_put_string16_x(struct binder_io *bio, const char *_str);
|
||||||
|
|
||||||
uint32_t bio_get_uint32(struct binder_io *bio);
|
uint32_t bio_get_uint32(struct binder_io *bio);
|
||||||
uint16_t *bio_get_string16(struct binder_io *bio, size_t *sz);
|
uint16_t *bio_get_string16(struct binder_io *bio, size_t *sz);
|
||||||
void *bio_get_ref(struct binder_io *bio);
|
uint32_t bio_get_ref(struct binder_io *bio);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,7 +50,7 @@ static struct {
|
|||||||
{ AID_KEYSTORE, "android.security.keystore" },
|
{ AID_KEYSTORE, "android.security.keystore" },
|
||||||
};
|
};
|
||||||
|
|
||||||
void *svcmgr_handle;
|
uint32_t svcmgr_handle;
|
||||||
|
|
||||||
const char *str8(const uint16_t *x)
|
const char *str8(const uint16_t *x)
|
||||||
{
|
{
|
||||||
@ -93,7 +93,7 @@ int svc_can_register(uid_t uid, const uint16_t *name)
|
|||||||
struct svcinfo
|
struct svcinfo
|
||||||
{
|
{
|
||||||
struct svcinfo *next;
|
struct svcinfo *next;
|
||||||
void *ptr;
|
uint32_t handle;
|
||||||
struct binder_death death;
|
struct binder_death death;
|
||||||
int allow_isolated;
|
int allow_isolated;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -120,9 +120,9 @@ void svcinfo_death(struct binder_state *bs, void *ptr)
|
|||||||
struct svcinfo *si = (struct svcinfo* ) ptr;
|
struct svcinfo *si = (struct svcinfo* ) ptr;
|
||||||
|
|
||||||
ALOGI("service '%s' died\n", str8(si->name));
|
ALOGI("service '%s' died\n", str8(si->name));
|
||||||
if (si->ptr) {
|
if (si->handle) {
|
||||||
binder_release(bs, si->ptr);
|
binder_release(bs, si->handle);
|
||||||
si->ptr = 0;
|
si->handle = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,13 +132,13 @@ uint16_t svcmgr_id[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void *do_find_service(struct binder_state *bs, const uint16_t *s, size_t len, uid_t uid)
|
uint32_t do_find_service(struct binder_state *bs, const uint16_t *s, size_t len, uid_t uid)
|
||||||
{
|
{
|
||||||
struct svcinfo *si;
|
struct svcinfo *si;
|
||||||
si = find_svc(s, len);
|
si = find_svc(s, len);
|
||||||
|
|
||||||
// ALOGI("check_service('%s') ptr = %p\n", str8(s), si ? si->ptr : 0);
|
//ALOGI("check_service('%s') handle = %x\n", str8(s), si ? si->handle : 0);
|
||||||
if (si && si->ptr) {
|
if (si && si->handle) {
|
||||||
if (!si->allow_isolated) {
|
if (!si->allow_isolated) {
|
||||||
// If this service doesn't allow access from isolated processes,
|
// If this service doesn't allow access from isolated processes,
|
||||||
// then check the uid to see if it is isolated.
|
// then check the uid to see if it is isolated.
|
||||||
@ -147,7 +147,7 @@ void *do_find_service(struct binder_state *bs, const uint16_t *s, size_t len, ui
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return si->ptr;
|
return si->handle;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -155,37 +155,37 @@ void *do_find_service(struct binder_state *bs, const uint16_t *s, size_t len, ui
|
|||||||
|
|
||||||
int do_add_service(struct binder_state *bs,
|
int do_add_service(struct binder_state *bs,
|
||||||
const uint16_t *s, size_t len,
|
const uint16_t *s, size_t len,
|
||||||
void *ptr, uid_t uid, int allow_isolated)
|
uint32_t handle, uid_t uid, int allow_isolated)
|
||||||
{
|
{
|
||||||
struct svcinfo *si;
|
struct svcinfo *si;
|
||||||
//ALOGI("add_service('%s',%p,%s) uid=%d\n", str8(s), ptr,
|
//ALOGI("add_service('%s',%x,%s) uid=%d\n", str8(s), handle,
|
||||||
// allow_isolated ? "allow_isolated" : "!allow_isolated", uid);
|
// allow_isolated ? "allow_isolated" : "!allow_isolated", uid);
|
||||||
|
|
||||||
if (!ptr || (len == 0) || (len > 127))
|
if (!handle || (len == 0) || (len > 127))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!svc_can_register(uid, s)) {
|
if (!svc_can_register(uid, s)) {
|
||||||
ALOGE("add_service('%s',%p) uid=%d - PERMISSION DENIED\n",
|
ALOGE("add_service('%s',%x) uid=%d - PERMISSION DENIED\n",
|
||||||
str8(s), ptr, uid);
|
str8(s), handle, uid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
si = find_svc(s, len);
|
si = find_svc(s, len);
|
||||||
if (si) {
|
if (si) {
|
||||||
if (si->ptr) {
|
if (si->handle) {
|
||||||
ALOGE("add_service('%s',%p) uid=%d - ALREADY REGISTERED, OVERRIDE\n",
|
ALOGE("add_service('%s',%x) uid=%d - ALREADY REGISTERED, OVERRIDE\n",
|
||||||
str8(s), ptr, uid);
|
str8(s), handle, uid);
|
||||||
svcinfo_death(bs, si);
|
svcinfo_death(bs, si);
|
||||||
}
|
}
|
||||||
si->ptr = ptr;
|
si->handle = handle;
|
||||||
} else {
|
} else {
|
||||||
si = malloc(sizeof(*si) + (len + 1) * sizeof(uint16_t));
|
si = malloc(sizeof(*si) + (len + 1) * sizeof(uint16_t));
|
||||||
if (!si) {
|
if (!si) {
|
||||||
ALOGE("add_service('%s',%p) uid=%d - OUT OF MEMORY\n",
|
ALOGE("add_service('%s',%x) uid=%d - OUT OF MEMORY\n",
|
||||||
str8(s), ptr, uid);
|
str8(s), handle, uid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
si->ptr = ptr;
|
si->handle = handle;
|
||||||
si->len = len;
|
si->len = len;
|
||||||
memcpy(si->name, s, (len + 1) * sizeof(uint16_t));
|
memcpy(si->name, s, (len + 1) * sizeof(uint16_t));
|
||||||
si->name[len] = '\0';
|
si->name[len] = '\0';
|
||||||
@ -196,8 +196,8 @@ int do_add_service(struct binder_state *bs,
|
|||||||
svclist = si;
|
svclist = si;
|
||||||
}
|
}
|
||||||
|
|
||||||
binder_acquire(bs, ptr);
|
binder_acquire(bs, handle);
|
||||||
binder_link_to_death(bs, ptr, &si->death);
|
binder_link_to_death(bs, handle, &si->death);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ int svcmgr_handler(struct binder_state *bs,
|
|||||||
struct svcinfo *si;
|
struct svcinfo *si;
|
||||||
uint16_t *s;
|
uint16_t *s;
|
||||||
size_t len;
|
size_t len;
|
||||||
void *ptr;
|
uint32_t handle;
|
||||||
uint32_t strict_policy;
|
uint32_t strict_policy;
|
||||||
int allow_isolated;
|
int allow_isolated;
|
||||||
|
|
||||||
@ -235,17 +235,17 @@ int svcmgr_handler(struct binder_state *bs,
|
|||||||
case SVC_MGR_GET_SERVICE:
|
case SVC_MGR_GET_SERVICE:
|
||||||
case SVC_MGR_CHECK_SERVICE:
|
case SVC_MGR_CHECK_SERVICE:
|
||||||
s = bio_get_string16(msg, &len);
|
s = bio_get_string16(msg, &len);
|
||||||
ptr = do_find_service(bs, s, len, txn->sender_euid);
|
handle = do_find_service(bs, s, len, txn->sender_euid);
|
||||||
if (!ptr)
|
if (!handle)
|
||||||
break;
|
break;
|
||||||
bio_put_ref(reply, ptr);
|
bio_put_ref(reply, handle);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case SVC_MGR_ADD_SERVICE:
|
case SVC_MGR_ADD_SERVICE:
|
||||||
s = bio_get_string16(msg, &len);
|
s = bio_get_string16(msg, &len);
|
||||||
ptr = bio_get_ref(msg);
|
handle = bio_get_ref(msg);
|
||||||
allow_isolated = bio_get_uint32(msg) ? 1 : 0;
|
allow_isolated = bio_get_uint32(msg) ? 1 : 0;
|
||||||
if (do_add_service(bs, s, len, ptr, txn->sender_euid, allow_isolated))
|
if (do_add_service(bs, s, len, handle, txn->sender_euid, allow_isolated))
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user