Lines Matching refs:proc

76 BINDER_DEBUG_ENTRY(proc);
230 struct binder_proc *proc;
254 /* node + proc => ref (transaction) */
255 /* desc + proc => ref (transaction, inc/dec ref) */
256 /* node => refs + procs (proc exit) */
261 struct binder_proc *proc;
338 struct binder_proc *proc;
372 binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer);
374 static int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
376 struct files_struct *files = proc->files;
383 if (!lock_task_sighand(proc->tsk, &irqs))
386 rlim_cur = task_rlimit(proc->tsk, RLIMIT_NOFILE);
387 unlock_task_sighand(proc->tsk, &irqs);
396 struct binder_proc *proc, unsigned int fd, struct file *file)
398 if (proc->files)
399 __fd_install(proc->files, fd, file);
405 static long task_close_fd(struct binder_proc *proc, unsigned int fd)
409 if (proc->files == NULL)
412 retval = __close_fd(proc->files, fd);
454 static size_t binder_buffer_size(struct binder_proc *proc,
457 if (list_is_last(&buffer->entry, &proc->buffers))
458 return proc->buffer + proc->buffer_size - (void *)buffer->data;
463 static void binder_insert_free_buffer(struct binder_proc *proc,
466 struct rb_node **p = &proc->free_buffers.rb_node;
474 new_buffer_size = binder_buffer_size(proc, new_buffer);
478 proc->pid, new_buffer_size, new_buffer);
485 buffer_size = binder_buffer_size(proc, buffer);
493 rb_insert_color(&new_buffer->rb_node, &proc->free_buffers);
496 static void binder_insert_allocated_buffer(struct binder_proc *proc,
499 struct rb_node **p = &proc->allocated_buffers.rb_node;
518 rb_insert_color(&new_buffer->rb_node, &proc->allocated_buffers);
521 static struct binder_buffer *binder_buffer_lookup(struct binder_proc *proc,
524 struct rb_node *n = proc->allocated_buffers.rb_node;
528 kern_ptr = (struct binder_buffer *)(user_ptr - proc->user_buffer_offset
545 static int binder_update_page_range(struct binder_proc *proc, int allocate,
556 "%d: %s pages %p-%p\n", proc->pid,
562 trace_binder_update_page_range(proc, allocate, start, end);
567 mm = get_task_mm(proc->tsk);
571 vma = proc->vma;
572 if (vma && mm != proc->vma_vm_mm) {
574 proc->pid);
584 proc->pid);
591 page = &proc->pages[(page_addr - proc->buffer) / PAGE_SIZE];
597 proc->pid, page_addr);
605 proc->pid, page_addr);
609 (uintptr_t)page_addr + proc->user_buffer_offset;
613 proc->pid, user_page_addr);
627 page = &proc->pages[(page_addr - proc->buffer) / PAGE_SIZE];
630 proc->user_buffer_offset, PAGE_SIZE, NULL);
647 static struct binder_buffer *binder_alloc_buf(struct binder_proc *proc,
651 struct rb_node *n = proc->free_buffers.rb_node;
659 if (proc->vma == NULL) {
661 proc->pid);
670 proc->pid, data_size, offsets_size);
675 proc->free_async_space < size + sizeof(struct binder_buffer)) {
678 proc->pid, size);
685 buffer_size = binder_buffer_size(proc, buffer);
699 proc->pid, size);
704 buffer_size = binder_buffer_size(proc, buffer);
709 proc->pid, size, buffer, buffer_size);
723 if (binder_update_page_range(proc, 1,
727 rb_erase(best_fit, &proc->free_buffers);
729 binder_insert_allocated_buffer(proc, buffer);
735 binder_insert_free_buffer(proc, new_buffer);
739 proc->pid, size, buffer);
744 proc->free_async_space -= size + sizeof(struct binder_buffer);
747 proc->pid, size, proc->free_async_space);
763 static void binder_delete_free_buffer(struct binder_proc *proc,
770 BUG_ON(proc->buffers.next == &buffer->entry);
779 proc->pid, buffer, prev);
782 if (!list_is_last(&buffer->entry, &proc->buffers)) {
792 proc->pid, buffer, prev);
799 proc->pid, buffer, free_page_start ? "" : " end",
801 binder_update_page_range(proc, 0, free_page_start ?
808 static void binder_free_buf(struct binder_proc *proc,
813 buffer_size = binder_buffer_size(proc, buffer);
820 proc->pid, buffer, size, buffer_size);
825 BUG_ON((void *)buffer < proc->buffer);
826 BUG_ON((void *)buffer > proc->buffer + proc->buffer_size);
829 proc->free_async_space += size + sizeof(struct binder_buffer);
833 proc->pid, size, proc->free_async_space);
836 binder_update_page_range(proc, 0,
840 rb_erase(&buffer->rb_node, &proc->allocated_buffers);
842 if (!list_is_last(&buffer->entry, &proc->buffers)) {
847 rb_erase(&next->rb_node, &proc->free_buffers);
848 binder_delete_free_buffer(proc, next);
851 if (proc->buffers.next != &buffer->entry) {
856 binder_delete_free_buffer(proc, buffer);
857 rb_erase(&prev->rb_node, &proc->free_buffers);
861 binder_insert_free_buffer(proc, buffer);
864 static struct binder_node *binder_get_node(struct binder_proc *proc,
867 struct rb_node *n = proc->nodes.rb_node;
883 static struct binder_node *binder_new_node(struct binder_proc *proc,
887 struct rb_node **p = &proc->nodes.rb_node;
908 rb_insert_color(&node->rb_node, &proc->nodes);
910 node->proc = proc;
918 proc->pid, current->pid, node->debug_id,
973 if (node->proc && (node->has_strong_ref || node->has_weak_ref)) {
975 list_add_tail(&node->work.entry, &node->proc->todo);
976 wake_up_interruptible(&node->proc->wait);
982 if (node->proc) {
983 rb_erase(&node->rb_node, &node->proc->nodes);
1002 static struct binder_ref *binder_get_ref(struct binder_proc *proc,
1005 struct rb_node *n = proc->refs_by_desc.rb_node;
1021 static struct binder_ref *binder_get_ref_for_node(struct binder_proc *proc,
1025 struct rb_node **p = &proc->refs_by_node.rb_node;
1045 new_ref->proc = proc;
1048 rb_insert_color(&new_ref->rb_node_node, &proc->refs_by_node);
1051 for (n = rb_first(&proc->refs_by_desc); n != NULL; n = rb_next(n)) {
1058 p = &proc->refs_by_desc.rb_node;
1071 rb_insert_color(&new_ref->rb_node_desc, &proc->refs_by_desc);
1077 proc->pid, new_ref->debug_id, new_ref->desc,
1082 proc->pid, new_ref->debug_id, new_ref->desc);
1091 ref->proc->pid, ref->debug_id, ref->desc,
1094 rb_erase(&ref->rb_node_desc, &ref->proc->refs_by_desc);
1095 rb_erase(&ref->rb_node_node, &ref->proc->refs_by_node);
1103 ref->proc->pid, ref->debug_id, ref->desc);
1141 ref->proc->pid, ref->debug_id,
1156 ref->proc->pid, ref->debug_id,
1204 target_thread->proc->pid,
1212 target_thread->proc->pid,
1237 static void binder_transaction_buffer_release(struct binder_proc *proc,
1246 proc->pid, buffer->debug_id,
1272 struct binder_node *node = binder_get_node(proc, fp->binder);
1286 struct binder_ref *ref = binder_get_ref(proc, fp->handle);
1303 task_close_fd(proc, fp->handle);
1314 static void binder_transaction(struct binder_proc *proc,
1333 e->from_proc = proc->pid;
1343 proc->pid, thread->pid);
1350 proc->pid, thread->pid, in_reply_to->debug_id,
1367 proc->pid, thread->pid,
1376 target_proc = target_thread->proc;
1381 ref = binder_get_ref(proc, tr->target.handle);
1384 proc->pid, thread->pid);
1397 target_proc = target_node->proc;
1402 if (security_binder_transaction(proc->tsk, target_proc->tsk) < 0) {
1412 proc->pid, thread->pid, tmp->debug_id,
1420 if (tmp->from && tmp->from->proc == target_proc)
1457 proc->pid, thread->pid, t->debug_id,
1465 proc->pid, thread->pid, t->debug_id,
1475 t->sender_euid = task_euid(proc->tsk);
1504 proc->pid, thread->pid);
1511 proc->pid, thread->pid);
1517 proc->pid, thread->pid, (u64)tr->offsets_size);
1531 proc->pid, thread->pid, (u64)*offp,
1544 struct binder_node *node = binder_get_node(proc, fp->binder);
1547 node = binder_new_node(proc, fp->binder, fp->cookie);
1557 proc->pid, thread->pid,
1563 if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) {
1588 struct binder_ref *ref = binder_get_ref(proc, fp->handle);
1592 proc->pid,
1597 if (security_binder_transfer_binder(proc->tsk, target_proc->tsk)) {
1601 if (ref->node->proc == target_proc) {
1640 proc->pid, thread->pid, fp->handle);
1646 proc->pid, thread->pid, fp->handle);
1654 proc->pid, thread->pid, fp->handle);
1658 if (security_binder_transfer_file(proc->tsk, target_proc->tsk, file) < 0) {
1679 proc->pid, thread->pid, fp->type);
1736 proc->pid, thread->pid, return_error,
1754 static int binder_thread_write(struct binder_proc *proc,
1771 proc->stats.bc[_IOC_NR(cmd)]++;
1788 ref = binder_get_ref_for_node(proc,
1792 proc->pid, thread->pid,
1796 ref = binder_get_ref(proc, target);
1799 proc->pid, thread->pid, target);
1823 proc->pid, thread->pid, debug_string, ref->debug_id,
1839 node = binder_get_node(proc, node_ptr);
1842 proc->pid, thread->pid,
1851 proc->pid, thread->pid,
1861 proc->pid, thread->pid,
1869 proc->pid, thread->pid,
1878 proc->pid, thread->pid,
1898 buffer = binder_buffer_lookup(proc, data_ptr);
1901 proc->pid, thread->pid, (u64)data_ptr);
1906 proc->pid, thread->pid, (u64)data_ptr);
1911 proc->pid, thread->pid, (u64)data_ptr,
1927 binder_transaction_buffer_release(proc, buffer, NULL);
1928 binder_free_buf(proc, buffer);
1939 binder_transaction(proc, thread, &tr, cmd == BC_REPLY);
1946 proc->pid, thread->pid);
1950 proc->pid, thread->pid);
1951 } else if (proc->requested_threads == 0) {
1954 proc->pid, thread->pid);
1956 proc->requested_threads--;
1957 proc->requested_threads_started++;
1964 proc->pid, thread->pid);
1968 proc->pid, thread->pid);
1975 proc->pid, thread->pid);
1992 ref = binder_get_ref(proc, target);
1995 proc->pid, thread->pid,
2005 proc->pid, thread->pid,
2015 proc->pid, thread->pid);
2023 proc->pid, thread->pid);
2030 if (ref->node->proc == NULL) {
2035 list_add_tail(&ref->death->work.entry, &proc->todo);
2036 wake_up_interruptible(&proc->wait);
2042 proc->pid, thread->pid);
2048 proc->pid, thread->pid,
2059 list_add_tail(&death->work.entry, &proc->todo);
2060 wake_up_interruptible(&proc->wait);
2077 list_for_each_entry(w, &proc->delivered_death, entry) {
2087 proc->pid, thread->pid, (u64)cookie,
2091 proc->pid, thread->pid, (u64)cookie);
2101 list_add_tail(&death->work.entry, &proc->todo);
2102 wake_up_interruptible(&proc->wait);
2109 proc->pid, thread->pid, cmd);
2117 static void binder_stat_br(struct binder_proc *proc,
2123 proc->stats.br[_IOC_NR(cmd)]++;
2128 static int binder_has_proc_work(struct binder_proc *proc,
2131 return !list_empty(&proc->todo) ||
2141 static int binder_thread_read(struct binder_proc *proc,
2168 binder_stat_br(proc, thread, thread->return_error2);
2176 binder_stat_br(proc, thread, thread->return_error);
2184 proc->ready_threads++;
2195 proc->pid, thread->pid, thread->looper);
2199 binder_set_nice(proc->default_priority);
2201 if (!binder_has_proc_work(proc, thread))
2204 ret = wait_event_freezable_exclusive(proc->wait, binder_has_proc_work(proc, thread));
2216 proc->ready_threads--;
2231 } else if (!list_empty(&proc->todo) && wait_for_proc_work) {
2232 w = list_first_entry(&proc->todo, struct binder_work,
2255 binder_stat_br(proc, thread, cmd);
2258 proc->pid, thread->pid);
2305 binder_stat_br(proc, thread, cmd);
2308 proc->pid, thread->pid, cmd_name,
2316 proc->pid, thread->pid,
2320 rb_erase(&node->rb_node, &proc->nodes);
2326 proc->pid, thread->pid,
2351 binder_stat_br(proc, thread, cmd);
2354 proc->pid, thread->pid,
2365 list_move(&w->entry, &proc->delivered_death);
2398 struct task_struct *sender = t->from->proc->tsk;
2410 proc->user_buffer_offset);
2423 binder_stat_br(proc, thread, cmd);
2426 proc->pid, thread->pid,
2429 t->debug_id, t->from ? t->from->proc->pid : 0,
2451 if (proc->requested_threads + proc->ready_threads == 0 &&
2452 proc->requested_threads_started < proc->max_threads &&
2456 proc->requested_threads++;
2459 proc->pid, thread->pid);
2462 binder_stat_br(proc, thread, BR_SPAWN_LOOPER);
2517 static struct binder_thread *binder_get_thread(struct binder_proc *proc)
2521 struct rb_node **p = &proc->threads.rb_node;
2539 thread->proc = proc;
2544 rb_insert_color(&thread->rb_node, &proc->threads);
2552 static int binder_free_thread(struct binder_proc *proc,
2559 rb_erase(&thread->rb_node, &proc->threads);
2567 proc->pid, thread->pid,
2596 struct binder_proc *proc = filp->private_data;
2602 thread = binder_get_thread(proc);
2610 if (binder_has_proc_work(proc, thread))
2612 poll_wait(filp, &proc->wait, wait);
2613 if (binder_has_proc_work(proc, thread))
2630 struct binder_proc *proc = filp->private_data;
2645 proc->pid, thread->pid,
2650 ret = binder_thread_write(proc, thread,
2663 ret = binder_thread_read(proc, thread, bwr.read_buffer,
2668 if (!list_empty(&proc->todo))
2669 wake_up_interruptible(&proc->wait);
2678 proc->pid, thread->pid,
2692 struct binder_proc *proc = filp->private_data;
2712 binder_context_mgr_node = binder_new_node(proc, 0, 0);
2728 struct binder_proc *proc = filp->private_data;
2734 proc->pid, current->pid, cmd, arg);*/
2743 thread = binder_get_thread(proc);
2756 if (copy_from_user(&proc->max_threads, ubuf, sizeof(proc->max_threads))) {
2765 ret = security_binder_set_context_mgr(proc->tsk);
2771 proc->pid, thread->pid);
2772 binder_free_thread(proc, thread);
2800 pr_info("%d:%d ioctl %x %lx returned %d\n", proc->pid, current->pid, cmd, arg, ret);
2808 struct binder_proc *proc = vma->vm_private_data;
2812 proc->pid, vma->vm_start, vma->vm_end,
2819 struct binder_proc *proc = vma->vm_private_data;
2823 proc->pid, vma->vm_start, vma->vm_end,
2826 proc->vma = NULL;
2827 proc->vma_vm_mm = NULL;
2828 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
2846 struct binder_proc *proc = filp->private_data;
2850 if (proc->tsk != current)
2858 proc->pid, vma->vm_start, vma->vm_end,
2870 if (proc->buffer) {
2882 proc->buffer = area->addr;
2883 proc->user_buffer_offset = vma->vm_start - (uintptr_t)proc->buffer;
2888 while (CACHE_COLOUR((vma->vm_start ^ (uint32_t)proc->buffer))) {
2889 pr_info("binder_mmap: %d %lx-%lx maps %p bad alignment\n", proc->pid, vma->vm_start, vma->vm_end, proc->buffer);
2894 proc->pages = kzalloc(sizeof(proc->pages[0]) * ((vma->vm_end - vma->vm_start) / PAGE_SIZE), GFP_KERNEL);
2895 if (proc->pages == NULL) {
2900 proc->buffer_size = vma->vm_end - vma->vm_start;
2903 vma->vm_private_data = proc;
2905 if (binder_update_page_range(proc, 1, proc->buffer, proc->buffer + PAGE_SIZE, vma)) {
2910 buffer = proc->buffer;
2911 INIT_LIST_HEAD(&proc->buffers);
2912 list_add(&buffer->entry, &proc->buffers);
2914 binder_insert_free_buffer(proc, buffer);
2915 proc->free_async_space = proc->buffer_size / 2;
2917 proc->files = get_files_struct(current);
2918 proc->vma = vma;
2919 proc->vma_vm_mm = vma->vm_mm;
2922 proc->pid, vma->vm_start, vma->vm_end, proc->buffer);*/
2926 kfree(proc->pages);
2927 proc->pages = NULL;
2930 vfree(proc->buffer);
2931 proc->buffer = NULL;
2937 proc->pid, vma->vm_start, vma->vm_end, failure_string, ret);
2943 struct binder_proc *proc;
2948 proc = kzalloc(sizeof(*proc), GFP_KERNEL);
2949 if (proc == NULL)
2952 proc->tsk = current;
2953 INIT_LIST_HEAD(&proc->todo);
2954 init_waitqueue_head(&proc->wait);
2955 proc->default_priority = task_nice(current);
2960 hlist_add_head(&proc->proc_node, &binder_procs);
2961 proc->pid = current->group_leader->pid;
2962 INIT_LIST_HEAD(&proc->delivered_death);
2963 filp->private_data = proc;
2970 snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
2971 proc->debugfs_entry = debugfs_create_file(strbuf, S_IRUGO,
2972 binder_debugfs_dir_entry_proc, proc, &binder_proc_fops);
2980 struct binder_proc *proc = filp->private_data;
2982 binder_defer_work(proc, BINDER_DEFERRED_FLUSH);
2987 static void binder_deferred_flush(struct binder_proc *proc)
2992 for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n)) {
3001 wake_up_interruptible_all(&proc->wait);
3004 "binder_flush: %d woke %d threads\n", proc->pid,
3010 struct binder_proc *proc = filp->private_data;
3012 debugfs_remove(proc->debugfs_entry);
3013 binder_defer_work(proc, BINDER_DEFERRED_RELEASE);
3033 node->proc = NULL;
3049 &ref->proc->todo);
3050 wake_up_interruptible(&ref->proc->wait);
3062 static void binder_deferred_release(struct binder_proc *proc)
3069 BUG_ON(proc->vma);
3070 BUG_ON(proc->files);
3072 hlist_del(&proc->proc_node);
3074 if (binder_context_mgr_node && binder_context_mgr_node->proc == proc) {
3077 __func__, proc->pid);
3083 while ((n = rb_first(&proc->threads))) {
3088 active_transactions += binder_free_thread(proc, thread);
3093 while ((n = rb_first(&proc->nodes))) {
3098 rb_erase(&node->rb_node, &proc->nodes);
3103 while ((n = rb_first(&proc->refs_by_desc))) {
3111 binder_release_work(&proc->todo);
3112 binder_release_work(&proc->delivered_death);
3115 while ((n = rb_first(&proc->allocated_buffers))) {
3124 pr_err("release proc %d, transaction %d, not freed\n",
3125 proc->pid, t->debug_id);
3129 binder_free_buf(proc, buffer);
3136 if (proc->pages) {
3139 for (i = 0; i < proc->buffer_size / PAGE_SIZE; i++) {
3142 if (!proc->pages[i])
3145 page_addr = proc->buffer + i * PAGE_SIZE;
3148 __func__, proc->pid, i, page_addr);
3150 __free_page(proc->pages[i]);
3153 kfree(proc->pages);
3154 vfree(proc->buffer);
3157 put_task_struct(proc->tsk);
3161 __func__, proc->pid, threads, nodes, incoming_refs,
3164 kfree(proc);
3169 struct binder_proc *proc;
3178 proc = hlist_entry(binder_deferred_list.first,
3180 hlist_del_init(&proc->deferred_work_node);
3181 defer = proc->deferred_work;
3182 proc->deferred_work = 0;
3184 proc = NULL;
3191 files = proc->files;
3193 proc->files = NULL;
3197 binder_deferred_flush(proc);
3200 binder_deferred_release(proc); /* frees proc */
3205 } while (proc);
3210 binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer)
3213 proc->deferred_work |= defer;
3214 if (hlist_unhashed(&proc->deferred_work_node)) {
3215 hlist_add_head(&proc->deferred_work_node,
3228 t->from ? t->from->proc->pid : 0,
3339 seq_puts(m, " proc");
3341 seq_printf(m, " %d", ref->proc->pid);
3352 ref->debug_id, ref->desc, ref->node->proc ? "" : "dead ",
3357 struct binder_proc *proc, int print_all)
3364 seq_printf(m, "proc %d\n", proc->pid);
3367 for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n))
3370 for (n = rb_first(&proc->nodes); n != NULL; n = rb_next(n)) {
3377 for (n = rb_first(&proc->refs_by_desc);
3383 for (n = rb_first(&proc->allocated_buffers); n != NULL; n = rb_next(n))
3386 list_for_each_entry(w, &proc->todo, entry)
3388 list_for_each_entry(w, &proc->delivered_death, entry) {
3438 "proc",
3482 struct binder_proc *proc)
3488 seq_printf(m, "proc %d\n", proc->pid);
3490 for (n = rb_first(&proc->threads); n != NULL; n = rb_next(n))
3495 " free async space %zd\n", proc->requested_threads,
3496 proc->requested_threads_started, proc->max_threads,
3497 proc->ready_threads, proc->free_async_space);
3499 for (n = rb_first(&proc->nodes); n != NULL; n = rb_next(n))
3505 for (n = rb_first(&proc->refs_by_desc); n != NULL; n = rb_next(n)) {
3515 for (n = rb_first(&proc->allocated_buffers); n != NULL; n = rb_next(n))
3520 list_for_each_entry(w, &proc->todo, entry) {
3531 print_binder_stats(m, " ", &proc->stats);
3537 struct binder_proc *proc;
3551 hlist_for_each_entry(proc, &binder_procs, proc_node)
3552 print_binder_proc(m, proc, 1);
3560 struct binder_proc *proc;
3570 hlist_for_each_entry(proc, &binder_procs, proc_node)
3571 print_binder_proc_stats(m, proc);
3579 struct binder_proc *proc;
3586 hlist_for_each_entry(proc, &binder_procs, proc_node)
3587 print_binder_proc(m, proc, 0);
3595 struct binder_proc *proc = m->private;
3600 seq_puts(m, "binder proc state:\n");
3601 print_binder_proc(m, proc, 1);
3664 binder_debugfs_dir_entry_proc = debugfs_create_dir("proc",