2013-05-08 22:43:49 +08:00
|
|
|
//===-- sanitizer_syscall_linux_x86_64.inc ----------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-05-08 22:43:49 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Implementations of internal_syscall and internal_iserror for Linux/x86_64.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-07 18:03:54 +08:00
|
|
|
#define SYSCALL(name) __NR_ ## name
|
|
|
|
|
2013-05-08 22:43:49 +08:00
|
|
|
static uptr internal_syscall(u64 nr) {
|
|
|
|
u64 retval;
|
asan/msan/tsan: fix broken linux syscalls
Currently the following source code:
u64 NanoTime() {
kernel_timeval tv = {};
internal_syscall(__NR_gettimeofday, &tv, 0);
return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}
generates the following assembly:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007ff30657d380 <+0>: lea -0x10(%rsp),%rdi
0x00007ff30657d385 <+5>: xor %esi,%esi
0x00007ff30657d387 <+7>: mov $0x60,%eax
0x00007ff30657d38c <+12>: syscall
0x00007ff30657d38e <+14>: mov $0,%eax
0x00007ff30657d393 <+19>: retq
with this change:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007faab834f380 <+0>: movq $0x0,-0x10(%rsp)
0x00007faab834f389 <+9>: movq $0x0,-0x8(%rsp)
0x00007faab834f392 <+18>: lea -0x10(%rsp),%rdi
0x00007faab834f397 <+23>: xor %esi,%esi
0x00007faab834f399 <+25>: mov $0x60,%eax
0x00007faab834f39e <+30>: syscall
0x00007faab834f3a0 <+32>: mov -0x8(%rsp),%rax
0x00007faab834f3a5 <+37>: mov -0x10(%rsp),%rcx
0x00007faab834f3aa <+42>: imul $0x3e8,%rax,%rdx
0x00007faab834f3b1 <+49>: imul $0x3b9aca00,%rcx,%rax
0x00007faab834f3b8 <+56>: add %rdx,%rax
0x00007faab834f3bb <+59>: retq
llvm-svn: 191908
2013-10-04 00:53:50 +08:00
|
|
|
asm volatile("syscall" : "=a"(retval) : "a"(nr) : "rcx", "r11",
|
|
|
|
"memory", "cc");
|
2013-05-08 22:43:49 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T1>
|
|
|
|
static uptr internal_syscall(u64 nr, T1 arg1) {
|
|
|
|
u64 retval;
|
|
|
|
asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1) :
|
asan/msan/tsan: fix broken linux syscalls
Currently the following source code:
u64 NanoTime() {
kernel_timeval tv = {};
internal_syscall(__NR_gettimeofday, &tv, 0);
return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}
generates the following assembly:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007ff30657d380 <+0>: lea -0x10(%rsp),%rdi
0x00007ff30657d385 <+5>: xor %esi,%esi
0x00007ff30657d387 <+7>: mov $0x60,%eax
0x00007ff30657d38c <+12>: syscall
0x00007ff30657d38e <+14>: mov $0,%eax
0x00007ff30657d393 <+19>: retq
with this change:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007faab834f380 <+0>: movq $0x0,-0x10(%rsp)
0x00007faab834f389 <+9>: movq $0x0,-0x8(%rsp)
0x00007faab834f392 <+18>: lea -0x10(%rsp),%rdi
0x00007faab834f397 <+23>: xor %esi,%esi
0x00007faab834f399 <+25>: mov $0x60,%eax
0x00007faab834f39e <+30>: syscall
0x00007faab834f3a0 <+32>: mov -0x8(%rsp),%rax
0x00007faab834f3a5 <+37>: mov -0x10(%rsp),%rcx
0x00007faab834f3aa <+42>: imul $0x3e8,%rax,%rdx
0x00007faab834f3b1 <+49>: imul $0x3b9aca00,%rcx,%rax
0x00007faab834f3b8 <+56>: add %rdx,%rax
0x00007faab834f3bb <+59>: retq
llvm-svn: 191908
2013-10-04 00:53:50 +08:00
|
|
|
"rcx", "r11", "memory", "cc");
|
2013-05-08 22:43:49 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T1, typename T2>
|
|
|
|
static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2) {
|
|
|
|
u64 retval;
|
|
|
|
asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
|
asan/msan/tsan: fix broken linux syscalls
Currently the following source code:
u64 NanoTime() {
kernel_timeval tv = {};
internal_syscall(__NR_gettimeofday, &tv, 0);
return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}
generates the following assembly:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007ff30657d380 <+0>: lea -0x10(%rsp),%rdi
0x00007ff30657d385 <+5>: xor %esi,%esi
0x00007ff30657d387 <+7>: mov $0x60,%eax
0x00007ff30657d38c <+12>: syscall
0x00007ff30657d38e <+14>: mov $0,%eax
0x00007ff30657d393 <+19>: retq
with this change:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007faab834f380 <+0>: movq $0x0,-0x10(%rsp)
0x00007faab834f389 <+9>: movq $0x0,-0x8(%rsp)
0x00007faab834f392 <+18>: lea -0x10(%rsp),%rdi
0x00007faab834f397 <+23>: xor %esi,%esi
0x00007faab834f399 <+25>: mov $0x60,%eax
0x00007faab834f39e <+30>: syscall
0x00007faab834f3a0 <+32>: mov -0x8(%rsp),%rax
0x00007faab834f3a5 <+37>: mov -0x10(%rsp),%rcx
0x00007faab834f3aa <+42>: imul $0x3e8,%rax,%rdx
0x00007faab834f3b1 <+49>: imul $0x3b9aca00,%rcx,%rax
0x00007faab834f3b8 <+56>: add %rdx,%rax
0x00007faab834f3bb <+59>: retq
llvm-svn: 191908
2013-10-04 00:53:50 +08:00
|
|
|
"S"((u64)arg2) : "rcx", "r11", "memory", "cc");
|
2013-05-08 22:43:49 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T1, typename T2, typename T3>
|
|
|
|
static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3) {
|
|
|
|
u64 retval;
|
|
|
|
asm volatile("syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
|
asan/msan/tsan: fix broken linux syscalls
Currently the following source code:
u64 NanoTime() {
kernel_timeval tv = {};
internal_syscall(__NR_gettimeofday, &tv, 0);
return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}
generates the following assembly:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007ff30657d380 <+0>: lea -0x10(%rsp),%rdi
0x00007ff30657d385 <+5>: xor %esi,%esi
0x00007ff30657d387 <+7>: mov $0x60,%eax
0x00007ff30657d38c <+12>: syscall
0x00007ff30657d38e <+14>: mov $0,%eax
0x00007ff30657d393 <+19>: retq
with this change:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007faab834f380 <+0>: movq $0x0,-0x10(%rsp)
0x00007faab834f389 <+9>: movq $0x0,-0x8(%rsp)
0x00007faab834f392 <+18>: lea -0x10(%rsp),%rdi
0x00007faab834f397 <+23>: xor %esi,%esi
0x00007faab834f399 <+25>: mov $0x60,%eax
0x00007faab834f39e <+30>: syscall
0x00007faab834f3a0 <+32>: mov -0x8(%rsp),%rax
0x00007faab834f3a5 <+37>: mov -0x10(%rsp),%rcx
0x00007faab834f3aa <+42>: imul $0x3e8,%rax,%rdx
0x00007faab834f3b1 <+49>: imul $0x3b9aca00,%rcx,%rax
0x00007faab834f3b8 <+56>: add %rdx,%rax
0x00007faab834f3bb <+59>: retq
llvm-svn: 191908
2013-10-04 00:53:50 +08:00
|
|
|
"S"((u64)arg2), "d"((u64)arg3) : "rcx", "r11", "memory", "cc");
|
2013-05-08 22:43:49 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T1, typename T2, typename T3, typename T4>
|
|
|
|
static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4) {
|
|
|
|
u64 retval;
|
|
|
|
asm volatile("mov %5, %%r10;"
|
|
|
|
"syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
|
|
|
|
"S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4) :
|
asan/msan/tsan: fix broken linux syscalls
Currently the following source code:
u64 NanoTime() {
kernel_timeval tv = {};
internal_syscall(__NR_gettimeofday, &tv, 0);
return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}
generates the following assembly:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007ff30657d380 <+0>: lea -0x10(%rsp),%rdi
0x00007ff30657d385 <+5>: xor %esi,%esi
0x00007ff30657d387 <+7>: mov $0x60,%eax
0x00007ff30657d38c <+12>: syscall
0x00007ff30657d38e <+14>: mov $0,%eax
0x00007ff30657d393 <+19>: retq
with this change:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007faab834f380 <+0>: movq $0x0,-0x10(%rsp)
0x00007faab834f389 <+9>: movq $0x0,-0x8(%rsp)
0x00007faab834f392 <+18>: lea -0x10(%rsp),%rdi
0x00007faab834f397 <+23>: xor %esi,%esi
0x00007faab834f399 <+25>: mov $0x60,%eax
0x00007faab834f39e <+30>: syscall
0x00007faab834f3a0 <+32>: mov -0x8(%rsp),%rax
0x00007faab834f3a5 <+37>: mov -0x10(%rsp),%rcx
0x00007faab834f3aa <+42>: imul $0x3e8,%rax,%rdx
0x00007faab834f3b1 <+49>: imul $0x3b9aca00,%rcx,%rax
0x00007faab834f3b8 <+56>: add %rdx,%rax
0x00007faab834f3bb <+59>: retq
llvm-svn: 191908
2013-10-04 00:53:50 +08:00
|
|
|
"rcx", "r11", "r10", "memory", "cc");
|
2013-05-08 22:43:49 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T1, typename T2, typename T3, typename T4, typename T5>
|
|
|
|
static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
|
|
|
|
T5 arg5) {
|
|
|
|
u64 retval;
|
|
|
|
asm volatile("mov %5, %%r10;"
|
|
|
|
"mov %6, %%r8;"
|
|
|
|
"syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
|
|
|
|
"S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4), "r"((u64)arg5) :
|
asan/msan/tsan: fix broken linux syscalls
Currently the following source code:
u64 NanoTime() {
kernel_timeval tv = {};
internal_syscall(__NR_gettimeofday, &tv, 0);
return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}
generates the following assembly:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007ff30657d380 <+0>: lea -0x10(%rsp),%rdi
0x00007ff30657d385 <+5>: xor %esi,%esi
0x00007ff30657d387 <+7>: mov $0x60,%eax
0x00007ff30657d38c <+12>: syscall
0x00007ff30657d38e <+14>: mov $0,%eax
0x00007ff30657d393 <+19>: retq
with this change:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007faab834f380 <+0>: movq $0x0,-0x10(%rsp)
0x00007faab834f389 <+9>: movq $0x0,-0x8(%rsp)
0x00007faab834f392 <+18>: lea -0x10(%rsp),%rdi
0x00007faab834f397 <+23>: xor %esi,%esi
0x00007faab834f399 <+25>: mov $0x60,%eax
0x00007faab834f39e <+30>: syscall
0x00007faab834f3a0 <+32>: mov -0x8(%rsp),%rax
0x00007faab834f3a5 <+37>: mov -0x10(%rsp),%rcx
0x00007faab834f3aa <+42>: imul $0x3e8,%rax,%rdx
0x00007faab834f3b1 <+49>: imul $0x3b9aca00,%rcx,%rax
0x00007faab834f3b8 <+56>: add %rdx,%rax
0x00007faab834f3bb <+59>: retq
llvm-svn: 191908
2013-10-04 00:53:50 +08:00
|
|
|
"rcx", "r11", "r10", "r8", "memory", "cc");
|
2013-05-08 22:43:49 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
|
|
|
typename T6>
|
|
|
|
static uptr internal_syscall(u64 nr, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
|
|
|
|
T5 arg5, T6 arg6) {
|
|
|
|
u64 retval;
|
|
|
|
asm volatile("mov %5, %%r10;"
|
|
|
|
"mov %6, %%r8;"
|
|
|
|
"mov %7, %%r9;"
|
|
|
|
"syscall" : "=a"(retval) : "a"(nr), "D"((u64)arg1),
|
|
|
|
"S"((u64)arg2), "d"((u64)arg3), "r"((u64)arg4), "r"((u64)arg5),
|
asan/msan/tsan: fix broken linux syscalls
Currently the following source code:
u64 NanoTime() {
kernel_timeval tv = {};
internal_syscall(__NR_gettimeofday, &tv, 0);
return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000;
}
generates the following assembly:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007ff30657d380 <+0>: lea -0x10(%rsp),%rdi
0x00007ff30657d385 <+5>: xor %esi,%esi
0x00007ff30657d387 <+7>: mov $0x60,%eax
0x00007ff30657d38c <+12>: syscall
0x00007ff30657d38e <+14>: mov $0,%eax
0x00007ff30657d393 <+19>: retq
with this change:
Dump of assembler code for function __sanitizer::NanoTime():
=> 0x00007faab834f380 <+0>: movq $0x0,-0x10(%rsp)
0x00007faab834f389 <+9>: movq $0x0,-0x8(%rsp)
0x00007faab834f392 <+18>: lea -0x10(%rsp),%rdi
0x00007faab834f397 <+23>: xor %esi,%esi
0x00007faab834f399 <+25>: mov $0x60,%eax
0x00007faab834f39e <+30>: syscall
0x00007faab834f3a0 <+32>: mov -0x8(%rsp),%rax
0x00007faab834f3a5 <+37>: mov -0x10(%rsp),%rcx
0x00007faab834f3aa <+42>: imul $0x3e8,%rax,%rdx
0x00007faab834f3b1 <+49>: imul $0x3b9aca00,%rcx,%rax
0x00007faab834f3b8 <+56>: add %rdx,%rax
0x00007faab834f3bb <+59>: retq
llvm-svn: 191908
2013-10-04 00:53:50 +08:00
|
|
|
"r"((u64)arg6) : "rcx", "r11", "r10", "r8", "r9",
|
|
|
|
"memory", "cc");
|
2013-05-08 22:43:49 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool internal_iserror(uptr retval, int *rverrno) {
|
|
|
|
if (retval >= (uptr)-4095) {
|
|
|
|
if (rverrno)
|
|
|
|
*rverrno = -retval;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|