summaryrefslogtreecommitdiff
path: root/firmware/include/buflib_malloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/include/buflib_malloc.h')
-rw-r--r--firmware/include/buflib_malloc.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/firmware/include/buflib_malloc.h b/firmware/include/buflib_malloc.h
new file mode 100644
index 0000000000..32c837e7b7
--- /dev/null
+++ b/firmware/include/buflib_malloc.h
@@ -0,0 +1,53 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2023 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _BUFLIB_MALLOC_H_
22#define _BUFLIB_MALLOC_H_
23
24#ifndef _BUFLIB_H_
25# error "include buflib.h instead"
26#endif
27
28struct buflib_malloc_handle
29{
30 void *data;
31 void *user;
32 size_t size;
33 unsigned int pin_count;
34 struct buflib_callbacks *ops;
35};
36
37struct buflib_context
38{
39 struct buflib_malloc_handle *allocs;
40 size_t num_allocs;
41
42 void *buf;
43 size_t bufsize;
44};
45
46#ifndef BUFLIB_DEBUG_GET_DATA
47static inline void *buflib_get_data(struct buflib_context *ctx, int handle)
48{
49 return ctx->allocs[handle - 1].user;
50}
51#endif
52
53#endif /* _BUFLIB_MALLOC_H_ */