Skip to content

Commit 07e67bc

Browse files
committed
[libc][syscall] Add detailed function comments for memory management functions
1 parent d3ba09a commit 07e67bc

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

components/libc/compilers/armlibc/syscall_mem.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Date Author Notes
88
* 2014-08-03 bernard Add file header
99
* 2021-11-13 Meco Man implement no-heap warning
10+
* 2025-11-1 MaChengyang Add detailed function comments
1011
*/
1112

1213
#include <rtthread.h>
@@ -27,6 +28,22 @@
2728
#pragma import(__use_no_heap)
2829
#endif /* __CC_ARM */
2930

31+
/**
32+
* @brief Allocate memory block
33+
*
34+
* Allocates a block of size bytes of memory, returning a pointer to the
35+
* beginning of the block. The content of the newly allocated block of
36+
* memory is not initialized, remaining with indeterminate values.
37+
*
38+
* @param n the size of the memory block, in bytes.
39+
*
40+
* @return On success, a pointer to the memory block allocated by the function.
41+
* If the system is configured without heap (RT_USING_HEAP is not defined),
42+
* the function will assert and return RT_NULL.
43+
*
44+
* @note The returned pointer is always suitably aligned for any built-in type.
45+
* @see rt_malloc
46+
*/
3047
void *malloc(size_t n)
3148
{
3249
#ifdef RT_USING_HEAP
@@ -38,6 +55,30 @@ void *malloc(size_t n)
3855
}
3956
RTM_EXPORT(malloc);
4057

58+
/**
59+
* @brief Reallocate memory block
60+
*
61+
* Changes the size of the memory block pointed to by rmem.
62+
* The function may move the memory block to a new location
63+
* (whose address is returned by the function).
64+
* The content of the memory block is preserved up to the
65+
* lesser of the new and old sizes, even if the block is
66+
* moved to a new location. If the new size is larger,
67+
* the value of the newly allocated portion is indeterminate.
68+
*
69+
* @param rmem pointer to a memory block previously allocated with
70+
* malloc, calloc or realloc to be reallocated.
71+
* If this is RT_NULL, a new block is allocated and
72+
* a pointer to it is returned by the function.
73+
* @param newsize new size for the memory block, in bytes.
74+
*
75+
* @return A pointer to the reallocated memory block, which may be either
76+
* the same as the rmem pointer or a new location.
77+
* If the system is configured without heap (RT_USING_HEAP is not defined),
78+
* the function will assert and return RT_NULL.
79+
*
80+
* @see rt_realloc
81+
*/
4182
void *realloc(void *rmem, size_t newsize)
4283
{
4384
#ifdef RT_USING_HEAP
@@ -49,6 +90,23 @@ void *realloc(void *rmem, size_t newsize)
4990
}
5091
RTM_EXPORT(realloc);
5192

93+
/**
94+
* @brief Allocate and zero-initialize array
95+
*
96+
* Allocates a block of memory for an array of nelem elements, each of them
97+
* elsize bytes long, and initializes all its bits to zero.
98+
* The effective result is the allocation of a zero-initialized memory block
99+
* of (nelem*elsize) bytes.
100+
*
101+
* @param nelem number of elements to allocate.
102+
* @param elsize size of each element.
103+
*
104+
* @return On success, a pointer to the memory block allocated by the function.
105+
* If the system is configured without heap (RT_USING_HEAP is not defined),
106+
* the function will assert and return RT_NULL.
107+
*
108+
* @see rt_calloc
109+
*/
52110
void *calloc(size_t nelem, size_t elsize)
53111
{
54112
#ifdef RT_USING_HEAP
@@ -60,6 +118,20 @@ void *calloc(size_t nelem, size_t elsize)
60118
}
61119
RTM_EXPORT(calloc);
62120

121+
/**
122+
* @brief Deallocate memory block
123+
*
124+
* A block of memory previously allocated by a call to malloc, calloc or realloc
125+
* is deallocated, making it available again for further allocations.
126+
*
127+
* @param rmem pointer to a memory block previously allocated with malloc,
128+
* calloc or realloc to be deallocated. If a null pointer is
129+
* passed as argument, no action occurs.
130+
*
131+
* @note If the system is configured without heap (RT_USING_HEAP is not defined),
132+
* the function will assert.
133+
* @see rt_free
134+
*/
63135
void free(void *rmem)
64136
{
65137
#ifdef RT_USING_HEAP

0 commit comments

Comments
 (0)