fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / proc / task_mmu.c
index 91b7c15..34f01f2 100644 (file)
@@ -43,7 +43,11 @@ char *task_mem(struct mm_struct *mm, char *buffer)
                "VmStk:\t%8lu kB\n"
                "VmExe:\t%8lu kB\n"
                "VmLib:\t%8lu kB\n"
-               "VmPTE:\t%8lu kB\n",
+               "VmPTE:\t%8lu kB\n"
+               "StaBrk:\t%08lx kB\n"
+               "Brk:\t%08lx kB\n"
+               "StaStk:\t%08lx kB\n"
+               ,
                hiwater_vm << (PAGE_SHIFT-10),
                (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
                mm->locked_vm << (PAGE_SHIFT-10),
@@ -51,7 +55,13 @@ char *task_mem(struct mm_struct *mm, char *buffer)
                total_rss << (PAGE_SHIFT-10),
                data << (PAGE_SHIFT-10),
                mm->stack_vm << (PAGE_SHIFT-10), text, lib,
-               (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
+               (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
+               mm->start_brk, mm->brk, mm->start_stack);
+#ifdef __i386__
+       if (!nx_enabled)
+               buffer += sprintf(buffer,
+                       "ExecLim:\t%08lx\n", mm->context.exec_limit);
+#endif
        return buffer;
 }
 
@@ -75,9 +85,13 @@ int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount *
 {
        struct vm_area_struct * vma;
        int result = -ENOENT;
-       struct task_struct *task = proc_task(inode);
-       struct mm_struct * mm = get_task_mm(task);
+       struct task_struct *task = get_proc_task(inode);
+       struct mm_struct * mm = NULL;
 
+       if (task) {
+               mm = get_task_mm(task);
+               put_task_struct(task);
+       }
        if (!mm)
                goto out;
        down_read(&mm->mmap_sem);
@@ -90,8 +104,8 @@ int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount *
        }
 
        if (vma) {
-               *mnt = mntget(vma->vm_file->f_vfsmnt);
-               *dentry = dget(vma->vm_file->f_dentry);
+               *mnt = mntget(vma->vm_file->f_path.mnt);
+               *dentry = dget(vma->vm_file->f_path.dentry);
                result = 0;
        }
 
@@ -120,7 +134,11 @@ struct mem_size_stats
 
 static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats *mss)
 {
-       struct task_struct *task = m->private;
+       struct proc_maps_private *priv = m->private;
+       struct task_struct *task = priv->task;
+#ifdef __i386__
+       struct mm_struct *tmm = get_task_mm(task);
+#endif
        struct vm_area_struct *vma = v;
        struct mm_struct *mm = vma->vm_mm;
        struct file *file = vma->vm_file;
@@ -130,7 +148,7 @@ static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats
        int len;
 
        if (file) {
-               struct inode *inode = vma->vm_file->f_dentry->d_inode;
+               struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
                dev = inode->i_sb->s_dev;
                ino = inode->i_ino;
        }
@@ -140,10 +158,20 @@ static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats
                        vma->vm_end,
                        flags & VM_READ ? 'r' : '-',
                        flags & VM_WRITE ? 'w' : '-',
-                       flags & VM_EXEC ? 'x' : '-',
+                       (flags & VM_EXEC
+#ifdef __i386__
+                               || (!nx_enabled && tmm &&
+                               (vma->vm_start < tmm->context.exec_limit))
+#endif
+                       )
+                               ? 'x' : '-',
                        flags & VM_MAYSHARE ? 's' : 'p',
                        vma->vm_pgoff << PAGE_SHIFT,
                        MAJOR(dev), MINOR(dev), ino, &len);
