Lines Matching refs:pid

48 struct pid init_struct_pid = {
105 void put_pid(struct pid *pid) in put_pid() argument
109 if (!pid) in put_pid()
112 ns = pid->numbers[pid->level].ns; in put_pid()
113 if (refcount_dec_and_test(&pid->count)) { in put_pid()
114 kmem_cache_free(ns->pid_cachep, pid); in put_pid()
122 struct pid *pid = container_of(rhp, struct pid, rcu); in delayed_put_pid() local
123 put_pid(pid); in delayed_put_pid()
126 void free_pid(struct pid *pid) in free_pid() argument
133 for (i = 0; i <= pid->level; i++) { in free_pid()
134 struct upid *upid = pid->numbers + i; in free_pid()
156 call_rcu(&pid->rcu, delayed_put_pid); in free_pid()
159 struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, in alloc_pid()
162 struct pid *pid; in alloc_pid() local
180 pid = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL); in alloc_pid()
181 if (!pid) in alloc_pid()
185 pid->level = ns->level; in alloc_pid()
244 pid->numbers[i].nr = nr; in alloc_pid()
245 pid->numbers[i].ns = tmp; in alloc_pid()
260 refcount_set(&pid->count, 1); in alloc_pid()
261 spin_lock_init(&pid->lock); in alloc_pid()
263 INIT_HLIST_HEAD(&pid->tasks[type]); in alloc_pid()
265 init_waitqueue_head(&pid->wait_pidfd); in alloc_pid()
266 INIT_HLIST_HEAD(&pid->inodes); in alloc_pid()
268 upid = pid->numbers + ns->level; in alloc_pid()
272 for ( ; upid >= pid->numbers; --upid) { in alloc_pid()
274 idr_replace(&upid->ns->idr, pid, upid->nr); in alloc_pid()
279 return pid; in alloc_pid()
288 upid = pid->numbers + i; in alloc_pid()
298 kmem_cache_free(ns->pid_cachep, pid); in alloc_pid()
309 struct pid *find_pid_ns(int nr, struct pid_namespace *ns) in find_pid_ns()
315 struct pid *find_vpid(int nr) in find_vpid()
321 static struct pid **task_pid_ptr(struct task_struct *task, enum pid_type type) in task_pid_ptr()
333 struct pid *pid = *task_pid_ptr(task, type); in attach_pid() local
334 hlist_add_head_rcu(&task->pid_links[type], &pid->tasks[type]); in attach_pid()
338 struct pid *new) in __change_pid()
340 struct pid **pid_ptr = task_pid_ptr(task, type); in __change_pid()
341 struct pid *pid; in __change_pid() local
344 pid = *pid_ptr; in __change_pid()
350 if (pid_has_task(pid, tmp)) in __change_pid()
353 free_pid(pid); in __change_pid()
362 struct pid *pid) in change_pid() argument
364 __change_pid(task, type, pid); in change_pid()
370 struct pid *pid1 = left->thread_pid; in exchange_tids()
371 struct pid *pid2 = right->thread_pid; in exchange_tids()
383 WRITE_ONCE(left->pid, pid_nr(pid2)); in exchange_tids()
384 WRITE_ONCE(right->pid, pid_nr(pid1)); in exchange_tids()
396 struct task_struct *pid_task(struct pid *pid, enum pid_type type) in pid_task() argument
399 if (pid) { in pid_task()
401 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]), in pid_task()
438 struct pid *get_task_pid(struct task_struct *task, enum pid_type type) in get_task_pid()
440 struct pid *pid; in get_task_pid() local
442 pid = get_pid(rcu_dereference(*task_pid_ptr(task, type))); in get_task_pid()
444 return pid; in get_task_pid()
448 struct task_struct *get_pid_task(struct pid *pid, enum pid_type type) in get_pid_task() argument
452 result = pid_task(pid, type); in get_pid_task()
460 struct pid *find_get_pid(pid_t nr) in find_get_pid()
462 struct pid *pid; in find_get_pid() local
465 pid = get_pid(find_vpid(nr)); in find_get_pid()
468 return pid; in find_get_pid()
472 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns) in pid_nr_ns() argument
477 if (pid && ns->level <= pid->level) { in pid_nr_ns()
478 upid = &pid->numbers[ns->level]; in pid_nr_ns()
486 pid_t pid_vnr(struct pid *pid) in pid_vnr() argument
488 return pid_nr_ns(pid, task_active_pid_ns(current)); in pid_vnr()
518 struct pid *find_ge_pid(int nr, struct pid_namespace *ns) in find_ge_pid()
523 struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags) in pidfd_get_pid()
526 struct pid *pid; in pidfd_get_pid() local
532 pid = pidfd_pid(f.file); in pidfd_get_pid()
533 if (!IS_ERR(pid)) { in pidfd_get_pid()
534 get_pid(pid); in pidfd_get_pid()
539 return pid; in pidfd_get_pid()
562 struct pid *pid; in pidfd_get_task() local
565 pid = pidfd_get_pid(pidfd, &f_flags); in pidfd_get_task()
566 if (IS_ERR(pid)) in pidfd_get_task()
567 return ERR_CAST(pid); in pidfd_get_task()
569 task = get_pid_task(pid, PIDTYPE_TGID); in pidfd_get_task()
570 put_pid(pid); in pidfd_get_task()
594 int pidfd_create(struct pid *pid, unsigned int flags) in pidfd_create() argument
598 if (!pid || !pid_has_task(pid, PIDTYPE_TGID)) in pidfd_create()
604 fd = anon_inode_getfd("[pidfd]", &pidfd_fops, get_pid(pid), in pidfd_create()
607 put_pid(pid); in pidfd_create()
628 SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags) in SYSCALL_DEFINE2() argument
631 struct pid *p; in SYSCALL_DEFINE2()
636 if (pid <= 0) in SYSCALL_DEFINE2()
639 p = find_get_pid(pid); in SYSCALL_DEFINE2()
663 init_pid_ns.pid_cachep = KMEM_CACHE(pid, in pid_idr_init()
686 static int pidfd_getfd(struct pid *pid, int fd) in pidfd_getfd() argument
692 task = get_pid_task(pid, PIDTYPE_PID); in pidfd_getfd()
726 struct pid *pid; in SYSCALL_DEFINE3() local
738 pid = pidfd_pid(f.file); in SYSCALL_DEFINE3()
739 if (IS_ERR(pid)) in SYSCALL_DEFINE3()
740 ret = PTR_ERR(pid); in SYSCALL_DEFINE3()
742 ret = pidfd_getfd(pid, fd); in SYSCALL_DEFINE3()