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, *mod2 = NULL;
349 char *name, *n_name, *name_tmp = NULL;
350 long namelen, n_namelen, i, error;
351 unsigned long mod_user_size, flags;
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 /* Copying mod_user directly over mod breaks the module_list chain and
391 * races against search_exception_table. copy_from_user may sleep so it
392 * cannot be under modlist_lock, do the copy in two stages.
394 if (!(mod2 = vmalloc(mod_user_size))) {
398 error = copy_from_user(mod2, mod_user, mod_user_size);
403 spin_lock_irqsave(&modlist_lock, flags);
404 memcpy(mod, mod2, mod_user_size);
405 mod->next = mod_tmp.next;
406 spin_unlock_irqrestore(&modlist_lock, flags);
408 /* Sanity check the size of the module. */
411 if (mod->size > mod_tmp.size) {
412 printk(KERN_ERR "init_module: Size of initialized module "
413 "exceeds size of created module.\n");
417 /* Make sure all interesting pointers are sane. */
419 if (!mod_bound(mod->name, namelen, mod)) {
420 printk(KERN_ERR "init_module: mod->name out of bounds.\n");
423 if (mod->nsyms && !mod_bound(mod->syms, mod->nsyms, mod)) {
424 printk(KERN_ERR "init_module: mod->syms out of bounds.\n");
427 if (mod->ndeps && !mod_bound(mod->deps, mod->ndeps, mod)) {
428 printk(KERN_ERR "init_module: mod->deps out of bounds.\n");
431 if (mod->init && !mod_bound(mod->init, 0, mod)) {
432 printk(KERN_ERR "init_module: mod->init out of bounds.\n");
435 if (mod->cleanup && !mod_bound(mod->cleanup, 0, mod)) {
436 printk(KERN_ERR "init_module: mod->cleanup out of bounds.\n");
439 if (mod->ex_table_start > mod->ex_table_end
440 || (mod->ex_table_start &&
441 !((unsigned long)mod->ex_table_start >= ((unsigned long)mod + mod->size_of_struct)
442 && ((unsigned long)mod->ex_table_end
443 < (unsigned long)mod + mod->size)))
444 || (((unsigned long)mod->ex_table_start
445 - (unsigned long)mod->ex_table_end)
446 % sizeof(struct exception_table_entry))) {
447 printk(KERN_ERR "init_module: mod->ex_table_* invalid.\n");
450 if (mod->flags & ~MOD_AUTOCLEAN) {
451 printk(KERN_ERR "init_module: mod->flags invalid.\n");
454 if (mod_member_present(mod, can_unload)
455 && mod->can_unload && !mod_bound(mod->can_unload, 0, mod)) {
456 printk(KERN_ERR "init_module: mod->can_unload out of bounds.\n");
459 if (mod_member_present(mod, kallsyms_end)) {
460 if (mod->kallsyms_end &&
461 (!mod_bound(mod->kallsyms_start, 0, mod) ||
462 !mod_bound(mod->kallsyms_end, 0, mod))) {
463 printk(KERN_ERR "init_module: mod->kallsyms out of bounds.\n");
466 if (mod->kallsyms_start > mod->kallsyms_end) {
467 printk(KERN_ERR "init_module: mod->kallsyms invalid.\n");
471 if (mod_member_present(mod, archdata_end)) {
472 if (mod->archdata_end &&
473 (!mod_bound(mod->archdata_start, 0, mod) ||
474 !mod_bound(mod->archdata_end, 0, mod))) {
475 printk(KERN_ERR "init_module: mod->archdata out of bounds.\n");
478 if (mod->archdata_start > mod->archdata_end) {
479 printk(KERN_ERR "init_module: mod->archdata invalid.\n");
483 if (mod_member_present(mod, kernel_data) && mod->kernel_data) {
484 printk(KERN_ERR "init_module: mod->kernel_data must be zero.\n");
488 /* Check that the user isn't doing something silly with the name. */
490 if ((n_namelen = get_mod_name(mod->name - (unsigned long)mod
491 + (unsigned long)mod_user,
493 printk(KERN_ERR "init_module: get_mod_name failure.\n");
497 if (namelen != n_namelen || strcmp(n_name, name_tmp) != 0) {
498 printk(KERN_ERR "init_module: changed module name to "
504 /* Ok, that's about all the sanity we can stomach; copy the rest. */
506 if (copy_from_user((char *)mod+mod_user_size,
507 (char *)mod_user+mod_user_size,
508 mod->size-mod_user_size)) {
513 if (module_arch_init(mod))
516 /* On some machines it is necessary to do something here
517 to make the I and D caches consistent. */
518 flush_icache_range((unsigned long)mod, (unsigned long)mod + mod->size);
522 /* Sanity check the module's dependents */
523 for (i = 0, dep = mod->deps; i < mod->ndeps; ++i, ++dep) {
524 struct module *o, *d = dep->dep;
526 /* Make sure the indicated dependencies are really modules. */
528 printk(KERN_ERR "init_module: self-referential "
529 "dependency in mod->deps.\n");
533 /* Scan the current modules for this dependency */
534 for (o = module_list; o != &kernel_module && o != d; o = o->next)
538 printk(KERN_ERR "init_module: found dependency that is "
539 "(no longer?) a module.\n");
544 /* Update module references. */
545 for (i = 0, dep = mod->deps; i < mod->ndeps; ++i, ++dep) {
546 struct module *d = dep->dep;
549 dep->next_ref = d->refs;
551 /* Being referenced by a dependent module counts as a
552 use as far as kmod is concerned. */
553 d->flags |= MOD_USED_ONCE;
556 /* Free our temporary memory. */
557 put_mod_name(n_name);
560 /* Initialize the module. */
561 atomic_set(&mod->uc.usecount,1);
562 mod->flags |= MOD_INITIALIZING;
563 if (mod->init && (error = mod->init()) != 0) {
564 atomic_set(&mod->uc.usecount,0);
565 mod->flags &= ~MOD_INITIALIZING;
566 if (error > 0) /* Buggy module */
570 atomic_dec(&mod->uc.usecount);
572 /* And set it running. */
573 mod->flags = (mod->flags | MOD_RUNNING) & ~MOD_INITIALIZING;
578 put_mod_name(n_name);
581 strcpy((char *)mod->name, name_tmp); /* We know there is room for this */
592 static spinlock_t unload_lock = SPIN_LOCK_UNLOCKED;
593 int try_inc_mod_count(struct module *mod)
597 spin_lock(&unload_lock);
598 if (mod->flags & MOD_DELETED)
601 __MOD_INC_USE_COUNT(mod);
602 spin_unlock(&unload_lock);
608 sys_delete_module(const char *name_user)
610 struct module *mod, *next;
613 int something_changed;
615 if (!capable(CAP_SYS_MODULE))
620 if ((error = get_mod_name(name_user, &name)) < 0)
623 if ((mod = find_module(name)) == NULL) {
629 if (mod->refs != NULL)
632 spin_lock(&unload_lock);
633 if (!__MOD_IN_USE(mod)) {
634 mod->flags |= MOD_DELETED;
635 spin_unlock(&unload_lock);
639 spin_unlock(&unload_lock);
644 /* Do automatic reaping */
646 something_changed = 0;
648 for (mod = module_list; mod != &kernel_module; mod = next) {
650 spin_lock(&unload_lock);
651 if (mod->refs == NULL
652 && (mod->flags & MOD_AUTOCLEAN)
653 && (mod->flags & MOD_RUNNING)
654 && !(mod->flags & MOD_DELETED)
655 && (mod->flags & MOD_USED_ONCE)
656 && !__MOD_IN_USE(mod)) {
657 if ((mod->flags & MOD_VISITED)
658 && !(mod->flags & MOD_JUST_FREED)) {
659 spin_unlock(&unload_lock);
660 mod->flags &= ~MOD_VISITED;
662 mod->flags |= MOD_DELETED;
663 spin_unlock(&unload_lock);
665 something_changed = 1;
668 spin_unlock(&unload_lock);
672 if (something_changed)
675 for (mod = module_list; mod != &kernel_module; mod = mod->next)
676 mod->flags &= ~MOD_JUST_FREED;
684 /* Query various bits about modules. */
687 qm_modules(char *buf, size_t bufsize, size_t *ret)
690 size_t nmod, space, len;
694 for (mod=module_list; mod != &kernel_module; mod=mod->next, ++nmod) {
695 len = strlen(mod->name)+1;
697 goto calc_space_needed;
698 if (copy_to_user(buf, mod->name, len))
705 if (put_user(nmod, ret))
712 while ((mod = mod->next) != &kernel_module)
713 space += strlen(mod->name)+1;
715 if (put_user(space, ret))
722 qm_deps(struct module *mod, char *buf, size_t bufsize, size_t *ret)
724 size_t i, space, len;
726 if (mod == &kernel_module)
728 if (!MOD_CAN_QUERY(mod))
729 if (put_user(0, ret))
735 for (i = 0; i < mod->ndeps; ++i) {
736 const char *dep_name = mod->deps[i].dep->name;
738 len = strlen(dep_name)+1;
740 goto calc_space_needed;
741 if (copy_to_user(buf, dep_name, len))
748 if (put_user(i, ret))
755 while (++i < mod->ndeps)
756 space += strlen(mod->deps[i].dep->name)+1;
758 if (put_user(space, ret))
765 qm_refs(struct module *mod, char *buf, size_t bufsize, size_t *ret)
767 size_t nrefs, space, len;
768 struct module_ref *ref;
770 if (mod == &kernel_module)
772 if (!MOD_CAN_QUERY(mod))
773 if (put_user(0, ret))
779 for (nrefs = 0, ref = mod->refs; ref ; ++nrefs, ref = ref->next_ref) {
780 const char *ref_name = ref->ref->name;
782 len = strlen(ref_name)+1;
784 goto calc_space_needed;
785 if (copy_to_user(buf, ref_name, len))
792 if (put_user(nrefs, ret))
799 while ((ref = ref->next_ref) != NULL)
800 space += strlen(ref->ref->name)+1;
802 if (put_user(space, ret))
809 qm_symbols(struct module *mod, char *buf, size_t bufsize, size_t *ret)
811 size_t i, space, len;
812 struct module_symbol *s;
816 if (!MOD_CAN_QUERY(mod))
817 if (put_user(0, ret))
822 space = mod->nsyms * 2*sizeof(void *);
828 goto calc_space_needed;
830 if (!access_ok(VERIFY_WRITE, buf, space))
834 vals = (unsigned long *)buf;
837 for (; i < mod->nsyms ; ++i, ++s, vals += 2) {
838 len = strlen(s->name)+1;
840 goto calc_space_needed;
842 if (copy_to_user(strings, s->name, len)
843 || __put_user(s->value, vals+0)
844 || __put_user(space, vals+1))
851 if (put_user(i, ret))
857 for (; i < mod->nsyms; ++i, ++s)
858 space += strlen(s->name)+1;
860 if (put_user(space, ret))
867 qm_info(struct module *mod, char *buf, size_t bufsize, size_t *ret)
871 if (mod == &kernel_module)
874 if (sizeof(struct module_info) <= bufsize) {
875 struct module_info info;
876 info.addr = (unsigned long)mod;
877 info.size = mod->size;
878 info.flags = mod->flags;
880 /* usecount is one too high here - report appropriately to
881 compensate for locking */
882 info.usecount = (mod_member_present(mod, can_unload)
883 && mod->can_unload ? -1 : atomic_read(&mod->uc.usecount)-1);
885 if (copy_to_user(buf, &info, sizeof(struct module_info)))
890 if (put_user(sizeof(struct module_info), ret))
897 sys_query_module(const char *name_user, int which, char *buf, size_t bufsize,
904 if (name_user == NULL)
905 mod = &kernel_module;
910 if ((namelen = get_mod_name(name_user, &name)) < 0) {
915 if ((mod = find_module(name)) == NULL) {
922 /* __MOD_ touches the flags. We must avoid that */
924 atomic_inc(&mod->uc.usecount);
932 err = qm_modules(buf, bufsize, ret);
935 err = qm_deps(mod, buf, bufsize, ret);
938 err = qm_refs(mod, buf, bufsize, ret);
941 err = qm_symbols(mod, buf, bufsize, ret);
944 err = qm_info(mod, buf, bufsize, ret);
950 atomic_dec(&mod->uc.usecount);
958 * Copy the kernel symbol table to user space. If the argument is
959 * NULL, just return the size of the table.
961 * This call is obsolete. New programs should use query_module+QM_SYMBOLS
962 * which does not arbitrarily limit the length of symbols.
966 sys_get_kernel_syms(struct kernel_sym *table)
970 struct kernel_sym ksym;
973 for (mod = module_list, i = 0; mod; mod = mod->next) {
974 /* include the count for the module name! */
981 /* So that we don't give the user our stack content */
982 memset (&ksym, 0, sizeof (ksym));
984 for (mod = module_list, i = 0; mod; mod = mod->next) {
985 struct module_symbol *msym;
988 if (!MOD_CAN_QUERY(mod))
991 /* magic: write module info as a pseudo symbol */
992 ksym.value = (unsigned long)mod;
994 strncpy(ksym.name+1, mod->name, sizeof(ksym.name)-1);
995 ksym.name[sizeof(ksym.name)-1] = '\0';
997 if (copy_to_user(table, &ksym, sizeof(ksym)) != 0)
1001 if (mod->nsyms == 0)
1004 for (j = 0, msym = mod->syms; j < mod->nsyms; ++j, ++msym) {
1005 ksym.value = msym->value;
1006 strncpy(ksym.name, msym->name, sizeof(ksym.name));
1007 ksym.name[sizeof(ksym.name)-1] = '\0';
1009 if (copy_to_user(table, &ksym, sizeof(ksym)) != 0)
1020 * Look for a module by name, ignoring modules marked for deletion.
1024 find_module(const char *name)
1028 for (mod = module_list; mod ; mod = mod->next) {
1029 if (mod->flags & MOD_DELETED)
1031 if (!strcmp(mod->name, name))
1039 * Free the given module.
1043 free_module(struct module *mod, int tag_freed)
1045 struct module_ref *dep;
1047 unsigned long flags;
1049 /* Let the module clean up. */
1051 if (mod->flags & MOD_RUNNING)
1055 mod->flags &= ~MOD_RUNNING;
1058 /* Remove the module from the dependency lists. */
1060 for (i = 0, dep = mod->deps; i < mod->ndeps; ++i, ++dep) {
1061 struct module_ref **pp;
1062 for (pp = &dep->dep->refs; *pp != dep; pp = &(*pp)->next_ref)
1064 *pp = dep->next_ref;
1065 if (tag_freed && dep->dep->refs == NULL)
1066 dep->dep->flags |= MOD_JUST_FREED;
1069 /* And from the main module list. */
1071 spin_lock_irqsave(&modlist_lock, flags);
1072 if (mod == module_list) {
1073 module_list = mod->next;
1076 for (p = module_list; p->next != mod; p = p->next)
1078 p->next = mod->next;
1080 spin_unlock_irqrestore(&modlist_lock, flags);
1082 /* And free the memory. */
1088 * Called by the /proc file system to return a current list of modules.
1091 int get_module_list(char *p)
1093 size_t left = PAGE_SIZE;
1096 struct module_ref *ref;
1098 for (mod = module_list; mod != &kernel_module; mod = mod->next) {
1102 #define safe_copy_str(str, len) \
1106 memcpy(p, str, len); p += len, left -= len; \
1108 #define safe_copy_cstr(str) safe_copy_str(str, sizeof(str)-1)
1110 len = strlen(mod->name);
1111 safe_copy_str(mod->name, len);
1113 if ((len = 20 - len) > 0) {
1116 memset(p, ' ', len);
1121 len = sprintf(tmpstr, "%8lu", mod->size);
1122 safe_copy_str(tmpstr, len);
1124 if (mod->flags & MOD_RUNNING) {
1125 len = sprintf(tmpstr, "%4ld",
1126 (mod_member_present(mod, can_unload)
1128 ? -1L : (long)atomic_read(&mod->uc.usecount)));
1129 safe_copy_str(tmpstr, len);
1132 if (mod->flags & MOD_DELETED)
1133 safe_copy_cstr(" (deleted)");
1134 else if (mod->flags & MOD_RUNNING) {
1135 if (mod->flags & MOD_AUTOCLEAN)
1136 safe_copy_cstr(" (autoclean)");
1137 if (!(mod->flags & MOD_USED_ONCE))
1138 safe_copy_cstr(" (unused)");
1140 else if (mod->flags & MOD_INITIALIZING)
1141 safe_copy_cstr(" (initializing)");
1143 safe_copy_cstr(" (uninitialized)");
1145 if ((ref = mod->refs) != NULL) {
1146 safe_copy_cstr(" [");
1150 safe_copy_str(q, len);
1152 if ((ref = ref->next_ref) != NULL)
1153 safe_copy_cstr(" ");
1157 safe_copy_cstr("]");
1159 safe_copy_cstr("\n");
1161 #undef safe_copy_str
1162 #undef safe_copy_cstr
1166 return PAGE_SIZE - left;
1170 * Called by the /proc file system to return a current list of ksyms.
1180 static void *s_start(struct seq_file *m, loff_t *pos)
1182 struct mod_sym *p = kmalloc(sizeof(*p), GFP_KERNEL);
1187 return ERR_PTR(-ENOMEM);
1189 for (v = module_list, n = *pos; v; n -= v->nsyms, v = v->next) {
1201 static void *s_next(struct seq_file *m, void *p, loff_t *pos)
1203 struct mod_sym *v = p;
1205 if (++v->index >= v->mod->nsyms) {
1207 v->mod = v->mod->next;
1213 } while (!v->mod->nsyms);
1219 static void s_stop(struct seq_file *m, void *p)
1221 if (p && !IS_ERR(p)) {
1227 static int s_show(struct seq_file *m, void *p)
1229 struct mod_sym *v = p;
1230 struct module_symbol *sym;
1232 if (!MOD_CAN_QUERY(v->mod))
1234 sym = &v->mod->syms[v->index];
1236 seq_printf(m, "%0*lx %s\t[%s]\n", (int)(2*sizeof(void*)),
1237 sym->value, sym->name, v->mod->name);
1239 seq_printf(m, "%0*lx %s\n", (int)(2*sizeof(void*)),
1240 sym->value, sym->name);
1244 struct seq_operations ksyms_op = {
1251 #else /* CONFIG_MODULES */
1253 /* Dummy syscalls for people who don't want modules */
1255 asmlinkage unsigned long
1256 sys_create_module(const char *name_user, size_t size)
1262 sys_init_module(const char *name_user, struct module *mod_user)
1268 sys_delete_module(const char *name_user)
1274 sys_query_module(const char *name_user, int which, char *buf, size_t bufsize,
1277 /* Let the program know about the new interface. Not that
1278 it'll do them much good. */
1286 sys_get_kernel_syms(struct kernel_sym *table)
1291 int try_inc_mod_count(struct module *mod)
1296 #endif /* CONFIG_MODULES */