linux fifth week experiment program and summary

 

First, the study concluded

  • MenuOS time and to increase the time-asm command (command four steps)

rm menu -rf 强制删除
git clone http://github.com/mengning/menu.git   克隆相关信息
cd menu
make rootfs 一个脚本,自动编译自动生成根文件系统,并自动启动MenuOS
  • Using gdb tracking system calls the kernel function sys_time

(gdb)b sys_time
(gdb)c    # 启动到MenuOs
// 在MenuOs中使用time,会停在time函数处
(gdb)list # 可以看到对应代码
(gdb)s    # 单步执行
(gdb)finish # 将这个函数执行完
// 以上两步重复使用,可以看到sys_time函数中的函数,直到看见return i
// sys_time返回后进入汇编代码处理,gdb无法继续进行追踪

System call instruction:

// 执行int 0x80之后执行system_call对应的代码
(gdb)b system_call # 是可以设置断点的,但是这段是汇编代码,运行时不能在这个断点处停下逐句分析。
  • The system interrupt handling procedure call

    •       System call flow diagram

    

    • sys_call_table system call dispatch table
    • syscall_after_all, we need to hold the return value
    • sys_exit_work
      not this would restore_all, return to user mode.
      Once inside sys_exit_work: there will be a process of scheduling opportunity

  • Easy to understand the simplified pseudo code system_call
    enter description here
  • Main code between system_call to iret
SAVE_ALL preserve the scene 

call * sys_call_table (,% eax, 4) call processing system scheduling function, eax system call number is stored, this is the actual system scheduler.

RESTORE_ALL
INTERRUPT_RETURN, a macro, in fact iret, end.
This process will sys_exit_work 
sys_exit_work there will work_pending
work_pending there will work_notifysig, used to process signals
may call schedule process scheduling Code
may also jump to restore_all, the recovery site.
As can be seen from the above:
  1. Before the system call returns, the process of scheduling may occur in the process of scheduling process context switch occurs
  2. Interprocess communication signal may have to deal with
System call is a special little break, so it has to protect the site and restore the site .

Second, the experiments: analysis system_call interrupt processing

  • Increase system calls

    • Test.c two functions in increasing, Getpid and GetpidAsm
      enter description here
      enter description here

               enter description here

    • After make rootfs, the input help displays the current menu

              enter description here

  • Using gdb debugging

    It should be noted that, because the current directory is in the menu, and the required image file is not in this directory, then need to use the full path, otherwise there will be mistakes like the above second map appears. To set a breakpoint at the time:

 

    • enter description here
      After c running, use time in MenuOs, you can see it stopped
      enter description here

Guess you like

Origin www.cnblogs.com/chx791046982/p/11032569.html