This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <asm/unistd.h> | |
#include <sys/wait.h> | |
#include <sys/time.h> | |
#include <time.h> | |
long __syscall(int syscallno, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6); | |
int main(int argc, char * argv[]) { | |
argc; | |
if (argc == 2) { | |
for (int i = 0 ; i < 1000000 ; i++) { | |
struct timeval t; | |
gettimeofday(&t, NULL); | |
} | |
} else { | |
for (int i = 0 ; i < 1000000 ; i++) { | |
struct timeval t; | |
__syscall(__NR_gettimeofday, (long)&t, 0L, 0L, 0L, 0L, 0L); | |
} | |
} | |
return 0; | |
} | |
asm(".pushsection .text, \"ax\", @progbits\n" | |
"__syscall:" | |
".internal __syscall\n" | |
".globl __syscall\n" | |
".type __syscall, @function\n" | |
#if defined(__x86_64__) | |
"movq %rdi, %rax\n" /* place syscall number into %rax */ | |
"movq %rsi, %rdi\n" /* shift arg1 - arg5 */ | |
"movq %rdx, %rsi\n" | |
"movq %rcx, %rdx\n" | |
"movq %r8, %r10\n" | |
"movq %r9, %r8\n" | |
"movq 8(%rsp),%r9\n" /* arg6 is on the stack */ | |
"syscall\n" /* do the system call */ | |
"ret\n" /* return to caller */ | |
#else | |
#error Unsupported target platform | |
#endif | |
".size __syscall, .-__syscall\n" | |
".popsection\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment