任何人都可以了解gettimeofday的作品? [英] Anyone can understand how gettimeofday works?
问题描述
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);
我认为disas应该很容易anough,只要prepare两个指针,并调用相关的系统调用
。
但其disas是做多:
But its disas 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.
和我没有看到系统调用
的。
任何人都了解它是如何工作的?
Anyone understands 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).
该机制的特定内核创建code页面映射到用户内存,让一些系统调用可以在没有用户/内核上下文切换的开销进行,而是作为普通的函数调用。实际的实现是<一个href=\"http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/x86/vdso/vclock_gettime.c;hb=HEAD\">right这里。
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的作品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!