small updates

This commit is contained in:
daanx 2024-12-11 14:29:06 -08:00
parent 565656919e
commit ab53a73cbd
5 changed files with 74 additions and 71 deletions

View file

@ -5,8 +5,8 @@ terms of the MIT license. A copy of the license can be found in the file
"LICENSE" at the root of this distribution. "LICENSE" at the root of this distribution.
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#pragma once #pragma once
#ifndef MIMALLOC_ATOMIC_H #ifndef MI_ATOMIC_H
#define MIMALLOC_ATOMIC_H #define MI_ATOMIC_H
// include windows.h or pthreads.h // include windows.h or pthreads.h
#if defined(_WIN32) #if defined(_WIN32)
@ -509,4 +509,4 @@ static inline void mi_lock_done(mi_lock_t* lock) {
#endif // __MIMALLOC_ATOMIC_H #endif // MI_ATOMIC_H

View file

@ -5,8 +5,8 @@ terms of the MIT license. A copy of the license can be found in the file
"LICENSE" at the root of this distribution. "LICENSE" at the root of this distribution.
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#pragma once #pragma once
#ifndef MIMALLOC_INTERNAL_H #ifndef MI_INTERNAL_H
#define MIMALLOC_INTERNAL_H #define MI_INTERNAL_H
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -239,27 +239,42 @@ bool _mi_page_is_valid(mi_page_t* page);
#endif #endif
// ------------------------------------------------------
// Debug
// ------------------------------------------------------
#if !defined(MI_DEBUG_UNINIT)
#define MI_DEBUG_UNINIT (0xD0)
#endif
#if !defined(MI_DEBUG_FREED)
#define MI_DEBUG_FREED (0xDF)
#endif
#if !defined(MI_DEBUG_PADDING)
#define MI_DEBUG_PADDING (0xDE)
#endif
/* ----------------------------------------------------------- /* -----------------------------------------------------------
Error codes passed to `_mi_fatal_error` Assertions
All are recoverable but EFAULT is a serious error and aborts by default in secure mode.
For portability define undefined error codes using common Unix codes:
<https://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html>
----------------------------------------------------------- */ ----------------------------------------------------------- */
#include <errno.h>
#ifndef EAGAIN // double free #if (MI_DEBUG)
#define EAGAIN (11) // use our own assertion to print without memory allocation
void _mi_assert_fail(const char* assertion, const char* fname, unsigned int line, const char* func);
#define mi_assert(expr) ((expr) ? (void)0 : _mi_assert_fail(#expr,__FILE__,__LINE__,__func__))
#else
#define mi_assert(x)
#endif #endif
#ifndef ENOMEM // out of memory
#define ENOMEM (12) #if (MI_DEBUG>1)
#define mi_assert_internal mi_assert
#else
#define mi_assert_internal(x)
#endif #endif
#ifndef EFAULT // corrupted free-list or meta-data
#define EFAULT (14) #if (MI_DEBUG>2)
#endif #define mi_assert_expensive mi_assert
#ifndef EINVAL // trying to free an invalid pointer #else
#define EINVAL (22) #define mi_assert_expensive(x)
#endif
#ifndef EOVERFLOW // count*size overflow
#define EOVERFLOW (75)
#endif #endif
@ -1023,4 +1038,4 @@ static inline void _mi_memzero_aligned(void* dst, size_t n) {
} }
#endif #endif // MI_INTERNAL_H

View file

