Commit Graph

1096 Commits

Author SHA1 Message Date
Aliaksey Kandratsenka
46d9a6293a introduce tcmalloc::kInvalidTLSKey
The intention is to initialize tls-key variable with this invalid
value. This will help us avoid separate "tls ready" flag and possible
memory ordering issues around distinct tls key and tls-ready
variables.

On windows we use TLS_OUT_OF_INDEXES values which is properly
"impossible" tls index value. On POSIX systems we add theoretically
unportable, but practically portable assumption that tls keys are
integers. And we make value of -1 be that invalid key.
2024-05-18 13:53:34 -04:00
Aliaksey Kandratsenka
65ce9e899e better abort in internal_logging.cc:Log
We use __builtin_trap (which compiles to explicitly undefined
instruction or "int 3" on x64-en), when available, to make those
crashing Log invokations a little nicer to debug.
2024-05-18 13:53:34 -04:00
Aliaksey Kandratsenka
a6864ae233 clean up FLAGS_tcmalloc_heap_limit_mb value in page heap tests
This will not only make things right w.r.t. possible order of test
runs, but it also unbreaks test failures on windows (where gtest ends
up doing some malloc after test completion, hits the limit and dies).
2024-05-18 13:51:54 -04:00
Aliaksey Kandratsenka
de12f89d2a expand emergency malloc test coverage
We add coverage of calloc and we also cover no-hooks case.
2024-05-01 17:43:49 -04:00
Aliaksey Kandratsenka
77ba2cf133 don't include malloc_extension.h in page_heap.h 2024-05-01 17:43:49 -04:00
Aliaksey Kandratsenka
d63b2fad17 introduce thread::SelfThreadId
Sadly, certain/many implementations of std::this_thread::id invoke
malloc. So we need something more robust. On Unix systems we use
address of errno as thread identifier. Sadly, this doesn't cover
windows where MS's C runtime facility will occasionally malloc when
errno location is grabbed (with some special trickery for when malloc
itself needs to set errno to ENOMEM!). So on windows, we do
GetCurrentThreadId which appears to be roughly as efficient as
"normal" system's __errno_location implementation.
2024-05-01 17:43:49 -04:00
Aliaksey Kandratsenka
13aecbe197 make debugallocation calloc hook invocation order consistent
I.e. we normally call new hook just before returning. In calloc's case
this means after zeroing allocated memory.
2024-05-01 16:54:32 -04:00
Aliaksey Kandratsenka
bc2aac871a re-introduce missing initial-exec attribute for per-thread data 2024-05-01 16:54:10 -04:00
Aliaksey Kandratsenka
786ecdfbc8 handle re-entrancy in check-address facility
We use mmap when we initialize it, which could via heap checker
recurse back into backtracing and check-address. So before we do mmap
and rest of initialization, we now set check-address implementation
to conservative two-syscalls version.
2024-05-01 16:51:29 -04:00
Aliaksey Kandratsenka
a038c8c23f unbreak cmake build around HAVE_SBRK check 2024-04-30 23:25:17 -04:00
leap
1bdabc0e37 Unbreak proc_maps_iterator.cc compilation on QNX
We had duplicate definition of flags_tmp variable.

Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
[alkondratenko@gmail.com] updated commit message
2024-04-10 13:49:48 -04:00
Aliaksey Kandratsenka
7c0cbb3a0c avoid depending on {s,}brk on FreeBSD systems without it
Apparently some recent FreeBSDs occasionally lack brk. So our code
which previously hard-coded that this OS has brk (which we use to
implement hooked sbrk) fails to compile.

Our configure scripts already detects sbrk, so we simply need to pay
attention. Fixes github issue #1499
2024-04-03 15:46:06 -04:00
Aliaksey Kandratsenka
8dde01b4de unbreak emergency malloc tests on systems without "good" TLS
Our implementation of emergency malloc slow-path actually depends on
good TLS implementation. So on systems without good TLS (i.e. OSX), we
lied to ourselves that emergency malloc is available, but then failed
tests.
2024-03-27 18:36:29 -04:00
Aliaksey Kandratsenka
4cbd8ad245 refactor and simplify LowLevelAlloc
We don't expose DefaultArena anymore. Simply passing nullptr implies
default arena.

We also streamline default arena initialization (we
previously relied on combination of lazy initialazation in ArenaInit
and constexpr construction).

There is also no need to have elaborate ArenaLock thingy. We use plain
SpinLockHolder instead.
2024-03-27 18:18:20 -04:00
Aliaksey Kandratsenka
2cd876cdfd amputate unused LowLevelAlloc flags 2024-03-27 18:17:29 -04:00
Aliaksey Kandratsenka
6babeb1a12 apply StaticStorage to windows/system-alloc.cc 2024-03-27 15:48:30 -04:00
Aliaksey Kandratsenka
fa3753dc86 apply StaticStorage across the source code 2024-03-27 15:48:30 -04:00
Aliaksey Kandratsenka
ee123a1a0d apply StaticStorage to TrivialOnce 2024-03-27 15:48:30 -04:00
Aliaksey Kandratsenka
86606eef40 introduce tcmalloc::StaticStorage
We have a number of things that are explicitly constructed in some
statically allocated space, so lets finally have a helper for that.
2024-03-27 15:48:30 -04:00
Aliaksey Kandratsenka
7cbbbdd099 use DirectAnonMMap in emergency allocator
It is just more straightforward and cleaner than going via
LowLevelAllocators "default" pages allocator, which does direct mmap
thingy anyways.
2024-03-27 15:48:30 -04:00
Aliaksey Kandratsenka
6785aeb027 add test coverage of emergency malloc 2024-03-27 15:48:30 -04:00
Aliaksey Kandratsenka
703dc970fc add missing override declarations to TestingPortalImpl 2024-03-27 15:48:30 -04:00
hmihaylov-sc
e80e863e37 remove deprecated register storage class 2024-03-27 12:11:30 -04:00
Aliaksey Kandratsenka
c71e512664 implement support for hidden visibility
This is off by default for now. And autotools-only. But after
significant preparatory work, we're now able to do it cleanly. Stuff
that was previously exported just for tests (like page heap stuff or
flags) is now unexported.

