1
0
Fork 0
forked from len0rd/rockbox

add way to lock portion of plugin buffer for TSR plugins

Some things in core that should probably be plugins steal the plugin buffer
for their own use, TSR plugins have no way to detect or prevent this
lock buffer reserves buffer_size bytes directly after the plugin itself
returns the unreserved bytes still available from the plugin buffer

Change-Id: I5a7849e209129b09400036a594569ef396b1b85f
This commit is contained in:
William Wilgus 2022-03-25 10:28:35 -04:00 committed by William Wilgus
parent 5d0f697e87
commit 8eb4689ab1
2 changed files with 24 additions and 0 deletions

View file

@ -809,6 +809,7 @@ static const struct plugin_api rockbox_api = {
onplay_show_playlist_menu, onplay_show_playlist_menu,
queue_remove_from_head, queue_remove_from_head,
core_set_keyremap, core_set_keyremap,
plugin_reserve_buffer,
}; };
static int plugin_buffer_handle; static int plugin_buffer_handle;
@ -963,6 +964,27 @@ int plugin_load(const char* plugin, const void* parameter)
return rc; return rc;
} }
/* For Terminate Stay Resident plugins
* Locks buffer_size bytes of the plugin buffer
* freed on plugin exit; call plugin_get_buffer first then reserve all
* or a portion with plugin_reserve_buffer()
* Returns size of buffer remaining */
size_t plugin_reserve_buffer(size_t buffer_size)
{
size_t locked_size = 0;
if (current_plugin_handle)
{
locked_size = ALIGN_UP(plugin_size + buffer_size, 0x8);
if (locked_size > PLUGIN_BUFFER_SIZE)
locked_size = PLUGIN_BUFFER_SIZE;
plugin_size = locked_size;
}
return (PLUGIN_BUFFER_SIZE - locked_size);
}
/* Returns a pointer to the portion of the plugin buffer that is not already /* Returns a pointer to the portion of the plugin buffer that is not already
being used. If no plugin is loaded, returns the entire plugin buffer */ being used. If no plugin is loaded, returns the entire plugin buffer */
void* plugin_get_buffer(size_t *buffer_size) void* plugin_get_buffer(size_t *buffer_size)

View file

@ -49,6 +49,7 @@
char* strncpy(char *, const char *, size_t); char* strncpy(char *, const char *, size_t);
void* plugin_get_buffer(size_t *buffer_size); void* plugin_get_buffer(size_t *buffer_size);
size_t plugin_reserve_buffer(size_t buffer_size);
int plugin_open(const char *plugin, const char *parameter); int plugin_open(const char *plugin, const char *parameter);
#ifndef __PCTOOL__ #ifndef __PCTOOL__
@ -935,6 +936,7 @@ struct plugin_api {
void (*onplay_show_playlist_menu)(const char* path, void (*playlist_insert_cb)); void (*onplay_show_playlist_menu)(const char* path, void (*playlist_insert_cb));
void (*queue_remove_from_head)(struct event_queue *q, long id); void (*queue_remove_from_head)(struct event_queue *q, long id);
int (*core_set_keyremap)(struct button_mapping* core_keymap, int count); int (*core_set_keyremap)(struct button_mapping* core_keymap, int count);
size_t (*plugin_reserve_buffer)(size_t buffer_size);
}; };
/* plugin header */ /* plugin header */