Reduce memory needed by ASAN morgue

This commit is contained in:
Justine Tunney 2021-08-19 09:24:26 -07:00
parent d5a37de435
commit ed485391da
5 changed files with 34 additions and 10 deletions

View file

@ -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);

View file

@ -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() */