Changeset View
Changeset View
Standalone View
Standalone View
stand/libsa/zalloc_malloc.c
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
#ifdef malloc | #ifdef malloc | ||||
#undef malloc | #undef malloc | ||||
#undef free | #undef free | ||||
#endif | #endif | ||||
static void *Malloc_align(size_t, size_t); | static void *Malloc_align(size_t, size_t); | ||||
#ifndef MIN | |||||
# define MIN(a,b) ((a) <= (b)) ? (a) : (b) | |||||
#endif | |||||
void * | void * | ||||
Malloc(size_t bytes, const char *file __unused, int line __unused) | Malloc(size_t bytes, const char *file __unused, int line __unused) | ||||
{ | { | ||||
return (Malloc_align(bytes, 1)); | return (Malloc_align(bytes, 1)); | ||||
} | } | ||||
void * | void * | ||||
Memalign(size_t alignment, size_t bytes, const char *file __unused, | Memalign(size_t alignment, size_t bytes, const char *file __unused, | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | if (ptr != NULL) { | ||||
if (file == NULL) | if (file == NULL) | ||||
file = "unknown"; | file = "unknown"; | ||||
#ifdef USEGUARD | #ifdef USEGUARD | ||||
if (res->ga_Magic == GAFREE) { | if (res->ga_Magic == GAFREE) { | ||||
printf("free: duplicate free @ %p from %s:%d\n", | printf("free: duplicate free @ %p from %s:%d\n", | ||||
ptr, file, line); | ptr, file, line); | ||||
return; | return; | ||||
} | } | ||||
if (res->ga_Magic != GAMAGIC) | if (res->ga_Magic != GAMAGIC) { | ||||
size_t dump_bytes; | |||||
dump_bytes = MIN((ptr - MallocPool.mp_Base), 512); | |||||
hexdump(ptr - dump_bytes, dump_bytes); | |||||
panic("free: guard1 fail @ %p from %s:%d", | panic("free: guard1 fail @ %p from %s:%d", | ||||
ptr, file, line); | ptr, file, line); | ||||
} | |||||
res->ga_Magic = GAFREE; | res->ga_Magic = GAFREE; | ||||
#endif | #endif | ||||
#ifdef USEENDGUARD | #ifdef USEENDGUARD | ||||
if (*((signed char *)res + res->ga_Bytes - 1) == -1) { | if (*((signed char *)res + res->ga_Bytes - 1) == -1) { | ||||
printf("free: duplicate2 free @ %p from %s:%d\n", | printf("free: duplicate2 free @ %p from %s:%d\n", | ||||
ptr, file, line); | ptr, file, line); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |