llvm/compiler-rt/lib/memprof/memprof_interceptors.cpp

//===-- memprof_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 MemProfiler, a memory profiler.
//
// Intercept various libc functions.
//===----------------------------------------------------------------------===//

#include "memprof_interceptors.h"
#include "memprof_allocator.h"
#include "memprof_internal.h"
#include "memprof_mapping.h"
#include "memprof_stack.h"
#include "memprof_stats.h"
#include "sanitizer_common/sanitizer_libc.h"
#include "sanitizer_common/sanitizer_posix.h"

namespace __memprof {

#define MEMPROF_READ_STRING(s, n)

static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {}

void SetThreadName(const char *name) {}

int OnExit() {}

} // namespace __memprof

// ---------------------- Wrappers ---------------- {{{1
usingnamespace__memprof;

DECLARE_REAL_AND_INTERCEPTOR()
DECLARE_REAL_AND_INTERCEPTOR()

#define COMMON_INTERCEPT_FUNCTION_VER(name, ver)
#define COMMON_INTERCEPT_FUNCTION_VER_UNVERSIONED_FALLBACK(name, ver)
#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)
// Should be memprofThreadRegistry().SetThreadNameByUserId(thread, name)
// But memprof does not remember UserId's for threads (pthread_t);
// and remembers all ever existed threads, so the linear search by UserId
// can be slow.
#define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name)
#define COMMON_INTERCEPTOR_BLOCK_REAL(name)
#define COMMON_INTERCEPTOR_ON_EXIT(ctx)
#define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle)
#define COMMON_INTERCEPTOR_LIBRARY_UNLOADED()
#define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED
#define COMMON_INTERCEPTOR_GET_TLS_RANGE(begin, end)

#include "sanitizer_common/sanitizer_common_interceptors.inc"

#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"

struct ThreadStartParam {};

static thread_return_t THREAD_CALLING_CONV memprof_thread_start(void *arg) {}

INTERCEPTOR(int, pthread_create, void *thread, void *attr,
            void *(*start_routine)(void *), void *arg) {}

INTERCEPTOR(int, pthread_join, void *t, void **arg) {}

DEFINE_INTERNAL_PTHREAD_FUNCTIONS

INTERCEPTOR(char *, index, const char *string, int c)
ALIAS(WRAP(strchr));

// For both strcat() and strncat() we need to check the validity of |to|
// argument irrespective of the |from| length.
INTERCEPTOR(char *, strcat, char *to, const char *from) {}

INTERCEPTOR(char *, strncat, char *to, const char *from, uptr size) {}

INTERCEPTOR(char *, strcpy, char *to, const char *from) {}

INTERCEPTOR(char *, strdup, const char *s) {}

INTERCEPTOR(char *, __strdup, const char *s) {}

INTERCEPTOR(char *, strncpy, char *to, const char *from, uptr size) {}

INTERCEPTOR(long, strtol, const char *nptr, char **endptr, int base) {}

INTERCEPTOR(int, atoi, const char *nptr) {}

INTERCEPTOR(long, atol, const char *nptr) {}

INTERCEPTOR(long long, strtoll, const char *nptr, char **endptr, int base) {}

INTERCEPTOR(long long, atoll, const char *nptr) {}

// ---------------------- InitializeMemprofInterceptors ---------------- {{{1
namespace __memprof {
void InitializeMemprofInterceptors() {}

} // namespace __memprof