summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/safestack/safestack_platform.h
blob: 6b042f4b493c7ea157d51130c4beaa4ab7596124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//===-- safestack_platform.h ----------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file implements platform specific parts of SafeStack runtime.
//
//===----------------------------------------------------------------------===//

#ifndef SAFESTACK_PLATFORM_H
#define SAFESTACK_PLATFORM_H

#include "sanitizer_common/sanitizer_platform.h"

#include <stdint.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>

#if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX)
#error "Support for your platform has not been implemented"
#endif

#if SANITIZER_NETBSD
#include <lwp.h>
#endif

#if SANITIZER_FREEBSD
#include <sys/thr.h>
#endif

namespace safestack {

using ThreadId = uint64_t;

inline ThreadId GetTid() {
#if SANITIZER_NETBSD
  return _lwp_self();
#elif SANITIZER_FREEBSD
  long Tid;
  thr_self(&Tid);
  return Tid;
#else
  return syscall(SYS_gettid);
#endif
}

inline int TgKill(pid_t pid, ThreadId tid, int sig) {
#if SANITIZER_NETBSD
  (void)pid;
  return _lwp_kill(tid, sig);
#elif SANITIZER_FREEBSD
  return syscall(SYS_thr_kill2, pid, tid, sig);
#else
  return syscall(SYS_tgkill, pid, tid, sig);
#endif
}

}  // namespace safestack

#endif  // SAFESTACK_PLATFORM_H
OpenPOWER on IntegriCloud