黄胤凯 原创作品转载请注明出处 《Linux内核分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000
上周说了系统调用的三层皮:xyz system_call sys_xyz
本周学习内容如下:
给MenuOS增加time和time-asm命令需要
分析system_call中断处理过程
博客内容的具体要求如下:
用实验楼的虚拟机打开shell,更新menu,给MenuOS增加Pid和PidAsm
|
1
2
3
4
5
6
|
cd LinuxKernelrm menu -rfgit clone https://github.com/mengning/menu.gitcd menuvi test.cmake rootfs |
使用gdb跟踪分析
|
1
|
qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd rootfs.img -s -S |
|
1
2
3
4
5
6
7
8
9
10
11
|
gdbfile linux-3.18.6/vmlinux加载调试用的符号表target remote:1234b start_kernel 设置断点cb sys_getpid |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
ENTRY(system_call)RING0_INT_FRAME# can‘t unwind into user space anywayASM_CLACpushl_cfi %eax# save orig_eaxSAVE_ALLGET_THREAD_INFO(%ebp)# system call tracing in operation / emulationtestl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)jnz syscall_trace_entrycmpl $(NR_syscalls), %eaxjae syscall_badsyssyscall_call:call *sys_call_table(,%eax,4)syscall_after_call:movl %eax,PT_EAX(%esp)# store the return valuesyscall_exit:LOCKDEP_SYS_EXITDISABLE_INTERRUPTS(CLBR_ANY)# make sure we don‘t miss an interrupt# setting need_resched or sigpending# between sampling and the iretTRACE_IRQS_OFFmovl TI_flags(%ebp), %ecxtestl $_TIF_ALLWORK_MASK, %ecx# current->workjne syscall_exit_workrestore_all:TRACE_IRQS_IRETrestore_all_notrace:#ifdef CONFIG_X86_ESPFIX32movl PT_EFLAGS(%esp), %eax# mix EFLAGS, SS and CS# Warning: PT_OLDSS(%esp) contains the wrong/random values if we# are returning to the kernel.# See comments in process.c:copy_thread() for details.movb PT_OLDSS(%esp), %ahmovb PT_CS(%esp), %alandl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eaxcmpl $((SEGMENT_LDT << 8) | USER_RPL), %eaxCFI_REMEMBER_STATEje ldt_ss# returning to user-space with LDT SS#endifrestore_nocheck:RESTORE_REGS 4# skip orig_eax/error_codeirq_return:INTERRUPT_RETURN |




原文:http://www.cnblogs.com/20132109HKK/p/5326729.html