mirror of
https://github.com/git-for-windows/git.git
synced 2026-03-20 08:15:39 -05:00
This commit imports mimalloc's source code as per v2.0.9, fetched from the tag at https://github.com/microsoft/mimalloc. The .c files are from the src/ subdirectory, and the .h files from the include/ subdirectory. We will subsequently modify the source code to accommodate building within Git's context. Since we plan on using the `mi_*()` family of functions, we skip the C++-specific source code, some POSIX compliant functions to interact with mimalloc, and the code that wants to support auto-magic overriding of the `malloc()` function (mimalloc-new-delete.h, alloc-posix.c, mimalloc-override.h, alloc-override.c, alloc-override-osx.c, alloc-override-win.c and static.c). To appease the `check-whitespace` job of Git's Continuous Integration, this commit was washed one time via `git rebase --whitespace=fix`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
63 lines
2.5 KiB
C
63 lines
2.5 KiB
C
/* ----------------------------------------------------------------------------
|
|
Copyright (c) 2018-2021, Microsoft Research, Daan Leijen
|
|
This is free software; you can redistribute it and/or modify it under the
|
|
terms of the MIT license. A copy of the license can be found in the file
|
|
"LICENSE" at the root of this distribution.
|
|
-----------------------------------------------------------------------------*/
|
|
#pragma once
|
|
#ifndef MIMALLOC_TRACK_H
|
|
#define MIMALLOC_TRACK_H
|
|
|
|
// ------------------------------------------------------
|
|
// Track memory ranges with macros for tools like Valgrind
|
|
// address sanitizer, or other memory checkers.
|
|
// ------------------------------------------------------
|
|
|
|
#if MI_VALGRIND
|
|
|
|
#define MI_TRACK_ENABLED 1
|
|
#define MI_TRACK_TOOL "valgrind"
|
|
|
|
#include <valgrind/valgrind.h>
|
|
#include <valgrind/memcheck.h>
|
|
|
|
#define mi_track_malloc(p,size,zero) VALGRIND_MALLOCLIKE_BLOCK(p,size,MI_PADDING_SIZE /*red zone*/,zero)
|
|
#define mi_track_resize(p,oldsize,newsize) VALGRIND_RESIZEINPLACE_BLOCK(p,oldsize,newsize,MI_PADDING_SIZE /*red zone*/)
|
|
#define mi_track_free(p) VALGRIND_FREELIKE_BLOCK(p,MI_PADDING_SIZE /*red zone*/)
|
|
#define mi_track_free_size(p,_size) mi_track_free(p)
|
|
#define mi_track_mem_defined(p,size) VALGRIND_MAKE_MEM_DEFINED(p,size)
|
|
#define mi_track_mem_undefined(p,size) VALGRIND_MAKE_MEM_UNDEFINED(p,size)
|
|
#define mi_track_mem_noaccess(p,size) VALGRIND_MAKE_MEM_NOACCESS(p,size)
|
|
|
|
#elif MI_ASAN
|
|
|
|
#define MI_TRACK_ENABLED 1
|
|
#define MI_TRACK_TOOL "asan"
|
|
|
|
#include <sanitizer/asan_interface.h>
|
|
|
|
#define mi_track_malloc(p,size,zero) ASAN_UNPOISON_MEMORY_REGION(p,size)
|
|
#define mi_track_resize(p,oldsize,newsize) ASAN_POISON_MEMORY_REGION(p,oldsize); ASAN_UNPOISON_MEMORY_REGION(p,newsize)
|
|
#define mi_track_free(p) ASAN_POISON_MEMORY_REGION(p,mi_usable_size(p))
|
|
#define mi_track_free_size(p,size) ASAN_POISON_MEMORY_REGION(p,size)
|
|
#define mi_track_mem_defined(p,size) ASAN_UNPOISON_MEMORY_REGION(p,size)
|
|
#define mi_track_mem_undefined(p,size) ASAN_UNPOISON_MEMORY_REGION(p,size)
|
|
#define mi_track_mem_noaccess(p,size) ASAN_POISON_MEMORY_REGION(p,size)
|
|
|
|
#else
|
|
|
|
#define MI_TRACK_ENABLED 0
|
|
#define MI_TRACK_TOOL "none"
|
|
|
|
#define mi_track_malloc(p,size,zero)
|
|
#define mi_track_resize(p,oldsize,newsize)
|
|
#define mi_track_free(p)
|
|
#define mi_track_free_size(p,_size)
|
|
#define mi_track_mem_defined(p,size)
|
|
#define mi_track_mem_undefined(p,size)
|
|
#define mi_track_mem_noaccess(p,size)
|
|
|
|
#endif
|
|
|
|
#endif
|