Add malloc logging tool

STATIC_YOINK("enable_memory_log");
This commit is contained in:
Justine Tunney 2022-05-26 23:17:19 -07:00
parent 7e9fb0a9f1
commit cb67223051
25 changed files with 502 additions and 78 deletions

View file

@ -0,0 +1,27 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/testlib/testlib.h"
// pcmpestrm
/* TEST(pcmpstr, test) { */
/* EXPECT_EQ(0, pcmpstr()); */
/* EXPECT_STREQ("", pcmpstr()); */
/* } */

View file

@ -357,12 +357,7 @@ int count;
void *ptrs[N];
void BenchUnmap(void) {
int i;
for (i = 0; i < count; ++i) {
if (ptrs[i]) {
ASSERT_EQ(0, munmap(ptrs[i], FRAMESIZE));
}
}
ASSERT_EQ(0, munmap(ptrs[count++], FRAMESIZE));
}
void BenchMmapPrivate(void) {
@ -375,16 +370,11 @@ void BenchMmapPrivate(void) {
BENCH(mmap, bench) {
EZBENCH2("mmap", donothing, BenchMmapPrivate());
BenchUnmap();
EZBENCH2("munmap", donothing, BenchUnmap());
}
void BenchUnmapLinux(void) {
int i;
for (i = 0; i < count; ++i) {
if (ptrs[i]) {
ASSERT_EQ(0, LinuxMunmap(ptrs[i], FRAMESIZE));
}
}
ASSERT_EQ(0, LinuxMunmap(ptrs[count++], FRAMESIZE));
}
void BenchMmapPrivateLinux(void) {
@ -399,5 +389,5 @@ BENCH(mmap, benchLinux) {
void *p;
if (!IsLinux()) return;
EZBENCH2("mmap (linux)", donothing, BenchMmapPrivateLinux());
BenchUnmapLinux();
EZBENCH2("munmap (linux)", donothing, BenchUnmapLinux());
}

View file

@ -53,8 +53,8 @@ noasan bool MemoryExists(char *p) {
sigaction(SIGSEGV, &sa, old + 0);
sigaction(SIGBUS, &sa, old + 1);
c = atomic_load(p);
sigaction(SIGSEGV, old + 0, 0);
sigaction(SIGBUS, old + 1, 0);
sigaction(SIGSEGV, old + 0, 0);
return !gotsignal;
}