static void __bionic_heap_usage_error(const char* function, void* address) { __libc_fatal_no_abort("invalid address or address of corrupt block %p passed to %s", address, function); // So that debuggerd gives us a memory dump around the specific address. // TODO: improve the debuggerd protocol so we can tell it to dump an address when we abort. *((int**) 0xdeadbaad) = (int*) address; }
TEST(libc, __libc_fatal_no_abort) { struct logger_list *logger_list; pid_t pid = getpid(); ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( (log_id_t)LOG_ID_MAIN, O_RDONLY | O_NDELAY, 1000, pid))); char b[80]; struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); __libc_fatal_no_abort("%u.%09u", (unsigned)ts.tv_sec, (unsigned)ts.tv_nsec); snprintf(b, sizeof(b),"%u.%09u", (unsigned)ts.tv_sec, (unsigned)ts.tv_nsec); usleep(1000000); int count = 0; for (;;) { log_msg log_msg; if (android_logger_list_read(logger_list, &log_msg) <= 0) { break; } ASSERT_EQ(log_msg.entry.pid, pid); if ((int)log_msg.id() != LOG_ID_MAIN) { continue; } char *data = log_msg.msg(); if ((*data == ANDROID_LOG_FATAL) && !strcmp(data + 1, "libc") && !strcmp(data + 1 + strlen(data + 1) + 1, b)) { ++count; } } EXPECT_EQ(1, count); android_logger_list_close(logger_list); }