1
0
Fork 0
forked from len0rd/rockbox

buflib: add a common dummy callbacks struct & use it

There are various allocations that can't be moved or shrunk.
Provide a global callback struct for this use case instead of
making each caller declare its own dummy struct.

Also fixed ROLO and x1000 installer code which incorrectly
used movable allocations.

Change-Id: I00088396b9826e02e69a4a33477fe1a7816374f1
This commit is contained in:
Aidan MacDonald 2022-01-18 18:57:06 +00:00
parent 95dfc489b5
commit e8faf2f2ad
14 changed files with 43 additions and 30 deletions

View file

@ -51,7 +51,7 @@ int xf_nandio_init(struct xf_nandio* nio)
alloc_size += CACHEALIGN_SIZE - 1;
alloc_size += nio->block_size * 2;
nio->alloc_handle = core_alloc("xf_nandio", alloc_size);
nio->alloc_handle = core_alloc_ex("xf_nandio", alloc_size, &buflib_ops_locked);
if(nio->alloc_handle < 0) {
rc = XF_E_OUT_OF_MEMORY;
goto out_nclose;

View file

@ -49,7 +49,7 @@ static int pkg_alloc(struct xf_package* pkg)
alloc_size += ALIGN_UP_P2(METADATA_SIZE, 3);
alloc_size += 7; /* for alignment */
pkg->alloc_handle = core_alloc("xf_package", alloc_size);
pkg->alloc_handle = core_alloc_ex("xf_package", alloc_size, &buflib_ops_locked);
if(pkg->alloc_handle < 0)
return XF_E_OUT_OF_MEMORY;

View file

@ -25,6 +25,7 @@
#define N_POINTERS 100
static void* pointers[N_POINTERS];
struct buflib_callbacks buflib_ops_locked = {NULL, NULL, NULL};
int core_alloc(const char* name, size_t size)
{
@ -46,6 +47,12 @@ int core_alloc(const char* name, size_t size)
return -1;
}
int core_alloc_ex(const char* name, size_t size, struct buflib_callbacks* cb)
{
(void)cb;
return core_alloc(name, size);
}
int core_free(int handle)
{
if(handle > 0) {

View file

@ -25,8 +25,18 @@
#define CORE_ALLOC_H
#include <stddef.h>
#include <stdbool.h>
struct buflib_callbacks {
int (*move_callback)(int handle, void* current, void* new);
int (*shrink_callback)(int handle, unsigned hints, void* start, size_t old_size);
void (*sync_callback)(int handle, bool sync_on);
};
extern struct buflib_callbacks buflib_ops_locked;
int core_alloc(const char* name, size_t size);
int core_alloc_ex(const char* name, size_t size, struct buflib_callbacks* cb);
int core_free(int handle);
void* core_get_data(int handle);