summaryrefslogtreecommitdiff
path: root/tests/malloc_test.cpp
diff options
context:
space:
mode:
authorRyan Savitski <rsavitski@google.com>2020-01-02 19:54:57 +0000
committerRyan Savitski <rsavitski@google.com>2020-01-15 22:55:03 +0000
commit175c8867b05ec14a8da1fd528c2bf17c4e67c280 (patch)
treeac5536a5465cb98d1810c204dd6762544abdbc5a /tests/malloc_test.cpp
parenta04764bd286cf86f28d65487e1b6d6d36c9671e8 (diff)
allow for heapprofd's signal to be multiplexed
This patch refactors heapprofd_malloc to make it easier to reuse the reserved signal for multiple purposes. We define a new generic signal handler for profilers, which dispatches to more specific logic based on the signal's payload (si_value). The profiler signal handler is installed during libc preinit, after malloc initialization (so races against synchronous heapprofd initialization need not be considered). In terms of code organization, I copied the existing approach with a loosely referenced function in bionic_globals.h. Do tell if you'd rather a different approach here. The profileability of a process is quite tied to the malloc files/interfaces in bionic - in particular, it's set through android_mallopt. I do not change that, but instead introduce a new android_mallopt option to be able to query profileability of the process (which is now used by the new profiler signal handler). As part of that, gZygoteChildProfileable is moved from heapprofd_malloc to common (alongside gZygoteChild). I've removed the masking and reraising of the heapprofd signal when racing against malloc_limit init. We're ok with taking a simpler approach and dropping the heapprofd signal in such an unlikely race. Note: this requires a corresponding change in heapprofd to use sigqueue() instead of kill(), as the latter leaves the si_value uninitialized(?) on the receiving side. Bug: 144281346 Change-Id: I93bb2e82cff5870e5ca499cf86439860aca9dfa5
Diffstat (limited to 'tests/malloc_test.cpp')
-rw-r--r--tests/malloc_test.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index ebbd24793..c7050dc68 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -18,14 +18,15 @@
#include <elf.h>
#include <limits.h>
+#include <malloc.h>
#include <pthread.h>
+#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <malloc.h>
#include <unistd.h>
#include <atomic>
@@ -962,7 +963,11 @@ static void SetAllocationLimitMultipleThreads() {
// Let them go all at once.
go = true;
- ASSERT_EQ(0, kill(getpid(), __SIGRTMIN + 4));
+ // Send hardcoded signal (BIONIC_SIGNAL_PROFILER with value 0) to trigger
+ // heapprofd handler.
+ union sigval signal_value;
+ signal_value.sival_int = 0;
+ ASSERT_EQ(0, sigqueue(getpid(), __SIGRTMIN + 4, signal_value));
size_t num_successful = 0;
for (size_t i = 0; i < kNumThreads; i++) {