在哪里放置 Scudo 分配器 __scudo_default_options 回调?

问题描述

来自 Scudo 页面:

Some parameters of the allocator can be defined on a per-process basis through several ways:

Statically: Define a __scudo_default_options function in the program that returns the options string to be parsed. This function must have the following prototype: extern "C" const char *__scudo_default_options().
Dynamically: Use the environment variable SCUDO_OPTIONS containing the options string to be parsed. Options defined this way override any definition made through __scudo_default_options.

我对 Android 还很陌生,有人能帮我理解在 cpp 代码中将 __scudo_default_options 之类的函数放在哪里吗,我有 MainActivity.cpp 和 MidiManager.cpp

解决方法

该函数可以位于应用程序中的任何位置,只要它可以被链接器发现。将它放在主编译单元附近可能会更好。 您想确保符号具有公开可见性。

您可以在此处参考测试中的示例: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/scudo/standalone/tests/scudo_unit_test_main.cpp#L23

例如。在 MainActivity.cpp 中,达到以下程度:

extern "C" __attribute__((visibility("default"))) const char *
__scudo_default_options() {
  return "quarantine_size_kb=256:thread_local_quarantine_size_kb=128:"
         "quarantine_max_chunk_size=512";
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...