Skip to content

Commit 5b87ac6

Browse files
authored
[libc][syscall] add detailed function comments for memory management
1 parent 8153fe5 commit 5b87ac6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

components/libc/compilers/armlibc/syscall_mem.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
#pragma import(__use_no_heap)
2828
#endif /* __CC_ARM */
2929

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

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

89+
/**
90+
* @brief Allocate and zero-initialize array
91+
*
92+
* Allocates a block of memory for an array of nelem elements, each of them
93+
* elsize bytes long, and initializes all its bits to zero.
94+
* The effective result is the allocation of a zero-initialized memory block
95+
* of (nelem*elsize) bytes.
96+
*
97+
* @param[in] nelem number of elements to allocate.
98+
* @param[in] elsize size of each element.
99+
*
100+
* @return On success, a pointer to the memory block allocated by the function.
101+
* If the system is configured without heap (RT_USING_HEAP is not defined),
102+
* the function will assert and return RT_NULL.
103+
*/
52104
void *calloc(size_t nelem, size_t elsize)
53105
{
54106
#ifdef RT_USING_HEAP
@@ -60,6 +112,19 @@ void *calloc(size_t nelem, size_t elsize)
60112
}
61113
RTM_EXPORT(calloc);
62114

115+
/**
116+
* @brief Deallocate memory block
117+
*
118+
* A block of memory previously allocated by a call to malloc, calloc or realloc
119+
* is deallocated, making it available again for further allocations.
120+
*
121+
* @param[in] rmem pointer to a memory block previously allocated with malloc,
122+
* calloc or realloc to be deallocated. If a null pointer is
123+
* passed as argument, no action occurs.
124+
*
125+
* @note If the system is configured without heap (RT_USING_HEAP is not defined),
126+
* the function will assert.
127+
*/
63128
void free(void *rmem)
64129
{
65130
#ifdef RT_USING_HEAP

0 commit comments

Comments
 (0)