llvm/compiler-rt/lib/hwasan/hwasan_interceptors.cpp

//===-- hwasan_interceptors.cpp -------------------------------------------===//
//
// 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 is a part of HWAddressSanitizer.
//
// Interceptors for standard library functions.
//
// FIXME: move as many interceptors as possible into
// sanitizer_common/sanitizer_common_interceptors.h
//===----------------------------------------------------------------------===//

#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS

#include "hwasan.h"
#include "hwasan_allocator.h"
#include "hwasan_checks.h"
#include "hwasan_mapping.h"
#include "hwasan_platform_interceptors.h"
#include "hwasan_thread.h"
#include "hwasan_thread_list.h"
#include "interception/interception.h"
#include "sanitizer_common/sanitizer_errno.h"
#include "sanitizer_common/sanitizer_linux.h"
#include "sanitizer_common/sanitizer_stackdepot.h"

#if !SANITIZER_FUCHSIA

usingnamespace__hwasan;

struct HWAsanInterceptorContext {};

#define ACCESS_MEMORY_RANGE(offset, size, access)

#define HWASAN_READ_RANGE(offset, size)
#define HWASAN_WRITE_RANGE(offset, size)

#  if !SANITIZER_APPLE
#define HWASAN_INTERCEPT_FUNC(name)
#define HWASAN_INTERCEPT_FUNC_VER(name, ver)
#define HWASAN_INTERCEPT_FUNC_VER_UNVERSIONED_FALLBACK(name, ver)

#  else
// OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION.
#define HWASAN_INTERCEPT_FUNC
#  endif  // SANITIZER_APPLE

#  if HWASAN_WITH_INTERCEPTORS

#define COMMON_SYSCALL_PRE_READ_RANGE(p, s)
#define COMMON_SYSCALL_PRE_WRITE_RANGE(p, s)
#define COMMON_SYSCALL_POST_READ_RANGE(p, s)
#define COMMON_SYSCALL_POST_WRITE_RANGE(p, s)
#    include "sanitizer_common/sanitizer_common_syscalls.inc"
#    include "sanitizer_common/sanitizer_syscalls_netbsd.inc"

#define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, size)

#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size)

#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)

#define COMMON_INTERCEPTOR_DIR_ACQUIRE(ctx, path)

#define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd)

#define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd)

#define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd)

#define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name)

#define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name)

#define COMMON_INTERCEPTOR_BLOCK_REAL(name)

#define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, dst, v, size)

#define COMMON_INTERCEPTOR_STRERROR()

#define COMMON_INTERCEPT_FUNCTION(name)

#define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED

// The main purpose of the mmap interceptor is to prevent the user from
// allocating on top of shadow pages.
//
// For compatibility, it does not tag pointers, nor does it allow
// MAP_FIXED in combination with a tagged pointer. (Since mmap itself
// will not return a tagged pointer, the tagged pointer must have come
// from elsewhere, such as the secondary allocator, which makes it a
// very odd usecase.)
template <class Mmap>
static void *mmap_interceptor(Mmap real_mmap, void *addr, SIZE_T length,
                              int prot, int flags, int fd, OFF64_T offset) {}

template <class Munmap>
static int munmap_interceptor(Munmap real_munmap, void *addr, SIZE_T length) {}

#define COMMON_INTERCEPTOR_MMAP_IMPL(ctx, mmap, addr, length, prot, flags, \
                                         fd, offset)

#define COMMON_INTERCEPTOR_MUNMAP_IMPL(ctx, addr, length)

#    include "sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc"
#    include "sanitizer_common/sanitizer_common_interceptors.inc"

struct ThreadStartArg {};

static void *HwasanThreadStartFunc(void *arg) {}

extern "C" {
int pthread_attr_getdetachstate(void *attr, int *v);
}

INTERCEPTOR(int, pthread_create, void *thread, void *attr,
            void *(*callback)(void *), void *param) {}

INTERCEPTOR(int, pthread_join, void *thread, void **retval) {}

INTERCEPTOR(int, pthread_detach, void *thread) {}

INTERCEPTOR(void, pthread_exit, void *retval) {}

#    if SANITIZER_GLIBC
INTERCEPTOR(int, pthread_tryjoin_np, void *thread, void **ret) {}

INTERCEPTOR(int, pthread_timedjoin_np, void *thread, void **ret,
            const struct timespec *abstime) {}
#    endif

DEFINE_INTERNAL_PTHREAD_FUNCTIONS

DEFINE_REAL()
DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER()

// Get and/or change the set of blocked signals.
extern "C" int sigprocmask(int __how, const __hw_sigset_t *__restrict __set,
                           __hw_sigset_t *__restrict __oset);
#define SIG_BLOCK
#define SIG_SETMASK
extern "C" int __sigjmp_save(__hw_sigjmp_buf env, int savemask) {}

static void __attribute__((always_inline))
InternalLongjmp(__hw_register_buf env, int retval) {}

INTERCEPTOR(void, siglongjmp, __hw_sigjmp_buf env, int val) {}

// Required since glibc libpthread calls __libc_longjmp on pthread_exit, and
// _setjmp on start_thread.  Hence we have to intercept the longjmp on
// pthread_exit so the __hw_jmp_buf order matches.
INTERCEPTOR(void, __libc_longjmp, __hw_jmp_buf env, int val) {}

INTERCEPTOR(void, longjmp, __hw_jmp_buf env, int val) {}
#    undef SIG_BLOCK
#    undef SIG_SETMASK

#  endif  // HWASAN_WITH_INTERCEPTORS

namespace __hwasan {

int OnExit() {}

}  // namespace __hwasan

namespace __hwasan {

void InitializeInterceptors() {}
}  // namespace __hwasan

#endif  // #if !SANITIZER_FUCHSIA