blob: 199088ee969b1ec956fb85337e614c9ec42c92ab [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/mm.h>
2#include <linux/hugetlb.h>
3#include <linux/mount.h>
4#include <linux/seq_file.h>
Mauricio Line070ad42005-09-03 15:55:10 -07005#include <linux/highmem.h>
Christoph Lameter6e21c8f2005-09-03 15:54:45 -07006#include <linux/pagemap.h>
7#include <linux/mempolicy.h>
Mauricio Line070ad42005-09-03 15:55:10 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <asm/elf.h>
10#include <asm/uaccess.h>
Mauricio Line070ad42005-09-03 15:55:10 -070011#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "internal.h"
13
14char *task_mem(struct mm_struct *mm, char *buffer)
15{
16 unsigned long data, text, lib;
Hugh Dickins365e9c872005-10-29 18:16:18 -070017 unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss;
18
19 /*
20 * Note: to minimize their overhead, mm maintains hiwater_vm and
21 * hiwater_rss only when about to *lower* total_vm or rss. Any
22 * collector of these hiwater stats must therefore get total_vm
23 * and rss too, which will usually be the higher. Barriers? not
24 * worth the effort, such snapshots can always be inconsistent.
25 */
26 hiwater_vm = total_vm = mm->total_vm;
27 if (hiwater_vm < mm->hiwater_vm)
28 hiwater_vm = mm->hiwater_vm;
29 hiwater_rss = total_rss = get_mm_rss(mm);
30 if (hiwater_rss < mm->hiwater_rss)
31 hiwater_rss = mm->hiwater_rss;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33 data = mm->total_vm - mm->shared_vm - mm->stack_vm;
34 text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10;
35 lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
36 buffer += sprintf(buffer,
Hugh Dickins365e9c872005-10-29 18:16:18 -070037 "VmPeak:\t%8lu kB\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 "VmSize:\t%8lu kB\n"
39 "VmLck:\t%8lu kB\n"
Hugh Dickins365e9c872005-10-29 18:16:18 -070040 "VmHWM:\t%8lu kB\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 "VmRSS:\t%8lu kB\n"
42 "VmData:\t%8lu kB\n"
43 "VmStk:\t%8lu kB\n"
44 "VmExe:\t%8lu kB\n"
45 "VmLib:\t%8lu kB\n"
46 "VmPTE:\t%8lu kB\n",
Hugh Dickins365e9c872005-10-29 18:16:18 -070047 hiwater_vm << (PAGE_SHIFT-10),
48 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 mm->locked_vm << (PAGE_SHIFT-10),
Hugh Dickins365e9c872005-10-29 18:16:18 -070050 hiwater_rss << (PAGE_SHIFT-10),
51 total_rss << (PAGE_SHIFT-10),
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 data << (PAGE_SHIFT-10),
53 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
54 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
55 return buffer;
56}
57
58unsigned long task_vsize(struct mm_struct *mm)
59{
60 return PAGE_SIZE * mm->total_vm;
61}
62
63int task_statm(struct mm_struct *mm, int *shared, int *text,
64 int *data, int *resident)
65{
Hugh Dickins42946212005-10-29 18:16:05 -070066 *shared = get_mm_counter(mm, file_rss);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
68 >> PAGE_SHIFT;
69 *data = mm->total_vm - mm->shared_vm;
Hugh Dickins42946212005-10-29 18:16:05 -070070 *resident = *shared + get_mm_counter(mm, anon_rss);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 return mm->total_vm;
72}
73
74int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount **mnt)
75{
76 struct vm_area_struct * vma;
77 int result = -ENOENT;
Eric W. Biederman99f89552006-06-26 00:25:55 -070078 struct task_struct *task = get_proc_task(inode);
79 struct mm_struct * mm = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Eric W. Biederman99f89552006-06-26 00:25:55 -070081 if (task) {
82 mm = get_task_mm(task);
83 put_task_struct(task);
84 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 if (!mm)
86 goto out;
87 down_read(&mm->mmap_sem);
88
89 vma = mm->mmap;
90 while (vma) {
91 if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
92 break;
93 vma = vma->vm_next;
94 }
95
96 if (vma) {
Josef "Jeff" Sipek2fddfee2006-12-08 02:36:36 -080097 *mnt = mntget(vma->vm_file->f_path.mnt);
98 *dentry = dget(vma->vm_file->f_path.dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 result = 0;
100 }
101
102 up_read(&mm->mmap_sem);
103 mmput(mm);
104out:
105 return result;
106}
107
108static void pad_len_spaces(struct seq_file *m, int len)
109{
110 len = 25 + sizeof(void*) * 6 - len;
111 if (len < 1)
112 len = 1;
113 seq_printf(m, "%*c", len, ' ');
114}
115
Mauricio Line070ad42005-09-03 15:55:10 -0700116struct mem_size_stats
117{
118 unsigned long resident;
119 unsigned long shared_clean;
120 unsigned long shared_dirty;
121 unsigned long private_clean;
122 unsigned long private_dirty;
David Rientjesf79f1772007-05-06 14:49:22 -0700123 unsigned long referenced;
Mauricio Line070ad42005-09-03 15:55:10 -0700124};
125
David Rientjes826fad12007-05-06 14:49:21 -0700126struct pmd_walker {
127 struct vm_area_struct *vma;
128 void *private;
129 void (*action)(struct vm_area_struct *, pmd_t *, unsigned long,
130 unsigned long, void *);
131};
132
Mauricio Line070ad42005-09-03 15:55:10 -0700133static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats *mss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Eric W. Biederman99f89552006-06-26 00:25:55 -0700135 struct proc_maps_private *priv = m->private;
136 struct task_struct *task = priv->task;
Mauricio Line070ad42005-09-03 15:55:10 -0700137 struct vm_area_struct *vma = v;
138 struct mm_struct *mm = vma->vm_mm;
139 struct file *file = vma->vm_file;
140 int flags = vma->vm_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 unsigned long ino = 0;
142 dev_t dev = 0;
143 int len;
144
145 if (file) {
Josef "Jeff" Sipek2fddfee2006-12-08 02:36:36 -0800146 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 dev = inode->i_sb->s_dev;
148 ino = inode->i_ino;
149 }
150
151 seq_printf(m, "%08lx-%08lx %c%c%c%c %08lx %02x:%02x %lu %n",
Mauricio Line070ad42005-09-03 15:55:10 -0700152 vma->vm_start,
153 vma->vm_end,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 flags & VM_READ ? 'r' : '-',
155 flags & VM_WRITE ? 'w' : '-',
156 flags & VM_EXEC ? 'x' : '-',
157 flags & VM_MAYSHARE ? 's' : 'p',
Mauricio Line070ad42005-09-03 15:55:10 -0700158 vma->vm_pgoff << PAGE_SHIFT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 MAJOR(dev), MINOR(dev), ino, &len);
160
161 /*
162 * Print the dentry name for named mappings, and a
163 * special [heap] marker for the heap:
164 */
Mauricio Line070ad42005-09-03 15:55:10 -0700165 if (file) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 pad_len_spaces(m, len);
Josef "Jeff" Sipek2fddfee2006-12-08 02:36:36 -0800167 seq_path(m, file->f_path.mnt, file->f_path.dentry, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 } else {
Ingo Molnare6e54942006-06-27 02:53:50 -0700169 const char *name = arch_vma_name(vma);
170 if (!name) {
171 if (mm) {
172 if (vma->vm_start <= mm->start_brk &&
Mauricio Line070ad42005-09-03 15:55:10 -0700173 vma->vm_end >= mm->brk) {
Ingo Molnare6e54942006-06-27 02:53:50 -0700174 name = "[heap]";
175 } else if (vma->vm_start <= mm->start_stack &&
176 vma->vm_end >= mm->start_stack) {
177 name = "[stack]";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
Ingo Molnare6e54942006-06-27 02:53:50 -0700179 } else {
180 name = "[vdso]";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
Ingo Molnare6e54942006-06-27 02:53:50 -0700182 }
183 if (name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 pad_len_spaces(m, len);
Ingo Molnare6e54942006-06-27 02:53:50 -0700185 seq_puts(m, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187 }
188 seq_putc(m, '\n');
Mauricio Line070ad42005-09-03 15:55:10 -0700189
190 if (mss)
191 seq_printf(m,
David Rientjesf79f1772007-05-06 14:49:22 -0700192 "Size: %8lu kB\n"
193 "Rss: %8lu kB\n"
194 "Shared_Clean: %8lu kB\n"
195 "Shared_Dirty: %8lu kB\n"
196 "Private_Clean: %8lu kB\n"
197 "Private_Dirty: %8lu kB\n"
198 "Pgs_Referenced: %8lu kB\n",
Mauricio Line070ad42005-09-03 15:55:10 -0700199 (vma->vm_end - vma->vm_start) >> 10,
200 mss->resident >> 10,
201 mss->shared_clean >> 10,
202 mss->shared_dirty >> 10,
203 mss->private_clean >> 10,
David Rientjesf79f1772007-05-06 14:49:22 -0700204 mss->private_dirty >> 10,
205 mss->referenced >> 10);
Mauricio Line070ad42005-09-03 15:55:10 -0700206
207 if (m->count < m->size) /* vma is copied successfully */
208 m->version = (vma != get_gate_vma(task))? vma->vm_start: 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return 0;
210}
211
Mauricio Line070ad42005-09-03 15:55:10 -0700212static int show_map(struct seq_file *m, void *v)
213{
Luiz Fernando Capitulino0f5c79f2005-11-13 16:07:20 -0800214 return show_map_internal(m, v, NULL);
Mauricio Line070ad42005-09-03 15:55:10 -0700215}
216
David Rientjes826fad12007-05-06 14:49:21 -0700217static void smaps_one_pmd(struct vm_area_struct *vma, pmd_t *pmd,
218 unsigned long addr, unsigned long end,
219 void *private)
Mauricio Line070ad42005-09-03 15:55:10 -0700220{
David Rientjes826fad12007-05-06 14:49:21 -0700221 struct mem_size_stats *mss = private;
Mauricio Line070ad42005-09-03 15:55:10 -0700222 pte_t *pte, ptent;
Hugh Dickins705e87c2005-10-29 18:16:27 -0700223 spinlock_t *ptl;
Mauricio Line070ad42005-09-03 15:55:10 -0700224 struct page *page;
225
Hugh Dickins705e87c2005-10-29 18:16:27 -0700226 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
David Rientjes826fad12007-05-06 14:49:21 -0700227 for (; addr != end; pte++, addr += PAGE_SIZE) {
Mauricio Line070ad42005-09-03 15:55:10 -0700228 ptent = *pte;
Hugh Dickins705e87c2005-10-29 18:16:27 -0700229 if (!pte_present(ptent))
Mauricio Line070ad42005-09-03 15:55:10 -0700230 continue;
231
232 mss->resident += PAGE_SIZE;
Nick Pigginad820c5d2006-03-06 15:42:58 -0800233
234 page = vm_normal_page(vma, addr, ptent);
235 if (!page)
Mauricio Line070ad42005-09-03 15:55:10 -0700236 continue;
237
David Rientjesf79f1772007-05-06 14:49:22 -0700238 /* Accumulate the size in pages that have been accessed. */
239 if (pte_young(ptent) || PageReferenced(page))
240 mss->referenced += PAGE_SIZE;
Nick Pigginad820c5d2006-03-06 15:42:58 -0800241 if (page_mapcount(page) >= 2) {
Mauricio Line070ad42005-09-03 15:55:10 -0700242 if (pte_dirty(ptent))
243 mss->shared_dirty += PAGE_SIZE;
244 else
245 mss->shared_clean += PAGE_SIZE;
246 } else {
247 if (pte_dirty(ptent))
248 mss->private_dirty += PAGE_SIZE;
249 else
250 mss->private_clean += PAGE_SIZE;
251 }
David Rientjes826fad12007-05-06 14:49:21 -0700252 }
Hugh Dickins705e87c2005-10-29 18:16:27 -0700253 pte_unmap_unlock(pte - 1, ptl);
254 cond_resched();
Mauricio Line070ad42005-09-03 15:55:10 -0700255}
256
David Rientjes826fad12007-05-06 14:49:21 -0700257static inline void for_each_pmd_in_pud(struct pmd_walker *walker, pud_t *pud,
258 unsigned long addr, unsigned long end)
Mauricio Line070ad42005-09-03 15:55:10 -0700259{
260 pmd_t *pmd;
261 unsigned long next;
262
David Rientjes826fad12007-05-06 14:49:21 -0700263 for (pmd = pmd_offset(pud, addr); addr != end;
264 pmd++, addr = next) {
Mauricio Line070ad42005-09-03 15:55:10 -0700265 next = pmd_addr_end(addr, end);
266 if (pmd_none_or_clear_bad(pmd))
267 continue;
David Rientjes826fad12007-05-06 14:49:21 -0700268 walker->action(walker->vma, pmd, addr, next, walker->private);
269 }
Mauricio Line070ad42005-09-03 15:55:10 -0700270}
271
David Rientjes826fad12007-05-06 14:49:21 -0700272static inline void for_each_pud_in_pgd(struct pmd_walker *walker, pgd_t *pgd,
273 unsigned long addr, unsigned long end)
Mauricio Line070ad42005-09-03 15:55:10 -0700274{
275 pud_t *pud;
276 unsigned long next;
277
David Rientjes826fad12007-05-06 14:49:21 -0700278 for (pud = pud_offset(pgd, addr); addr != end;
279 pud++, addr = next) {
Mauricio Line070ad42005-09-03 15:55:10 -0700280 next = pud_addr_end(addr, end);
281 if (pud_none_or_clear_bad(pud))
282 continue;
David Rientjes826fad12007-05-06 14:49:21 -0700283 for_each_pmd_in_pud(walker, pud, addr, next);
284 }
Mauricio Line070ad42005-09-03 15:55:10 -0700285}
286
David Rientjes826fad12007-05-06 14:49:21 -0700287static inline void for_each_pmd(struct vm_area_struct *vma,
288 void (*action)(struct vm_area_struct *, pmd_t *,
289 unsigned long, unsigned long,
290 void *),
291 void *private)
Mauricio Line070ad42005-09-03 15:55:10 -0700292{
David Rientjes826fad12007-05-06 14:49:21 -0700293 unsigned long addr = vma->vm_start;
294 unsigned long end = vma->vm_end;
295 struct pmd_walker walker = {
296 .vma = vma,
297 .private = private,
298 .action = action,
299 };
Mauricio Line070ad42005-09-03 15:55:10 -0700300 pgd_t *pgd;
301 unsigned long next;
302
David Rientjes826fad12007-05-06 14:49:21 -0700303 for (pgd = pgd_offset(vma->vm_mm, addr); addr != end;
304 pgd++, addr = next) {
Mauricio Line070ad42005-09-03 15:55:10 -0700305 next = pgd_addr_end(addr, end);
306 if (pgd_none_or_clear_bad(pgd))
307 continue;
David Rientjes826fad12007-05-06 14:49:21 -0700308 for_each_pud_in_pgd(&walker, pgd, addr, next);
309 }
Mauricio Line070ad42005-09-03 15:55:10 -0700310}
311
312static int show_smap(struct seq_file *m, void *v)
313{
314 struct vm_area_struct *vma = v;
Mauricio Line070ad42005-09-03 15:55:10 -0700315 struct mem_size_stats mss;
316
317 memset(&mss, 0, sizeof mss);
Nick Piggin5ddfae12006-03-06 15:42:57 -0800318 if (vma->vm_mm && !is_vm_hugetlb_page(vma))
David Rientjes826fad12007-05-06 14:49:21 -0700319 for_each_pmd(vma, smaps_one_pmd, &mss);
Mauricio Line070ad42005-09-03 15:55:10 -0700320 return show_map_internal(m, v, &mss);
321}
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323static void *m_start(struct seq_file *m, loff_t *pos)
324{
Eric W. Biederman99f89552006-06-26 00:25:55 -0700325 struct proc_maps_private *priv = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 unsigned long last_addr = m->version;
327 struct mm_struct *mm;
Eric W. Biederman99f89552006-06-26 00:25:55 -0700328 struct vm_area_struct *vma, *tail_vma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 loff_t l = *pos;
330
Eric W. Biederman99f89552006-06-26 00:25:55 -0700331 /* Clear the per syscall fields in priv */
332 priv->task = NULL;
333 priv->tail_vma = NULL;
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /*
336 * We remember last_addr rather than next_addr to hit with
337 * mmap_cache most of the time. We have zero last_addr at
Mauricio Line070ad42005-09-03 15:55:10 -0700338 * the beginning and also after lseek. We will have -1 last_addr
339 * after the end of the vmas.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 */
341
342 if (last_addr == -1UL)
343 return NULL;
344
Eric W. Biederman13b41b02006-06-26 00:25:56 -0700345 priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
Eric W. Biederman99f89552006-06-26 00:25:55 -0700346 if (!priv->task)
347 return NULL;
348
349 mm = get_task_mm(priv->task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (!mm)
351 return NULL;
352
Eric W. Biederman99f89552006-06-26 00:25:55 -0700353 priv->tail_vma = tail_vma = get_gate_vma(priv->task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 down_read(&mm->mmap_sem);
355
356 /* Start with last addr hint */
Mauricio Line070ad42005-09-03 15:55:10 -0700357 if (last_addr && (vma = find_vma(mm, last_addr))) {
358 vma = vma->vm_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 goto out;
360 }
361
362 /*
Mauricio Line070ad42005-09-03 15:55:10 -0700363 * Check the vma index is within the range and do
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 * sequential scan until m_index.
365 */
Mauricio Line070ad42005-09-03 15:55:10 -0700366 vma = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 if ((unsigned long)l < mm->map_count) {
Mauricio Line070ad42005-09-03 15:55:10 -0700368 vma = mm->mmap;
369 while (l-- && vma)
370 vma = vma->vm_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 goto out;
372 }
373
374 if (l != mm->map_count)
Mauricio Line070ad42005-09-03 15:55:10 -0700375 tail_vma = NULL; /* After gate vma */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377out:
Mauricio Line070ad42005-09-03 15:55:10 -0700378 if (vma)
379 return vma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Mauricio Line070ad42005-09-03 15:55:10 -0700381 /* End of vmas has been reached */
382 m->version = (tail_vma != NULL)? 0: -1UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 up_read(&mm->mmap_sem);
384 mmput(mm);
Mauricio Line070ad42005-09-03 15:55:10 -0700385 return tail_vma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386}
387
Eric W. Biederman99f89552006-06-26 00:25:55 -0700388static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Eric W. Biederman99f89552006-06-26 00:25:55 -0700390 if (vma && vma != priv->tail_vma) {
Mauricio Line070ad42005-09-03 15:55:10 -0700391 struct mm_struct *mm = vma->vm_mm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 up_read(&mm->mmap_sem);
393 mmput(mm);
394 }
395}
396
397static void *m_next(struct seq_file *m, void *v, loff_t *pos)
398{
Eric W. Biederman99f89552006-06-26 00:25:55 -0700399 struct proc_maps_private *priv = m->private;
Mauricio Line070ad42005-09-03 15:55:10 -0700400 struct vm_area_struct *vma = v;
Eric W. Biederman99f89552006-06-26 00:25:55 -0700401 struct vm_area_struct *tail_vma = priv->tail_vma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 (*pos)++;
Mauricio Line070ad42005-09-03 15:55:10 -0700404 if (vma && (vma != tail_vma) && vma->vm_next)
405 return vma->vm_next;
Eric W. Biederman99f89552006-06-26 00:25:55 -0700406 vma_stop(priv, vma);
Mauricio Line070ad42005-09-03 15:55:10 -0700407 return (vma != tail_vma)? tail_vma: NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
Eric W. Biederman99f89552006-06-26 00:25:55 -0700410static void m_stop(struct seq_file *m, void *v)
411{
412 struct proc_maps_private *priv = m->private;
413 struct vm_area_struct *vma = v;
414
415 vma_stop(priv, vma);
416 if (priv->task)
417 put_task_struct(priv->task);
418}
419
Eric W. Biederman662795d2006-06-26 00:25:48 -0700420static struct seq_operations proc_pid_maps_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .start = m_start,
422 .next = m_next,
423 .stop = m_stop,
424 .show = show_map
425};
Christoph Lameter6e21c8f2005-09-03 15:54:45 -0700426
Eric W. Biederman662795d2006-06-26 00:25:48 -0700427static struct seq_operations proc_pid_smaps_op = {
Mauricio Line070ad42005-09-03 15:55:10 -0700428 .start = m_start,
429 .next = m_next,
430 .stop = m_stop,
431 .show = show_smap
432};
433
Eric W. Biederman662795d2006-06-26 00:25:48 -0700434static int do_maps_open(struct inode *inode, struct file *file,
435 struct seq_operations *ops)
436{
Eric W. Biederman99f89552006-06-26 00:25:55 -0700437 struct proc_maps_private *priv;
438 int ret = -ENOMEM;
439 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
440 if (priv) {
Eric W. Biederman13b41b02006-06-26 00:25:56 -0700441 priv->pid = proc_pid(inode);
Eric W. Biederman99f89552006-06-26 00:25:55 -0700442 ret = seq_open(file, ops);
443 if (!ret) {
444 struct seq_file *m = file->private_data;
445 m->private = priv;
446 } else {
447 kfree(priv);
448 }
Eric W. Biederman662795d2006-06-26 00:25:48 -0700449 }
450 return ret;
451}
452
453static int maps_open(struct inode *inode, struct file *file)
454{
455 return do_maps_open(inode, file, &proc_pid_maps_op);
456}
457
Arjan van de Ven00977a52007-02-12 00:55:34 -0800458const struct file_operations proc_maps_operations = {
Eric W. Biederman662795d2006-06-26 00:25:48 -0700459 .open = maps_open,
460 .read = seq_read,
461 .llseek = seq_lseek,
Eric W. Biederman99f89552006-06-26 00:25:55 -0700462 .release = seq_release_private,
Eric W. Biederman662795d2006-06-26 00:25:48 -0700463};
464
Christoph Lameter6e21c8f2005-09-03 15:54:45 -0700465#ifdef CONFIG_NUMA
Christoph Lameter1a75a6c2006-01-08 01:01:02 -0800466extern int show_numa_map(struct seq_file *m, void *v);
Christoph Lameter6e21c8f2005-09-03 15:54:45 -0700467
Eric W. Biederman662795d2006-06-26 00:25:48 -0700468static struct seq_operations proc_pid_numa_maps_op = {
Christoph Lameter1a75a6c2006-01-08 01:01:02 -0800469 .start = m_start,
470 .next = m_next,
471 .stop = m_stop,
472 .show = show_numa_map
Christoph Lameter6e21c8f2005-09-03 15:54:45 -0700473};
Eric W. Biederman662795d2006-06-26 00:25:48 -0700474
475static int numa_maps_open(struct inode *inode, struct file *file)
476{
477 return do_maps_open(inode, file, &proc_pid_numa_maps_op);
478}
479
Arjan van de Ven00977a52007-02-12 00:55:34 -0800480const struct file_operations proc_numa_maps_operations = {
Eric W. Biederman662795d2006-06-26 00:25:48 -0700481 .open = numa_maps_open,
482 .read = seq_read,
483 .llseek = seq_lseek,
Eric W. Biederman99f89552006-06-26 00:25:55 -0700484 .release = seq_release_private,
Eric W. Biederman662795d2006-06-26 00:25:48 -0700485};
Christoph Lameter6e21c8f2005-09-03 15:54:45 -0700486#endif
Eric W. Biederman662795d2006-06-26 00:25:48 -0700487
488static int smaps_open(struct inode *inode, struct file *file)
489{
490 return do_maps_open(inode, file, &proc_pid_smaps_op);
491}
492
Arjan van de Ven00977a52007-02-12 00:55:34 -0800493const struct file_operations proc_smaps_operations = {
Eric W. Biederman662795d2006-06-26 00:25:48 -0700494 .open = smaps_open,
495 .read = seq_read,
496 .llseek = seq_lseek,
Eric W. Biederman99f89552006-06-26 00:25:55 -0700497 .release = seq_release_private,
Eric W. Biederman662795d2006-06-26 00:25:48 -0700498};