Switch syscall(2)/__syscall(2) calls to libc calls on NetBSD
authorKamil Rytarowski <n54@gmx.com>
Mon, 1 Oct 2018 19:50:12 +0000 (19:50 +0000)
committerKamil Rytarowski <n54@gmx.com>
Mon, 1 Oct 2018 19:50:12 +0000 (19:50 +0000)
commit162aac511a569557a73bcfbfbab73f9882e6aa95
treeb74f3baf206350f7436a4c615b86f9c2a22ab240
parentdcf1d97c5c0ca92a52faae0d1b3b37becce2b4ef
Switch syscall(2)/__syscall(2) calls to libc calls on NetBSD

Summary:
When possible, switch syscall(2)/__syscall(2) calls
to direct calls of internal libc symbols.

Add a new function to detect address of a libc
symbol of a function that could be intercepted.
With the address detector in GetRealLibcAddress(),
an optional interceptor of libc call will be bypassed.

The original approach with syscall(2)/__syscall(2)
wasn't portable across supported ABIs and CPU
architectures. The indirect syscall interface is
also a candidate for removal in future revisions
of NetBSD, as the C language ABI is not a good
domain for serialization of arbitrary functions
arguments.

Switch the following functions to libc calls:
 - internal_mmap()
 - internal_munmap()
 - internal_mprotect()
 - internal_close()
 - internal_open()
 - internal_read()
 - internal_write()
 - internal_ftruncate()
 - internal_stat()
 - internal_lstat()
 - internal_fstat()
 - internal_dup2()
 - internal_readlink()
 - internal_unlink()
 - internal_rename()
 - internal_sched_yield()
 - internal__exit()
 - internal_sleep()
 - internal_execve()
 - NanoTime()
 - internal_clock_gettime()
 - internal_waitpid()
 - internal_getpid()
 - internal_getppid()
 - internal_getdents()
 - internal_lseek()
 - internal_sigaltstack()
 - internal_fork()
 - internal_sigprocmask()
 - internal_sysctl()
 - internal_sigemptyset()
 - internal_sigfillset()
 - GetTid()
 - TgKill()

This revision leaves room for refactoring in subsequent commits.

Reviewers: vitalybuka, kcc, joerg

Reviewed By: vitalybuka

Subscribers: mgorny, fedor.sergeev, jfb, loverszhaokai, devnexen, kubamracek, llvm-commits, ro, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D51419

llvm-svn: 343523
compiler-rt/lib/sanitizer_common/CMakeLists.txt
compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cc [new file with mode: 0644]
compiler-rt/lib/tsan/go/buildgo.sh