blob: 43f0bb590da3822dec59baddacdb2ee9afec9b92 [file] [log] [blame]
Alex Perrycb7da4b2019-08-28 19:35:56 -07001#include "aos/realtime.h"
2
Austin Schuh77f3f222022-06-10 16:49:21 -07003#include <dirent.h>
Austin Schuhcc6070c2020-10-10 20:25:56 -07004#include <malloc.h>
5#include <sched.h>
Alex Perrycb7da4b2019-08-28 19:35:56 -07006#include <sys/mman.h>
Austin Schuhcc6070c2020-10-10 20:25:56 -07007#include <sys/prctl.h>
Alex Perrycb7da4b2019-08-28 19:35:56 -07008#include <sys/resource.h>
9#include <sys/types.h>
10#include <unistd.h>
Alex Perrycb7da4b2019-08-28 19:35:56 -070011
Tyler Chatowbf0609c2021-07-31 16:13:27 -070012#include <cerrno>
13#include <cstdint>
14#include <cstdio>
15#include <cstdlib>
16#include <cstring>
17
Austin Schuh99f7c6a2024-06-25 22:07:44 -070018#include "absl/base/internal/raw_logging.h"
19#include "absl/flags/flag.h"
20#include "absl/log/check.h"
21#include "absl/log/log.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070022
James Kuszmaula791b762023-07-13 14:56:21 -070023#include "aos/uuid.h"
Philipp Schrader790cb542023-07-05 21:06:52 -070024
Austin Schuh99f7c6a2024-06-25 22:07:44 -070025ABSL_FLAG(
26 bool, die_on_malloc, true,
Austin Schuh62288252020-11-18 23:26:04 -080027 "If true, die when the application allocates memory in a RT section.");
Austin Schuh99f7c6a2024-06-25 22:07:44 -070028ABSL_FLAG(bool, skip_realtime_scheduler, false,
29 "If true, skip changing the scheduler. Pretend that we changed "
30 "the scheduler instead.");
31ABSL_FLAG(bool, skip_locking_memory, false,
32 "If true, skip locking memory. Pretend that we did it instead.");
Austin Schuh27553152020-11-18 21:26:37 -080033
Austin Schuh62288252020-11-18 23:26:04 -080034extern "C" {
Tyler Chatowbf0609c2021-07-31 16:13:27 -070035typedef void (*MallocHook_NewHook)(const void *ptr, size_t size);
Austin Schuh62288252020-11-18 23:26:04 -080036int MallocHook_AddNewHook(MallocHook_NewHook hook) __attribute__((weak));
37int MallocHook_RemoveNewHook(MallocHook_NewHook hook) __attribute__((weak));
38
Tyler Chatowbf0609c2021-07-31 16:13:27 -070039typedef void (*MallocHook_DeleteHook)(const void *ptr);
Austin Schuh62288252020-11-18 23:26:04 -080040int MallocHook_AddDeleteHook(MallocHook_DeleteHook hook) __attribute__((weak));
Tyler Chatowbf0609c2021-07-31 16:13:27 -070041int MallocHook_RemoveDeleteHook(MallocHook_DeleteHook hook)
42 __attribute__((weak));
Tyler Chatow582c6c72021-07-16 13:45:07 -070043
44// Declare tc_malloc weak so we can check if it exists.
45void *tc_malloc(size_t size) __attribute__((weak));
46
47void *__libc_malloc(size_t size);
48void __libc_free(void *ptr);
Austin Schuh99f7c6a2024-06-25 22:07:44 -070049void *__libc_realloc(void *ptr, size_t size);
50void *__libc_calloc(size_t n, size_t elem_size);
Tyler Chatowbf0609c2021-07-31 16:13:27 -070051} // extern "C"
Austin Schuh62288252020-11-18 23:26:04 -080052
Alex Perrycb7da4b2019-08-28 19:35:56 -070053namespace FLAG__namespace_do_not_use_directly_use_DECLARE_double_instead {
54extern double FLAGS_tcmalloc_release_rate __attribute__((weak));
55}
56using FLAG__namespace_do_not_use_directly_use_DECLARE_double_instead::
57 FLAGS_tcmalloc_release_rate;
58
59namespace aos {
Stephan Pleinesf63bde82024-01-13 15:59:33 -080060
61namespace logging::internal {
Alex Perrycb7da4b2019-08-28 19:35:56 -070062
63// Implemented in aos/logging/context.cc.
64void ReloadThreadName() __attribute__((weak));
65
Stephan Pleinesf63bde82024-01-13 15:59:33 -080066} // namespace logging::internal
Alex Perrycb7da4b2019-08-28 19:35:56 -070067
68namespace {
69
Austin Schuh27553152020-11-18 21:26:37 -080070enum class SetLimitForRoot { kYes, kNo };
James Kuszmaulb4874eb2020-01-18 17:50:35 -080071
Austin Schuh27553152020-11-18 21:26:37 -080072enum class AllowSoftLimitDecrease { kYes, kNo };
James Kuszmaulb4874eb2020-01-18 17:50:35 -080073
74void SetSoftRLimit(
75 int resource, rlim64_t soft, SetLimitForRoot set_for_root,
Austin Schuh27553152020-11-18 21:26:37 -080076 std::string_view help_string,
James Kuszmaulb4874eb2020-01-18 17:50:35 -080077 AllowSoftLimitDecrease allow_decrease = AllowSoftLimitDecrease::kYes) {
Alex Perrycb7da4b2019-08-28 19:35:56 -070078 bool am_root = getuid() == 0;
James Kuszmaulb4874eb2020-01-18 17:50:35 -080079 if (set_for_root == SetLimitForRoot::kYes || !am_root) {
Alex Perrycb7da4b2019-08-28 19:35:56 -070080 struct rlimit64 rlim;
81 PCHECK(getrlimit64(resource, &rlim) == 0)
Brian Silverman6a54ff32020-04-28 16:41:39 -070082 << ": getting limit for " << resource;
Alex Perrycb7da4b2019-08-28 19:35:56 -070083
James Kuszmaulb4874eb2020-01-18 17:50:35 -080084 if (allow_decrease == AllowSoftLimitDecrease::kYes) {
85 rlim.rlim_cur = soft;
86 } else {
87 rlim.rlim_cur = std::max(rlim.rlim_cur, soft);
88 }
Alex Perrycb7da4b2019-08-28 19:35:56 -070089 rlim.rlim_max = ::std::max(rlim.rlim_max, soft);
90
91 PCHECK(setrlimit64(resource, &rlim) == 0)
Brian Silverman6a54ff32020-04-28 16:41:39 -070092 << ": changing limit for " << resource << " to " << rlim.rlim_cur
Austin Schuh27553152020-11-18 21:26:37 -080093 << " with max of " << rlim.rlim_max << help_string;
Alex Perrycb7da4b2019-08-28 19:35:56 -070094 }
95}
96
97} // namespace
98
99void LockAllMemory() {
Austin Schuhcc6070c2020-10-10 20:25:56 -0700100 CheckNotRealtime();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700101 // Allow locking as much as we want into RAM.
Austin Schuh27553152020-11-18 21:26:37 -0800102 SetSoftRLimit(RLIMIT_MEMLOCK, RLIM_INFINITY, SetLimitForRoot::kNo,
103 "use --skip_locking_memory to not lock memory.");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700104
Austin Schuh27553152020-11-18 21:26:37 -0800105 PCHECK(mlockall(MCL_CURRENT | MCL_FUTURE) == 0)
106 << ": Failed to lock memory, use --skip_locking_memory to bypass this. "
107 "Bypassing will impact RT performance.";
Alex Perrycb7da4b2019-08-28 19:35:56 -0700108
Brian Silverman4dbbcce2020-09-18 15:27:38 -0700109#if !__has_feature(address_sanitizer) && !__has_feature(memory_sanitizer)
Alex Perrycb7da4b2019-08-28 19:35:56 -0700110 // Don't give freed memory back to the OS.
111 CHECK_EQ(1, mallopt(M_TRIM_THRESHOLD, -1));
112 // Don't use mmap for large malloc chunks.
113 CHECK_EQ(1, mallopt(M_MMAP_MAX, 0));
Austin Schuh85faf672020-09-10 22:58:46 -0700114#endif
Alex Perrycb7da4b2019-08-28 19:35:56 -0700115
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700116 // TODO(austin): new tcmalloc does this differently...
Alex Perrycb7da4b2019-08-28 19:35:56 -0700117 if (&FLAGS_tcmalloc_release_rate) {
118 // Tell tcmalloc not to return memory.
119 FLAGS_tcmalloc_release_rate = 0.0;
120 }
121
122 // Forces the memory pages for all the stack space that we're ever going to
123 // use to be loaded into memory (so it can be locked there).
124 uint8_t data[4096 * 8];
125 // Not 0 because linux might optimize that to a 0-filled page.
126 memset(data, 1, sizeof(data));
Austin Schuh27553152020-11-18 21:26:37 -0800127 __asm__ __volatile__("" ::"m"(data));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700128
129 static const size_t kHeapPreallocSize = 512 * 1024;
130 char *const heap_data = static_cast<char *>(malloc(kHeapPreallocSize));
131 memset(heap_data, 1, kHeapPreallocSize);
Austin Schuh27553152020-11-18 21:26:37 -0800132 __asm__ __volatile__("" ::"m"(heap_data));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700133 free(heap_data);
134}
135
136void InitRT() {
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700137 if (absl::GetFlag(FLAGS_skip_locking_memory)) {
Austin Schuh27553152020-11-18 21:26:37 -0800138 LOG(WARNING) << "Ignoring request to lock all memory due to "
139 "--skip_locking_memory.";
140 return;
141 }
142
Austin Schuhcc6070c2020-10-10 20:25:56 -0700143 CheckNotRealtime();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700144 LockAllMemory();
145
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700146 if (absl::GetFlag(FLAGS_skip_realtime_scheduler)) {
Austin Schuh27553152020-11-18 21:26:37 -0800147 return;
148 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700149 // Only let rt processes run for 3 seconds straight.
Austin Schuh27553152020-11-18 21:26:37 -0800150 SetSoftRLimit(
151 RLIMIT_RTTIME, 3000000, SetLimitForRoot::kYes,
152 ", use --skip_realtime_scheduler to stay non-rt and bypass this "
153 "warning.");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700154
155 // Allow rt processes up to priority 40.
Austin Schuh27553152020-11-18 21:26:37 -0800156 SetSoftRLimit(
157 RLIMIT_RTPRIO, 40, SetLimitForRoot::kNo,
158 ", use --skip_realtime_scheduler to stay non-rt and bypass this "
159 "warning.");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700160}
161
162void UnsetCurrentThreadRealtimePriority() {
163 struct sched_param param;
164 param.sched_priority = 0;
Brian Silverman6a54ff32020-04-28 16:41:39 -0700165 PCHECK(sched_setscheduler(0, SCHED_OTHER, &param) == 0);
Austin Schuhcc6070c2020-10-10 20:25:56 -0700166 MarkRealtime(false);
Brian Silverman6a54ff32020-04-28 16:41:39 -0700167}
168
169void SetCurrentThreadAffinity(const cpu_set_t &cpuset) {
Philipp Schrader36d77932024-02-01 18:31:19 -0800170 PCHECK(sched_setaffinity(0, sizeof(cpuset), &cpuset) == 0) << cpuset;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700171}
172
James Kuszmaul57c2baa2020-01-19 14:52:52 -0800173void SetCurrentThreadName(const std::string_view name) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700174 CHECK_LE(name.size(), 16u) << ": thread name '" << name << "' too long";
175 VLOG(1) << "This thread is changing to '" << name << "'";
James Kuszmaul57c2baa2020-01-19 14:52:52 -0800176 std::string string_name(name);
Brian Silverman6a54ff32020-04-28 16:41:39 -0700177 PCHECK(prctl(PR_SET_NAME, string_name.c_str()) == 0)
178 << ": changing name to " << string_name;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700179 if (&logging::internal::ReloadThreadName != nullptr) {
180 logging::internal::ReloadThreadName();
181 }
182}
183
Austin Schuhde973292021-10-12 18:09:49 -0700184cpu_set_t GetCurrentThreadAffinity() {
185 cpu_set_t result;
186 PCHECK(sched_getaffinity(0, sizeof(result), &result) == 0);
187 return result;
188}
189
Alex Perrycb7da4b2019-08-28 19:35:56 -0700190void SetCurrentThreadRealtimePriority(int priority) {
James Kuszmaula791b762023-07-13 14:56:21 -0700191 // Ensure that we won't get expensive reads of /dev/random when the realtime
192 // scheduler is running.
193 UUID::Random();
194
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700195 if (absl::GetFlag(FLAGS_skip_realtime_scheduler)) {
Austin Schuh27553152020-11-18 21:26:37 -0800196 LOG(WARNING) << "Ignoring request to switch to the RT scheduler due to "
197 "--skip_realtime_scheduler.";
198 return;
199 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700200 // Make sure we will only be allowed to run for 3 seconds straight.
Austin Schuh27553152020-11-18 21:26:37 -0800201 SetSoftRLimit(
202 RLIMIT_RTTIME, 3000000, SetLimitForRoot::kYes,
203 ", use --skip_realtime_scheduler to stay non-rt and bypass this "
204 "warning.");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700205
Brian Silvermanb3826f52020-07-02 19:41:18 -0700206 // Raise our soft rlimit if necessary.
Austin Schuh27553152020-11-18 21:26:37 -0800207 SetSoftRLimit(
208 RLIMIT_RTPRIO, priority, SetLimitForRoot::kNo,
209 ", use --skip_realtime_scheduler to stay non-rt and bypass this "
210 "warning.",
211 AllowSoftLimitDecrease::kNo);
Brian Silvermanb3826f52020-07-02 19:41:18 -0700212
Alex Perrycb7da4b2019-08-28 19:35:56 -0700213 struct sched_param param;
214 param.sched_priority = priority;
Austin Schuhcc6070c2020-10-10 20:25:56 -0700215 MarkRealtime(true);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700216 PCHECK(sched_setscheduler(0, SCHED_FIFO, &param) == 0)
Austin Schuh27553152020-11-18 21:26:37 -0800217 << ": changing to SCHED_FIFO with " << priority
218 << ", if you want to bypass this check for testing, use "
219 "--skip_realtime_scheduler";
Alex Perrycb7da4b2019-08-28 19:35:56 -0700220}
221
222void WriteCoreDumps() {
223 // Do create core files of unlimited size.
Austin Schuh27553152020-11-18 21:26:37 -0800224 SetSoftRLimit(RLIMIT_CORE, RLIM_INFINITY, SetLimitForRoot::kYes, "");
James Kuszmaulb4874eb2020-01-18 17:50:35 -0800225}
226
227void ExpandStackSize() {
Austin Schuh27553152020-11-18 21:26:37 -0800228 SetSoftRLimit(RLIMIT_STACK, 1000000, SetLimitForRoot::kYes, "",
James Kuszmaulb4874eb2020-01-18 17:50:35 -0800229 AllowSoftLimitDecrease::kNo);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700230}
231
Austin Schuhcc6070c2020-10-10 20:25:56 -0700232namespace {
Austin Schuhf239e332021-07-30 15:27:26 -0700233// Bool to track if malloc hooks have failed to be configured.
234bool has_malloc_hook = true;
Austin Schuhf7bfb652023-08-25 14:22:50 -0700235thread_local bool is_realtime = false;
Tyler Chatowbf0609c2021-07-31 16:13:27 -0700236} // namespace
Austin Schuhcc6070c2020-10-10 20:25:56 -0700237
238bool MarkRealtime(bool realtime) {
Austin Schuhf239e332021-07-30 15:27:26 -0700239 if (realtime) {
240 // For some applications (generally tools built for the host in Bazel), we
241 // don't have malloc hooks available, but we also don't go realtime. Delay
242 // complaining in that case until we try to go RT and it matters.
Victor Valenciab009bfc2022-09-30 13:30:11 -0700243#if !__has_feature(address_sanitizer) && !__has_feature(memory_sanitizer)
Austin Schuhf239e332021-07-30 15:27:26 -0700244 CHECK(has_malloc_hook)
245 << ": Failed to register required malloc hooks before going realtime. "
246 "Disable --die_on_malloc to continue.";
Victor Valenciab009bfc2022-09-30 13:30:11 -0700247#endif
Austin Schuhf239e332021-07-30 15:27:26 -0700248 }
Austin Schuhcc6070c2020-10-10 20:25:56 -0700249 const bool prior = is_realtime;
250 is_realtime = realtime;
251 return prior;
252}
253
254void CheckRealtime() { CHECK(is_realtime); }
255
256void CheckNotRealtime() { CHECK(!is_realtime); }
257
258ScopedRealtimeRestorer::ScopedRealtimeRestorer() : prior_(is_realtime) {}
259
Austin Schuh62288252020-11-18 23:26:04 -0800260void NewHook(const void *ptr, size_t size) {
261 if (is_realtime) {
262 is_realtime = false;
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700263 ABSL_RAW_LOG(FATAL, "Malloced %p -> %zu bytes", ptr, size);
Austin Schuh62288252020-11-18 23:26:04 -0800264 }
265}
266
267void DeleteHook(const void *ptr) {
Austin Schuhf239e332021-07-30 15:27:26 -0700268 // It is legal to call free(nullptr) unconditionally and assume that it won't
269 // do anything. Eigen does this. So, if we are RT, ignore any of these
270 // calls.
271 if (is_realtime && ptr != nullptr) {
Austin Schuh62288252020-11-18 23:26:04 -0800272 is_realtime = false;
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700273 ABSL_RAW_LOG(FATAL, "Delete Hook %p", ptr);
Austin Schuh62288252020-11-18 23:26:04 -0800274 }
275}
276
Tyler Chatow582c6c72021-07-16 13:45:07 -0700277extern "C" {
278
279// malloc hooks for libc. Tcmalloc will replace everything it finds (malloc,
280// __libc_malloc, etc.), so we need its specific hook above as well.
281void *aos_malloc_hook(size_t size) {
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700282 if (absl::GetFlag(FLAGS_die_on_malloc) && aos::is_realtime) {
Tyler Chatow582c6c72021-07-16 13:45:07 -0700283 aos::is_realtime = false;
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700284 ABSL_RAW_LOG(FATAL, "Malloced %zu bytes", size);
Tyler Chatow582c6c72021-07-16 13:45:07 -0700285 return nullptr;
286 } else {
287 return __libc_malloc(size);
288 }
289}
290
291void aos_free_hook(void *ptr) {
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700292 if (absl::GetFlag(FLAGS_die_on_malloc) && aos::is_realtime &&
293 ptr != nullptr) {
Tyler Chatow582c6c72021-07-16 13:45:07 -0700294 aos::is_realtime = false;
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700295 ABSL_RAW_LOG(FATAL, "Deleted %p", ptr);
Tyler Chatow582c6c72021-07-16 13:45:07 -0700296 } else {
297 __libc_free(ptr);
298 }
299}
300
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700301void *aos_realloc_hook(void *ptr, size_t size) {
302 if (absl::GetFlag(FLAGS_die_on_malloc) && aos::is_realtime) {
303 aos::is_realtime = false;
304 ABSL_RAW_LOG(FATAL, "Malloced %p -> %zu bytes", ptr, size);
305 return nullptr;
306 } else {
307 return __libc_realloc(ptr, size);
308 }
309}
310
311void *aos_calloc_hook(size_t n, size_t elem_size) {
312 if (absl::GetFlag(FLAGS_die_on_malloc) && aos::is_realtime) {
313 aos::is_realtime = false;
314 ABSL_RAW_LOG(FATAL, "Malloced %zu * %zu bytes", n, elem_size);
315 return nullptr;
316 } else {
317 return __libc_calloc(n, elem_size);
318 }
319}
320
Tyler Chatow582c6c72021-07-16 13:45:07 -0700321void *malloc(size_t size) __attribute__((weak, alias("aos_malloc_hook")));
322void free(void *ptr) __attribute__((weak, alias("aos_free_hook")));
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700323void *realloc(void *ptr, size_t size)
324 __attribute__((weak, alias("aos_realloc_hook")));
325void *calloc(size_t n, size_t elem_size)
326 __attribute__((weak, alias("aos_calloc_hook")));
Tyler Chatow582c6c72021-07-16 13:45:07 -0700327}
328
Austin Schuh77f3f222022-06-10 16:49:21 -0700329void FatalUnsetRealtimePriority() {
Austin Schuh4737ad62022-12-30 14:47:03 -0800330 int saved_errno = errno;
Austin Schuh77f3f222022-06-10 16:49:21 -0700331 // Drop our priority first. We are about to do lots of work to undo
332 // everything, don't get overly clever.
333 struct sched_param param;
Austin Schuh4737ad62022-12-30 14:47:03 -0800334 param.sched_priority = 0;
Austin Schuh77f3f222022-06-10 16:49:21 -0700335 sched_setscheduler(0, SCHED_OTHER, &param);
336
337 is_realtime = false;
338
339 // Put all sub-tasks back to non-rt priority too.
340 DIR *dirp = opendir("/proc/self/task");
341 if (dirp) {
342 struct dirent *directory_entry;
343 while ((directory_entry = readdir(dirp)) != NULL) {
344 int thread_id = std::atoi(directory_entry->d_name);
345
346 // ignore . and .. which are zeroes for some reason
347 if (thread_id != 0) {
348 struct sched_param param;
Austin Schuh4737ad62022-12-30 14:47:03 -0800349 param.sched_priority = 0;
Austin Schuh77f3f222022-06-10 16:49:21 -0700350 sched_setscheduler(thread_id, SCHED_OTHER, &param);
351 }
352 }
353 closedir(dirp);
354 }
Austin Schuh4737ad62022-12-30 14:47:03 -0800355 errno = saved_errno;
Austin Schuh77f3f222022-06-10 16:49:21 -0700356}
357
Austin Schuh62288252020-11-18 23:26:04 -0800358void RegisterMallocHook() {
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700359 if (absl::GetFlag(FLAGS_die_on_malloc)) {
Tyler Chatow582c6c72021-07-16 13:45:07 -0700360 // tcmalloc redefines __libc_malloc, so use this as a feature test.
361 if (&__libc_malloc == &tc_malloc) {
James Kuszmaul4af7fa62023-08-05 13:33:22 -0700362 if (VLOG_IS_ON(1)) {
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700363 ABSL_RAW_LOG(INFO, "Hooking tcmalloc for die_on_malloc");
James Kuszmaul4af7fa62023-08-05 13:33:22 -0700364 }
Tyler Chatow582c6c72021-07-16 13:45:07 -0700365 if (&MallocHook_AddNewHook != nullptr) {
366 CHECK(MallocHook_AddNewHook(&NewHook));
367 } else {
368 has_malloc_hook = false;
369 }
370 if (&MallocHook_AddDeleteHook != nullptr) {
371 CHECK(MallocHook_AddDeleteHook(&DeleteHook));
372 } else {
373 has_malloc_hook = false;
374 }
Austin Schuh62288252020-11-18 23:26:04 -0800375 } else {
Austin Schuh6d8afc02023-05-28 13:27:42 -0700376 if (VLOG_IS_ON(1)) {
Austin Schuh99f7c6a2024-06-25 22:07:44 -0700377 ABSL_RAW_LOG(INFO, "Replacing glibc malloc");
Austin Schuh6d8afc02023-05-28 13:27:42 -0700378 }
Tyler Chatow582c6c72021-07-16 13:45:07 -0700379 if (&malloc != &aos_malloc_hook) {
380 has_malloc_hook = false;
381 }
382 if (&free != &aos_free_hook) {
383 has_malloc_hook = false;
384 }
Austin Schuh62288252020-11-18 23:26:04 -0800385 }
386 }
387}
388
Alex Perrycb7da4b2019-08-28 19:35:56 -0700389} // namespace aos