#include "sanitizer_platform.h"
#if SANITIZER_SOLARIS
#include <stdio.h>
#include "sanitizer_common.h"
#include "sanitizer_flags.h"
#include "sanitizer_internal_defs.h"
#include "sanitizer_libc.h"
#include "sanitizer_placement_new.h"
#include "sanitizer_platform_limits_posix.h"
#include "sanitizer_procmaps.h"
#include <fcntl.h>
#include <pthread.h>
#include <sched.h>
#include <thread.h>
#include <synch.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
namespace __sanitizer {
#define _REAL …
#define DECLARE__REAL …
#define DECLARE__REAL_AND_INTERNAL …
#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
#define _REAL64 …
#else
#define _REAL64 …
#endif
#define DECLARE__REAL64 …
#define DECLARE__REAL_AND_INTERNAL64 …
DECLARE__REAL_AND_INTERNAL64(uptr, mmap, void *addr, uptr length,
int prot, int flags, int fd, OFF_T offset) {
return (uptr)_REAL64(mmap)(addr, length, prot, flags, fd, offset);
}
DECLARE__REAL_AND_INTERNAL(uptr, munmap, void *addr, uptr length) {
return _REAL(munmap)(addr, length);
}
DECLARE__REAL_AND_INTERNAL(int, mprotect, void *addr, uptr length, int prot) {
return _REAL(mprotect)(addr, length, prot);
}
extern "C" int madvise(void *, size_t, int);
int internal_madvise(uptr addr, uptr length, int advice) {
return madvise((void *)addr, length, advice);
}
DECLARE__REAL_AND_INTERNAL(uptr, close, fd_t fd) {
return _REAL(close)(fd);
}
extern "C" int _REAL64(open)(const char *, int, ...);
uptr internal_open(const char *filename, int flags) {
return _REAL64(open)(filename, flags);
}
uptr internal_open(const char *filename, int flags, u32 mode) {
return _REAL64(open)(filename, flags, mode);
}
DECLARE__REAL_AND_INTERNAL(uptr, read, fd_t fd, void *buf, uptr count) {
return _REAL(read)(fd, buf, count);
}
DECLARE__REAL_AND_INTERNAL(uptr, write, fd_t fd, const void *buf, uptr count) {
return _REAL(write)(fd, buf, count);
}
DECLARE__REAL_AND_INTERNAL(uptr, ftruncate, fd_t fd, uptr size) {
return ftruncate(fd, size);
}
DECLARE__REAL_AND_INTERNAL64(uptr, stat, const char *path, void *buf) {
return _REAL64(stat)(path, (struct stat *)buf);
}
DECLARE__REAL_AND_INTERNAL64(uptr, lstat, const char *path, void *buf) {
return _REAL64(lstat)(path, (struct stat *)buf);
}
DECLARE__REAL_AND_INTERNAL64(uptr, fstat, fd_t fd, void *buf) {
return _REAL64(fstat)(fd, (struct stat *)buf);
}
uptr internal_filesize(fd_t fd) {
struct stat st;
if (internal_fstat(fd, &st))
return -1;
return (uptr)st.st_size;
}
DECLARE__REAL_AND_INTERNAL(uptr, dup, int oldfd) {
return _REAL(dup)(oldfd);
}
DECLARE__REAL_AND_INTERNAL(uptr, dup2, int oldfd, int newfd) {
return _REAL(dup2)(oldfd, newfd);
}
DECLARE__REAL_AND_INTERNAL(uptr, readlink, const char *path, char *buf,
uptr bufsize) {
return _REAL(readlink)(path, buf, bufsize);
}
DECLARE__REAL_AND_INTERNAL(uptr, unlink, const char *path) {
return _REAL(unlink)(path);
}
DECLARE__REAL_AND_INTERNAL(uptr, rename, const char *oldpath,
const char *newpath) {
return _REAL(rename)(oldpath, newpath);
}
DECLARE__REAL_AND_INTERNAL(uptr, sched_yield, void) {
return sched_yield();
}
DECLARE__REAL_AND_INTERNAL(void, usleep, u64 useconds) {
struct timespec ts;
ts.tv_sec = useconds / 1000000;
ts.tv_nsec = (useconds % 1000000) * 1000;
nanosleep(&ts, nullptr);
}
DECLARE__REAL_AND_INTERNAL(uptr, execve, const char *filename,
char *const argv[], char *const envp[]) {
return _REAL(execve)(filename, argv, envp);
}
DECLARE__REAL_AND_INTERNAL(uptr, waitpid, int pid, int *status, int options) {
return _REAL(waitpid)(pid, status, options);
}
DECLARE__REAL_AND_INTERNAL(uptr, getpid, void) {
return _REAL(getpid)();
}
DECLARE__REAL_AND_INTERNAL64(uptr, getdents, fd_t fd, struct linux_dirent *dirp,
unsigned int count) {
return _REAL64(getdents)(fd, dirp, count);
}
DECLARE__REAL_AND_INTERNAL64(uptr, lseek, fd_t fd, OFF_T offset, int whence) {
return _REAL64(lseek)(fd, offset, whence);
}
DECLARE__REAL_AND_INTERNAL(void, sigfillset, __sanitizer_sigset_t *set) {
_REAL(sigfillset)(set);
}
DECLARE__REAL_AND_INTERNAL(uptr, sigprocmask, int how,
__sanitizer_sigset_t *set,
__sanitizer_sigset_t *oldset) {
return _REAL(sigprocmask)(how, set, oldset);
}
DECLARE__REAL_AND_INTERNAL(int, fork, void) {
return _REAL(fork)();
}
u64 NanoTime() {
return gethrtime();
}
uptr internal_clock_gettime(__sanitizer_clockid_t clk_id, void *tp) {
return clock_gettime(clk_id, (timespec *)tp);
}
void FutexWait(atomic_uint32_t *p, u32 cmp) {
sched_yield();
}
void FutexWake(atomic_uint32_t *p, u32 count) {}
}
#endif