diff options
author | Andreas Kling <kling@serenityos.org> | 2021-03-09 08:17:06 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-09 08:59:10 +0100 |
commit | 4faeaf101c228ffc3d0540ed88d04b26d01f0929 (patch) | |
tree | 5ed85aedb4515e72aa7c1d0bd68d94769b9fe00a | |
parent | 84725ef3a5dfe9fb52f61af770b59d56de0b6f25 (diff) | |
download | serenity-4faeaf101c228ffc3d0540ed88d04b26d01f0929.zip |
LibC: Don't scrub memory in malloc/free when running in UE
Since UE is keeping track of the heap anyway, we can skip the scrubbing
and drastically improve the speed of malloc and free when emulating.
-rw-r--r-- | Userland/Libraries/LibC/malloc.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Userland/Libraries/LibC/malloc.cpp b/Userland/Libraries/LibC/malloc.cpp index fe410c9467..8e6d2579ca 100644 --- a/Userland/Libraries/LibC/malloc.cpp +++ b/Userland/Libraries/LibC/malloc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,6 +39,7 @@ #include <string.h> #include <sys/internals.h> #include <sys/mman.h> +#include <syscall.h> // FIXME: Thread safety. @@ -74,6 +75,7 @@ static bool s_log_malloc = false; static bool s_scrub_malloc = true; static bool s_scrub_free = true; static bool s_profiling = false; +static bool s_in_userspace_emulator = false; struct MallocStats { size_t number_of_malloc_calls; @@ -425,6 +427,17 @@ void __malloc_init() { new (&malloc_lock()) LibThread::Lock(); +#ifdef __serenity__ + s_in_userspace_emulator = syscall(SC_emuctl) != ENOSYS; +#endif + + if (s_in_userspace_emulator) { + // Don't bother scrubbing memory if we're running in UE since it + // keeps track of heap memory anyway. + s_scrub_malloc = false; + s_scrub_free = false; + } + if (secure_getenv("LIBC_NOSCRUB_MALLOC")) s_scrub_malloc = false; if (secure_getenv("LIBC_NOSCRUB_FREE")) |