nommu.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* nommu.c: mmu-less memory info files
  3. *
  4. * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells ([email protected])
  6. */
  7. #include <linux/init.h>
  8. #include <linux/module.h>
  9. #include <linux/errno.h>
  10. #include <linux/time.h>
  11. #include <linux/kernel.h>
  12. #include <linux/string.h>
  13. #include <linux/mman.h>
  14. #include <linux/proc_fs.h>
  15. #include <linux/mm.h>
  16. #include <linux/mmzone.h>
  17. #include <linux/pagemap.h>
  18. #include <linux/swap.h>
  19. #include <linux/smp.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/hugetlb.h>
  22. #include <linux/vmalloc.h>
  23. #include <asm/tlb.h>
  24. #include <asm/div64.h>
  25. #include "internal.h"
  26. /*
  27. * display a single region to a sequenced file
  28. */
  29. static int nommu_region_show(struct seq_file *m, struct vm_region *region)
  30. {
  31. unsigned long ino = 0;
  32. struct file *file;
  33. dev_t dev = 0;
  34. int flags;
  35. flags = region->vm_flags;
  36. file = region->vm_file;
  37. if (file) {
  38. struct inode *inode = file_inode(region->vm_file);
  39. dev = inode->i_sb->s_dev;
  40. ino = inode->i_ino;
  41. }
  42. seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
  43. seq_printf(m,
  44. "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
  45. region->vm_start,
  46. region->vm_end,
  47. flags & VM_READ ? 'r' : '-',
  48. flags & VM_WRITE ? 'w' : '-',
  49. flags & VM_EXEC ? 'x' : '-',
  50. flags & VM_MAYSHARE ? flags & VM_SHARED ? 'S' : 's' : 'p',
  51. ((loff_t)region->vm_pgoff) << PAGE_SHIFT,
  52. MAJOR(dev), MINOR(dev), ino);
  53. if (file) {
  54. seq_pad(m, ' ');
  55. seq_file_path(m, file, "");
  56. }
  57. seq_putc(m, '\n');
  58. return 0;
  59. }
  60. /*
  61. * display a list of all the REGIONs the kernel knows about
  62. * - nommu kernels have a single flat list
  63. */
  64. static int nommu_region_list_show(struct seq_file *m, void *_p)
  65. {
  66. struct rb_node *p = _p;
  67. return nommu_region_show(m, rb_entry(p, struct vm_region, vm_rb));
  68. }
  69. static void *nommu_region_list_start(struct seq_file *m, loff_t *_pos)
  70. {
  71. struct rb_node *p;
  72. loff_t pos = *_pos;
  73. down_read(&nommu_region_sem);
  74. for (p = rb_first(&nommu_region_tree); p; p = rb_next(p))
  75. if (pos-- == 0)
  76. return p;
  77. return NULL;
  78. }
  79. static void nommu_region_list_stop(struct seq_file *m, void *v)
  80. {
  81. up_read(&nommu_region_sem);
  82. }
  83. static void *nommu_region_list_next(struct seq_file *m, void *v, loff_t *pos)
  84. {
  85. (*pos)++;
  86. return rb_next((struct rb_node *) v);
  87. }
  88. static const struct seq_operations proc_nommu_region_list_seqop = {
  89. .start = nommu_region_list_start,
  90. .next = nommu_region_list_next,
  91. .stop = nommu_region_list_stop,
  92. .show = nommu_region_list_show
  93. };
  94. static int __init proc_nommu_init(void)
  95. {
  96. proc_create_seq("maps", S_IRUGO, NULL, &proc_nommu_region_list_seqop);
  97. return 0;
  98. }
  99. fs_initcall(proc_nommu_init);