//------------------------------------------------------------------- // brkdemo.cpp // // This program demonstrates the effects of directly invoking // the Linux kernel's 'brk' system-call as distinguished from // the 'brk()' library-function as documented on 'man' pages. // // programmer: ALLAN CRUSE // date begun: 14 APR 2005 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read(), write(), close() #define __NR_brk 45 // from #define BUFFERSZ (16<<10) // 16-kilobytes (=0x4000) // global variables (used for easy assembler access) unsigned int sys_call_id = __NR_brk; unsigned int bufferlength = BUFFERSZ; unsigned int original_brk, modified_brk; int main( int argc, char **argv ) { // ask kernel for the current 'brk' value asm(" movl sys_call_id, %eax "); asm(" xorl %ebx, %ebx "); asm(" int $0x80 "); asm(" movl %eax, original_brk "); printf( "original brk-value: %p \n", original_brk ); // ask kernel to modify the 'brk' value asm(" movl sys_call_id, %eax "); asm(" movl original_brk, %ebx "); asm(" addl bufferlength, %ebx "); asm(" int $0x80 "); // ask kernel for the current 'brk' value asm(" movl sys_call_id, %eax "); asm(" xorl %ebx, %ebx "); asm(" int $0x80 "); asm(" movl %eax, modified_brk "); printf( "modified brk-value: %p \n", modified_brk ); }