Blame view

fs/proc/nommu.c 2.64 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
  /* nommu.c: mmu-less memory info files
   *
   * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
   * Written by David Howells (dhowells@redhat.com)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
8
9
10
11
12
13
14
15
16
17
18
19
   */
  
  #include <linux/init.h>
  #include <linux/module.h>
  #include <linux/errno.h>
  #include <linux/time.h>
  #include <linux/kernel.h>
  #include <linux/string.h>
  #include <linux/mman.h>
  #include <linux/proc_fs.h>
  #include <linux/mm.h>
  #include <linux/mmzone.h>
  #include <linux/pagemap.h>
  #include <linux/swap.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
22
23
  #include <linux/smp.h>
  #include <linux/seq_file.h>
  #include <linux/hugetlb.h>
  #include <linux/vmalloc.h>
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
24
  #include <linux/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
28
29
  #include <asm/tlb.h>
  #include <asm/div64.h>
  #include "internal.h"
  
  /*
8feae1311   David Howells   NOMMU: Make VMAs ...
30
   * display a single region to a sequenced file
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
   */
8feae1311   David Howells   NOMMU: Make VMAs ...
32
  static int nommu_region_show(struct seq_file *m, struct vm_region *region)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
35
36
  	unsigned long ino = 0;
  	struct file *file;
  	dev_t dev = 0;
652586df9   Tetsuo Handa   seq_file: remove ...
37
  	int flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38

8feae1311   David Howells   NOMMU: Make VMAs ...
39
40
  	flags = region->vm_flags;
  	file = region->vm_file;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
42
  
  	if (file) {
496ad9aa8   Al Viro   new helper: file_...
43
  		struct inode *inode = file_inode(region->vm_file);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
46
  		dev = inode->i_sb->s_dev;
  		ino = inode->i_ino;
  	}
652586df9   Tetsuo Handa   seq_file: remove ...
47
  	seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
  	seq_printf(m,
652586df9   Tetsuo Handa   seq_file: remove ...
49
  		   "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
8feae1311   David Howells   NOMMU: Make VMAs ...
50
51
  		   region->vm_start,
  		   region->vm_end,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
54
55
  		   flags & VM_READ ? 'r' : '-',
  		   flags & VM_WRITE ? 'w' : '-',
  		   flags & VM_EXEC ? 'x' : '-',
  		   flags & VM_MAYSHARE ? flags & VM_SHARED ? 'S' : 's' : 'p',
8feae1311   David Howells   NOMMU: Make VMAs ...
56
  		   ((loff_t)region->vm_pgoff) << PAGE_SHIFT,
652586df9   Tetsuo Handa   seq_file: remove ...
57
  		   MAJOR(dev), MINOR(dev), ino);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
59
  
  	if (file) {
652586df9   Tetsuo Handa   seq_file: remove ...
60
  		seq_pad(m, ' ');
2726d5662   Miklos Szeredi   vfs: add seq_file...
61
  		seq_file_path(m, file, "");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
64
65
66
67
  	}
  
  	seq_putc(m, '
  ');
  	return 0;
  }
dbf8685c8   David Howells   [PATCH] NOMMU: Im...
68
  /*
8feae1311   David Howells   NOMMU: Make VMAs ...
69
   * display a list of all the REGIONs the kernel knows about
973c32beb   Uwe Kleine-König   trivial: fix typo...
70
   * - nommu kernels have a single flat list
dbf8685c8   David Howells   [PATCH] NOMMU: Im...
71
   */
8feae1311   David Howells   NOMMU: Make VMAs ...
72
  static int nommu_region_list_show(struct seq_file *m, void *_p)
dbf8685c8   David Howells   [PATCH] NOMMU: Im...
73
  {
8feae1311   David Howells   NOMMU: Make VMAs ...
74
  	struct rb_node *p = _p;
dbf8685c8   David Howells   [PATCH] NOMMU: Im...
75

8feae1311   David Howells   NOMMU: Make VMAs ...
76
  	return nommu_region_show(m, rb_entry(p, struct vm_region, vm_rb));
dbf8685c8   David Howells   [PATCH] NOMMU: Im...
77
  }
8feae1311   David Howells   NOMMU: Make VMAs ...
78
  static void *nommu_region_list_start(struct seq_file *m, loff_t *_pos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  {
8feae1311   David Howells   NOMMU: Make VMAs ...
80
  	struct rb_node *p;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  	loff_t pos = *_pos;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82

8feae1311   David Howells   NOMMU: Make VMAs ...
83
  	down_read(&nommu_region_sem);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84

8feae1311   David Howells   NOMMU: Make VMAs ...
85
86
87
88
  	for (p = rb_first(&nommu_region_tree); p; p = rb_next(p))
  		if (pos-- == 0)
  			return p;
  	return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
  }
8feae1311   David Howells   NOMMU: Make VMAs ...
90
  static void nommu_region_list_stop(struct seq_file *m, void *v)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
  {
8feae1311   David Howells   NOMMU: Make VMAs ...
92
  	up_read(&nommu_region_sem);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
  }
8feae1311   David Howells   NOMMU: Make VMAs ...
94
  static void *nommu_region_list_next(struct seq_file *m, void *v, loff_t *pos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
96
97
98
  {
  	(*pos)++;
  	return rb_next((struct rb_node *) v);
  }
88e9d34c7   James Morris   seq_file: constif...
99
  static const struct seq_operations proc_nommu_region_list_seqop = {
8feae1311   David Howells   NOMMU: Make VMAs ...
100
101
102
103
  	.start	= nommu_region_list_start,
  	.next	= nommu_region_list_next,
  	.stop	= nommu_region_list_stop,
  	.show	= nommu_region_list_show
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
106
  static int __init proc_nommu_init(void)
  {
fddda2b7b   Christoph Hellwig   proc: introduce p...
107
  	proc_create_seq("maps", S_IRUGO, NULL, &proc_nommu_region_list_seqop);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108
109
  	return 0;
  }
abaf3787a   Paul Gortmaker   fs/proc: don't us...
110
  fs_initcall(proc_nommu_init);