diff options
author | Jens Arnold <amiconn@rockbox.org> | 2006-01-17 20:39:44 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2006-01-17 20:39:44 +0000 |
commit | a40d355ee7c57b96dc3e5320f16ea6cc808483f3 (patch) | |
tree | a1e602b7ed18addd4286e55d528f414d02240248 | |
parent | 2f56ee9d0ffecbae531dd198cfe51a334e05dbe4 (diff) | |
download | rockbox-a40d355ee7c57b96dc3e5320f16ea6cc808483f3.tar.gz rockbox-a40d355ee7c57b96dc3e5320f16ea6cc808483f3.zip |
Simplified new plugin loader (only read plugin once).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8360 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugin.c | 54 |
1 files changed, 17 insertions, 37 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index a2cb0dedcb..a6b9703f1a 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -368,13 +368,10 @@ static const struct plugin_api rockbox_api = { int plugin_load(const char* plugin, void* parameter) { - enum plugin_status (*plugin_start)(struct plugin_api* api, void* param); int fd, rc; + struct plugin_header *hdr; #ifndef SIMULATOR - struct plugin_header header; ssize_t readsize; -#else - struct plugin_header *hdr; #endif #ifdef HAVE_LCD_BITMAP int xm, ym; @@ -387,14 +384,12 @@ int plugin_load(const char* plugin, void* parameter) plugin_loaded = false; } -#ifdef HAVE_LCD_BITMAP lcd_clear_display(); +#ifdef HAVE_LCD_BITMAP xm = lcd_getxmargin(); ym = lcd_getymargin(); lcd_setmargins(0,0); lcd_update(); -#else - lcd_clear_display(); #endif #ifdef SIMULATOR hdr = sim_plugin_load((char *)plugin, &fd); @@ -416,59 +411,44 @@ int plugin_load(const char* plugin, void* parameter) gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); return -1; } - plugin_start = hdr->entry_point; #else fd = open(plugin, O_RDONLY); if (fd < 0) { gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); return fd; } - readsize = read(fd, &header, sizeof(header)); + /* zero out plugin buffer to ensure a properly zeroed bss area */ + memset(pluginbuf, 0, PLUGIN_BUFFER_SIZE); + + readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE); close(fd); - /* Close for now. Less code than doing it in all error checks. - * Would need to seek back anyway. */ - if (readsize != sizeof(header)) { + if (readsize <= (signed)sizeof(struct plugin_header)) { gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin); return -1; } - if (header.magic != PLUGIN_MAGIC - || header.target_id != TARGET_ID - || header.load_addr != pluginbuf - || header.end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) { + hdr = (struct plugin_header *)pluginbuf; + + if (hdr->magic != PLUGIN_MAGIC + || hdr->target_id != TARGET_ID + || hdr->load_addr != pluginbuf + || hdr->end_addr > pluginbuf + PLUGIN_BUFFER_SIZE) { gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL)); return -1; } - if (header.api_version > PLUGIN_API_VERSION - || header.api_version < PLUGIN_MIN_API_VERSION) { + if (hdr->api_version > PLUGIN_API_VERSION + || hdr->api_version < PLUGIN_MIN_API_VERSION) { gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); return -1; } - /* zero out plugin buffer to ensure a properly zeroed bss area */ - memset(pluginbuf, 0, header.end_addr - pluginbuf); - - fd = open(plugin, O_RDONLY); - if (fd < 0) { - gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); - return fd; - } - readsize = read(fd, pluginbuf, PLUGIN_BUFFER_SIZE); - close(fd); - - if (readsize < 0) { - /* read error */ - gui_syncsplash(HZ*2, true, str(LANG_READ_FAILED), plugin); - return -1; - } - plugin_size = header.end_addr - header.load_addr; - plugin_start = header.entry_point; + plugin_size = hdr->end_addr - pluginbuf; #endif plugin_loaded = true; invalidate_icache(); - rc = plugin_start((struct plugin_api*) &rockbox_api, parameter); + rc = hdr->entry_point((struct plugin_api*) &rockbox_api, parameter); /* explicitly casting the pointer here to avoid touching every plugin. */ button_clear_queue(); |