gettimeofday syscall如何工作? [英] How does the gettimeofday syscall work?
问题描述
gettimeofday
是根据此页面的x86-86的系统调用(只需搜索gettimeofday
在框中):
gettimeofday
is a syscall of x86-86 according to this page(just search gettimeofday
in the box):
int gettimeofday(struct timeval *tv, struct timezone *tz);
我认为反汇编应该很容易,只需准备两个指针并调用相关的syscall
,但是反汇编的作用还很多:
I thought the disassembly should be easy enough, just prepare the two pointers and call the related syscall
, but its disassembly is doing much more:
(gdb) disas gettimeofday
Dump of assembler code for function gettimeofday:
0x00000034f408c2d0 <gettimeofday+0>: sub $0x8,%rsp
0x00000034f408c2d4 <gettimeofday+4>: mov $0xffffffffff600000,%rax
0x00000034f408c2db <gettimeofday+11>: callq *%rax
0x00000034f408c2dd <gettimeofday+13>: cmp $0xfffff001,%eax
0x00000034f408c2e2 <gettimeofday+18>: jae 0x34f408c2e9 <gettimeofday+25>
0x00000034f408c2e4 <gettimeofday+20>: add $0x8,%rsp
0x00000034f408c2e8 <gettimeofday+24>: retq
0x00000034f408c2e9 <gettimeofday+25>: mov 0x2c4cb8(%rip),%rcx # 0x34f4350fa8 <free+3356736>
0x00000034f408c2f0 <gettimeofday+32>: xor %edx,%edx
0x00000034f408c2f2 <gettimeofday+34>: sub %rax,%rdx
0x00000034f408c2f5 <gettimeofday+37>: mov %edx,%fs:(%rcx)
0x00000034f408c2f8 <gettimeofday+40>: or $0xffffffffffffffff,%rax
0x00000034f408c2fc <gettimeofday+44>: jmp 0x34f408c2e4 <gettimeofday+20>
End of assembler dump.
我完全看不到syscall
.
任何人都可以解释它的工作原理吗?
Can anyone explain how it works?
推荐答案
gettimeofday()
在Linux上称为vsyscall
和/或vdso
.因此,您会看到两行:
gettimeofday()
on Linux is what's called a vsyscall
and/or vdso
. Hence you see the two lines:
0x00000034f408c2d4 : mov $0xffffffffff600000,%rax
0x00000034f408c2db : callq *%rax
在您的反汇编中.地址0xffffffffff600000
是vsyscall页面(在x86_64上).
in your disassembly. The address 0xffffffffff600000
is the vsyscall page (on x86_64).
该机制将特定的内核创建的代码页映射到用户内存中,因此可以进行一些系统调用",而不会增加用户/内核上下文切换的开销,而是普通"函数调用.实际的实现是
The mechanism maps a specific kernel-created code page into user memory, so that a few "syscalls" can be made without the overhead of a user/kernel context switch, but rather as "ordinary" function call. The actual implementation is right here.
这篇关于gettimeofday syscall如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!