kindlebt
Bluetooth functionality for Kindle 11th gen and up
Loading...
Searching...
No Matches
compat_acealloc.c
1#define _GNU_SOURCE
2
3#include <kindlebt/compat_ace_shims.h>
4
5#include <dlfcn.h>
6
7#include "log.h"
8
9// Used in the bleWriteCharacteristics and bleWriteDescriptor calls.
10// I don't want to declare it because that would be a whole new linking dependency
11
12// Defined in ace/ace_modules.h
13#define ACE_MODULE_BT 33
14// Defined in ace/osal_alloc.h
15#define ACE_ALLOC_BUFFER_GENERIC 0
16
17typedef void (*aceAlloc_free_fn_t)(int, int, void*);
18void shadow_aceAlloc_free(void* p) {
19 static aceAlloc_free_fn_t api = NULL;
20 static bool initialized = false;
21
22 if (!initialized) {
23 api = (aceAlloc_free_fn_t)dlsym(RTLD_DEFAULT, "aceAlloc_free");
24 initialized = true;
25 }
26
27 if (api == NULL) {
28 log_error(
29 "[%s()]: couldn't match aceAlloc_free symbol. This is not supposed to happen", __func__
30 );
31 return;
32 }
33
34 return api(ACE_MODULE_BT, ACE_ALLOC_BUFFER_GENERIC, p);
35}