Skip to content

Commit e3246b8

Browse files
Jyri Sarhakv2019i
authored andcommitted
posix: alloc.h: Add dummy mod_alloc_ctx and sof_ctx_alloc() support
Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 216e69c commit e3246b8

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

posix/include/rtos/alloc.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,56 @@ void sof_heap_free(struct k_heap *heap, void *addr);
120120
struct k_heap *sof_sys_heap_get(void);
121121
struct k_heap *sof_sys_user_heap_get(void);
122122

123+
/* Posix version of struct mod_alloc_ctx without vregion support */
124+
struct vregion;
125+
126+
struct mod_alloc_ctx {
127+
struct k_heap *heap;
128+
struct vregion *vreg;
129+
};
130+
131+
/**
132+
* Allocate memory from a mod_alloc_ctx context.
133+
* Dummy version, only heap allocation is supported
134+
*/
135+
static inline void *sof_ctx_alloc(struct mod_alloc_ctx *ctx, uint32_t flags,
136+
size_t size, size_t alignment)
137+
{
138+
return sof_heap_alloc(ctx ? ctx->heap : NULL, flags, size, alignment);
139+
}
140+
141+
/**
142+
* Allocate zero-initialized memory from a mod_alloc_ctx context.
143+
* @param ctx Allocation context.
144+
* @param flags Allocation flags (SOF_MEM_FLAG_*).
145+
* @param size Size in bytes.
146+
* @param alignment Required alignment in bytes.
147+
* @return Pointer to allocated memory or NULL on failure.
148+
*/
149+
static inline void *sof_ctx_zalloc(struct mod_alloc_ctx *ctx, uint32_t flags,
150+
size_t size, size_t alignment)
151+
{
152+
void *ptr = sof_ctx_alloc(ctx, flags, size, alignment);
153+
154+
if (ptr)
155+
memset(ptr, 0, size);
156+
157+
return ptr;
158+
}
159+
160+
/**
161+
* Free memory allocated from a mod_alloc_ctx context.
162+
* @param ctx Allocation context.
163+
* @param ptr Pointer to free.
164+
*/
165+
static inline void sof_ctx_free(struct mod_alloc_ctx *ctx, void *ptr)
166+
{
167+
if (!ptr)
168+
return;
169+
170+
sof_heap_free(ctx ? ctx->heap : NULL, ptr);
171+
}
172+
123173
/**
124174
* Calculates length of the null-terminated string.
125175
* @param s String.

0 commit comments

Comments
 (0)