summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/overlay.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/overlay.c')
-rw-r--r--apps/plugins/lib/overlay.c76
1 files changed, 34 insertions, 42 deletions
diff --git a/apps/plugins/lib/overlay.c b/apps/plugins/lib/overlay.c
index 8a04cf8aa7..f64df29823 100644
--- a/apps/plugins/lib/overlay.c
+++ b/apps/plugins/lib/overlay.c
@@ -47,64 +47,56 @@
47enum plugin_status run_overlay(const void* parameter, 47enum plugin_status run_overlay(const void* parameter,
48 unsigned char *filename, unsigned char *name) 48 unsigned char *filename, unsigned char *name)
49{ 49{
50 int fd, readsize;
51 size_t audiobuf_size; 50 size_t audiobuf_size;
52 unsigned char *audiobuf; 51 unsigned char *audiobuf;
53 static struct plugin_header header; 52 void *handle;
53 struct plugin_header *p_hdr;
54 struct lc_header *hdr;
54 55
55 fd = rb->open(filename, O_RDONLY); 56 audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size);
56 if (fd < 0) 57 if (!audiobuf)
57 { 58 {
58 rb->splashf(2*HZ, "Can't open %s", filename); 59 rb->splash(2*HZ, "Can't optain memory");
59 return PLUGIN_ERROR; 60 goto error;
60 } 61 }
61 readsize = rb->read(fd, &header, sizeof(header));
62 rb->close(fd);
63 /* Close for now. Less code than doing it in all error checks.
64 * Would need to seek back anyway. */
65 62
66 if (readsize != sizeof(header)) 63 handle = rb->lc_open(filename, audiobuf, audiobuf_size);
67 { 64 if (!handle)
68 rb->splashf(2*HZ, "Reading %s overlay failed.", name);
69 return PLUGIN_ERROR;
70 }
71 if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID)
72 { 65 {
73 rb->splashf(2*HZ, "%s overlay: Incompatible model.", name); 66 rb->splashf(2*HZ, "Can't open %s", filename);
74 return PLUGIN_ERROR; 67 goto error;
75 }
76 if (header.api_version != PLUGIN_API_VERSION)
77 {
78 rb->splashf(2*HZ, "%s overlay: Incompatible version.", name);
79 return PLUGIN_ERROR;
80 } 68 }
81 69
82 audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size); 70 p_hdr = rb->lc_get_header(handle);
83 if (header.load_addr < audiobuf || 71 if (!p_hdr)
84 header.end_addr > audiobuf + audiobuf_size)
85 { 72 {
86 rb->splashf(2*HZ, "%s overlay doesn't fit into memory.", name); 73 rb->splash(2*HZ, "Can't get header");
87 return PLUGIN_ERROR; 74 goto error_close;
88 } 75 }
76 else
77 hdr = &p_hdr->lc_hdr;
89 78
90 fd = rb->open(filename, O_RDONLY); 79 if (hdr->magic != PLUGIN_MAGIC || hdr->target_id != TARGET_ID)
91 if (fd < 0)
92 { 80 {
93 rb->splashf(2*HZ, "Can't open %s", filename); 81 rb->splashf(2*HZ, "%s overlay: Incompatible model.", name);
94 return PLUGIN_ERROR; 82 goto error_close;
95 } 83 }
96 readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr);
97 rb->close(fd);
98 84
99 if (readsize < 0) 85
86 if (hdr->api_version > PLUGIN_API_VERSION
87 || hdr->api_version < PLUGIN_MIN_API_VERSION)
100 { 88 {
101 rb->splashf(2*HZ, "Reading %s overlay failed.", name); 89 rb->splashf(2*HZ, "%s overlay: Incompatible version.", name);
102 return PLUGIN_ERROR; 90 goto error_close;
103 } 91 }
104 /* Zero out bss area */
105 rb->memset(header.load_addr + readsize, 0,
106 header.end_addr - (header.load_addr + readsize));
107 92
108 *(header.api) = rb; 93 rb->lc_close(handle);
109 return header.entry_point(parameter); 94
95 *(p_hdr->api) = rb;
96 return p_hdr->entry_point(parameter);
97
98error_close:
99 rb->lc_close(handle);
100error:
101 return PLUGIN_ERROR;
110} 102}