@ -5,8 +5,8 @@ terms of the MIT license. A copy of the license can be found in the file
"LICENSE" at the root of this distribution. "LICENSE" at the root of this distribution.
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#pragma once #pragma once
#ifndef MIMALLOC_PRIM_H #ifndef MI_PRIM_H
#define MIMALLOC_PRIM_H #define MI_PRIM_H
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -370,4 +370,4 @@ static inline mi_heap_t* mi_prim_get_default_heap(void) {
#endif // mi_prim_get_default_heap() #endif // mi_prim_get_default_heap()
#endif // MIMALLOC_PRIM_H #endif // MI_PRIM_H

View file

@ -5,8 +5,8 @@ terms of the MIT license. A copy of the license can be found in the file
"LICENSE" at the root of this distribution. "LICENSE" at the root of this distribution.
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#pragma once #pragma once
#ifndef MIMALLOC_TRACK_H #ifndef MI_TRACK_H
#define MIMALLOC_TRACK_H #define MI_TRACK_H
/* ------------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------------
Track memory ranges with macros for tools like Valgrind address sanitizer, or other memory checkers. Track memory ranges with macros for tools like Valgrind address sanitizer, or other memory checkers.
@ -142,4 +142,4 @@ defined, undefined, or not accessible at all:
} }
#endif #endif
#endif #endif // MI_TRACK_H

View file

@ -5,8 +5,8 @@ terms of the MIT license. A copy of the license can be found in the file
"LICENSE" at the root of this distribution. "LICENSE" at the root of this distribution.
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#pragma once #pragma once
#ifndef MIMALLOC_TYPES_H #ifndef MI_TYPES_H
#define MIMALLOC_TYPES_H #define MI_TYPES_H
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// This file contains the main type definitions for mimalloc: // This file contains the main type definitions for mimalloc:
@ -21,12 +21,9 @@ terms of the MIT license. A copy of the license can be found in the file
#include <stddef.h> // ptrdiff_t #include <stddef.h> // ptrdiff_t
#include <stdint.h> // uintptr_t, uint16_t, etc #include <stdint.h> // uintptr_t, uint16_t, etc
#include "bits.h" // bit ops, size defines #include <errno.h> // error codes
#include "atomic.h" // _Atomic #include "bits.h" // size defines (MI_INTPTR_SIZE etc), bit operations
#include "atomic.h" // _Atomic primitives
#ifdef _MSC_VER
#pragma warning(disable:4214) // bitfield is not int
#endif
// Minimal alignment necessary. On most platforms 16 bytes are needed // Minimal alignment necessary. On most platforms 16 bytes are needed
// due to SSE registers for example. This must be at least `sizeof(void*)` // due to SSE registers for example. This must be at least `sizeof(void*)`
@ -351,6 +348,7 @@ typedef enum mi_page_kind_e {
// ------------------------------------------------------ // ------------------------------------------------------
// Heaps // Heaps
//
// Provide first-class heaps to allocate from. // Provide first-class heaps to allocate from.
// A heap just owns a set of pages for allocation and // A heap just owns a set of pages for allocation and
// can only be allocate/reallocate from the thread that created it. // can only be allocate/reallocate from the thread that created it.
@ -426,40 +424,6 @@ struct mi_heap_s {
}; };
// ------------------------------------------------------
// Debug
// ------------------------------------------------------
#if !defined(MI_DEBUG_UNINIT)
#define MI_DEBUG_UNINIT (0xD0)
#endif
#if !defined(MI_DEBUG_FREED)
#define MI_DEBUG_FREED (0xDF)
#endif
#if !defined(MI_DEBUG_PADDING)
#define MI_DEBUG_PADDING (0xDE)
#endif
#if (MI_DEBUG)
// use our own assertion to print without memory allocation
void _mi_assert_fail(const char* assertion, const char* fname, unsigned int line, const char* func );
#define mi_assert(expr) ((expr) ? (void)0 : _mi_assert_fail(#expr,__FILE__,__LINE__,__func__))
#else
#define mi_assert(x)
#endif
#if (MI_DEBUG>1)
#define mi_assert_internal mi_assert
#else
#define mi_assert_internal(x)
#endif
#if (MI_DEBUG>2)
#define mi_assert_expensive mi_assert
#else
#define mi_assert_expensive(x)
#endif
// ------------------------------------------------------ // ------------------------------------------------------
// Statistics // Statistics
// ------------------------------------------------------ // ------------------------------------------------------
@ -575,4 +539,28 @@ struct mi_tld_s {
mi_stats_t stats; // statistics mi_stats_t stats; // statistics
}; };
/* -----------------------------------------------------------
Error codes passed to `_mi_fatal_error`
All are recoverable but EFAULT is a serious error and aborts by default in secure mode.
For portability define undefined error codes using common Unix codes:
<https://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html>
----------------------------------------------------------- */
#ifndef EAGAIN // double free
#define EAGAIN (11)
#endif #endif
#ifndef ENOMEM // out of memory
#define ENOMEM (12)
#endif
#ifndef EFAULT // corrupted free-list or meta-data
#define EFAULT (14)
#endif
#ifndef EINVAL // trying to free an invalid pointer
#define EINVAL (22)
#endif
#ifndef EOVERFLOW // count*size overflow
#define EOVERFLOW (75)
#endif
#endif // MI_TYPES_H