Just like on windows all symbols explicitly exported by
PERFTOOLS_DLL_DECL are visible and exported and rest are hidden. Those
include all the malloc/new APIs of course, and all the other symbols
we advertise in our headers (e.g. MallocExtension, MallocHook).

Updates issue #600
2024-03-24 19:56:57 -04:00
Aliaksey Kandratsenka
38d741710b drop unused pwd.h/grp.h checks 2024-03-24 16:59:58 -04:00
Aliaksey Kandratsenka
02f10c15a5 update heap-checker_unittest to reach into malloc guts via TestingPortal 2024-03-24 16:59:58 -04:00
Aliaksey Kandratsenka
d5bd0087c1 avoid VLOG dependency in heap-profiler test
This makes the test compatible with -fvisibility=hidden
2024-03-24 16:59:58 -04:00
Aliaksey Kandratsenka
c23bbdb4c7 don't dllexport Log and HookList 2024-03-24 16:59:58 -04:00
Aliaksey Kandratsenka
ea4fceb796 don't dllexport flags 2024-03-24 16:59:58 -04:00
Aliaksey Kandratsenka
274038486b ensure dllexport/public visibility of all aliases we generate 2024-03-24 16:59:58 -04:00
Aliaksey Kandratsenka
32796c754e export all mmap and sbrk replacement functions 2024-03-24 16:59:58 -04:00
Aliaksey Kandratsenka
5cba04ead2 export IsHeapProfilerRunning symbol
It is part of our API and ABI, so it needs to public visibility
declaration, like rest of functions declared in the same public header.
2024-03-24 16:59:57 -04:00
Aliaksey Kandratsenka
2436c80d6c ensure that malloc_extension_c_test includes config.h first
Like we do everywhere.
2024-03-24 16:59:57 -04:00
Aliaksey Kandratsenka
701777bbee dont define unused HAVE_MEMORY_H in windows config.h 2024-03-24 16:59:57 -04:00
Aliaksey Kandratsenka
6038a09c76 simplify vdso_support.h/elf_mem_image.h integration
This is only used by Linux/PPC, so lets make it simpler and
clearer (e.g. no need to do __GLIBC__ test).
2024-03-24 16:59:57 -04:00
Aliaksey Kandratsenka
ae31e6afa3 drop unused LT_OBJDIR from cmake config.h template 2024-03-24 16:59:57 -04:00
Aliaksey Kandratsenka
e867bb7818 amputate unused Elf32_Versym check 2024-03-24 16:59:57 -04:00
Aliaksey Kandratsenka
b65b9e3e61 amputate unused AC_INSTALL_PREFIX 2024-03-24 16:59:57 -04:00
Aliaksey Kandratsenka
fc496c87c4 liberate our tests from makefile setting TCMALLOC_SAMPLE_PARAMETER 2024-03-20 16:06:59 -04:00
Aliaksey Kandratsenka
abc0ac6147 drop legacy_assertions.h 2024-03-20 16:06:57 -04:00
Aliaksey Kandratsenka
8cb41da4f9 gtestify debugallocation_test
As part of that we eliminate use of shell script and rely on gtest's
death testing facility instead (which this test was originally using).
2024-03-20 16:06:48 -04:00
Aliaksey Kandratsenka
14598dd4ac gtestify and refactor tcmalloc_unittest
While it still needs more work to be up to highest standards of
cleanness and clarity, we made it better.

One big part of this change is we're now liberated from
tcmalloc_unittest.sh. We now arrange testing of various environment
variable tweaks in C++ by self-execing with updated environment at the
end of tests.
2024-03-20 16:05:14 -04:00
Aliaksey Kandratsenka
93380fc754 drop dependency on sys/resource.h
Biggest part of it is removal of SetTestResourceLimit. The reasoning
behind it is, we don't do it on windows. Tests pass just fine. So,
there is no reason to bother.
2024-03-20 16:05:06 -04:00
Aliaksey Kandratsenka
a4fe2d7cd0 liberate sampling test from use of shell script
As part of that we do somewhat tighter job with temp files.
2024-03-20 16:04:52 -04:00
Aliaksey Kandratsenka
c3e9ad95f1 minor cleanup of thread_dealloc_unittest 2024-03-20 16:04:47 -04:00
Aliaksey Kandratsenka
6b53b1a4c1 gtestify and cleanup system-alloc_unittest 2024-03-20 16:04:45 -04:00
Aliaksey Kandratsenka
f7c8b45dcd gtestify realloc_unittest 2024-03-20 16:04:41 -04:00
Aliaksey Kandratsenka
0dddc476b3 gtestify malloc_extension_c_test 2024-03-20 16:04:39 -04:00
Aliaksey Kandratsenka
3cda0c4185 gtestify malloc_extension_test 2024-03-20 16:04:37 -04:00
Aliaksey Kandratsenka
2de5f833fb page_heap_test: test that more OS-es can release memory
I just dealt with somewhat curious failure in page heap test and the
change was due to breakage of HaveSystemRelease on OSX. And since OSX
can truly release memory and Windows too, lets assert this.
2024-03-20 16:04:31 -04:00