From 88239a270c29994b71b54ac86f96b9a5e0400e49 Mon Sep 17 00:00:00 2001 From: wangwenjun Date: Tue, 6 May 2025 15:03:58 +0800 Subject: [PATCH 1/2] musl add malloc_check_from_ptr Signed-off-by: wangwenjun --- third_party/musl/ndk_musl_include/malloc.h | 44 +++++++++++++++++++ .../musl/ndk_script/adapter/libc.ndk.json | 3 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/third_party/musl/ndk_musl_include/malloc.h b/third_party/musl/ndk_musl_include/malloc.h index 4817d5a5e..abfeb81eb 100644 --- a/third_party/musl/ndk_musl_include/malloc.h +++ b/third_party/musl/ndk_musl_include/malloc.h @@ -1,3 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @addtogroup MuslMalloc + * @{ + * + * @brief Provide some methods related to memory management. + * @since 12 + */ +/** + * @file malloc.h + * + * @brief Includes some memory-related methods and structures, + * such as: malloc, calloc, realloc, and so on. + * + * @library libc.so + * @kit CstandardLibrary + * @since 12 + */ + #ifndef _MALLOC_H #define _MALLOC_H @@ -35,6 +67,17 @@ void *memalign(size_t, size_t); size_t malloc_usable_size(void *); int mallopt(int param, int value); +/** + * @brief This function determines whether a given memory block was allocated using + * Standard C library Memory Allocator. + * This function is MT-Safe(multi-thread safe) but not signal-safe. + * @param {void *} ptr A pointer to the memory block to be checked. + * @return 1 - The memory block was allocated using Standard C library Memory Allocator. + * 0 - The memory block was not allocated using Standard C library Memory Allocator. + * -1 - The function is not implemented or other error: + */ +int malloc_check_from_ptr(void *ptr); + struct mallinfo { int arena; int ordblks; @@ -66,3 +109,4 @@ struct mallinfo2 { #endif #endif +/** @} */ \ No newline at end of file diff --git a/third_party/musl/ndk_script/adapter/libc.ndk.json b/third_party/musl/ndk_script/adapter/libc.ndk.json index 4a86a82df..c1dfaf89d 100644 --- a/third_party/musl/ndk_script/adapter/libc.ndk.json +++ b/third_party/musl/ndk_script/adapter/libc.ndk.json @@ -1588,5 +1588,6 @@ { "name": "__recv_chk"}, { "name": "__recvfrom_chk"}, { "name": "__open_chk"}, - { "name": "__strlcat_chk"} + { "name": "__strlcat_chk"}, + { "name": "malloc_check_from_ptr"} ] -- Gitee From 87669a188fabf7fa0c367126b8ee846b50a9ab56 Mon Sep 17 00:00:00 2001 From: wangwenjun Date: Tue, 6 May 2025 15:29:48 +0800 Subject: [PATCH 2/2] musl add malloc_check_from_ptr Signed-off-by: wangwenjun --- third_party/musl/ndk_musl_include/malloc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/musl/ndk_musl_include/malloc.h b/third_party/musl/ndk_musl_include/malloc.h index abfeb81eb..3601b2625 100644 --- a/third_party/musl/ndk_musl_include/malloc.h +++ b/third_party/musl/ndk_musl_include/malloc.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the "License"), * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -74,7 +74,7 @@ int mallopt(int param, int value); * @param {void *} ptr A pointer to the memory block to be checked. * @return 1 - The memory block was allocated using Standard C library Memory Allocator. * 0 - The memory block was not allocated using Standard C library Memory Allocator. - * -1 - The function is not implemented or other error: + * -1 - The function is not implemented or other error. */ int malloc_check_from_ptr(void *ptr); -- Gitee