Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binder驱动中binder_ioctl方法会先获取一个thread,为啥根据binder_thread->pid在红黑树寻找thread?难道同一个进程的不同线程的pid不一样吗? #43

Open
zhuzhibin1991 opened this issue Jun 16, 2023 · 1 comment

Comments

@zhuzhibin1991
Copy link

`static struct binder_thread *binder_get_thread_ilocked(
struct binder_proc *proc, struct binder_thread *new_thread)
{
struct binder_thread *thread = NULL;
struct rb_node *parent = NULL;
struct rb_node **p = &proc->threads.rb_node;

while (*p) {
	parent = *p;
	thread = rb_entry(parent, struct binder_thread, rb_node);

	if (current->pid < thread->pid)
		p = &(*p)->rb_left;
	else if (current->pid > thread->pid)
		p = &(*p)->rb_right;
	else
		return thread;
}
if (!new_thread)
	return NULL;
thread = new_thread;
binder_stats_created(BINDER_STAT_THREAD);
thread->proc = proc;
thread->pid = current->pid;
get_task_struct(current);
thread->task = current;
atomic_set(&thread->tmp_ref, 0);
init_waitqueue_head(&thread->wait);
INIT_LIST_HEAD(&thread->todo);
rb_link_node(&thread->rb_node, parent, p);
rb_insert_color(&thread->rb_node, &proc->threads);
thread->looper_need_return = true;
thread->return_error.work.type = BINDER_WORK_RETURN_ERROR;
thread->return_error.cmd = BR_OK;
thread->reply_error.work.type = BINDER_WORK_RETURN_ERROR;
thread->reply_error.cmd = BR_OK;
spin_lock_init(&thread->prio_lock);
thread->prio_state = BINDER_PRIO_SET;
INIT_LIST_HEAD(&new_thread->waiting_thread_node);
return thread;

}`
以上代码中可以看到赋值语句thread->pid = current->pid;
#define get_current() (current_thread_info()->task)
#define current get_current()
thread->pid拿到的其实是当前线程对应的 task_struct中的pid,这个pid其实是线程id,不同线程的id是不同的

@yuandaimaahao
Copy link
Owner

主线程pid 和进程 pid 相同

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants