In this experiment, the 64-bit linux3.4.1 source code is modified. Due to some changes in the Code Organization Mode of the new version, some previous methods on the Internet are not feasible. The procedure is as follows:
1. Download the source code of linux3.4.1
2. Switch to the root account and decompress it to/usr/src.
3. Add the following code at the end of the/kernel/sys. c file:
Asmlinkage int sys_addtotal (INT numdata)
{
Int I = 0, enddata = 0;
While (I <= numdata)
Enddata + = I ++;
Return enddata;
}
4. Modify/ARCH/x86/syscils/syscall_64.tbl to add code.
312 64 addtotal sys_addtotal
5. Add the following code at the end of the/include/Linux/syscils. h file:
Asmlinkage int sys_addtotal (INT numdata );
6. Compile the kernel
Restart and test the Code as follows:
# Include "stdio. H"
# Include <unistd. h>
# Include <Linux/unistd. h>
# DEFINE _ nr_addtotal 312
// _ Syscall1 (INT, addtotal, Int, num)
Int main ()
{
Int I, J;
Printf ("lease input a number \ n ");
While (scanf ("% d", & I) = EOF );
J = syscall (_ nr_addtotal, I );
Printf ("Total from 0 to % d is % d \ n", I, j );
Return 0;
}