llvm/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp

//===-- sanitizer_posix.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 shared between AddressSanitizer and ThreadSanitizer
// run-time libraries and implements POSIX-specific functions from
// sanitizer_posix.h.
//===----------------------------------------------------------------------===//

#include "sanitizer_platform.h"

#if SANITIZER_POSIX

#include "sanitizer_common.h"
#include "sanitizer_file.h"
#include "sanitizer_flags.h"
#include "sanitizer_libc.h"
#include "sanitizer_posix.h"
#include "sanitizer_procmaps.h"

#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/mman.h>

#if SANITIZER_FREEBSD
// The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before
// that, it was never implemented.  So just define it to zero.
#undef  MAP_NORESERVE
#define MAP_NORESERVE
#endif

namespace __sanitizer {

// ------------- sanitizer_common.h
uptr GetMmapGranularity() {}

bool ErrorIsOOM(error_t err) {}

void *MmapOrDie(uptr size, const char *mem_type, bool raw_report) {}

void UnmapOrDie(void *addr, uptr size, bool raw_report) {}

void *MmapOrDieOnFatalError(uptr size, const char *mem_type) {}

// We want to map a chunk of address space aligned to 'alignment'.
// We do it by mapping a bit more and then unmapping redundant pieces.
// We probably can do it with fewer syscalls in some OS-dependent way.
void *MmapAlignedOrDieOnFatalError(uptr size, uptr alignment,
                                   const char *mem_type) {}

void *MmapNoReserveOrDie(uptr size, const char *mem_type) {}

static void *MmapFixedImpl(uptr fixed_addr, uptr size, bool tolerate_enomem,
                           const char *name) {}

void *MmapFixedOrDie(uptr fixed_addr, uptr size, const char *name) {}

void *MmapFixedOrDieOnFatalError(uptr fixed_addr, uptr size, const char *name) {}

bool MprotectNoAccess(uptr addr, uptr size) {}

bool MprotectReadOnly(uptr addr, uptr size) {}

bool MprotectReadWrite(uptr addr, uptr size) {}

#if !SANITIZER_APPLE
void MprotectMallocZones(void *addr, int prot) {}
#endif

fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *errno_p) {}

void CloseFile(fd_t fd) {}

bool ReadFromFile(fd_t fd, void *buff, uptr buff_size, uptr *bytes_read,
                  error_t *error_p) {}

bool WriteToFile(fd_t fd, const void *buff, uptr buff_size, uptr *bytes_written,
                 error_t *error_p) {}

void *MapFileToMemory(const char *file_name, uptr *buff_size) {}

void *MapWritableFileToMemory(void *addr, uptr size, fd_t fd, OFF_T offset) {}

static inline bool IntervalsAreSeparate(uptr start1, uptr end1,
                                        uptr start2, uptr end2) {}

// FIXME: this is thread-unsafe, but should not cause problems most of the time.
// When the shadow is mapped only a single thread usually exists (plus maybe
// several worker threads on Mac, which aren't expected to map big chunks of
// memory).
bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) {}

#if !SANITIZER_APPLE
void DumpProcessMap() {}
#endif

const char *GetPwd() {}

bool IsPathSeparator(const char c) {}

bool IsAbsolutePath(const char *path) {}

void ReportFile::Write(const char *buffer, uptr length) {}

bool GetCodeRangeForFile(const char *module, uptr *start, uptr *end) {}

uptr SignalContext::GetAddress() const {}

bool SignalContext::IsMemoryAccess() const {}

int SignalContext::GetType() const {}

const char *SignalContext::Describe() const {}

fd_t ReserveStandardFds(fd_t fd) {}

bool ShouldMockFailureToOpen(const char *path) {}

bool OpenReadsVaArgs(int oflag) {}

#  if SANITIZER_LINUX && !SANITIZER_ANDROID && !SANITIZER_GO
int GetNamedMappingFd(const char *name, uptr size, int *flags) {}
#else
int GetNamedMappingFd(const char *name, uptr size, int *flags) {
  return -1;
}
#endif

#if SANITIZER_ANDROID
#define PR_SET_VMA
#define PR_SET_VMA_ANON_NAME
void DecorateMapping(uptr addr, uptr size, const char *name) {
  if (!common_flags()->decorate_proc_maps || !name)
    return;
  internal_prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, addr, size, (uptr)name);
}
#else
void DecorateMapping(uptr addr, uptr size, const char *name) {}
#endif

uptr MmapNamed(void *addr, uptr length, int prot, int flags, const char *name) {}


} // namespace __sanitizer

#endif // SANITIZER_POSIX