On Wed, Feb 26, 2003 at 05:31:51PM +0200, Muli Ben-Yehuda wrote: > > On Wed, Feb 26, 2003 at 03:47:43PM +0000, Dr William Bland wrote: > > > Hello all, > > I wrote my first module just a few days ago, so I'm very new to > > all this. I want to be able to perform a kernel symbol lookup from within > > a module, i.e. to have a function of one argument, a char*, returning a > > void* (or whatever) where the input is the name of the kernel symbol > > (e.g. "printk") and the output is the address that the symbol refers to > > (e.g. the address of the printk function). > > If you're using a late 2.5 version of the kernel, take a look at > kernel/kallsyms.c, kallsyms_lookup(). > I'm using 2.4 at the moment, but thanks for the pointer. > > Someone pointed me towards query_module(NULL, ...), but as far as I can > > see this is intended to be called from user space programs and won't work > > from within a module. Is this correct? > > This is correct. However, by looking at the sys_query_module code in > the kernel, you can find out how to accomplish what you want to > do. Specifically, take a look at kernel/module.c, qm_symbols(), which > is what whoever pointed you probably meant. This call is in 2.4, but > doesn't exist in 2.5. > Thanks for the pointer. I took a look at the source and copied some of it into my source. I ended up with: static void* kernel_symbol_lookup( char* name ) { struct module *mod; mod = &kernel_module; size_t i; struct module_symbol *s; s = mod->syms; for (i=0; i < mod->nsyms; ++i, ++s) { if( strcmp( s->name, name ) == 0 ) return( (void*)s->value ); } return (void*)NULL; } which looks good to me, except that kernel_module is undefined. I copied the definition of that into my module as well, and now it compiles but when I try to insmod I have unresolved symbols like __start___ksymtab (these symbols are used in the definition of kernel_module). I don't know what to do about that since kernel/module.c defines the above symbol as: extern struct module_symbol __start___ksymtab[]; which is what I have done in my module but it doesn't work there. Any ideas? Cheers, Bill. -- Dr. William Bland. Computer Programmer, UK. www.abstractnonsense.com -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/