|
|
@@ -440,9 +440,8 @@ struct binder_buffer {
|
|
|
};
|
|
|
|
|
|
enum binder_deferred_state {
|
|
|
- BINDER_DEFERRED_PUT_FILES = 0x01,
|
|
|
- BINDER_DEFERRED_FLUSH = 0x02,
|
|
|
- BINDER_DEFERRED_RELEASE = 0x04,
|
|
|
+ BINDER_DEFERRED_FLUSH = 0x01,
|
|
|
+ BINDER_DEFERRED_RELEASE = 0x02,
|
|
|
};
|
|
|
|
|
|
#ifdef BINDER_MONITOR
|
|
|
@@ -464,7 +463,6 @@ struct binder_proc {
|
|
|
struct vm_area_struct *vma;
|
|
|
struct mm_struct *vma_vm_mm;
|
|
|
struct task_struct *tsk;
|
|
|
- struct files_struct *files;
|
|
|
struct hlist_node deferred_work_node;
|
|
|
int deferred_work;
|
|
|
void *buffer;
|
|
|
@@ -1267,22 +1265,34 @@ static void binder_check_buf(struct binder_proc *target_proc, size_t size, int i
|
|
|
#endif
|
|
|
}
|
|
|
#endif
|
|
|
+struct files_struct *binder_get_files_struct(struct binder_proc *proc)
|
|
|
+{
|
|
|
+ return get_files_struct(proc->tsk);
|
|
|
+}
|
|
|
+
|
|
|
static int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
|
|
|
{
|
|
|
- struct files_struct *files = proc->files;
|
|
|
+ struct files_struct *files;
|
|
|
unsigned long rlim_cur;
|
|
|
unsigned long irqs;
|
|
|
+ int ret;
|
|
|
|
|
|
+ files = binder_get_files_struct(proc);
|
|
|
if (files == NULL)
|
|
|
return -ESRCH;
|
|
|
|
|
|
- if (!lock_task_sighand(proc->tsk, &irqs))
|
|
|
- return -EMFILE;
|
|
|
+ if (!lock_task_sighand(proc->tsk, &irqs)) {
|
|
|
+ ret = -EMFILE;
|
|
|
+ goto err;
|
|
|
+ }
|
|
|
|
|
|
rlim_cur = task_rlimit(proc->tsk, RLIMIT_NOFILE);
|
|
|
unlock_task_sighand(proc->tsk, &irqs);
|
|
|
|
|
|
- return __alloc_fd(files, 0, rlim_cur, flags);
|
|
|
+ ret = __alloc_fd(files, 0, rlim_cur, flags);
|
|
|
+err:
|
|
|
+ put_files_struct(files);
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -1290,8 +1300,12 @@ static int task_get_unused_fd_flags(struct binder_proc *proc, int flags)
|
|
|
*/
|
|
|
static void task_fd_install(struct binder_proc *proc, unsigned int fd, struct file *file)
|
|
|
{
|
|
|
- if (proc->files)
|
|
|
- __fd_install(proc->files, fd, file);
|
|
|
+ struct files_struct *files = binder_get_files_struct(proc);
|
|
|
+
|
|
|
+ if (files) {
|
|
|
+ __fd_install(files, fd, file);
|
|
|
+ put_files_struct(files);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -1299,17 +1313,19 @@ static void task_fd_install(struct binder_proc *proc, unsigned int fd, struct fi
|
|
|
*/
|
|
|
static long task_close_fd(struct binder_proc *proc, unsigned int fd)
|
|
|
{
|
|
|
+ struct files_struct *files = binder_get_files_struct(proc);
|
|
|
int retval;
|
|
|
|
|
|
- if (proc->files == NULL)
|
|
|
+ if (files == NULL)
|
|
|
return -ESRCH;
|
|
|
|
|
|
- retval = __close_fd(proc->files, fd);
|
|
|
+ retval = __close_fd(files, fd);
|
|
|
/* can't restart close syscall because file table entry was cleared */
|
|
|
if (unlikely(retval == -ERESTARTSYS ||
|
|
|
retval == -ERESTARTNOINTR ||
|
|
|
retval == -ERESTARTNOHAND || retval == -ERESTART_RESTARTBLOCK))
|
|
|
retval = -EINTR;
|
|
|
+ put_files_struct(files);
|
|
|
|
|
|
return retval;
|
|
|
}
|
|
|
@@ -4242,7 +4258,6 @@ static void binder_vma_close(struct vm_area_struct *vma)
|
|
|
(unsigned long)pgprot_val(vma->vm_page_prot));
|
|
|
proc->vma = NULL;
|
|
|
proc->vma_vm_mm = NULL;
|
|
|
- binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
|
|
|
}
|
|
|
|
|
|
static int binder_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
|
|
|
@@ -4340,7 +4355,6 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
|
|
|
binder_insert_free_buffer(proc, buffer);
|
|
|
proc->free_async_space = proc->buffer_size / 2;
|
|
|
barrier();
|
|
|
- proc->files = get_files_struct(current);
|
|
|
proc->vma = vma;
|
|
|
proc->vma_vm_mm = vma->vm_mm;
|
|
|
|
|
|
@@ -4531,7 +4545,6 @@ static void binder_deferred_release(struct binder_proc *proc)
|
|
|
int threads, nodes, incoming_refs, outgoing_refs, buffers, active_transactions, page_count;
|
|
|
|
|
|
BUG_ON(proc->vma);
|
|
|
- BUG_ON(proc->files);
|
|
|
|
|
|
hlist_del(&proc->proc_node);
|
|
|
|
|
|
@@ -4654,7 +4667,6 @@ static void binder_deferred_release(struct binder_proc *proc)
|
|
|
static void binder_deferred_func(struct work_struct *work)
|
|
|
{
|
|
|
struct binder_proc *proc;
|
|
|
- struct files_struct *files;
|
|
|
|
|
|
int defer;
|
|
|
|
|
|
@@ -4673,13 +4685,6 @@ static void binder_deferred_func(struct work_struct *work)
|
|
|
}
|
|
|
mutex_unlock(&binder_deferred_lock);
|
|
|
|
|
|
- files = NULL;
|
|
|
- if (defer & BINDER_DEFERRED_PUT_FILES) {
|
|
|
- files = proc->files;
|
|
|
- if (files)
|
|
|
- proc->files = NULL;
|
|
|
- }
|
|
|
-
|
|
|
if (defer & BINDER_DEFERRED_FLUSH)
|
|
|
binder_deferred_flush(proc);
|
|
|
|
|
|
@@ -4687,8 +4692,6 @@ static void binder_deferred_func(struct work_struct *work)
|
|
|
binder_deferred_release(proc); /* frees proc */
|
|
|
|
|
|
binder_unlock(__func__);
|
|
|
- if (files)
|
|
|
- put_files_struct(files);
|
|
|
} while (proc);
|
|
|
}
|
|
|
|