sys_call_table is not exported anymore for kernel modules to tinker with (for a number of good reasons mentioned elsewhere). This code is groping in the kernel address space to figure out the location of the sys_call_table. On Fri, Jan 31, 2003 at 05:24:06PM +0530, Mohanasundaram C wrote: > Hi All, > > I tried to understand the code below but could not. Can any one please explain me. > > Regards, > Mohan. > > #include <linux/syscall.h> > #include <asm/unistd.h> > > static void **sys_call_table; > > //nearest exported symbol to syscalls in my kernel, > //i hope in others kernels too > //but in other form you can look at your kernel sources > > extern void *system_utsname; > > .... > > static int locate_sys_call_table(void) { > unsigned long *begin; > int i; > > begin=(unsigned long *) &system_utsname; > for (i=0;i<1024;i++) { > if (*(begin+i)==(unsigned long) sys_socketcall) { > sys_call_table=(void *) (begin+i-__NR_socketcall); > //are you sure? > if (sys_call_table[__NR_exit]==(void *) sys_exit) { > printk("success: located sys_call_table: %X\n",(unsigned > int) sys_call_table); > return(1); > } > } > } > return(0); > } > > > int __init init_exportmodule (void) > { > > if (!locate_sys_call_table()) { > // ... cry again and return error > } > > //.....sys_call_table[] works now!! > //......do something like export symbol > //.... or intercept any syscall > > } > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ > -- Vamsi Krishna S. Linux Technology Center, IBM Software Lab, Bangalore. Ph: +91 80 5044959 Internet: vamsi@in.ibm.com -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/