Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[powerpc.git] / kernel / kallsyms.c
index eeac3e3..5a0de84 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/proc_fs.h>
 #include <linux/sched.h>       /* for cond_resched */
 #include <linux/mm.h>
+#include <linux/ctype.h>
 
 #include <asm/sections.h>
 
 #endif
 
 /* These will be re-linked against their real values during the second link stage */
-extern unsigned long kallsyms_addresses[] __attribute__((weak));
-extern unsigned long kallsyms_num_syms __attribute__((weak,section("data")));
-extern u8 kallsyms_names[] __attribute__((weak));
+extern const unsigned long kallsyms_addresses[] __attribute__((weak));
+extern const unsigned long kallsyms_num_syms __attribute__((weak));
+extern const u8 kallsyms_names[] __attribute__((weak));
 
-extern u8 kallsyms_token_table[] __attribute__((weak));
-extern u16 kallsyms_token_index[] __attribute__((weak));
+extern const u8 kallsyms_token_table[] __attribute__((weak));
+extern const u16 kallsyms_token_index[] __attribute__((weak));
 
-extern unsigned long kallsyms_markers[] __attribute__((weak));
+extern const unsigned long kallsyms_markers[] __attribute__((weak));
 
 static inline int is_kernel_inittext(unsigned long addr)
 {
@@ -83,7 +84,7 @@ static int is_ksym_addr(unsigned long addr)
 static unsigned int kallsyms_expand_symbol(unsigned int off, char *result)
 {
        int len, skipped_first = 0;
-       u8 *tptr, *data;
+       const u8 *tptr, *data;
 
        /* get the compressed symbol length from the first symbol byte */
        data = &kallsyms_names[off];
@@ -131,7 +132,7 @@ static char kallsyms_get_symbol_type(unsigned int off)
  * kallsyms array */
 static unsigned int get_symbol_offset(unsigned long pos)
 {
-       u8 *name;
+       const u8 *name;
        int i;
 
        /* use the closest marker we have. We have markers every 256 positions,
@@ -266,27 +267,33 @@ const char *kallsyms_lookup(unsigned long addr,
        return NULL;
 }
 
-/* Replace "%s" in format with address, or returns -errno. */
-void __print_symbol(const char *fmt, unsigned long address)
+/* Look up a kernel symbol and return it in a text buffer. */
+int sprint_symbol(char *buffer, unsigned long address)
 {
        char *modname;
        const char *name;
        unsigned long offset, size;
        char namebuf[KSYM_NAME_LEN+1];
-       char buffer[sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN +
-                   2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1];
 
        name = kallsyms_lookup(address, &size, &offset, &modname, namebuf);
-
        if (!name)
-               sprintf(buffer, "0x%lx", address);
+               return sprintf(buffer, "0x%lx", address);
        else {
                if (modname)
-                       sprintf(buffer, "%s+%#lx/%#lx [%s]", name, offset,
+                       return sprintf(buffer, "%s+%#lx/%#lx [%s]", name, offset,
                                size, modname);
                else
-                       sprintf(buffer, "%s+%#lx/%#lx", name, offset, size);
+                       return sprintf(buffer, "%s+%#lx/%#lx", name, offset, size);
        }
+}
+
+/* Look up a kernel symbol and print it to the kernel messages. */
+void __print_symbol(const char *fmt, unsigned long address)
+{
+       char buffer[KSYM_SYMBOL_LEN];
+
+       sprint_symbol(buffer, address);
+
        printk(fmt, buffer);
 }
 
@@ -301,13 +308,6 @@ struct kallsym_iter
        char name[KSYM_NAME_LEN+1];
 };
 
-/* Only label it "global" if it is exported. */
-static void upcase_if_global(struct kallsym_iter *iter)
-{
-       if (is_exported(iter->name, iter->owner))
-               iter->type += 'A' - 'a';
-}
-
 static int get_ksymbol_mod(struct kallsym_iter *iter)
 {
        iter->owner = module_get_kallsym(iter->pos - kallsyms_num_syms,
@@ -316,7 +316,10 @@ static int get_ksymbol_mod(struct kallsym_iter *iter)
        if (iter->owner == NULL)
                return 0;
 
-       upcase_if_global(iter);
+       /* Label it "global" if it is exported, "local" if not exported. */
+       iter->type = is_exported(iter->name, iter->owner)
+               ? toupper(iter->type) : tolower(iter->type);
+
        return 1;
 }
 
@@ -401,7 +404,7 @@ static int s_show(struct seq_file *m, void *p)
        return 0;
 }
 
-static struct seq_operations kallsyms_op = {
+static const struct seq_operations kallsyms_op = {
        .start = s_start,
        .next = s_next,
        .stop = s_stop,
@@ -436,7 +439,7 @@ static int kallsyms_release(struct inode *inode, struct file *file)
        return seq_release(inode, file);
 }
 
-static struct file_operations kallsyms_operations = {
+static const struct file_operations kallsyms_operations = {
        .open = kallsyms_open,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -455,3 +458,4 @@ static int __init kallsyms_init(void)
 __initcall(kallsyms_init);
 
 EXPORT_SYMBOL(__print_symbol);
+EXPORT_SYMBOL_GPL(sprint_symbol);