2 #include <linux/hugetlb.h>
3 #include <linux/mount.h>
4 #include <linux/seq_file.h>
6 #include <asm/uaccess.h>
9 char *task_mem(struct mm_struct *mm, char *buffer)
11 unsigned long data, text, lib;
13 data = mm->total_vm - mm->shared_vm - mm->stack_vm;
14 text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10;
15 lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
16 buffer += sprintf(buffer,
29 (mm->total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
30 mm->locked_vm << (PAGE_SHIFT-10),
31 get_mm_counter(mm, rss) << (PAGE_SHIFT-10),
32 data << (PAGE_SHIFT-10),
33 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
34 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
35 mm->start_brk, mm->brk, mm->start_stack);
38 buffer += sprintf(buffer,
39 "ExecLim:\t%08lx\n", mm->context.exec_limit);
44 unsigned long task_vsize(struct mm_struct *mm)
46 return PAGE_SIZE * mm->total_vm;
49 int task_statm(struct mm_struct *mm, int *shared, int *text,
50 int *data, int *resident)
52 int rss = get_mm_counter(mm, rss);
54 *shared = rss - get_mm_counter(mm, anon_rss);
55 *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
57 *data = mm->total_vm - mm->shared_vm;
62 int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
64 struct vm_area_struct * vma;
66 struct task_struct *task = proc_task(inode);
67 struct mm_struct * mm = get_task_mm(task);
71 down_read(&mm->mmap_sem);
75 if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
81 *mnt = mntget(vma->vm_file->f_vfsmnt);
82 *dentry = dget(vma->vm_file->f_dentry);
86 up_read(&mm->mmap_sem);
92 static void pad_len_spaces(struct seq_file *m, int len)
94 len = 25 + sizeof(void*) * 6 - len;
97 seq_printf(m, "%*c", len, ' ');
100 static int show_map(struct seq_file *m, void *v)
102 struct task_struct *task = m->private;
103 struct vm_area_struct *map = v;
104 struct mm_struct *mm = map->vm_mm;
105 struct file *file = map->vm_file;
106 int flags = map->vm_flags;
107 unsigned long ino = 0;
112 struct inode *inode = map->vm_file->f_dentry->d_inode;
113 dev = inode->i_sb->s_dev;
117 seq_printf(m, "%08lx-%08lx %c%c%c%c %08lx %02x:%02x %lu %n",
120 flags & VM_READ ? 'r' : '-',
121 flags & VM_WRITE ? 'w' : '-',
125 (map->vm_start < task->mm->context.exec_limit))
129 flags & VM_MAYSHARE ? 's' : 'p',
130 map->vm_pgoff << PAGE_SHIFT,
131 MAJOR(dev), MINOR(dev), ino, &len);
134 * Print the dentry name for named mappings, and a
135 * special [heap] marker for the heap:
138 pad_len_spaces(m, len);
139 seq_path(m, file->f_vfsmnt, file->f_dentry, "");
142 if (map->vm_end == mm->brk) {
143 pad_len_spaces(m, len);
144 seq_puts(m, "[heap]");
146 if (map->vm_start <= mm->start_stack &&
147 map->vm_end >= mm->start_stack) {
149 pad_len_spaces(m, len);
150 seq_puts(m, "[stack]");
154 pad_len_spaces(m, len);
155 seq_puts(m, "[vdso]");
159 if (m->count < m->size) /* map is copied successfully */
160 m->version = (map != get_gate_vma(task))? map->vm_start: 0;
164 static void *m_start(struct seq_file *m, loff_t *pos)
166 struct task_struct *task = m->private;
167 unsigned long last_addr = m->version;
168 struct mm_struct *mm;
169 struct vm_area_struct *map, *tail_map;
173 * We remember last_addr rather than next_addr to hit with
174 * mmap_cache most of the time. We have zero last_addr at
175 * the begining and also after lseek. We will have -1 last_addr
176 * after the end of the maps.
179 if (last_addr == -1UL)
182 mm = get_task_mm(task);
186 tail_map = get_gate_vma(task);
187 down_read(&mm->mmap_sem);
189 /* Start with last addr hint */
190 if (last_addr && (map = find_vma(mm, last_addr))) {
196 * Check the map index is within the range and do
197 * sequential scan until m_index.
200 if ((unsigned long)l < mm->map_count) {
207 if (l != mm->map_count)
208 tail_map = NULL; /* After gate map */
214 /* End of maps has reached */
215 m->version = (tail_map != NULL)? 0: -1UL;
216 up_read(&mm->mmap_sem);
221 static void m_stop(struct seq_file *m, void *v)
223 struct task_struct *task = m->private;
224 struct vm_area_struct *map = v;
225 if (map && map != get_gate_vma(task)) {
226 struct mm_struct *mm = map->vm_mm;
227 up_read(&mm->mmap_sem);
232 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
234 struct task_struct *task = m->private;
235 struct vm_area_struct *map = v;
236 struct vm_area_struct *tail_map = get_gate_vma(task);
239 if (map && (map != tail_map) && map->vm_next)
242 return (map != tail_map)? tail_map: NULL;
245 struct seq_operations proc_pid_maps_op = {