我編寫了一個內核模塊,用於將一些數據量導出到創建的proc條目中。如果數據量較少,我可以輕鬆創建一個proc入口和出口數據。但是,如果數據量很大,則會導致緩衝區溢出錯誤。如何寫入處理大量數據
我用功能int read_proc(char *buf,char **start,off_t offset,int count, int *eof, void *data)
導出數據。我寫了這樣的數據:
length =sprintf(buf,"The RESTART_SYSCALL address is %x\n",syscall_table[__NR_restart_syscall]);
length +=sprintf(buf+length,"The EXIT address is %x\n",syscall_table[__NR_exit]);
length +=sprintf(buf+length,"The FORK address is %x\n",syscall_table[__NR_fork]);
length +=sprintf(buf+length,"The READ address is %x\n",syscall_table[__NR_read]);
length +=sprintf(buf+length,"The WRITE address is %x\n",syscall_table[__NR_write]);
length +=sprintf(buf+length,"The OPEN address is %x\n",syscall_table[__NR_open]);
length +=sprintf(buf+length,"The CLOSE address is %x\n",syscall_table[__NR_close]);
length +=sprintf(buf+length,"The WAITPID address is %x\n",syscall_table[__NR_waitpid]);
length +=sprintf(buf+length,"The CREAT address is %x\n",syscall_table[__NR_creat]);
length +=sprintf(buf+length,"The LINK address is %x\n",syscall_table[__NR_link]);
length +=sprintf(buf+length,"The UNLINK address is %x\n",syscall_table[__NR_unlink]);
length +=sprintf(buf+length,"The EXECVE address is %x\n",syscall_table[__NR_execve]);
length +=sprintf(buf+length,"The TIME address is %x\n",syscall_table[__NR_time]);
length +=sprintf(buf+length,"The MKNOD address is %x\n",syscall_table[__NR_mknod]);
length +=sprintf(buf+length,"The LCHOWN address is %x\n",syscall_table[__NR_lchown]);
length +=sprintf(buf+length,"The BREAK address is %x\n",syscall_table[__NR_break]);
length +=sprintf(buf+length,"The OLDSTAT address is %x\n",syscall_table[__NR_oldstat]);
length +=sprintf(buf+length,"The LSEEK address is %x\n",syscall_table[__NR_lseek]);
length +=sprintf(buf+length,"The GETPID address is %x\n",syscall_table[__NR_getpid]);
-----------------------------------
---------------------------------
---------------------------------
我讀到,默認情況下只有一個PAGE_SIZE,即4kb導出。我介紹了LDD以找出如何導出大量數據。但我無法理解那裏寫的是什麼。任何人都可以幫助我。
我會看看例如'/ proc/self/maps'或'/ proc/vmallocinfo'。他們可能每次寫一行,並保持某種狀態。 – 2011-12-27 06:32:02