Bérénice Angremy
I. Summary of knowledge points (i) Add time and Time-asm commands to Menuos
- 1. Update the menu code to the latest version
- 2.test.c in main function, add Menuconfig ()
- 3. Add a corresponding two functions, time and TIMEASM functions
- 4.make rootfs Automatic Compilation script
(ii) Call the kernel function using the GDB debug tracking system Sys_time
- After you set a breakpoint for the system call Systime that handles the time function, time is executed in Menuos. The discovery system stopped at Systime. Continue to press N to step into the schedule function.
- After the Sys_time returns to the assembly code processing, GDB cannot continue tracing.
- If the breakpoint is set at Syscall (entry32. S), and after entering C, it is found that it will not stop at Sys_call (because this is a system call function rather than a normal function).
(iii) process of system invocation in kernel code
1. Mechanism and initialization of system calls in kernel code
Time is important throughout the system call process.
In the case of System_call, the int 0x80 directive and the Systemcall are linked by an interrupt vector, and the API and the corresponding SYS are linked by the system call number.
- User state, the system calls XYZ () using int 0x80, which corresponds to calling System_call.
The process on the right (assembly code) is very important to match by the system call number.
2. Initialization of the system invocation mechanism
trap_initThere is a function inside the function set_system_trap_gate that involves the interrupt vector of the system call SYSCALL_VECTOR and the assembly code entry system_call , once the int 0x80,cpu directly jumps to system_call execute.
3. Simplified, easy-to-understand system_call pseudo-code
The Systemcall is located at entry (Systemcall), and the other interrupts are treated similarly.
Save_all: Save Site
call *sys_call_table(,%eax,4)Call the system dispatch processing function, EAX is the system call number, is the actual system scheduler
sys_call_table: System call Dispatch table
syscall_after_all: Save return value
If there is sys_exit_work , then enter sys_exit_work : There will be a process scheduling timing.
work_pending -> work_notifysigTo handle the signal.
- Possible call schedule: Process dispatch code.
- May jump to Restore_all and resume the scene.
If none sys_exit_work , the recovery is performed restore_all and the user state is returned.
Interrupt_return <=> iret, end.
4. Simply browse system_call to the main code between the Iret
- 1.save_all: Save Site
- 2.syscall_call: Called the system call handler function
- 3.restore_all: Recovering the scene (because the system calls the handler function is also a special "interrupt")
- 4.syscallexitwork: As described in 3.
- 5.INTERRUPT RETURN: That is iret, the system call ends here
Second, the experiment: Analysis System_call Interrupt processing process one) use GDB trace to parse a system call kernel function (last week selected system call)--getpid
1. Execute RM MENU-RF First, forcibly delete the original menu folder, and update the menu code to the latest version using the git command.
2. Adding C functions, assembly functions in TEST.c
3.make Rootfs, enter help to see the addition of the commands we added earlier in QEMU.
System_call to Iret process flowchart
Linux Fifth Week study summary