• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "memory_trace.h"
17 #ifdef HOOK_ENABLE
18 #include "common_def.h"
19 #include "musl_preinit_common.h"
20 #endif
21 
memtrace(void * addr,size_t size,const char * tag,bool is_using)22 void memtrace(void* addr, size_t size, const char* tag, bool is_using)
23 {
24 #ifdef HOOK_ENABLE
25 	volatile const struct MallocDispatchType* dispatch_table = (struct MallocDispatchType *)atomic_load_explicit(
26 		&__musl_libc_globals.current_dispatch_table, memory_order_acquire);
27 	if (__predict_false(dispatch_table != NULL)) {
28 		if (__get_memleak_hook_flag()) {
29 			return;
30 		}
31 		if (!__get_global_hook_flag()) {
32 			return;
33 		}
34 		else if (!__get_hook_flag()) {
35 			return;
36 		}
37 		return dispatch_table->memtrace(addr, size, tag, is_using);
38 	}
39 #endif
40     return;
41 }
42