From 07e67bc07556004ae567cc3fea20c8aa042bf67e Mon Sep 17 00:00:00 2001 From: MaChengyang <3427742239@qq.com> Date: Sat, 1 Nov 2025 17:07:32 +0800 Subject: [PATCH 1/3] [libc][syscall] Add detailed function comments for memory management functions --- .../libc/compilers/armlibc/syscall_mem.c | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/components/libc/compilers/armlibc/syscall_mem.c b/components/libc/compilers/armlibc/syscall_mem.c index f831bd173b2..8128128ba39 100644 --- a/components/libc/compilers/armlibc/syscall_mem.c +++ b/components/libc/compilers/armlibc/syscall_mem.c @@ -7,6 +7,7 @@ * Date Author Notes * 2014-08-03 bernard Add file header * 2021-11-13 Meco Man implement no-heap warning + * 2025-11-1 MaChengyang Add detailed function comments */ #include @@ -27,6 +28,22 @@ #pragma import(__use_no_heap) #endif /* __CC_ARM */ +/** + * @brief Allocate memory block + * + * Allocates a block of size bytes of memory, returning a pointer to the + * beginning of the block. The content of the newly allocated block of + * memory is not initialized, remaining with indeterminate values. + * + * @param n the size of the memory block, in bytes. + * + * @return On success, a pointer to the memory block allocated by the function. + * If the system is configured without heap (RT_USING_HEAP is not defined), + * the function will assert and return RT_NULL. + * + * @note The returned pointer is always suitably aligned for any built-in type. + * @see rt_malloc + */ void *malloc(size_t n) { #ifdef RT_USING_HEAP @@ -38,6 +55,30 @@ void *malloc(size_t n) } RTM_EXPORT(malloc); +/** + * @brief Reallocate memory block + * + * Changes the size of the memory block pointed to by rmem. + * The function may move the memory block to a new location + * (whose address is returned by the function). + * The content of the memory block is preserved up to the + * lesser of the new and old sizes, even if the block is + * moved to a new location. If the new size is larger, + * the value of the newly allocated portion is indeterminate. + * + * @param rmem pointer to a memory block previously allocated with + * malloc, calloc or realloc to be reallocated. + * If this is RT_NULL, a new block is allocated and + * a pointer to it is returned by the function. + * @param newsize new size for the memory block, in bytes. + * + * @return A pointer to the reallocated memory block, which may be either + * the same as the rmem pointer or a new location. + * If the system is configured without heap (RT_USING_HEAP is not defined), + * the function will assert and return RT_NULL. + * + * @see rt_realloc + */ void *realloc(void *rmem, size_t newsize) { #ifdef RT_USING_HEAP @@ -49,6 +90,23 @@ void *realloc(void *rmem, size_t newsize) } RTM_EXPORT(realloc); +/** + * @brief Allocate and zero-initialize array + * + * Allocates a block of memory for an array of nelem elements, each of them + * elsize bytes long, and initializes all its bits to zero. + * The effective result is the allocation of a zero-initialized memory block + * of (nelem*elsize) bytes. + * + * @param nelem number of elements to allocate. + * @param elsize size of each element. + * + * @return On success, a pointer to the memory block allocated by the function. + * If the system is configured without heap (RT_USING_HEAP is not defined), + * the function will assert and return RT_NULL. + * + * @see rt_calloc + */ void *calloc(size_t nelem, size_t elsize) { #ifdef RT_USING_HEAP @@ -60,6 +118,20 @@ void *calloc(size_t nelem, size_t elsize) } RTM_EXPORT(calloc); +/** + * @brief Deallocate memory block + * + * A block of memory previously allocated by a call to malloc, calloc or realloc + * is deallocated, making it available again for further allocations. + * + * @param rmem pointer to a memory block previously allocated with malloc, + * calloc or realloc to be deallocated. If a null pointer is + * passed as argument, no action occurs. + * + * @note If the system is configured without heap (RT_USING_HEAP is not defined), + * the function will assert. + * @see rt_free + */ void free(void *rmem) { #ifdef RT_USING_HEAP From 07e19ebd4d7b01ff43d5b28fdcf6d3d6f57fc50b Mon Sep 17 00:00:00 2001 From: MaChengyang <3427742239@qq.com> Date: Thu, 6 Nov 2025 17:15:01 +0800 Subject: [PATCH 2/3] [libc][syscall] (second) Add detailed function comments for memory management functions Signed-off-by: MaChengyang <3427742239@qq.com> --- .../libc/compilers/armlibc/syscall_mem.c | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/components/libc/compilers/armlibc/syscall_mem.c b/components/libc/compilers/armlibc/syscall_mem.c index 8128128ba39..2519ca6948c 100644 --- a/components/libc/compilers/armlibc/syscall_mem.c +++ b/components/libc/compilers/armlibc/syscall_mem.c @@ -6,8 +6,7 @@ * Change Logs: * Date Author Notes * 2014-08-03 bernard Add file header - * 2021-11-13 Meco Man implement no-heap warning - * 2025-11-1 MaChengyang Add detailed function comments + * 2021-11-13 Meco Man implement no-heap warning */ #include @@ -29,20 +28,19 @@ #endif /* __CC_ARM */ /** - * @brief Allocate memory block + * @brief Allocate memory block * * Allocates a block of size bytes of memory, returning a pointer to the * beginning of the block. The content of the newly allocated block of * memory is not initialized, remaining with indeterminate values. * - * @param n the size of the memory block, in bytes. + * @param[in] n the size of the memory block, in bytes. * * @return On success, a pointer to the memory block allocated by the function. * If the system is configured without heap (RT_USING_HEAP is not defined), * the function will assert and return RT_NULL. * * @note The returned pointer is always suitably aligned for any built-in type. - * @see rt_malloc */ void *malloc(size_t n) { @@ -56,7 +54,7 @@ void *malloc(size_t n) RTM_EXPORT(malloc); /** - * @brief Reallocate memory block + * @brief Reallocate memory block * * Changes the size of the memory block pointed to by rmem. * The function may move the memory block to a new location @@ -66,18 +64,16 @@ RTM_EXPORT(malloc); * moved to a new location. If the new size is larger, * the value of the newly allocated portion is indeterminate. * - * @param rmem pointer to a memory block previously allocated with + * @param[in,out] rmem pointer to a memory block previously allocated with * malloc, calloc or realloc to be reallocated. * If this is RT_NULL, a new block is allocated and * a pointer to it is returned by the function. - * @param newsize new size for the memory block, in bytes. + * @param[in] newsize new size for the memory block, in bytes. * * @return A pointer to the reallocated memory block, which may be either * the same as the rmem pointer or a new location. * If the system is configured without heap (RT_USING_HEAP is not defined), * the function will assert and return RT_NULL. - * - * @see rt_realloc */ void *realloc(void *rmem, size_t newsize) { @@ -91,21 +87,19 @@ void *realloc(void *rmem, size_t newsize) RTM_EXPORT(realloc); /** - * @brief Allocate and zero-initialize array + * @brief Allocate and zero-initialize array * * Allocates a block of memory for an array of nelem elements, each of them * elsize bytes long, and initializes all its bits to zero. * The effective result is the allocation of a zero-initialized memory block * of (nelem*elsize) bytes. * - * @param nelem number of elements to allocate. - * @param elsize size of each element. + * @param[in] nelem number of elements to allocate. + * @param[in] elsize size of each element. * * @return On success, a pointer to the memory block allocated by the function. * If the system is configured without heap (RT_USING_HEAP is not defined), * the function will assert and return RT_NULL. - * - * @see rt_calloc */ void *calloc(size_t nelem, size_t elsize) { @@ -119,18 +113,17 @@ void *calloc(size_t nelem, size_t elsize) RTM_EXPORT(calloc); /** - * @brief Deallocate memory block + * @brief Deallocate memory block * * A block of memory previously allocated by a call to malloc, calloc or realloc * is deallocated, making it available again for further allocations. * - * @param rmem pointer to a memory block previously allocated with malloc, + * @param[in] rmem pointer to a memory block previously allocated with malloc, * calloc or realloc to be deallocated. If a null pointer is * passed as argument, no action occurs. * * @note If the system is configured without heap (RT_USING_HEAP is not defined), * the function will assert. - * @see rt_free */ void free(void *rmem) { From fb69b308553f9991200f59112f5274cdda9501db Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 7 Nov 2025 20:51:50 -0500 Subject: [PATCH 3/3] Update components/libc/compilers/armlibc/syscall_mem.c --- components/libc/compilers/armlibc/syscall_mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/libc/compilers/armlibc/syscall_mem.c b/components/libc/compilers/armlibc/syscall_mem.c index 2519ca6948c..1638e8e90a1 100644 --- a/components/libc/compilers/armlibc/syscall_mem.c +++ b/components/libc/compilers/armlibc/syscall_mem.c @@ -6,7 +6,7 @@ * Change Logs: * Date Author Notes * 2014-08-03 bernard Add file header - * 2021-11-13 Meco Man implement no-heap warning + * 2021-11-13 Meco Man implement no-heap warning */ #include