Possessing + original works reproduced please specify the source + "Linux kernel analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000
Straight-in topics
Lab Procedure 1-Add new menu
- Update the menu//git cone
- Uhange main.c//Register menu function
- Add the CHMODC, chmodasm//Menu function implementation
- Make Rootfs//exciting moment, enter menuos call our new function
Chmodasm Code
Describes the embedded assembly code that invokes the CHMOD system call.
intChmodasm () {LongRC;Char* file_name ="/etc/passwd";unsigned Shortmode =0444;ASM("int $0x80":"=a"(RC):"0"(Sys_chmod),"B"((Long) file_name),"C"((Long) (mode));if( (unsigned Long) RC >= (unsigned Long)-123)//123 is the smallest error code{errno =-RC; RC =-1; }if(rc = =-1)fprintf(stderr,"Chmode failed,errno =%d\n", errno);Else printf("chmod ok\n");return 0;}
Code Show CHMODC
Tells the call to the chmod system call C code.
intCHMODC () {LongRC;Char* file_name ="/etc/passwd";unsigned Shortmode =0444; rc = chmod (file_name, mode);// if( (unsigned Long) RC >= (unsigned Long)-123) {errno =-RC; RC =-1; }if(rc = =-1)fprintf(stderr,"Chmode failed,errno =%d\n", errno);Else printf("chmod ok\n");return 0;}
Main function Main
int main () { Printmenuos (); Setprompt ( "menuos>>" ); Menuconfig ( "version" , "Menuos V1.0 (Based on Linux 3.18.6 ) ", NULL); Menuconfig ( "quit" , "quit from Menuos" , quit); Menuconfig ( "time" , "Show System time" , time); Menuconfig ( "time-asm" , "Show System time (ASM)" , TIMEASM); Menuconfig ( "chmod" , "chmod demo" , CHMODC); //new menuconfig ( "chmod-asm" , "chmod demo" , Chmodasm); //new Executemenu ();}
Comprehensive display
The experimental process is presented with a dynamic graph.
2 Analyzing the System_call process
System_call location in Entry_32.s, the teacher's pseudo-code framework is great, but here I draw a flowchart for myself for one hours.
Iret before the process scheduling time, is the schedule function call process in this flowchart, very clear explanation.
Classic pseudo-code flow
Collect the courseware from the teacher
section, the entire process from System_call to Iret,
Don't be bothered by details.
System Call Process Analysis
The system call process and the general interrupt processing process are analyzed together, here comes a classic graph bar (from Ulk).
Here, only from the return process,
You can see that either the Interrupt return (RET_FROM_INTR) or the system call returns, both Work_pending and resume_userspace are used
Summary
This content took 12 hours, originally wanted to try gdb tracking, but due to tool limitations, not code-based tracking, so use a flowchart analysis.
Key point: Determine the schdule time before iret in the flowchart.
System calls, in a sense, are a special kind of interruption. From his initialization/departure/return, we can all find commonalities, this article only a preliminary analysis of the return process.
Reference requirements
The topic is self-prepared, and the content revolves around the process of system call System_call;
The blog content needs to carefully analyze the System_call corresponding assembly code work process, pay special attention to the system call return Iret before the process scheduling time.
The summary part needs to clarify the understanding of "system call process", and further generalize to the general interrupt processing process.
Analysis on the Linux system invocation of dynamic-static-associative kernel