Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=a5c43dae7ae38c2a6b3e9a819bcf45f010bf6a4a
Commit:     a5c43dae7ae38c2a6b3e9a819bcf45f010bf6a4a
Parent:     9d65cb4a1718a072898c7a57a3bc61b2dc4bcd4d
Author:     Alexey Dobriyan <[EMAIL PROTECTED]>
AuthorDate: Tue May 8 00:28:47 2007 -0700
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Tue May 8 11:15:08 2007 -0700

    Fix race between cat /proc/slab_allocators and rmmod
    
    Same story as with cat /proc/*/wchan race vs rmmod race, only
    /proc/slab_allocators want more info than just symbol name.
    
    Signed-off-by: Alexey Dobriyan <[EMAIL PROTECTED]>
    Acked-by: Rusty Russell <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 include/linux/kallsyms.h |    6 ++++++
 include/linux/module.h   |    6 ++++++
 kernel/kallsyms.c        |   19 +++++++++++++++++++
 kernel/module.c          |   27 +++++++++++++++++++++++++++
 mm/slab.c                |   10 +++-------
 5 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index ae0117a..12178d2 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -31,6 +31,7 @@ extern int sprint_symbol(char *buffer, unsigned long address);
 extern void __print_symbol(const char *fmt, unsigned long address);
 
 int lookup_symbol_name(unsigned long addr, char *symname);
+int lookup_symbol_attrs(unsigned long addr, unsigned long *size, unsigned long 
*offset, char *modname, char *name);
 
 #else /* !CONFIG_KALLSYMS */
 
@@ -65,6 +66,11 @@ static inline int lookup_symbol_name(unsigned long addr, 
char *symname)
        return -ERANGE;
 }
 
+static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, 
unsigned long *offset, char *modname, char *name)
+{
+       return -ERANGE;
+}
+
 /* Stupid that this does nothing, but I didn't create this mess. */
 #define __print_symbol(fmt, addr)
 #endif /*CONFIG_KALLSYMS*/
diff --git a/include/linux/module.h b/include/linux/module.h
index 099ae59..6d3dc9c 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -455,6 +455,7 @@ const char *module_address_lookup(unsigned long addr,
                                  unsigned long *offset,
                                  char **modname);
 int lookup_module_symbol_name(unsigned long addr, char *symname);
+int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size, 
unsigned long *offset, char *modname, char *name);
 
 /* For extable.c to search modules' exception tables. */
 const struct exception_table_entry *search_module_extables(unsigned long addr);
@@ -531,6 +532,11 @@ static inline int lookup_module_symbol_name(unsigned long 
addr, char *symname)
        return -ERANGE;
 }
 
+static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long 
*size, unsigned long *offset, char *modname, char *name)
+{
+       return -ERANGE;
+}
+
 static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
                                        char *type, char *name,
                                        char *module_name, int *exported)
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 4e2ec19..c36581b 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -286,6 +286,25 @@ int lookup_symbol_name(unsigned long addr, char *symname)
        return lookup_module_symbol_name(addr, symname);
 }
 
+int lookup_symbol_attrs(unsigned long addr, unsigned long *size,
+                       unsigned long *offset, char *modname, char *name)
+{
+       name[0] = '\0';
+       name[KSYM_NAME_LEN] = '\0';
+
+       if (is_ksym_addr(addr)) {
+               unsigned long pos;
+
+               pos = get_symbol_pos(addr, size, offset);
+               /* Grab name */
+               kallsyms_expand_symbol(get_symbol_offset(pos), name);
+               modname[0] = '\0';
+               return 0;
+       }
+       /* see if it's in a module */
+       return lookup_module_symbol_attrs(addr, size, offset, modname, name);
+}
+
 /* Look up a kernel symbol and return it in a text buffer. */
 int sprint_symbol(char *buffer, unsigned long address)
 {
diff --git a/kernel/module.c b/kernel/module.c
index 3da76ad..d36e454 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2149,6 +2149,33 @@ out:
        return -ERANGE;
 }
 
+int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
+                       unsigned long *offset, char *modname, char *name)
+{
+       struct module *mod;
+
+       mutex_lock(&module_mutex);
+       list_for_each_entry(mod, &modules, list) {
+               if (within(addr, mod->module_init, mod->init_size) ||
+                   within(addr, mod->module_core, mod->core_size)) {
+                       const char *sym;
+
+                       sym = get_ksymbol(mod, addr, size, offset);
+                       if (!sym)
+                               goto out;
+                       if (modname)
+                               strlcpy(modname, mod->name, MODULE_NAME_LEN + 
1);
+                       if (name)
+                               strlcpy(name, sym, KSYM_NAME_LEN + 1);
+                       mutex_unlock(&module_mutex);
+                       return 0;
+               }
+       }
+out:
+       mutex_unlock(&module_mutex);
+       return -ERANGE;
+}
+
 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
                        char *name, char *module_name, int *exported)
 {
diff --git a/mm/slab.c b/mm/slab.c
index 1115e20..acda7e2 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4432,16 +4432,12 @@ static void handle_slab(unsigned long *n, struct 
kmem_cache *c, struct slab *s)
 static void show_symbol(struct seq_file *m, unsigned long address)
 {
 #ifdef CONFIG_KALLSYMS
-       char *modname;
-       const char *name;
        unsigned long offset, size;
-       char namebuf[KSYM_NAME_LEN+1];
-
-       name = kallsyms_lookup(address, &size, &offset, &modname, namebuf);
+       char modname[MODULE_NAME_LEN + 1], name[KSYM_NAME_LEN + 1];
 
-       if (name) {
+       if (lookup_symbol_attrs(address, &size, &offset, modname, name) == 0) {
                seq_printf(m, "%s+%#lx/%#lx", name, offset, size);
-               if (modname)
+               if (modname[0])
                        seq_printf(m, " [%s]", modname);
                return;
        }
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to