From 0d4585b28ffcac1b62ed37cee2c34de0515df468 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Thu, 9 Sep 2010 16:17:21 +0000 Subject: Extend lc_open() to also being able to load overlay plugins. For this it needs to look at the plugin header. Since lc_open() doesn't know it's a plugin, the header needs to be changed slightly to include the new lc_header (which needs to be the first element in plugin_header so it can be casted savely). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28054 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/lib/overlay.c | 76 +++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 42 deletions(-) (limited to 'apps/plugins/lib') diff --git a/apps/plugins/lib/overlay.c b/apps/plugins/lib/overlay.c index 8a04cf8..f64df29 100644 --- a/apps/plugins/lib/overlay.c +++ b/apps/plugins/lib/overlay.c @@ -47,64 +47,56 @@ enum plugin_status run_overlay(const void* parameter, unsigned char *filename, unsigned char *name) { - int fd, readsize; size_t audiobuf_size; unsigned char *audiobuf; - static struct plugin_header header; + void *handle; + struct plugin_header *p_hdr; + struct lc_header *hdr; - fd = rb->open(filename, O_RDONLY); - if (fd < 0) + audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size); + if (!audiobuf) { - rb->splashf(2*HZ, "Can't open %s", filename); - return PLUGIN_ERROR; + rb->splash(2*HZ, "Can't optain memory"); + goto error; } - readsize = rb->read(fd, &header, sizeof(header)); - rb->close(fd); - /* Close for now. Less code than doing it in all error checks. - * Would need to seek back anyway. */ - if (readsize != sizeof(header)) - { - rb->splashf(2*HZ, "Reading %s overlay failed.", name); - return PLUGIN_ERROR; - } - if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID) + handle = rb->lc_open(filename, audiobuf, audiobuf_size); + if (!handle) { - rb->splashf(2*HZ, "%s overlay: Incompatible model.", name); - return PLUGIN_ERROR; - } - if (header.api_version != PLUGIN_API_VERSION) - { - rb->splashf(2*HZ, "%s overlay: Incompatible version.", name); - return PLUGIN_ERROR; + rb->splashf(2*HZ, "Can't open %s", filename); + goto error; } - audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size); - if (header.load_addr < audiobuf || - header.end_addr > audiobuf + audiobuf_size) + p_hdr = rb->lc_get_header(handle); + if (!p_hdr) { - rb->splashf(2*HZ, "%s overlay doesn't fit into memory.", name); - return PLUGIN_ERROR; + rb->splash(2*HZ, "Can't get header"); + goto error_close; } + else + hdr = &p_hdr->lc_hdr; - fd = rb->open(filename, O_RDONLY); - if (fd < 0) + if (hdr->magic != PLUGIN_MAGIC || hdr->target_id != TARGET_ID) { - rb->splashf(2*HZ, "Can't open %s", filename); - return PLUGIN_ERROR; + rb->splashf(2*HZ, "%s overlay: Incompatible model.", name); + goto error_close; } - readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr); - rb->close(fd); - if (readsize < 0) + + if (hdr->api_version > PLUGIN_API_VERSION + || hdr->api_version < PLUGIN_MIN_API_VERSION) { - rb->splashf(2*HZ, "Reading %s overlay failed.", name); - return PLUGIN_ERROR; + rb->splashf(2*HZ, "%s overlay: Incompatible version.", name); + goto error_close; } - /* Zero out bss area */ - rb->memset(header.load_addr + readsize, 0, - header.end_addr - (header.load_addr + readsize)); - *(header.api) = rb; - return header.entry_point(parameter); + rb->lc_close(handle); + + *(p_hdr->api) = rb; + return p_hdr->entry_point(parameter); + +error_close: + rb->lc_close(handle); +error: + return PLUGIN_ERROR; } -- cgit v1.1