//------------------------------------------------------------------- // cr3.c // // This module creates a pseudo-file named 'cr3' in the '/proc' // directory which allows an application to obtain the physical // address of its page-directory. Using this information, with // our 'ram.c' device-driver installed, it becomes possible for // this application to locate, and to read in, its page-tables. // // NOTE: Developed and tested with Linux kernel version 2.4.20. // // programmer: ALLAN CRUSE // written on: 24 APR 2003 // revised on: 27 OCT 2004 -- for Linux kernel version 2.4.26 //------------------------------------------------------------------- #include // for init_module() #include // for create_proc_read_entry() #define SUCCESS 0 static char modname[] = "cr3"; static int my_proc_read( char *buf, char **start, off_t off, int count, int *eof, void *data ) { int cr3, len; asm(" movl %%cr3, %%eax \n movl %%eax, %0 " : "=m" (cr3) ); len = sprintf( buf, "cr3=%08X\n", cr3 ); *eof = 1; return len; } void cleanup_module( void ) { remove_proc_entry( modname, NULL ); printk( "<1>Removing \'%s\' module\n", modname ); } int init_module( void ) { printk( "<1>\nInstalling \'%s\' module\n", modname ); create_proc_read_entry( modname, 0, NULL, my_proc_read, NULL ); return SUCCESS; } MODULE_LICENSE("GPL");