Path: blob/main/contrib/llvm-project/compiler-rt/lib/memprof/memprof_interceptors_memintrinsics.cpp
35236 views
//===-- memprof_interceptors_memintrinsics.cpp ---------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===---------------------------------------------------------------------===//7//8// This file is a part of MemProfiler, a memory profiler.9//10// MemProf versions of memcpy, memmove, and memset.11//===---------------------------------------------------------------------===//1213#define SANITIZER_COMMON_NO_REDEFINE_BUILTINS1415#include "memprof_interceptors_memintrinsics.h"1617#include "memprof_interceptors.h"18#include "memprof_stack.h"1920using namespace __memprof;2122// memcpy is called during __memprof_init() from the internals of printf(...).23// We do not treat memcpy with to==from as a bug.24// See http://llvm.org/bugs/show_bug.cgi?id=11763.25#define MEMPROF_MEMCPY_IMPL(to, from, size) \26do { \27if (UNLIKELY(!memprof_inited)) \28return internal_memcpy(to, from, size); \29if (memprof_init_is_running) { \30return REAL(memcpy)(to, from, size); \31} \32ENSURE_MEMPROF_INITED(); \33MEMPROF_READ_RANGE(from, size); \34MEMPROF_WRITE_RANGE(to, size); \35return REAL(memcpy)(to, from, size); \36} while (0)3738// memset is called inside Printf.39#define MEMPROF_MEMSET_IMPL(block, c, size) \40do { \41if (UNLIKELY(!memprof_inited)) \42return internal_memset(block, c, size); \43if (memprof_init_is_running) { \44return REAL(memset)(block, c, size); \45} \46ENSURE_MEMPROF_INITED(); \47MEMPROF_WRITE_RANGE(block, size); \48return REAL(memset)(block, c, size); \49} while (0)5051#define MEMPROF_MEMMOVE_IMPL(to, from, size) \52do { \53if (UNLIKELY(!memprof_inited)) \54return internal_memmove(to, from, size); \55ENSURE_MEMPROF_INITED(); \56MEMPROF_READ_RANGE(from, size); \57MEMPROF_WRITE_RANGE(to, size); \58return internal_memmove(to, from, size); \59} while (0)6061#define COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, to, from, size) \62do { \63MEMPROF_INTERCEPTOR_ENTER(ctx, memmove); \64MEMPROF_MEMMOVE_IMPL(to, from, size); \65} while (false)6667#define COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, to, from, size) \68do { \69MEMPROF_INTERCEPTOR_ENTER(ctx, memcpy); \70MEMPROF_MEMCPY_IMPL(to, from, size); \71} while (false)7273#define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size) \74do { \75MEMPROF_INTERCEPTOR_ENTER(ctx, memset); \76MEMPROF_MEMSET_IMPL(block, c, size); \77} while (false)7879#include "sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc"8081void *__memprof_memcpy(void *to, const void *from, uptr size) {82MEMPROF_MEMCPY_IMPL(to, from, size);83}8485void *__memprof_memset(void *block, int c, uptr size) {86MEMPROF_MEMSET_IMPL(block, c, size);87}8889void *__memprof_memmove(void *to, const void *from, uptr size) {90MEMPROF_MEMMOVE_IMPL(to, from, size);91}929394