diff --git a/hiviewdfx/hidebug/include/hidebug/hidebug.h b/hiviewdfx/hidebug/include/hidebug/hidebug.h index 02bf031a4f9316004f032cc392d39dcde63e6a46..7b3c7756dba0c9e8bb322214d620a24a7782e459 100644 --- a/hiviewdfx/hidebug/include/hidebug/hidebug.h +++ b/hiviewdfx/hidebug/include/hidebug/hidebug.h @@ -151,6 +151,33 @@ HiDebug_ErrorCode OH_HiDebug_StopAppTraceCapture(); */ HiDebug_ErrorCode OH_HiDebug_GetGraphicsMemory(uint32_t *value); +/** + * @brief Replace MallocDispatch table with developer customized memory functions. + * + * @param dispatchTable Indicates pointer of custom dispatch table. + * @return Result code + * {@link HIDEBUG_SUCCESS} Set customized dispatch table success. + * {@link HIDEBUG_INVALID_ARGUMENT} Invalid argument, dispatchTable is null pointer + * @since 20 + */ +HiDebug_ErrorCode OH_HiDebug_SetMallocDispatchTable(struct HiDebug_MallocDispatch *dispatchTable); + +/** + * @brief Obtain current MallocDispatch table. + * + * @return The default dispatch table of malloc function. + + * @since 20 + */ +HiDebug_MallocDispatch* OH_HiDebug_GetDefaultMallocDispatchTable(void); + +/** + * @brief Restore original MallocDispatch table. + * + * @since 20 + */ +void OH_HiDebug_RestoreMallocDispatchTable(void); + /** * @brief Get backtrace frames start from the given frame pointer and the function is signal-safe. * diff --git a/hiviewdfx/hidebug/include/hidebug/hidebug_type.h b/hiviewdfx/hidebug/include/hidebug/hidebug_type.h index e771b6a69def7fa15186cabc47923170a54229b6..4779148f80fd369485be094b97f5d2438e6e4f17 100644 --- a/hiviewdfx/hidebug/include/hidebug/hidebug_type.h +++ b/hiviewdfx/hidebug/include/hidebug/hidebug_type.h @@ -39,7 +39,8 @@ #define HIVIEWDFX_HIDEBUG_TYPE_H #include - +#include +#include #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -180,6 +181,20 @@ typedef enum HiDebug_TraceFlag { HIDEBUG_TRACE_FLAG_ALL_THREADS = 2 } HiDebug_TraceFlag; +/** + * @brief Defines structure type of malloc dispatch table. + * + * @since 20 +*/ +typedef struct HiDebug_MallocDispatch { + void* (*malloc)(size_t); + void* (*calloc)(size_t, size_t); + void* (*realloc)(void*, size_t); + void (*free)(void*); + void* (*mmap) (void*, size_t, int, int, int, off_t); + int (*munmap) (void*, size_t); +} HiDebug_MallocDispatch; + /** * @brief Defines Js stack frame content * diff --git a/hiviewdfx/hidebug/libhidebug.ndk.json b/hiviewdfx/hidebug/libhidebug.ndk.json index 422952c975a178a2e706b3c96f059455c8d75104..d9862a9cabb0268c01df9526e68b607db2a6158b 100644 --- a/hiviewdfx/hidebug/libhidebug.ndk.json +++ b/hiviewdfx/hidebug/libhidebug.ndk.json @@ -39,6 +39,18 @@ "first_introduced": "14", "name": "OH_HiDebug_GetGraphicsMemory" }, + { + "first_introduced": "20", + "name": "OH_HiDebug_SetMallocDispatchTable" + }, + { + "first_introduced": "20", + "name": "OH_HiDebug_GetDefaultMallocDispatchTable" + }, + { + "first_introduced": "20", + "name": "OH_HiDebug_RestoreMallocDispatchTable" + }, { "first_introduced": "20", "name": "OH_HiDebug_BacktraceFromFp" @@ -55,4 +67,5 @@ "first_introduced": "20", "name": "OH_HiDebug_DestroyBacktraceObject" } + ] \ No newline at end of file