简体   繁体   中英

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. 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?

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

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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