mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-01-14 00:27:59 +08:00
merge from dev
This commit is contained in:
commit
97f56b1e08
@ -24,7 +24,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||
#define mi_attr_noexcept
|
||||
#endif
|
||||
|
||||
#if (__cplusplus >= 201703)
|
||||
#if defined(__cplusplus) && (__cplusplus >= 201703)
|
||||
#define mi_decl_nodiscard [[nodiscard]]
|
||||
#elif (__GNUC__ >= 4) || defined(__clang__) // includes clang, icc, and clang-cl
|
||||
#define mi_decl_nodiscard __attribute__((warn_unused_result))
|
||||
|
@ -20,6 +20,10 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||
#include <string.h> // memcpy
|
||||
#include <stdlib.h> // getenv
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4996) // getenv _wgetenv
|
||||
#endif
|
||||
|
||||
#ifndef EINVAL
|
||||
#define EINVAL 22
|
||||
#endif
|
||||
@ -111,8 +115,7 @@ mi_decl_restrict unsigned char* mi_mbsdup(const unsigned char* s) mi_attr_noexc
|
||||
int mi_dupenv_s(char** buf, size_t* size, const char* name) mi_attr_noexcept {
|
||||
if (buf==NULL || name==NULL) return EINVAL;
|
||||
if (size != NULL) *size = 0;
|
||||
#pragma warning(suppress:4996)
|
||||
char* p = getenv(name);
|
||||
char* p = getenv(name); // mscver warning 4996
|
||||
if (p==NULL) {
|
||||
*buf = NULL;
|
||||
}
|
||||
@ -132,8 +135,7 @@ int mi_wdupenv_s(unsigned short** buf, size_t* size, const unsigned short* name)
|
||||
*buf = NULL;
|
||||
return EINVAL;
|
||||
#else
|
||||
#pragma warning(suppress:4996)
|
||||
unsigned short* p = (unsigned short*)_wgetenv((const wchar_t*)name);
|
||||
unsigned short* p = (unsigned short*)_wgetenv((const wchar_t*)name); // msvc warning 4996
|
||||
if (p==NULL) {
|
||||
*buf = NULL;
|
||||
}
|
||||
|
@ -14,6 +14,11 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||
#include <ctype.h> // toupper
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4996) // strncpy, strncat
|
||||
#endif
|
||||
|
||||
|
||||
static uintptr_t mi_max_error_count = 16; // stop outputting errors after this
|
||||
|
||||
static void mi_add_stderr_output();
|
||||
@ -217,7 +222,6 @@ static void mi_out_buf_stderr(const char* msg, void* arg) {
|
||||
|
||||
// Should be atomic but gives errors on many platforms as generally we cannot cast a function pointer to a uintptr_t.
|
||||
// For now, don't register output from multiple threads.
|
||||
#pragma warning(suppress:4180)
|
||||
static mi_output_fun* volatile mi_out_default; // = NULL
|
||||
static _Atomic(void*) mi_out_arg; // = NULL
|
||||
|
||||
@ -391,13 +395,11 @@ void _mi_error_message(int err, const char* fmt, ...) {
|
||||
|
||||
static void mi_strlcpy(char* dest, const char* src, size_t dest_size) {
|
||||
dest[0] = 0;
|
||||
#pragma warning(suppress:4996)
|
||||
strncpy(dest, src, dest_size - 1);
|
||||
dest[dest_size - 1] = 0;
|
||||
}
|
||||
|
||||
static void mi_strlcat(char* dest, const char* src, size_t dest_size) {
|
||||
#pragma warning(suppress:4996)
|
||||
strncat(dest, src, dest_size - 1);
|
||||
dest[dest_size - 1] = 0;
|
||||
}
|
||||
@ -424,7 +426,7 @@ static bool mi_getenv(const char* name, char* result, size_t result_size) {
|
||||
#elif !defined(MI_USE_ENVIRON) || (MI_USE_ENVIRON!=0)
|
||||
// On Posix systemsr use `environ` to acces environment variables
|
||||
// even before the C runtime is initialized.
|
||||
#if defined(__APPLE__)
|
||||
#if defined(__APPLE__) && defined(__has_include) && __has_include(<crt_externs.h>)
|
||||
#include <crt_externs.h>
|
||||
static char** mi_get_environ(void) {
|
||||
return (*_NSGetEnviron());
|
||||
|
5
src/os.c
5
src/os.c
@ -22,6 +22,10 @@ terms of the MIT license. A copy of the license can be found in the file
|
||||
|
||||
#include <string.h> // strerror
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4996) // strerror
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <Windows.h>
|
||||
@ -229,7 +233,6 @@ static bool mi_os_mem_free(void* addr, size_t size, bool was_committed, mi_stats
|
||||
if (was_committed) _mi_stat_decrease(&stats->committed, size);
|
||||
_mi_stat_decrease(&stats->reserved, size);
|
||||
if (err) {
|
||||
#pragma warning(suppress:4996)
|
||||
_mi_warning_message("munmap failed: %s, addr 0x%8li, size %lu\n", strerror(errno), (size_t)addr, size);
|
||||
return false;
|
||||
}
|
||||
|
@ -176,6 +176,8 @@ static void double_free2();
|
||||
static void corrupt_free();
|
||||
static void block_overflow1();
|
||||
static void invalid_free();
|
||||
static void test_aslr(void);
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
@ -185,7 +187,8 @@ int main() {
|
||||
// double_free1();
|
||||
// double_free2();
|
||||
// corrupt_free();
|
||||
//block_overflow1();
|
||||
// block_overflow1();
|
||||
// test_aslr();
|
||||
invalid_free();
|
||||
|
||||
void* p1 = malloc(78);
|
||||
@ -287,3 +290,10 @@ static void corrupt_free() {
|
||||
malloc(SZ);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_aslr(void) {
|
||||
void* p[256];
|
||||
p[0] = malloc(378200);
|
||||
p[1] = malloc(1134626);
|
||||
printf("p1: %p, p2: %p\n", p[0], p[1]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user