Skip to content

Commit 90ef190

Browse files
committed
platform: library: add k_heap* types and functions
Add a definition of struct k_heap and SOF k_heap wrappers sof_heap_alloc() and sof_heap_free() for host native builds. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent a564dc5 commit 90ef190

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

posix/include/rtos/alloc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ void rfree(void *ptr);
131131
*/
132132
void *rzalloc_core_sys(int core, size_t bytes);
133133

134+
struct k_heap;
135+
static inline void k_heap_init(struct k_heap *heap, void *mem, size_t bytes)
136+
{
137+
}
138+
void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
139+
size_t alignment);
140+
void sof_heap_free(struct k_heap *heap, void *addr);
141+
134142
/**
135143
* Calculates length of the null-terminated string.
136144
* @param s String.

posix/include/rtos/kernel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ static inline void k_usleep(int32_t us)
4343
wait_delay_us(us);
4444
}
4545

46+
struct k_heap {
47+
int unused;
48+
};
49+
4650
#endif /* __POSIX_RTOS_KERNEL_H__ */

src/lib/alloc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,14 @@ int heap_info(int index, struct mm_info *out)
7171
return 0;
7272
}
7373
#endif
74+
75+
void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
76+
size_t alignment)
77+
{
78+
return malloc(bytes);
79+
}
80+
81+
void sof_heap_free(struct k_heap *heap, void *addr)
82+
{
83+
free(addr);
84+
}

src/platform/library/lib/alloc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes,
4848
return realloc(ptr, bytes);
4949
}
5050

51+
void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
52+
size_t alignment)
53+
{
54+
return malloc(bytes);
55+
}
56+
57+
void sof_heap_free(struct k_heap *heap, void *addr)
58+
{
59+
free(addr);
60+
}
61+
5162
void heap_trace(struct mm_heap *heap, int size)
5263
{
5364
#if MALLOC_DEBUG

test/cmocka/src/common_mocks.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ int WEAK mod_free(struct processing_module *mod, const void *ptr)
122122
return 0;
123123
}
124124

125+
void WEAK *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
126+
size_t alignment)
127+
{
128+
(void)heap;
129+
(void)flags;
130+
(void)alignment;
131+
132+
return malloc(bytes);
133+
}
134+
135+
void WEAK sof_heap_free(struct k_heap *heap, void *addr)
136+
{
137+
(void)heap;
138+
139+
free(addr);
140+
}
141+
125142
int WEAK memcpy_s(void *dest, size_t dest_size,
126143
const void *src, size_t count)
127144
{

0 commit comments

Comments
 (0)