+#ifdef __i386__
+       if (tmm)
+               mmput(tmm);
+#endif
 
        /*
         * Print the dentry name for named mappings, and a
@@ -151,24 +179,25 @@ static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats
         */
        if (file) {
                pad_len_spaces(m, len);
-               seq_path(m, file->f_vfsmnt, file->f_dentry, "\n");
+               seq_path(m, file->f_path.mnt, file->f_path.dentry, "\n");
        } else {
-               if (mm) {
-                       if (vma->vm_start <= mm->start_brk &&
+               const char *name = arch_vma_name(vma);
+               if (!name) {
+                       if (mm) {
+                               if (vma->vm_start <= mm->start_brk &&
                                                vma->vm_end >= mm->brk) {
-                               pad_len_spaces(m, len);
-                               seq_puts(m, "[heap]");
-                       } else {
-                               if (vma->vm_start <= mm->start_stack &&
-                                       vma->vm_end >= mm->start_stack) {
-
-                                       pad_len_spaces(m, len);
-                                       seq_puts(m, "[stack]");
+                                       name = "[heap]";
+                               } else if (vma->vm_start <= mm->start_stack &&
+                                          vma->vm_end >= mm->start_stack) {
+                                       name = "[stack]";
                                }
+                       } else {
+                               name = "[vdso]";
                        }
-               } else {
+               }
+               if (name) {
                        pad_len_spaces(m, len);
-                       seq_puts(m, "[vdso]");
+                       seq_puts(m, name);
                }
        }
        seq_putc(m, '\n');
@@ -295,12 +324,16 @@ static int show_smap(struct seq_file *m, void *v)
 
 static void *m_start(struct seq_file *m, loff_t *pos)
 {
-       struct task_struct *task = m->private;
+       struct proc_maps_private *priv = m->private;
        unsigned long last_addr = m->version;
        struct mm_struct *mm;
-       struct vm_area_struct *vma, *tail_vma;
+       struct vm_area_struct *vma, *tail_vma = NULL;
        loff_t l = *pos;
 
+       /* Clear the per syscall fields in priv */
+       priv->task = NULL;
+       priv->tail_vma = NULL;
+
        /*
         * We remember last_addr rather than next_addr to hit with
         * mmap_cache most of the time. We have zero last_addr at
@@ -311,12 +344,15 @@ static void *m_start(struct seq_file *m, loff_t *pos)
        if (last_addr == -1UL)
                return NULL;
 
-       mm = get_task_mm(task);
+       priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
+       if (!priv->task)
+               return NULL;
+
+       mm = mm_for_maps(priv->task);
        if (!mm)
                return NULL;
 
-       tail_vma = get_gate_vma(task);
-       down_read(&mm->mmap_sem);
+       priv->tail_vma = tail_vma = get_gate_vma(priv->task);
 
        /* Start with last addr hint */
        if (last_addr && (vma = find_vma(mm, last_addr))) {
@@ -350,11 +386,9 @@ out:
        return tail_vma;
 }
 
-static void m_stop(struct seq_file *m, void *v)
+static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma)
 {
-       struct task_struct *task = m->private;
-       struct vm_area_struct *vma = v;
-       if (vma && vma != get_gate_vma(task)) {
+       if (vma && vma != priv->tail_vma) {
                struct mm_struct *mm = vma->vm_mm;
                up_read(&mm->mmap_sem);
                mmput(mm);
@@ -363,38 +397,103 @@ static void m_stop(struct seq_file *m, void *v)
 
 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
 {
-       struct task_struct *task = m->private;
+       struct proc_maps_private *priv = m->private;
        struct vm_area_struct *vma = v;
-       struct vm_area_struct *tail_vma = get_gate_vma(task);
+       struct vm_area_struct *tail_vma = priv->tail_vma;
 
        (*pos)++;
        if (vma && (vma != tail_vma) && vma->vm_next)
                return vma->vm_next;
-       m_stop(m, v);
+       vma_stop(priv, vma);
        return (vma != tail_vma)? tail_vma: NULL;
 }
 
-struct seq_operations proc_pid_maps_op = {
+static void m_stop(struct seq_file *m, void *v)
+{
+       struct proc_maps_private *priv = m->private;
+       struct vm_area_struct *vma = v;
+
+       vma_stop(priv, vma);
+       if (priv->task)
+               put_task_struct(priv->task);
+}
+
+static struct seq_operations proc_pid_maps_op = {
        .start  = m_start,
        .next   = m_next,
        .stop   = m_stop,
        .show   = show_map
 };
 
-struct seq_operations proc_pid_smaps_op = {
+static struct seq_operations proc_pid_smaps_op = {
        .start  = m_start,
        .next   = m_next,
        .stop   = m_stop,
        .show   = show_smap
 };
 
+static int do_maps_open(struct inode *inode, struct file *file,
+                       struct seq_operations *ops)
+{
+       struct proc_maps_private *priv;
+       int ret = -ENOMEM;
+       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+       if (priv) {
+               priv->pid = proc_pid(inode);
+               ret = seq_open(file, ops);
+               if (!ret) {
+                       struct seq_file *m = file->private_data;
+                       m->private = priv;
+               } else {
+                       kfree(priv);
+               }
+       }
+       return ret;
+}
+
+static int maps_open(struct inode *inode, struct file *file)
+{
+       return do_maps_open(inode, file, &proc_pid_maps_op);
+}
+
+struct file_operations proc_maps_operations = {
+       .open           = maps_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release_private,
+};
+
 #ifdef CONFIG_NUMA
 extern int show_numa_map(struct seq_file *m, void *v);
 
-struct seq_operations proc_pid_numa_maps_op = {
+static struct seq_operations proc_pid_numa_maps_op = {
         .start  = m_start,
         .next   = m_next,
         .stop   = m_stop,
         .show   = show_numa_map
 };
+
+static int numa_maps_open(struct inode *inode, struct file *file)
+{
+       return do_maps_open(inode, file, &proc_pid_numa_maps_op);
+}
+
+struct file_operations proc_numa_maps_operations = {
+       .open           = numa_maps_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release_private,
+};
 #endif
+
+static int smaps_open(struct inode *inode, struct file *file)
+{
+       return do_maps_open(inode, file, &proc_pid_smaps_op);
+}
+
+struct file_operations proc_smaps_operations = {
+       .open           = smaps_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release_private,
+};