Final summary
Grasping Writer: Li Pengju No.: 20132201
(* Original works reproduced please specify the source *)
(Study course: "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000)
1: Disassembly a simple C-Program:
Http://www.cnblogs.com/puputongtong/p/5225332.html
2: How the operating system works:
Http://www.cnblogs.com/puputongtong/p/5248497.html
3: Trace Analysis of the boot process of the Linux kernel:
Http://www.cnblogs.com/puputongtong/p/5273199.html
4: Use the same system call using the Library function API and the embed assembly code in the C code two ways:
Http://www.cnblogs.com/puputongtong/p/5299566.html
5:system_call Interrupt Handling process:
Http://www.cnblogs.com/puputongtong/p/5326845.html
6: Analyze the process of creating a new process for the Linux kernel:
Http://www.cnblogs.com/puputongtong/p/5350702.html
7:linux how the kernel loads and launches an executable program:
Http://www.cnblogs.com/puputongtong/p/5375416.html
8: Understand the process of scheduling time tracking analysis process scheduling and process switching processes:
Http://www.cnblogs.com/puputongtong/p/5399405.html
----------------------------------------------------------------------------------------
Final Summary * * * How the computer works
Computer: A computer that implements complex functions, computes and processes large amounts of data, in fact by repeatedly repeating a large number of simple operations
Programs: tells the computer how to do the steps, the data entered, and how to store the processed results. The computer will, as faithfully as possible, take the instructions of each operation step out in the order of the program, turning it into machine language, working together through hardware and software
Assembly Language: assembly language is a translation of machine languages. Now the compiler is powerful, assembly language really does not use a lot of time, but can read the assembly statements, in the analysis of the actual process of execution, single-step debugging program has a great help
How the operating system works
The simple analog kernel code mainly includes:
function Call stack
function Stack Frame
Kernel initialization, interrupt, process context switching process and multi-channel program simulation based on time slice rotation
Operating system Three Magic Weapon:
Stored program computers
function Call stack
Interrupt mechanism operating system Two swords: interrupt context, Process context switch
Operating system core functions: Process scheduling and interrupt mechanism, through the cooperation with the hardware to achieve multi-tasking, coupled with the support of the upper application software, and eventually become a computer system can be easy to operate multi-process Linux operating system: The process must wait for the running process idle CPU to run Process switching: When a running process waits for additional system resources, the Linux kernel gains control of the CPU and allocates the CPU to other waiting processes. Process switching mechanism includes ESP switching, stack switching
Construct a simple Linux system menuos
The last sentence of the Start_kernel function is Rest_init ();
This process is always present at the kernel boot, process No. 0, processNo. 0 is the final idle process (rest_init)
This number No. 0 process creates process number 1th and other service threads.
Daosh One (start_kernel-->cpu_idle), a lifetime of two (Kernel_init and Kthreadd), two born three (i.e. front 0, 1 and 23 processes), Sansheng everything (1th process is the ancestor of all user-state processes, Process number 2nd is the ancestor of all kernel threads)
Three layers of skin (top) of the system call
System call: Even the simplest program, in the case of input and output operations, will also need to invoke the service provided by the operating system, that is, system calls. System calls under Linux are implemented by interrupts (int 0x80).
Pass parameters: When the int 80 instruction is executed, the function number of the system call is stored in the register eax, and the parameters passed to the system call must be placed in the Register Ebx,ecx,edx,esi,edi in order, and when the system call is complete, the return value can be obtained in register EAX. Linux uses the C-language invocation pattern, which means that all parameters must be stacked in the opposite order, that is, the last parameter is first in the stack, and the first parameter is the last one in the stack. User-State, kernel-state, and interrupt-handling processes use the Library function API and the C code in the embed assembler code to trigger the same system call using the Library function API to get the system current time using the C code in the embed assembler code to trigger system calls to get the system current time
Three-layer skin with a clawed application system (bottom)
Adding the time and Time-asm commands to menuos uses the GDB trace system to invoke kernel functions Sys_time system calls working in kernel code and initialization
A system call is a special kind of interrupt system call:
Save_all Save the scene.
Determine the interrupt information, pass the system call number through EAX, sys_call_table query to the calling system call, and then jump to the appropriate program for processing.
Processing interrupts.
Restore_all recovery system calls the scene, Iret returns the user state.
Description of the process and creation of the process
Description of the process: Process descriptor TASK_STRUCT Data structure
Understand fork () from the point of view of system invocation: Two returns at a time (the fork system call returns one time in the parent and child processes, 0 is returned in the child process, and the return value in the parent process is the PID of the child process)
Linux creates a new process by replicating the parent process, implementing it by calling Do_fork and dynamically assigning a task_struct structure to each newly created process the starting point is consistent with the kernel stack: Before setting the IP of the child process:Childregs = Current_pt_regs (); Assigns the regs parameter of the parent process to the child process's kernel stack, which holds the parameters of the Save_all stack in the beginning of the new process: Copy_thread (): P->thread.ip = (unsigned Long) RET _from _fork; Sets the EIP for the child process to the first address of the Ret_from _fork, which is performed by the child process starting from Ret_from_fork
Creation of the process:
Overview of process creation and user-state code for a process fork
Understand how complex code is created by the process
Browse key code related to process creation process
Where does the new process of creation start?
Use GDB to track the process of creating a new process executable loader------------------
About the program loading process and the elf file format. It mainly includes getting an executable procedure, structure and static link of elf file format, static loading process of executable program and dynamic loading process.
When Execve executes, it falls into the kernel state, overwrites the currently executing program with the program loaded in the EXECVE, and returns to the new executable starting point preprocessing, compiling, linking, and the format of the destination file when the system call returns:
How do you get the executable program?
Format of the destination file elf
Statically linked Elf executables and process address space executable programs, shared libraries, and dynamic loading:
Work before the executable program is loaded
Load-time dynamic link and run-time dynamic link application examples of executable program loading:
Analysis of key issues related to loading of executable programs
Internal process of Sys_execve
Using GDB to track the process of SYS_EXECVE kernel functions
Executable program loading and Zhuangsheng dream Butterfly Story
Simple analysis on loading of dynamically linked executable program
Process switching and general execution of the system
Process scheduling algorithm: According to different classification, scheduling design principles are also different process switching: Switching address space, switching kernel stacks, switching kernel control flow and some necessary register save and restore scheduling time: Kernel thread can directly call schedule () for process switching (active), It can also be scheduled (passive) during interrupt processing. The user-state process can not realize the active scheduling, only through the kernel state after a certain point in time to dispatch, that is, in the interrupt processing process for the use of the kernel: 32-bit x86 system, each process has a 4G address space, the user state 0-3g,3g above only the kernel state can be accessed. All processes above 3G are shared, and in the kernel code snippets, stack segments are the same, and return to the user state is different. Process into the kernel is the same, no process into the kernel to execute the No. No. 0 process. The kernel can be seen as a collection of various interrupt processing and kernel threads
Linux Kernel Learning Summary