* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#ifndef COMMON_UTILS_SANITIZERS_SANITIZER_OPTIONS_H_
#define COMMON_UTILS_SANITIZERS_SANITIZER_OPTIONS_H_
#if defined(__SANITIZE_ADDRESS__)
#include "sanitizer/lsan_interface.h"
* 控制地址消毒器关闭与开启.
* 开关仅在蓝区CI场景可用,仅在当前thread有效.
* DT_DETECT_LEAKS_OFF();
* // code block with memory leak
* DT_DETECT_LEAKS_ON();
*/
#define DT_DETECT_LEAKS_OFF() \
do { \
__lsan_disable(); \
} while (0)
#define DT_DETECT_LEAKS_ON() \
do { \
__lsan_enable(); \
} while (0)
#define DT_DO_DETECT_LEAKS() \
do { \
__lsan_do_leak_check(); \
} while (0)
#else
#define DT_DETECT_LEAKS_OFF() \
do { \
} while (0)
#define DT_DETECT_LEAKS_ON() \
do { \
} while (0)
#define DT_DO_DETECT_LEAKS() \
do { \
} while (0)
#endif
#define DT_ALLOW_LEAKS_GUARD(name) ::ge::LeaksGuarder leaks_guard_for_##name
namespace ge {
class LeaksGuarder {
public:
LeaksGuarder(const LeaksGuarder &) = delete;
LeaksGuarder &operator=(const LeaksGuarder &) = delete;
LeaksGuarder() {
DT_DETECT_LEAKS_OFF();
}
~LeaksGuarder() {
DT_DETECT_LEAKS_ON();
}
};
}
#endif