2 #include <linux/hugetlb.h>
3 #include <linux/seq_file.h>
5 #include <asm/uaccess.h>
7 char *task_mem(struct mm_struct *mm, char *buffer)
9 unsigned long data = 0, stack = 0, exec = 0, lib = 0;
10 struct vm_area_struct *vma;
12 down_read(&mm->mmap_sem);
13 for (vma = mm->mmap; vma; vma = vma->vm_next) {
14 unsigned long len = (vma->vm_end - vma->vm_start) >> 10;
17 if (vma->vm_flags & VM_GROWSDOWN)
21 if (vma->vm_flags & VM_WRITE)
23 if (vma->vm_flags & VM_EXEC) {
25 if (vma->vm_flags & VM_EXECUTABLE)
30 buffer += sprintf(buffer,
38 mm->total_vm << (PAGE_SHIFT-10),
39 mm->locked_vm << (PAGE_SHIFT-10),
40 mm->rss << (PAGE_SHIFT-10),
43 up_read(&mm->mmap_sem);
47 unsigned long task_vsize(struct mm_struct *mm)
49 return PAGE_SIZE * mm->total_vm;
52 int task_statm(struct mm_struct *mm, int *shared, int *text,
53 int *data, int *resident)
55 struct vm_area_struct *vma;
59 for (vma = mm->mmap; vma; vma = vma->vm_next) {
60 int pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
63 if (is_vm_hugetlb_page(vma)) {
64 if (!(vma->vm_flags & VM_DONTCOPY))
68 if (vma->vm_flags & VM_SHARED || !list_empty(&vma->shared))
70 if (vma->vm_flags & VM_EXECUTABLE)
79 #ifdef AT_SYSINFO_EHDR
81 static struct vm_area_struct gate_vmarea = {
82 /* Do _not_ mark this area as readable, cuz not the entire range may be readable
83 (e.g., due to execute-only pages or holes) and the tools that read
84 /proc/PID/maps should read the interesting bits from the gate-DSO file
86 .vm_start = FIXADDR_USER_START,
87 .vm_end = FIXADDR_USER_END
90 # define gate_map() &gate_vmarea
92 # define gate_map() NULL
95 static int show_map(struct seq_file *m, void *v)
97 struct vm_area_struct *map = v;
98 struct file *file = map->vm_file;
99 int flags = map->vm_flags;
100 unsigned long ino = 0;
105 struct inode *inode = map->vm_file->f_dentry->d_inode;
106 dev = inode->i_sb->s_dev;
110 seq_printf(m, "%08lx-%08lx %c%c%c%c %08lx %02x:%02x %lu %n",
113 flags & VM_READ ? 'r' : '-',
114 flags & VM_WRITE ? 'w' : '-',
115 flags & VM_EXEC ? 'x' : '-',
116 flags & VM_MAYSHARE ? 's' : 'p',
117 map->vm_pgoff << PAGE_SHIFT,
118 MAJOR(dev), MINOR(dev), ino, &len);
121 len = 25 + sizeof(void*) * 6 - len;
124 seq_printf(m, "%*c", len, ' ');
125 seq_path(m, file->f_vfsmnt, file->f_dentry, " \t\n\\");
131 static void *m_start(struct seq_file *m, loff_t *pos)
133 struct task_struct *task = m->private;
134 struct mm_struct *mm = get_task_mm(task);
135 struct vm_area_struct * map;
141 down_read(&mm->mmap_sem);
146 up_read(&mm->mmap_sem);
154 static void m_stop(struct seq_file *m, void *v)
156 struct vm_area_struct *map = v;
157 if (map && map != gate_map()) {
158 struct mm_struct *mm = map->vm_mm;
159 up_read(&mm->mmap_sem);
164 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
166 struct vm_area_struct *map = v;
171 if (map != gate_map())
176 struct seq_operations proc_pid_maps_op = {