~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/kernel/module/procfs.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Module proc support
  4  *
  5  * Copyright (C) 2008 Alexey Dobriyan
  6  */
  7 
  8 #include <linux/module.h>
  9 #include <linux/kallsyms.h>
 10 #include <linux/mutex.h>
 11 #include <linux/seq_file.h>
 12 #include <linux/proc_fs.h>
 13 #include "internal.h"
 14 
 15 #ifdef CONFIG_MODULE_UNLOAD
 16 static inline void print_unload_info(struct seq_file *m, struct module *mod)
 17 {
 18         struct module_use *use;
 19         int printed_something = 0;
 20 
 21         seq_printf(m, " %i ", module_refcount(mod));
 22 
 23         /*
 24          * Always include a trailing , so userspace can differentiate
 25          * between this and the old multi-field proc format.
 26          */
 27         list_for_each_entry(use, &mod->source_list, source_list) {
 28                 printed_something = 1;
 29                 seq_printf(m, "%s,", use->source->name);
 30         }
 31 
 32         if (mod->init && !mod->exit) {
 33                 printed_something = 1;
 34                 seq_puts(m, "[permanent],");
 35         }
 36 
 37         if (!printed_something)
 38                 seq_puts(m, "-");
 39 }
 40 #else /* !CONFIG_MODULE_UNLOAD */
 41 static inline void print_unload_info(struct seq_file *m, struct module *mod)
 42 {
 43         /* We don't know the usage count, or what modules are using. */
 44         seq_puts(m, " - -");
 45 }
 46 #endif /* CONFIG_MODULE_UNLOAD */
 47 
 48 /* Called by the /proc file system to return a list of modules. */
 49 static void *m_start(struct seq_file *m, loff_t *pos)
 50 {
 51         mutex_lock(&module_mutex);
 52         return seq_list_start(&modules, *pos);
 53 }
 54 
 55 static void *m_next(struct seq_file *m, void *p, loff_t *pos)
 56 {
 57         return seq_list_next(p, &modules, pos);
 58 }
 59 
 60 static void m_stop(struct seq_file *m, void *p)
 61 {
 62         mutex_unlock(&module_mutex);
 63 }
 64 
 65 static unsigned int module_total_size(struct module *mod)
 66 {
 67         int size = 0;
 68 
 69         for_each_mod_mem_type(type)
 70                 size += mod->mem[type].size;
 71         return size;
 72 }
 73 
 74 static int m_show(struct seq_file *m, void *p)
 75 {
 76         struct module *mod = list_entry(p, struct module, list);
 77         char buf[MODULE_FLAGS_BUF_SIZE];
 78         void *value;
 79         unsigned int size;
 80 
 81         /* We always ignore unformed modules. */
 82         if (mod->state == MODULE_STATE_UNFORMED)
 83                 return 0;
 84 
 85         size = module_total_size(mod);
 86         seq_printf(m, "%s %u", mod->name, size);
 87         print_unload_info(m, mod);
 88 
 89         /* Informative for users. */
 90         seq_printf(m, " %s",
 91                    mod->state == MODULE_STATE_GOING ? "Unloading" :
 92                    mod->state == MODULE_STATE_COMING ? "Loading" :
 93                    "Live");
 94         /* Used by oprofile and other similar tools. */
 95         value = m->private ? NULL : mod->mem[MOD_TEXT].base;
 96         seq_printf(m, " 0x%px", value);
 97 
 98         /* Taints info */
 99         if (mod->taints)
100                 seq_printf(m, " %s", module_flags(mod, buf, true));
101 
102         seq_puts(m, "\n");
103         return 0;
104 }
105 
106 /*
107  * Format: modulename size refcount deps address
108  *
109  * Where refcount is a number or -, and deps is a comma-separated list
110  * of depends or -.
111  */
112 static const struct seq_operations modules_op = {
113         .start  = m_start,
114         .next   = m_next,
115         .stop   = m_stop,
116         .show   = m_show
117 };
118 
119 /*
120  * This also sets the "private" pointer to non-NULL if the
121  * kernel pointers should be hidden (so you can just test
122  * "m->private" to see if you should keep the values private).
123  *
124  * We use the same logic as for /proc/kallsyms.
125  */
126 static int modules_open(struct inode *inode, struct file *file)
127 {
128         int err = seq_open(file, &modules_op);
129 
130         if (!err) {
131                 struct seq_file *m = file->private_data;
132 
133                 m->private = kallsyms_show_value(file->f_cred) ? NULL : (void *)8ul;
134         }
135 
136         return err;
137 }
138 
139 static const struct proc_ops modules_proc_ops = {
140         .proc_flags     = PROC_ENTRY_PERMANENT,
141         .proc_open      = modules_open,
142         .proc_read      = seq_read,
143         .proc_lseek     = seq_lseek,
144         .proc_release   = seq_release,
145 };
146 
147 static int __init proc_modules_init(void)
148 {
149         proc_create("modules", 0, NULL, &modules_proc_ops);
150         return 0;
151 }
152 module_init(proc_modules_init);
153 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php