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"
|
||||
|
||||
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];
|
||||
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))
|
||||
return 0;
|
||||
|
||||
ptr = bio_get_ref(&reply);
|
||||
handle = bio_get_ref(&reply);
|
||||
|
||||
if (ptr)
|
||||
binder_acquire(bs, ptr);
|
||||
if (handle)
|
||||
binder_acquire(bs, handle);
|
||||
|
||||
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 iodata[512/4];
|
||||
@ -59,7 +59,8 @@ int main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
struct binder_state *bs;
|
||||
void *svcmgr = BINDER_SERVICE_MANAGER;
|
||||
uint32_t svcmgr = BINDER_SERVICE_MANAGER;
|
||||
uint32_t handle;
|
||||
|
||||
bs = binder_open(128*1024);
|
||||
if (!bs) {
|
||||
@ -71,21 +72,20 @@ int main(int argc, char **argv)
|
||||
argv++;
|
||||
while (argc > 0) {
|
||||
if (!strcmp(argv[0],"alt")) {
|
||||
void *ptr = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr");
|
||||
if (!ptr) {
|
||||
handle = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr");
|
||||
if (!handle) {
|
||||
fprintf(stderr,"cannot find alt_svc_mgr\n");
|
||||
return -1;
|
||||
}
|
||||
svcmgr = ptr;
|
||||
fprintf(stderr,"svcmgr is via %p\n", ptr);
|
||||
svcmgr = handle;
|
||||
fprintf(stderr,"svcmgr is via %x\n", handle);
|
||||
} else if (!strcmp(argv[0],"lookup")) {
|
||||
void *ptr;
|
||||
if (argc < 2) {
|
||||
fprintf(stderr,"argument required\n");
|
||||
return -1;
|
||||
}
|
||||
ptr = svcmgr_lookup(bs, svcmgr, argv[1]);
|
||||
fprintf(stderr,"lookup(%s) = %p\n", argv[1], ptr);
|
||||
handle = svcmgr_lookup(bs, svcmgr, argv[1]);
|
||||
fprintf(stderr,"lookup(%s) = %x\n", argv[1], handle);
|
||||
argc--;
|
||||
argv++;
|
||||
} else if (!strcmp(argv[0],"publish")) {
|
||||
|
@ -279,27 +279,27 @@ int binder_parse(struct binder_state *bs, struct binder_io *bio,
|
||||
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];
|
||||
cmd[0] = BC_ACQUIRE;
|
||||
cmd[1] = (uint32_t) ptr;
|
||||
cmd[1] = target;
|
||||
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];
|
||||
cmd[0] = BC_RELEASE;
|
||||
cmd[1] = (uint32_t) ptr;
|
||||
cmd[1] = target;
|
||||
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];
|
||||
cmd[0] = BC_REQUEST_DEATH_NOTIFICATION;
|
||||
cmd[1] = (uint32_t) ptr;
|
||||
cmd[1] = (uint32_t) target;
|
||||
cmd[2] = (uint32_t) death;
|
||||
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,
|
||||
struct binder_io *msg, struct binder_io *reply,
|
||||
void *target, uint32_t code)
|
||||
uint32_t target, uint32_t code)
|
||||
{
|
||||
int res;
|
||||
struct binder_write_read bwr;
|
||||
@ -488,11 +488,11 @@ void bio_put_obj(struct binder_io *bio, void *ptr)
|
||||
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;
|
||||
|
||||
if (ptr)
|
||||
if (handle)
|
||||
obj = bio_alloc_obj(bio);
|
||||
else
|
||||
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->type = BINDER_TYPE_HANDLE;
|
||||
obj->handle = ptr;
|
||||
obj->handle = handle;
|
||||
obj->cookie = 0;
|
||||
}
|
||||
|
||||
@ -610,7 +610,7 @@ static struct flat_binder_object *_bio_get_obj(struct binder_io *bio)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *bio_get_ref(struct binder_io *bio)
|
||||
uint32_t bio_get_ref(struct binder_io *bio)
|
||||
{
|
||||
struct flat_binder_object *obj;
|
||||
|
||||
|
@ -27,8 +27,8 @@ struct binder_death {
|
||||
void *ptr;
|
||||
};
|
||||
|
||||
/* the one magic object */
|
||||
#define BINDER_SERVICE_MANAGER ((void*) 0)
|
||||
/* the one magic handle */
|
||||
#define BINDER_SERVICE_MANAGER 0U
|
||||
|
||||
#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,
|
||||
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
|
||||
* - 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);
|
||||
|
||||
/* manipulate strong references */
|
||||
void binder_acquire(struct binder_state *bs, void *ptr);
|
||||
void binder_release(struct binder_state *bs, void *ptr);
|
||||
void binder_acquire(struct binder_state *bs, uint32_t target);
|
||||
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);
|
||||
|
||||
@ -80,13 +80,13 @@ void bio_init(struct binder_io *bio, void *data,
|
||||
size_t maxdata, size_t maxobjects);
|
||||
|
||||
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_string16(struct binder_io *bio, const uint16_t *str);
|
||||
void bio_put_string16_x(struct binder_io *bio, const char *_str);
|
||||
|
||||
uint32_t bio_get_uint32(struct binder_io *bio);
|
||||
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
|
||||
|
@ -50,7 +50,7 @@ static struct {
|
||||
{ AID_KEYSTORE, "android.security.keystore" },
|
||||
};
|
||||
|
||||
void *svcmgr_handle;
|
||||
uint32_t svcmgr_handle;
|
||||
|
||||
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 *next;
|
||||
void *ptr;
|
||||
uint32_t handle;
|
||||
struct binder_death death;
|
||||
int allow_isolated;
|
||||
size_t len;
|
||||
@ -120,9 +120,9 @@ void svcinfo_death(struct binder_state *bs, void *ptr)
|
||||
struct svcinfo *si = (struct svcinfo* ) ptr;
|
||||
|
||||
ALOGI("service '%s' died\n", str8(si->name));
|
||||
if (si->ptr) {
|
||||
binder_release(bs, si->ptr);
|
||||
si->ptr = 0;
|
||||
if (si->handle) {
|
||||
binder_release(bs, si->handle);
|
||||
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;
|
||||
si = find_svc(s, len);
|
||||
|
||||
// ALOGI("check_service('%s') ptr = %p\n", str8(s), si ? si->ptr : 0);
|
||||
if (si && si->ptr) {
|
||||
//ALOGI("check_service('%s') handle = %x\n", str8(s), si ? si->handle : 0);
|
||||
if (si && si->handle) {
|
||||
if (!si->allow_isolated) {
|
||||
// If this service doesn't allow access from isolated processes,
|
||||
// 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 si->ptr;
|
||||
return si->handle;
|
||||
} else {
|
||||
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,
|
||||
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;
|
||||
//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);
|
||||
|
||||
if (!ptr || (len == 0) || (len > 127))
|
||||
if (!handle || (len == 0) || (len > 127))
|
||||
return -1;
|
||||
|
||||
if (!svc_can_register(uid, s)) {
|
||||
ALOGE("add_service('%s',%p) uid=%d - PERMISSION DENIED\n",
|
||||
str8(s), ptr, uid);
|
||||
ALOGE("add_service('%s',%x) uid=%d - PERMISSION DENIED\n",
|
||||
str8(s), handle, uid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
si = find_svc(s, len);
|
||||
if (si) {
|
||||
if (si->ptr) {
|
||||
ALOGE("add_service('%s',%p) uid=%d - ALREADY REGISTERED, OVERRIDE\n",
|
||||
str8(s), ptr, uid);
|
||||
if (si->handle) {
|
||||
ALOGE("add_service('%s',%x) uid=%d - ALREADY REGISTERED, OVERRIDE\n",
|
||||
str8(s), handle, uid);
|
||||
svcinfo_death(bs, si);
|
||||
}
|
||||
si->ptr = ptr;
|
||||
si->handle = handle;
|
||||
} else {
|
||||
si = malloc(sizeof(*si) + (len + 1) * sizeof(uint16_t));
|
||||
if (!si) {
|
||||
ALOGE("add_service('%s',%p) uid=%d - OUT OF MEMORY\n",
|
||||
str8(s), ptr, uid);
|
||||
ALOGE("add_service('%s',%x) uid=%d - OUT OF MEMORY\n",
|
||||
str8(s), handle, uid);
|
||||
return -1;
|
||||
}
|
||||
si->ptr = ptr;
|
||||
si->handle = handle;
|
||||
si->len = len;
|
||||
memcpy(si->name, s, (len + 1) * sizeof(uint16_t));
|
||||
si->name[len] = '\0';
|
||||
@ -196,8 +196,8 @@ int do_add_service(struct binder_state *bs,
|
||||
svclist = si;
|
||||
}
|
||||
|
||||
binder_acquire(bs, ptr);
|
||||
binder_link_to_death(bs, ptr, &si->death);
|
||||
binder_acquire(bs, handle);
|
||||
binder_link_to_death(bs, handle, &si->death);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ int svcmgr_handler(struct binder_state *bs,
|
||||
struct svcinfo *si;
|
||||
uint16_t *s;
|
||||
size_t len;
|
||||
void *ptr;
|
||||
uint32_t handle;
|
||||
uint32_t strict_policy;
|
||||
int allow_isolated;
|
||||
|
||||
@ -235,17 +235,17 @@ int svcmgr_handler(struct binder_state *bs,
|
||||
case SVC_MGR_GET_SERVICE:
|
||||
case SVC_MGR_CHECK_SERVICE:
|
||||
s = bio_get_string16(msg, &len);
|
||||
ptr = do_find_service(bs, s, len, txn->sender_euid);
|
||||
if (!ptr)
|
||||
handle = do_find_service(bs, s, len, txn->sender_euid);
|
||||
if (!handle)
|
||||
break;
|
||||
bio_put_ref(reply, ptr);
|
||||
bio_put_ref(reply, handle);
|
||||
return 0;
|
||||
|
||||
case SVC_MGR_ADD_SERVICE:
|
||||
s = bio_get_string16(msg, &len);
|
||||
ptr = bio_get_ref(msg);
|
||||
handle = bio_get_ref(msg);
|
||||
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;
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user