mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Reduce memory needed by ASAN morgue
This commit is contained in:
parent
d5a37de435
commit
ed485391da
5 changed files with 34 additions and 10 deletions
|
@ -594,7 +594,10 @@ static void __asan_deallocate(char *p, long kind) {
|
|||
WRITE64BE(p + c - 8, kind);
|
||||
__asan_poison((uintptr_t)p, c - 8, kind);
|
||||
if (weaken(dlfree)) {
|
||||
weaken(dlfree)(__asan_morgue_add(p));
|
||||
if (c <= FRAMESIZE) {
|
||||
p = __asan_morgue_add(p);
|
||||
}
|
||||
weaken(dlfree)(p);
|
||||
}
|
||||
} else {
|
||||
__asan_report_heap_fault(p, n);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @param mode may be _IOFBF, _IOLBF, or _IONBF
|
||||
* @param buf may optionally be non-NULL to set the stream's underlying
|
||||
* buffer, which the stream will own, but won't free, otherwise the
|
||||
* buffer which the caller still owns and won't free, otherwise the
|
||||
* existing buffer is used
|
||||
* @param size is ignored if buf is NULL
|
||||
* @return 0 on success or -1 on error
|
||||
|
|
16
third_party/dlmalloc/dlmalloc.c
vendored
16
third_party/dlmalloc/dlmalloc.c
vendored
|
@ -1,6 +1,7 @@
|
|||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/sysinfo.h"
|
||||
#include "libc/dce.h"
|
||||
|
@ -26,6 +27,8 @@ STATIC_YOINK("_init_dlmalloc");
|
|||
hidden struct MallocState g_dlmalloc[1];
|
||||
hidden struct MallocParams g_mparams;
|
||||
|
||||
#define MALLOC_BIGTRACE 0
|
||||
|
||||
/**
|
||||
* Acquires more system memory for dlmalloc.
|
||||
*
|
||||
|
@ -37,6 +40,19 @@ hidden struct MallocParams g_mparams;
|
|||
*/
|
||||
static void *dlmalloc_requires_more_vespene_gas(size_t size) {
|
||||
char *p;
|
||||
#if MALLOC_BIGTRACE
|
||||
struct MallocStats res = dlmalloc_stats(g_dlmalloc);
|
||||
(dprintf)(2, "\n");
|
||||
(dprintf)(2, "DLMALLOC REQUIRES MORE VESPENE GAS\n");
|
||||
(dprintf)(2, "request = %',10zu\n", size);
|
||||
(dprintf)(2, "max system bytes = %',10zu\n", res.maxfp);
|
||||
(dprintf)(2, "system bytes = %',10zu\n", res.fp);
|
||||
(dprintf)(2, "in use bytes = %',10zu\n", res.used);
|
||||
if (weaken(PrintBacktraceUsingSymbols) && weaken(GetSymbolTable)) {
|
||||
weaken(PrintBacktraceUsingSymbols)(2, __builtin_frame_address(0),
|
||||
weaken(GetSymbolTable)());
|
||||
}
|
||||
#endif
|
||||
if ((p = mapanon(size)) != MAP_FAILED) {
|
||||
if (weaken(__asan_poison)) {
|
||||
weaken(__asan_poison)((uintptr_t)p, size, kAsanHeapFree);
|
||||
|
|
12
third_party/dlmalloc/dlmalloc.internal.h
vendored
12
third_party/dlmalloc/dlmalloc.internal.h
vendored
|
@ -684,7 +684,7 @@ def bad(i):
|
|||
while i < len(lines):
|
||||
if lines[i].startswith(('BIRTH', 'DEATH')):
|
||||
break
|
||||
print lines[i]
|
||||
print(lines[i])
|
||||
i += 1
|
||||
for i, line in enumerate(lines):
|
||||
i += 1
|
||||
|
@ -694,22 +694,22 @@ for i, line in enumerate(lines):
|
|||
b = int(x[1], 16)
|
||||
if b in d:
|
||||
if d[b] < 0:
|
||||
print "OH NO", i, d[b]
|
||||
print("OH NO", i, d[b])
|
||||
else:
|
||||
d[b] = -d[b]
|
||||
else:
|
||||
print "wut", i
|
||||
print("wut", i)
|
||||
elif x[0] == 'BIRTH':
|
||||
b = int(x[1], 16)
|
||||
if b in d:
|
||||
if d[b] > 0:
|
||||
print "bad malloc", i, d[b]
|
||||
print("bad malloc", i, d[b])
|
||||
d[b] = i
|
||||
else:
|
||||
d[b] = i
|
||||
for k,v in d.items():
|
||||
if v > 0:
|
||||
print "unfreed", v
|
||||
print("unfreed", v)
|
||||
bad(v)
|
||||
*/
|
||||
#define MALLOC_TRACE 0
|
||||
|
@ -959,7 +959,7 @@ extern struct MallocParams g_mparams;
|
|||
#else /* GNUC */
|
||||
#define RTCHECK(e) (e)
|
||||
#endif /* GNUC */
|
||||
#else /* !IsTrustworthy() */
|
||||
#else /* !IsTrustworthy() */
|
||||
#define RTCHECK(e) (1)
|
||||
#endif /* !IsTrustworthy() */
|
||||
|
||||
|
|
9
third_party/mbedtls/test/lib.c
vendored
9
third_party/mbedtls/test/lib.c
vendored
|
@ -23,6 +23,7 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/rand/rand.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/stdio/append.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
@ -72,10 +73,13 @@ static uint64_t Rando(void) {
|
|||
}
|
||||
|
||||
int mbedtls_test_platform_setup(void) {
|
||||
char *p;
|
||||
int ret = 0;
|
||||
showcrashreports();
|
||||
setvbuf(stdout, malloc(BUFSIZ), _IOLBF, BUFSIZ);
|
||||
setvbuf(stderr, malloc(BUFSIZ), _IOLBF, BUFSIZ);
|
||||
setvbuf(stdout, (p = malloc(BUFSIZ)), _IOLBF, BUFSIZ);
|
||||
__cxa_atexit(free, p, 0);
|
||||
setvbuf(stderr, (p = malloc(BUFSIZ)), _IOLBF, BUFSIZ);
|
||||
__cxa_atexit(free, p, 0);
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
ret = mbedtls_platform_setup(&platform_ctx);
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
@ -90,6 +94,7 @@ void mbedtls_test_platform_teardown(void) {
|
|||
|
||||
wontreturn void exit(int rc) {
|
||||
if (rc) fwrite(output, 1, appendz(output).i, stderr);
|
||||
free(output);
|
||||
__cxa_finalize(0);
|
||||
_Exit(rc);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue