//------------------------------------------------------------------- // gpd.c // // This module creates a pseudo-file named 'gpd' in the /proc // directory which provides a way for application programs to // access to the current task's Global Page Directory, though // in raw binary format unsuitable for displaying with 'cat'. // // NOTE: Written and tested with Linux kernel version 2.4.20. // // programmer: ALLAN CRUSE // written on: 20 FEB 2003 //------------------------------------------------------------------- #define __KERNEL__ #define MODULE #include // for init_module() #include // for create_proc_read_entry() #include // for phys_to_virt() #define SUCCESS 0 static char modname[] = "gpd"; static char buffer[ 4096 ]; static int my_proc_read( char *buf, char **start, off_t off, int count, int *eof, void *data ) { unsigned long reg_cr3; void *gpd; asm(" movl %%cr3, %%eax ; movl %%eax, %0 " : "=m" (reg_cr3) ); gpd = phys_to_virt( reg_cr3 ); memcpy( buffer, gpd, 4096 ); *start = buffer; *eof = 1; return 4096; } 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");