ServiceManager: Add extra error handling
This patch extends the error handling. It also adds a check for a matching binder version - kernel/userspace. Change-Id: I43a262934b38c5711536aaa42754fed1ef04b39e Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
This commit is contained in:
parent
dc832dc551
commit
a44542ca74
@ -62,6 +62,10 @@ int main(int argc, char **argv)
|
|||||||
void *svcmgr = BINDER_SERVICE_MANAGER;
|
void *svcmgr = BINDER_SERVICE_MANAGER;
|
||||||
|
|
||||||
bs = binder_open(128*1024);
|
bs = binder_open(128*1024);
|
||||||
|
if (!bs) {
|
||||||
|
fprintf(stderr, "failed to open binder driver\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
@ -94,6 +94,7 @@ struct binder_state
|
|||||||
struct binder_state *binder_open(unsigned mapsize)
|
struct binder_state *binder_open(unsigned mapsize)
|
||||||
{
|
{
|
||||||
struct binder_state *bs;
|
struct binder_state *bs;
|
||||||
|
struct binder_version vers;
|
||||||
|
|
||||||
bs = malloc(sizeof(*bs));
|
bs = malloc(sizeof(*bs));
|
||||||
if (!bs) {
|
if (!bs) {
|
||||||
@ -108,6 +109,12 @@ struct binder_state *binder_open(unsigned mapsize)
|
|||||||
goto fail_open;
|
goto fail_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((ioctl(bs->fd, BINDER_VERSION, &vers) == -1) ||
|
||||||
|
(vers.protocol_version != BINDER_CURRENT_PROTOCOL_VERSION)) {
|
||||||
|
fprintf(stderr, "binder: driver version differs from user space\n");
|
||||||
|
goto fail_open;
|
||||||
|
}
|
||||||
|
|
||||||
bs->mapsize = mapsize;
|
bs->mapsize = mapsize;
|
||||||
bs->mapped = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, bs->fd, 0);
|
bs->mapped = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, bs->fd, 0);
|
||||||
if (bs->mapped == MAP_FAILED) {
|
if (bs->mapped == MAP_FAILED) {
|
||||||
@ -116,8 +123,6 @@ struct binder_state *binder_open(unsigned mapsize)
|
|||||||
goto fail_map;
|
goto fail_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: check version */
|
|
||||||
|
|
||||||
return bs;
|
return bs;
|
||||||
|
|
||||||
fail_map:
|
fail_map:
|
||||||
|
@ -275,6 +275,10 @@ int main(int argc, char **argv)
|
|||||||
void *svcmgr = BINDER_SERVICE_MANAGER;
|
void *svcmgr = BINDER_SERVICE_MANAGER;
|
||||||
|
|
||||||
bs = binder_open(128*1024);
|
bs = binder_open(128*1024);
|
||||||
|
if (!bs) {
|
||||||
|
ALOGE("failed to open binder driver\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (binder_become_context_manager(bs)) {
|
if (binder_become_context_manager(bs)) {
|
||||||
ALOGE("cannot become context manager (%s)\n", strerror(errno));
|
ALOGE("cannot become context manager (%s)\n", strerror(errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user