summaryrefslogtreecommitdiff
path: root/firmware/include/buflib_malloc.h
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2023-01-02 22:48:07 +0000
committerAidan MacDonald <amachronic@protonmail.com>2023-01-15 10:04:13 +0000
commit92565e9246f3a47b90fea4a436ecfd8e7a1198b8 (patch)
tree5e2fa26fff921296729b74bd8947dd225e69c84f /firmware/include/buflib_malloc.h
parentf2f198663edc01a1f19e35b8a0c302f8ee47ae5e (diff)
downloadrockbox-92565e9246f3a47b90fea4a436ecfd8e7a1198b8.tar.gz
rockbox-92565e9246f3a47b90fea4a436ecfd8e7a1198b8.zip
buflib: Add malloc-backed buflib
This is intended for improving the effectiveness of tools like ASAN when debugging memory errors in the sim. It's not meant to be a serious allocator for hosted targets. Enable it by changing the buflib backend in config.h. Change-Id: I0cf23cefa47ee35dede7b49e0e5b72dac60e8d3e
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_ */