Skip to content

Commit abcc615

Browse files
colincrossgregkh
authored andcommitted
ANDROID: binder: Add BINDER_GET_NODE_DEBUG_INFO ioctl
The BINDER_GET_NODE_DEBUG_INFO ioctl will return debug info on a node. Each successive call reusing the previous return value will return the next node. The data will be used by libmemunreachable to mark the pointers with kernel references as reachable. Signed-off-by: Colin Cross <ccross@android.com> Signed-off-by: Martijn Coenen <maco@android.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 408c68b commit abcc615

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎drivers/android/binder.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,31 @@ static int binder_ioctl_set_ctx_mgr(struct file *filp)
43894389
return ret;
43904390
}
43914391

4392+
static int binder_ioctl_get_node_debug_info(struct binder_proc *proc,
4393+
struct binder_node_debug_info *info)
4394+
{
4395+
struct rb_node *n;
4396+
binder_uintptr_t ptr = info->ptr;
4397+
4398+
memset(info, 0, sizeof(*info));
4399+
4400+
binder_inner_proc_lock(proc);
4401+
for (n = rb_first(&proc->nodes); n != NULL; n = rb_next(n)) {
4402+
struct binder_node *node = rb_entry(n, struct binder_node,
4403+
rb_node);
4404+
if (node->ptr > ptr) {
4405+
info->ptr = node->ptr;
4406+
info->cookie = node->cookie;
4407+
info->has_strong_ref = node->has_strong_ref;
4408+
info->has_weak_ref = node->has_weak_ref;
4409+
break;
4410+
}
4411+
}
4412+
binder_inner_proc_unlock(proc);
4413+
4414+
return 0;
4415+
}
4416+
43924417
static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
43934418
{
43944419
int ret;
@@ -4458,6 +4483,24 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
44584483
}
44594484
break;
44604485
}
4486+
case BINDER_GET_NODE_DEBUG_INFO: {
4487+
struct binder_node_debug_info info;
4488+
4489+
if (copy_from_user(&info, ubuf, sizeof(info))) {
4490+
ret = -EFAULT;
4491+
goto err;
4492+
}
4493+
4494+
ret = binder_ioctl_get_node_debug_info(proc, &info);
4495+
if (ret < 0)
4496+
goto err;
4497+
4498+
if (copy_to_user(ubuf, &info, sizeof(info))) {
4499+
ret = -EFAULT;
4500+
goto err;
4501+
}
4502+
break;
4503+
}
44614504
default:
44624505
ret = -EINVAL;
44634506
goto err;

‎include/uapi/linux/android/binder.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,27 @@ struct binder_version {
186186
#define BINDER_CURRENT_PROTOCOL_VERSION 8
187187
#endif
188188

189+
/*
190+
* Use with BINDER_GET_NODE_DEBUG_INFO, driver reads ptr, writes to all fields.
191+
* Set ptr to NULL for the first call to get the info for the first node, and
192+
* then repeat the call passing the previously returned value to get the next
193+
* nodes. ptr will be 0 when there are no more nodes.
194+
*/
195+
struct binder_node_debug_info {
196+
binder_uintptr_t ptr;
197+
binder_uintptr_t cookie;
198+
__u32 has_strong_ref;
199+
__u32 has_weak_ref;
200+
};
201+
189202
#define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
190203
#define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
191204
#define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
192205
#define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
193206
#define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
194207
#define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
195208
#define BINDER_VERSION _IOWR('b', 9, struct binder_version)
209+
#define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info)
196210

197211
/*
198212
* NOTE: Two special error codes you should check for when calling

0 commit comments

Comments
 (0)