llvm/compiler-rt/lib/scudo/standalone/linux.cpp

//===-- linux.cpp -----------------------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "platform.h"

#if SCUDO_LINUX

#include "common.h"
#include "internal_defs.h"
#include "linux.h"
#include "mutex.h"
#include "report_linux.h"
#include "string_utils.h"

#include <errno.h>
#include <fcntl.h>
#include <linux/futex.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

#if SCUDO_ANDROID
#include <sys/prctl.h>
// Definitions of prctl arguments to set a vma name in Android kernels.
#define ANDROID_PR_SET_VMA
#define ANDROID_PR_SET_VMA_ANON_NAME
#endif

namespace scudo {

#if !defined(SCUDO_PAGE_SIZE)
// This function is only used when page size is not hard-coded.
uptr getPageSize() {}
#endif

void NORETURN die() {}

// TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
void *map(void *Addr, uptr Size, UNUSED const char *Name, uptr Flags,
          UNUSED MapPlatformData *Data) {}

// TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
void unmap(void *Addr, uptr Size, UNUSED uptr Flags,
           UNUSED MapPlatformData *Data) {}

// TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
void setMemoryPermission(uptr Addr, uptr Size, uptr Flags,
                         UNUSED MapPlatformData *Data) {}

// TODO: Will be deprecated. Use the interfaces in MemMapLinux instead.
void releasePagesToOS(uptr BaseAddress, uptr Offset, uptr Size,
                      UNUSED MapPlatformData *Data) {}

// Calling getenv should be fine (c)(tm) at any time.
const char *getEnv(const char *Name) {}

namespace {
enum State : u32 {};
}

bool HybridMutex::tryLock() {}

// The following is based on https://akkadia.org/drepper/futex.pdf.
void HybridMutex::lockSlow() {}

void HybridMutex::unlock() {}

void HybridMutex::assertHeldImpl() {}

u64 getMonotonicTime() {}

u64 getMonotonicTimeFast() {}

u32 getNumberOfCPUs() {}

u32 getThreadID() {}

// Blocking is possibly unused if the getrandom block is not compiled in.
bool getRandom(void *Buffer, uptr Length, UNUSED bool Blocking) {}

// Allocation free syslog-like API.
extern "C" WEAK int async_safe_write_log(int pri, const char *tag,
                                         const char *msg);

void outputRaw(const char *Buffer) {}

extern "C" WEAK void android_set_abort_message(const char *);

void setAbortMessage(const char *Message) {}

} // namespace scudo

#endif // SCUDO_LINUX