#ifndef SAFESTACK_PLATFORM_H
#define SAFESTACK_PLATFORM_H
#include "safestack_util.h"
#include "sanitizer_common/sanitizer_platform.h"
#include <dlfcn.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#if !(SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX || \
SANITIZER_SOLARIS)
# error "Support for your platform has not been implemented"
#endif
#if SANITIZER_NETBSD
#include <lwp.h>
extern "C" void *__mmap(void *, size_t, int, int, int, int, off_t);
#endif
#if SANITIZER_FREEBSD
#include <sys/thr.h>
#endif
#if SANITIZER_SOLARIS
# include <thread.h>
#endif
#if SANITIZER_LINUX && \
(defined(__x86_64__) || defined(__powerpc64__) || \
SANITIZER_WORDSIZE == 64 || (defined(__mips__) && _MIPS_SIM == _ABIN32))
#define SANITIZER_LINUX_USES_64BIT_SYSCALLS …
#else
#define SANITIZER_LINUX_USES_64BIT_SYSCALLS …
#endif
namespace safestack {
#if SANITIZER_NETBSD
static void *GetRealLibcAddress(const char *symbol) {
void *real = dlsym(RTLD_NEXT, symbol);
if (!real)
real = dlsym(RTLD_DEFAULT, symbol);
if (!real) {
fprintf(stderr, "safestack GetRealLibcAddress failed for symbol=%s",
symbol);
abort();
}
return real;
}
#define _REAL …
#define DEFINE__REAL …
#endif
#if SANITIZER_SOLARIS
#define _REAL …
#define DEFINE__REAL …
# if !defined(_LP64) && _FILE_OFFSET_BITS == 64
#define _REAL64 …
# else
#define _REAL64 …
# endif
#define DEFINE__REAL64 …
DEFINE__REAL64(void *, mmap, void *a, size_t b, int c, int d, int e, off_t f);
DEFINE__REAL(int, munmap, void *a, size_t b);
DEFINE__REAL(int, mprotect, void *a, size_t b, int c);
#endif
ThreadId;
inline ThreadId GetTid() { … }
inline int TgKill(pid_t pid, ThreadId tid, int sig) { … }
inline void *Mmap(void *addr, size_t length, int prot, int flags, int fd,
off_t offset) { … }
inline int Munmap(void *addr, size_t length) { … }
inline int Mprotect(void *addr, size_t length, int prot) { … }
}
#endif