2019-01-18 09:53:37 +08:00
|
|
|
//===-- safestack_platform.h ----------------------------------------------===//
|
|
|
|
//
|
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
|
2019-01-18 09:53:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements platform specific parts of SafeStack runtime.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef SAFESTACK_PLATFORM_H
|
|
|
|
#define SAFESTACK_PLATFORM_H
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
|
|
|
|
2019-01-19 06:32:29 +08:00
|
|
|
#include <stdint.h>
|
2019-01-18 09:53:37 +08:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-01-19 06:32:29 +08:00
|
|
|
#if SANITIZER_NETBSD
|
|
|
|
#include <lwp.h>
|
|
|
|
#endif
|
|
|
|
|
2019-01-18 09:53:37 +08:00
|
|
|
namespace safestack {
|
|
|
|
|
2019-01-19 06:32:29 +08:00
|
|
|
using ThreadId = uint64_t;
|
|
|
|
|
|
|
|
inline ThreadId GetTid() {
|
2019-01-18 09:53:37 +08:00
|
|
|
#if SANITIZER_NETBSD
|
|
|
|
return _lwp_self();
|
|
|
|
#elif SANITIZER_FREEBSD
|
|
|
|
long Tid;
|
|
|
|
thr_self(&Tid);
|
|
|
|
return Tid;
|
|
|
|
#elif SANITIZER_OPENBSD
|
|
|
|
return syscall(SYS_getthrid);
|
|
|
|
#elif SANITIZER_SOLARIS
|
|
|
|
return thr_self();
|
|
|
|
#else
|
|
|
|
return syscall(SYS_gettid);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-01-19 06:32:29 +08:00
|
|
|
inline int TgKill(pid_t pid, ThreadId tid, int sig) {
|
2019-01-18 09:53:37 +08:00
|
|
|
#if SANITIZER_NETBSD
|
|
|
|
(void)pid;
|
|
|
|
return _lwp_kill(tid, sig);
|
|
|
|
#elif SANITIZER_LINUX
|
|
|
|
return syscall(SYS_tgkill, pid, tid, sig);
|
|
|
|
#elif SANITIZER_FREEBSD
|
|
|
|
return syscall(SYS_thr_kill2, pid, tid, sig);
|
|
|
|
#elif SANITIZER_OPENBSD
|
|
|
|
(void)pid;
|
|
|
|
return syscall(SYSCALL(thrkill), tid, sig, nullptr);
|
|
|
|
#elif SANITIZER_SOLARIS
|
|
|
|
(void)pid;
|
|
|
|
return thr_kill(tid, sig);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace safestack
|
|
|
|
|
|
|
|
#endif // SAFESTACK_PLATFORM_H
|