1 #include <linux/config.h>
3 #include <linux/module.h>
4 #include <asm/module.h>
5 #include <asm/uaccess.h>
6 #include <linux/vmalloc.h>
7 #include <linux/smp_lock.h>
8 #include <asm/pgalloc.h>
9 #include <linux/init.h>
10 #include <linux/slab.h>
11 #include <linux/kmod.h>
12 #include <linux/seq_file.h>
15 * Originally by Anonymous (as far as I know...)
16 * Linux version by Bas Laarhoven <bas@vimec.nl>
17 * 0.99.14 version by Jon Tombs <jon@gtex02.us.es>,
18 * Heavily modified by Bjorn Ekwall <bj0rn@blox.se> May 1994 (C)
19 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
20 * Add MOD_INITIALIZING Keith Owens <kaos@ocs.com.au> Nov 1999
21 * Add kallsyms support, Keith Owens <kaos@ocs.com.au> Apr 2000
22 * Add asm/module support, IA64 has special requirements. Keith Owens <kaos@ocs.com.au> Sep 2000
23 * Fix assorted bugs in module verification. Keith Owens <kaos@ocs.com.au> Sep 2000
24 * Fix sys_init_module race, Andrew Morton <andrewm@uow.edu.au> Oct 2000
25 * http://www.uwsg.iu.edu/hypermail/linux/kernel/0008.3/0379.html
26 * Replace xxx_module_symbol with inter_module_xxx. Keith Owens <kaos@ocs.com.au> Oct 2000
27 * Add a module list lock for kernel fault race fixing. Alan Cox <alan@redhat.com>
29 * This source is covered by the GNU GPL, the same as all kernel sources.
32 #if defined(CONFIG_MODULES) || defined(CONFIG_KALLSYMS)
34 extern struct module_symbol __start___ksymtab[];
35 extern struct module_symbol __stop___ksymtab[];
37 extern const struct exception_table_entry __start___ex_table[];
38 extern const struct exception_table_entry __stop___ex_table[];
40 extern const char __start___kallsyms[] __attribute__ ((weak));
41 extern const char __stop___kallsyms[] __attribute__ ((weak));
43 struct module kernel_module =
45 size_of_struct: sizeof(struct module),
49 syms: __start___ksymtab,
50 ex_table_start: __start___ex_table,
51 ex_table_end: __stop___ex_table,
52 kallsyms_start: __start___kallsyms,
53 kallsyms_end: __stop___kallsyms,
56 struct module *module_list = &kernel_module;
58 #endif /* defined(CONFIG_MODULES) || defined(CONFIG_KALLSYMS) */
60 /* inter_module functions are always available, even when the kernel is
61 * compiled without modules. Consumers of inter_module_xxx routines
62 * will always work, even when both are built into the kernel, this
63 * approach removes lots of #ifdefs in mainline code.
66 static struct list_head ime_list = LIST_HEAD_INIT(ime_list);
67 static spinlock_t ime_lock = SPIN_LOCK_UNLOCKED;
68 static int kmalloc_failed;
71 * This lock prevents modifications that might race the kernel fault
72 * fixups. It does not prevent reader walks that the modules code
73 * does. The kernel lock does that.
75 * Since vmalloc fault fixups occur in any context this lock is taken
76 * irqsave at all times.
79 spinlock_t modlist_lock = SPIN_LOCK_UNLOCKED;
82 * inter_module_register - register a new set of inter module data.
83 * @im_name: an arbitrary string to identify the data, must be unique
84 * @owner: module that is registering the data, always use THIS_MODULE
85 * @userdata: pointer to arbitrary userdata to be registered
87 * Description: Check that the im_name has not already been registered,
88 * complain if it has. For new data, add it to the inter_module_entry
91 void inter_module_register(const char *im_name, struct module *owner, const void *userdata)
93 struct list_head *tmp;
94 struct inter_module_entry *ime, *ime_new;
96 if (!(ime_new = kmalloc(sizeof(*ime), GFP_KERNEL))) {
97 /* Overloaded kernel, not fatal */
99 "Aiee, inter_module_register: cannot kmalloc entry for '%s'\n",
104 memset(ime_new, 0, sizeof(*ime_new));
105 ime_new->im_name = im_name;
106 ime_new->owner = owner;
107 ime_new->userdata = userdata;
109 spin_lock(&ime_lock);
110 list_for_each(tmp, &ime_list) {
111 ime = list_entry(tmp, struct inter_module_entry, list);
112 if (strcmp(ime->im_name, im_name) == 0) {
113 spin_unlock(&ime_lock);
115 /* Program logic error, fatal */
116 printk(KERN_ERR "inter_module_register: duplicate im_name '%s'", im_name);
120 list_add(&(ime_new->list), &ime_list);
121 spin_unlock(&ime_lock);
125 * inter_module_unregister - unregister a set of inter module data.
126 * @im_name: an arbitrary string to identify the data, must be unique
128 * Description: Check that the im_name has been registered, complain if
129 * it has not. For existing data, remove it from the
130 * inter_module_entry list.
132 void inter_module_unregister(const char *im_name)
134 struct list_head *tmp;
135 struct inter_module_entry *ime;
137 spin_lock(&ime_lock);
138 list_for_each(tmp, &ime_list) {
139 ime = list_entry(tmp, struct inter_module_entry, list);
140 if (strcmp(ime->im_name, im_name) == 0) {
141 list_del(&(ime->list));
142 spin_unlock(&ime_lock);
147 spin_unlock(&ime_lock);
148 if (kmalloc_failed) {
150 "inter_module_unregister: no entry for '%s', "
151 "probably caused by previous kmalloc failure\n",
156 /* Program logic error, fatal */
157 printk(KERN_ERR "inter_module_unregister: no entry for '%s'", im_name);
163 * inter_module_get - return arbitrary userdata from another module.
164 * @im_name: an arbitrary string to identify the data, must be unique
166 * Description: If the im_name has not been registered, return NULL.
167 * Try to increment the use count on the owning module, if that fails
168 * then return NULL. Otherwise return the userdata.
170 const void *inter_module_get(const char *im_name)
172 struct list_head *tmp;
173 struct inter_module_entry *ime;
174 const void *result = NULL;
176 spin_lock(&ime_lock);
177 list_for_each(tmp, &ime_list) {
178 ime = list_entry(tmp, struct inter_module_entry, list);
179 if (strcmp(ime->im_name, im_name) == 0) {
180 if (try_inc_mod_count(ime->owner))
181 result = ime->userdata;
185 spin_unlock(&ime_lock);
190 * inter_module_get_request - im get with automatic request_module.
191 * @im_name: an arbitrary string to identify the data, must be unique
192 * @modname: module that is expected to register im_name
194 * Description: If inter_module_get fails, do request_module then retry.
196 const void *inter_module_get_request(const char *im_name, const char *modname)
198 const void *result = inter_module_get(im_name);
200 request_module(modname);
201 result = inter_module_get(im_name);
207 * inter_module_put - release use of data from another module.
208 * @im_name: an arbitrary string to identify the data, must be unique
210 * Description: If the im_name has not been registered, complain,
211 * otherwise decrement the use count on the owning module.
213 void inter_module_put(const char *im_name)
215 struct list_head *tmp;
216 struct inter_module_entry *ime;
218 spin_lock(&ime_lock);
219 list_for_each(tmp, &ime_list) {
220 ime = list_entry(tmp, struct inter_module_entry, list);
221 if (strcmp(ime->im_name, im_name) == 0) {
223 __MOD_DEC_USE_COUNT(ime->owner);
224 spin_unlock(&ime_lock);
228 spin_unlock(&ime_lock);
229 printk(KERN_ERR "inter_module_put: no entry for '%s'", im_name);
234 #if defined(CONFIG_MODULES) /* The rest of the source */
236 static long get_mod_name(const char *user_name, char **buf);
237 static void put_mod_name(char *buf);
238 struct module *find_module(const char *name);
239 void free_module(struct module *, int tag_freed);
243 * Called at boot time
246 void __init init_modules(void)
248 kernel_module.nsyms = __stop___ksymtab - __start___ksymtab;
250 arch_init_modules(&kernel_module);
254 * Copy the name of a module from user space.
258 get_mod_name(const char *user_name, char **buf)
263 page = __get_free_page(GFP_KERNEL);
267 retval = strncpy_from_user((char *)page, user_name, PAGE_SIZE);
269 if (retval < PAGE_SIZE) {
273 retval = -ENAMETOOLONG;
282 put_mod_name(char *buf)
284 free_page((unsigned long)buf);
288 * Allocate space for a module.
291 asmlinkage unsigned long
292 sys_create_module(const char *name_user, size_t size)
299 if (!capable(CAP_SYS_MODULE))
302 if ((namelen = get_mod_name(name_user, &name)) < 0) {
306 if (size < sizeof(struct module)+namelen+1) {
310 if (find_module(name) != NULL) {
314 if ((mod = (struct module *)module_map(size)) == NULL) {
319 memset(mod, 0, sizeof(*mod));
320 mod->size_of_struct = sizeof(*mod);
321 mod->name = (char *)(mod + 1);
323 memcpy((char*)(mod+1), name, namelen+1);
327 spin_lock_irqsave(&modlist_lock, flags);
328 mod->next = module_list;
329 module_list = mod; /* link it in */
330 spin_unlock_irqrestore(&modlist_lock, flags);
342 * Initialize a module.
346 sys_init_module(const char *name_user, struct module *mod_user)
348 struct module mod_tmp, *mod;
349 char *name, *n_name, *name_tmp = NULL;
350 long namelen, n_namelen, i, error;
351 unsigned long mod_user_size;
352 struct module_ref *dep;
354 if (!capable(CAP_SYS_MODULE))
357 if ((namelen = get_mod_name(name_user, &name)) < 0) {
361 if ((mod = find_module(name)) == NULL) {
366 /* Check module header size. We allow a bit of slop over the
367 size we are familiar with to cope with a version of insmod
368 for a newer kernel. But don't over do it. */
369 if ((error = get_user(mod_user_size, &mod_user->size_of_struct)) != 0)
371 if (mod_user_size < (unsigned long)&((struct module *)0L)->persist_start
372 || mod_user_size > sizeof(struct module) + 16*sizeof(void*)) {
373 printk(KERN_ERR "init_module: Invalid module header size.\n"
374 KERN_ERR "A new version of the modutils is likely "
380 /* Hold the current contents while we play with the user's idea
383 name_tmp = kmalloc(strlen(mod->name) + 1, GFP_KERNEL); /* Where's kstrdup()? */
384 if (name_tmp == NULL) {
388 strcpy(name_tmp, mod->name);
390 error = copy_from_user(mod, mod_user, mod_user_size);
396 /* Sanity check the size of the module. */
399 if (mod->size > mod_tmp.size) {
400 printk(KERN_ERR "init_module: Size of initialized module "
401 "exceeds size of created module.\n");
405 /* Make sure all interesting pointers are sane. */
407 if (!mod_bound(mod->name, namelen, mod)) {
408 printk(KERN_ERR "init_module: mod->name out of bounds.\n");
411 if (mod->nsyms && !mod_bound(mod->syms, mod->nsyms, mod)) {
412 printk(KERN_ERR "init_module: mod->syms out of bounds.\n");
415 if (mod->ndeps && !mod_bound(mod->deps, mod->ndeps, mod)) {
416 printk(KERN_ERR "init_module: mod->deps out of bounds.\n");
419 if (mod->init && !mod_bound(mod->init, 0, mod)) {
420 printk(KERN_ERR "init_module: mod->init out of bounds.\n");
423 if (mod->cleanup && !mod_bound(mod->cleanup, 0, mod)) {
424 printk(KERN_ERR "init_module: mod->cleanup out of bounds.\n");
427 if (mod->ex_table_start > mod->ex_table_end
428 || (mod->ex_table_start &&
429 !((unsigned long)mod->ex_table_start >= ((unsigned long)mod + mod->size_of_struct)
430 && ((unsigned long)mod->ex_table_end
431 < (unsigned long)mod + mod->size)))
432 || (((unsigned long)mod->ex_table_start
433 - (unsigned long)mod->ex_table_end)
434 % sizeof(struct exception_table_entry))) {
435 printk(KERN_ERR "init_module: mod->ex_table_* invalid.\n");
438 if (mod->flags & ~MOD_AUTOCLEAN) {
439 printk(KERN_ERR "init_module: mod->flags invalid.\n");
442 if (mod_member_present(mod, can_unload)
443 && mod->can_unload && !mod_bound(mod->can_unload, 0, mod)) {
444 printk(KERN_ERR "init_module: mod->can_unload out of bounds.\n");
447 if (mod_member_present(mod, kallsyms_end)) {
448 if (mod->kallsyms_end &&
449 (!mod_bound(mod->kallsyms_start, 0, mod) ||
450 !mod_bound(mod->kallsyms_end, 0, mod))) {
451 printk(KERN_ERR "init_module: mod->kallsyms out of bounds.\n");
454 if (mod->kallsyms_start > mod->kallsyms_end) {
455 printk(KERN_ERR "init_module: mod->kallsyms invalid.\n");
459 if (mod_member_present(mod, archdata_end)) {
460 if (mod->archdata_end &&
461 (!mod_bound(mod->archdata_start, 0, mod) ||
462 !mod_bound(mod->archdata_end, 0, mod))) {
463 printk(KERN_ERR "init_module: mod->archdata out of bounds.\n");
466 if (mod->archdata_start > mod->archdata_end) {
467 printk(KERN_ERR "init_module: mod->archdata invalid.\n");
471 if (mod_member_present(mod, kernel_data) && mod->kernel_data) {
472 printk(KERN_ERR "init_module: mod->kernel_data must be zero.\n");
476 /* Check that the user isn't doing something silly with the name. */
478 if ((n_namelen = get_mod_name(mod->name - (unsigned long)mod
479 + (unsigned long)mod_user,
481 printk(KERN_ERR "init_module: get_mod_name failure.\n");
485 if (namelen != n_namelen || strcmp(n_name, name_tmp) != 0) {
486 printk(KERN_ERR "init_module: changed module name to "
492 /* Ok, that's about all the sanity we can stomach; copy the rest. */
494 if (copy_from_user((char *)mod+mod_user_size,
495 (char *)mod_user+mod_user_size,
496 mod->size-mod_user_size)) {
501 if (module_arch_init(mod))
504 /* On some machines it is necessary to do something here
505 to make the I and D caches consistent. */
506 flush_icache_range((unsigned long)mod, (unsigned long)mod + mod->size);
508 mod->next = mod_tmp.next;
511 /* Sanity check the module's dependents */
512 for (i = 0, dep = mod->deps; i < mod->ndeps; ++i, ++dep) {
513 struct module *o, *d = dep->dep;
515 /* Make sure the indicated dependencies are really modules. */
517 printk(KERN_ERR "init_module: self-referential "
518 "dependency in mod->deps.\n");
522 /* Scan the current modules for this dependency */
523 for (o = module_list; o != &kernel_module && o != d; o = o->next)
527 printk(KERN_ERR "init_module: found dependency that is "
528 "(no longer?) a module.\n");
533 /* Update module references. */
534 for (i = 0, dep = mod->deps; i < mod->ndeps; ++i, ++dep) {
535 struct module *d = dep->dep;
538 dep->next_ref = d->refs;
540 /* Being referenced by a dependent module counts as a
541 use as far as kmod is concerned. */
542 d->flags |= MOD_USED_ONCE;
545 /* Free our temporary memory. */
546 put_mod_name(n_name);
549 /* Initialize the module. */
550 atomic_set(&mod->uc.usecount,1);
551 mod->flags |= MOD_INITIALIZING;
552 if (mod->init && (error = mod->init()) != 0) {
553 atomic_set(&mod->uc.usecount,0);
554 mod->flags &= ~MOD_INITIALIZING;
555 if (error > 0) /* Buggy module */
559 atomic_dec(&mod->uc.usecount);
561 /* And set it running. */
562 mod->flags = (mod->flags | MOD_RUNNING) & ~MOD_INITIALIZING;
567 put_mod_name(n_name);
570 strcpy((char *)mod->name, name_tmp); /* We know there is room for this */
579 static spinlock_t unload_lock = SPIN_LOCK_UNLOCKED;
580 int try_inc_mod_count(struct module *mod)
584 spin_lock(&unload_lock);
585 if (mod->flags & MOD_DELETED)
588 __MOD_INC_USE_COUNT(mod);
589 spin_unlock(&unload_lock);
595 sys_delete_module(const char *name_user)
597 struct module *mod, *next;
600 int something_changed;
602 if (!capable(CAP_SYS_MODULE))
607 if ((error = get_mod_name(name_user, &name)) < 0)
610 if ((mod = find_module(name)) == NULL) {
616 if (mod->refs != NULL)
619 spin_lock(&unload_lock);
620 if (!__MOD_IN_USE(mod)) {
621 mod->flags |= MOD_DELETED;
622 spin_unlock(&unload_lock);
626 spin_unlock(&unload_lock);
631 /* Do automatic reaping */
633 something_changed = 0;
635 for (mod = module_list; mod != &kernel_module; mod = next) {
637 spin_lock(&unload_lock);
638 if (mod->refs == NULL
639 && (mod->flags & MOD_AUTOCLEAN)
640 && (mod->flags & MOD_RUNNING)
641 && !(mod->flags & MOD_DELETED)
642 && (mod->flags & MOD_USED_ONCE)
643 && !__MOD_IN_USE(mod)) {
644 if ((mod->flags & MOD_VISITED)
645 && !(mod->flags & MOD_JUST_FREED)) {
646 spin_unlock(&unload_lock);
647 mod->flags &= ~MOD_VISITED;
649 mod->flags |= MOD_DELETED;
650 spin_unlock(&unload_lock);
652 something_changed = 1;
655 spin_unlock(&unload_lock);
659 if (something_changed)
662 for (mod = module_list; mod != &kernel_module; mod = mod->next)
663 mod->flags &= ~MOD_JUST_FREED;
671 /* Query various bits about modules. */
674 qm_modules(char *buf, size_t bufsize, size_t *ret)
677 size_t nmod, space, len;
681 for (mod=module_list; mod != &kernel_module; mod=mod->next, ++nmod) {
682 len = strlen(mod->name)+1;
684 goto calc_space_needed;
685 if (copy_to_user(buf, mod->name, len))
692 if (put_user(nmod, ret))
699 while ((mod = mod->next) != &kernel_module)
700 space += strlen(mod->name)+1;
702 if (put_user(space, ret))
709 qm_deps(struct module *mod, char *buf, size_t bufsize, size_t *ret)
711 size_t i, space, len;
713 if (mod == &kernel_module)
715 if (!MOD_CAN_QUERY(mod))
716 if (put_user(0, ret))
722 for (i = 0; i < mod->ndeps; ++i) {
723 const char *dep_name = mod->deps[i].dep->name;
725 len = strlen(dep_name)+1;
727 goto calc_space_needed;
728 if (copy_to_user(buf, dep_name, len))
735 if (put_user(i, ret))
742 while (++i < mod->ndeps)
743 space += strlen(mod->deps[i].dep->name)+1;
745 if (put_user(space, ret))
752 qm_refs(struct module *mod, char *buf, size_t bufsize, size_t *ret)
754 size_t nrefs, space, len;
755 struct module_ref *ref;
757 if (mod == &kernel_module)
759 if (!MOD_CAN_QUERY(mod))
760 if (put_user(0, ret))
766 for (nrefs = 0, ref = mod->refs; ref ; ++nrefs, ref = ref->next_ref) {
767 const char *ref_name = ref->ref->name;
769 len = strlen(ref_name)+1;
771 goto calc_space_needed;
772 if (copy_to_user(buf, ref_name, len))
779 if (put_user(nrefs, ret))
786 while ((ref = ref->next_ref) != NULL)
787 space += strlen(ref->ref->name)+1;
789 if (put_user(space, ret))
796 qm_symbols(struct module *mod, char *buf, size_t bufsize, size_t *ret)
798 size_t i, space, len;
799 struct module_symbol *s;
803 if (!MOD_CAN_QUERY(mod))
804 if (put_user(0, ret))
809 space = mod->nsyms * 2*sizeof(void *);
815 goto calc_space_needed;
817 if (!access_ok(VERIFY_WRITE, buf, space))
821 vals = (unsigned long *)buf;
824 for (; i < mod->nsyms ; ++i, ++s, vals += 2) {
825 len = strlen(s->name)+1;
827 goto calc_space_needed;
829 if (copy_to_user(strings, s->name, len)
830 || __put_user(s->value, vals+0)
831 || __put_user(space, vals+1))
838 if (put_user(i, ret))
844 for (; i < mod->nsyms; ++i, ++s)
845 space += strlen(s->name)+1;
847 if (put_user(space, ret))
854 qm_info(struct module *mod, char *buf, size_t bufsize, size_t *ret)
858 if (mod == &kernel_module)
861 if (sizeof(struct module_info) <= bufsize) {
862 struct module_info info;
863 info.addr = (unsigned long)mod;
864 info.size = mod->size;
865 info.flags = mod->flags;
867 /* usecount is one too high here - report appropriately to
868 compensate for locking */
869 info.usecount = (mod_member_present(mod, can_unload)
870 && mod->can_unload ? -1 : atomic_read(&mod->uc.usecount)-1);
872 if (copy_to_user(buf, &info, sizeof(struct module_info)))
877 if (put_user(sizeof(struct module_info), ret))
884 sys_query_module(const char *name_user, int which, char *buf, size_t bufsize,
891 if (name_user == NULL)
892 mod = &kernel_module;
897 if ((namelen = get_mod_name(name_user, &name)) < 0) {
902 if ((mod = find_module(name)) == NULL) {
909 /* __MOD_ touches the flags. We must avoid that */
911 atomic_inc(&mod->uc.usecount);
919 err = qm_modules(buf, bufsize, ret);
922 err = qm_deps(mod, buf, bufsize, ret);
925 err = qm_refs(mod, buf, bufsize, ret);
928 err = qm_symbols(mod, buf, bufsize, ret);
931 err = qm_info(mod, buf, bufsize, ret);
937 atomic_dec(&mod->uc.usecount);
945 * Copy the kernel symbol table to user space. If the argument is
946 * NULL, just return the size of the table.
948 * This call is obsolete. New programs should use query_module+QM_SYMBOLS
949 * which does not arbitrarily limit the length of symbols.
953 sys_get_kernel_syms(struct kernel_sym *table)
957 struct kernel_sym ksym;
960 for (mod = module_list, i = 0; mod; mod = mod->next) {
961 /* include the count for the module name! */
968 /* So that we don't give the user our stack content */
969 memset (&ksym, 0, sizeof (ksym));
971 for (mod = module_list, i = 0; mod; mod = mod->next) {
972 struct module_symbol *msym;
975 if (!MOD_CAN_QUERY(mod))
978 /* magic: write module info as a pseudo symbol */
979 ksym.value = (unsigned long)mod;
981 strncpy(ksym.name+1, mod->name, sizeof(ksym.name)-1);
982 ksym.name[sizeof(ksym.name)-1] = '\0';
984 if (copy_to_user(table, &ksym, sizeof(ksym)) != 0)
991 for (j = 0, msym = mod->syms; j < mod->nsyms; ++j, ++msym) {
992 ksym.value = msym->value;
993 strncpy(ksym.name, msym->name, sizeof(ksym.name));
994 ksym.name[sizeof(ksym.name)-1] = '\0';
996 if (copy_to_user(table, &ksym, sizeof(ksym)) != 0)
1007 * Look for a module by name, ignoring modules marked for deletion.
1011 find_module(const char *name)
1015 for (mod = module_list; mod ; mod = mod->next) {
1016 if (mod->flags & MOD_DELETED)
1018 if (!strcmp(mod->name, name))
1026 * Free the given module.
1030 free_module(struct module *mod, int tag_freed)
1032 struct module_ref *dep;
1034 unsigned long flags;
1036 /* Let the module clean up. */
1038 if (mod->flags & MOD_RUNNING)
1042 mod->flags &= ~MOD_RUNNING;
1045 /* Remove the module from the dependency lists. */
1047 for (i = 0, dep = mod->deps; i < mod->ndeps; ++i, ++dep) {
1048 struct module_ref **pp;
1049 for (pp = &dep->dep->refs; *pp != dep; pp = &(*pp)->next_ref)
1051 *pp = dep->next_ref;
1052 if (tag_freed && dep->dep->refs == NULL)
1053 dep->dep->flags |= MOD_JUST_FREED;
1056 /* And from the main module list. */
1058 spin_lock_irqsave(&modlist_lock, flags);
1059 if (mod == module_list) {
1060 module_list = mod->next;
1063 for (p = module_list; p->next != mod; p = p->next)
1065 p->next = mod->next;
1067 spin_unlock_irqrestore(&modlist_lock, flags);
1069 /* And free the memory. */
1075 * Called by the /proc file system to return a current list of modules.
1078 int get_module_list(char *p)
1080 size_t left = PAGE_SIZE;
1083 struct module_ref *ref;
1085 for (mod = module_list; mod != &kernel_module; mod = mod->next) {
1089 #define safe_copy_str(str, len) \
1093 memcpy(p, str, len); p += len, left -= len; \
1095 #define safe_copy_cstr(str) safe_copy_str(str, sizeof(str)-1)
1097 len = strlen(mod->name);
1098 safe_copy_str(mod->name, len);
1100 if ((len = 20 - len) > 0) {
1103 memset(p, ' ', len);
1108 len = sprintf(tmpstr, "%8lu", mod->size);
1109 safe_copy_str(tmpstr, len);
1111 if (mod->flags & MOD_RUNNING) {
1112 len = sprintf(tmpstr, "%4ld",
1113 (mod_member_present(mod, can_unload)
1115 ? -1L : (long)atomic_read(&mod->uc.usecount)));
1116 safe_copy_str(tmpstr, len);
1119 if (mod->flags & MOD_DELETED)
1120 safe_copy_cstr(" (deleted)");
1121 else if (mod->flags & MOD_RUNNING) {
1122 if (mod->flags & MOD_AUTOCLEAN)
1123 safe_copy_cstr(" (autoclean)");
1124 if (!(mod->flags & MOD_USED_ONCE))
1125 safe_copy_cstr(" (unused)");
1127 else if (mod->flags & MOD_INITIALIZING)
1128 safe_copy_cstr(" (initializing)");
1130 safe_copy_cstr(" (uninitialized)");
1132 if ((ref = mod->refs) != NULL) {
1133 safe_copy_cstr(" [");
1137 safe_copy_str(q, len);
1139 if ((ref = ref->next_ref) != NULL)
1140 safe_copy_cstr(" ");
1144 safe_copy_cstr("]");
1146 safe_copy_cstr("\n");
1148 #undef safe_copy_str
1149 #undef safe_copy_cstr
1153 return PAGE_SIZE - left;
1157 * Called by the /proc file system to return a current list of ksyms.
1167 static void *s_start(struct seq_file *m, loff_t *pos)
1169 struct mod_sym *p = kmalloc(sizeof(*p), GFP_KERNEL);
1174 return ERR_PTR(-ENOMEM);
1176 for (v = module_list, n = *pos; v; n -= v->nsyms, v = v->next) {
1188 static void *s_next(struct seq_file *m, void *p, loff_t *pos)
1190 struct mod_sym *v = p;
1192 if (++v->index >= v->mod->nsyms) {
1194 v->mod = v->mod->next;
1200 } while (!v->mod->nsyms);
1206 static void s_stop(struct seq_file *m, void *p)
1208 if (p && !IS_ERR(p)) {
1214 static int s_show(struct seq_file *m, void *p)
1216 struct mod_sym *v = p;
1217 struct module_symbol *sym;
1219 if (!MOD_CAN_QUERY(v->mod))
1221 sym = &v->mod->syms[v->index];
1223 seq_printf(m, "%0*lx %s\t[%s]\n", (int)(2*sizeof(void*)),
1224 sym->value, sym->name, v->mod->name);
1226 seq_printf(m, "%0*lx %s\n", (int)(2*sizeof(void*)),
1227 sym->value, sym->name);
1231 struct seq_operations ksyms_op = {
1238 #else /* CONFIG_MODULES */
1240 /* Dummy syscalls for people who don't want modules */
1242 asmlinkage unsigned long
1243 sys_create_module(const char *name_user, size_t size)
1249 sys_init_module(const char *name_user, struct module *mod_user)
1255 sys_delete_module(const char *name_user)
1261 sys_query_module(const char *name_user, int which, char *buf, size_t bufsize,
1264 /* Let the program know about the new interface. Not that
1265 it'll do them much good. */
1273 sys_get_kernel_syms(struct kernel_sym *table)
1278 int try_inc_mod_count(struct module *mod)
1283 #endif /* CONFIG_MODULES */