procfs: mark thread stack correctly in proc/<pid>/maps
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / mm / util.c
index 136ac4f322b8248a5bea3c11d93c69c001b7bda8..ae962b31de888a55990769aae948bac3ef0db338 100644 (file)
--- a/mm/util.c
+++ b/mm/util.c
@@ -239,6 +239,47 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
                next->vm_prev = vma;
 }
 
+/* Check if the vma is being used as a stack by this task */
+static int vm_is_stack_for_task(struct task_struct *t,
+                               struct vm_area_struct *vma)
+{
+       return (vma->vm_start <= KSTK_ESP(t) && vma->vm_end >= KSTK_ESP(t));
+}
+
+/*
+ * Check if the vma is being used as a stack.
+ * If is_group is non-zero, check in the entire thread group or else
+ * just check in the current task. Returns the pid of the task that
+ * the vma is stack for.
+ */
+pid_t vm_is_stack(struct task_struct *task,
+                 struct vm_area_struct *vma, int in_group)
+{
+       pid_t ret = 0;
+
+       if (vm_is_stack_for_task(task, vma))
+               return task->pid;
+
+       if (in_group) {
+               struct task_struct *t;
+               rcu_read_lock();
+               if (!pid_alive(task))
+                       goto done;
+
+               t = task;
+               do {
+                       if (vm_is_stack_for_task(t, vma)) {
+                               ret = t->pid;
+                               goto done;
+                       }
+               } while_each_thread(task, t);
+done:
+               rcu_read_unlock();
+       }
+
+       return ret;
+}
+
 #if defined(CONFIG_MMU) && !defined(HAVE_ARCH_PICK_MMAP_LAYOUT)
 void arch_pick_mmap_layout(struct mm_struct *mm)
 {