//------------------------------------------------------------------- // invoke17.cpp // // This Linux application repeatedly invokes kernel system-call // number 17 (documented as an 'obsolete' system-call for Linux // kernel versions 2.4 and later). Normally this program shows // no change in the value of the integer whose address is given // as an argument to the system-call. But, if our 'myexport.o' // and 'newcall.o' modules are installed in the running kernel, // to provide a different behavior, then this program will show // the new effect of that system call, incrementing the integer // each time that system-call is invoked. // // compile using: ./gcc invoke17.cpp -o invoke17 // execute using: ./invoke17 // // Reference: Moshe Bar, "Linux Internals," McGraw-Hill (2000). // // programmer: ALLAN CRUSE // written on: 24 JUN 2004 // revised on: 28 SEP 2004 //------------------------------------------------------------------- #include // needed for printf() int exec_syscall_17( int *num ) { int retval = -1; asm(" movl $17, %eax "); asm(" movl %0, %%ebx " : : "m" (num) ); asm(" int $0x80 "); asm(" movl %%eax, %0 " : "=m" (retval) ); return retval; } int main( int argc, char **argv ) { int number = 15; printf( "\nDemonstrating system-call 17 ... \n" ); for (int i = 0; i <= 5; i++) { printf( "\n#%d: number=%d ", i, number ); exec_syscall_17( &number ); } printf( "\n\n" ); }