简体   繁体   English

macOS High Sierra 中 syscall_time 的值

[英]Value of syscall_time in macOS High Sierra

I am writing assembly-nasm program and I would like to use current time of a device.我正在编写 assembly-nasm 程序,我想使用设备的当前时间。 In Linux, there is a system call with number 201 which returns amount of seconds from the beginning of 1970. Does anyone know what is the value of a corresponding system call in macOS?在 Linux 中,有一个编号为 201 的系统调用,它返回从 1970 年开始的秒数。有谁知道 macOS 中相应系统调用的值是多少?

Thank you for your help, I have found the solution.感谢您的帮助,我已经找到了解决方案。 Below you can find how to load time to buffer storage您可以在下面找到如何将时间加载到缓冲存储

macOS苹果系统

load_time:
   mov rax, 0x2000074
   lea rdi, [rel buffer]
   mov rsi, 0
   syscall
   ret

You provide pointer to buffer as an argument to retrieve data in form of a structure您提供指向缓冲区的指针作为以结构形式检索数据的参数

_STRUCT_TIMEVAL {
    __darwin_time_t         tv_sec;         /* seconds */
    __darwin_suseconds_t    tv_usec;        /* and microseconds */
};

In case of Linux only seconds are returned在 Linux 的情况下只返回秒

load_time
    mov rax, 201
    mov rdi, 0
    syscall
    mov [rel buffer], rax
    ret

Just to complement your answer I found a very simple way to access seconds and microseconds by declaring:为了补充您的答案,我发现了一种通过声明访问秒和微秒的非常简单的方法:

timeval:
    tv_sec  dq 0
    tv_usec dq 0

timestr db "Secs: %ld and microsecs: %ld", 10, 0

After you do:做完之后:

    mov         rax, 0x2000074
    lea         rdi, [timeval]
    mov         rsi, 0          
    syscall

You can then access each by their name like for printing:然后,您可以按名称访问每个名称,例如打印:

    lea         rdi, [timestr]     
    mov         rsi, [tv_sec]
    mov         rdx, [tv_usec]
    call        _printf 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM