summaryrefslogtreecommitdiff
path: root/firmware/load_code.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/load_code.c')
-rw-r--r--firmware/load_code.c104
1 files changed, 0 insertions, 104 deletions
diff --git a/firmware/load_code.c b/firmware/load_code.c
index a76aca380d..d22d6bb3b2 100644
--- a/firmware/load_code.c
+++ b/firmware/load_code.c
@@ -25,8 +25,6 @@
25#include "debug.h" 25#include "debug.h"
26#include "load_code.h" 26#include "load_code.h"
27 27
28#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
29
30/* load binary blob from disk to memory, returning a handle */ 28/* load binary blob from disk to memory, returning a handle */
31void * lc_open(const char *filename, unsigned char *buf, size_t buf_size) 29void * lc_open(const char *filename, unsigned char *buf, size_t buf_size)
32{ 30{
@@ -97,105 +95,3 @@ error_fd:
97error: 95error:
98 return NULL; 96 return NULL;
99} 97}
100
101#elif (CONFIG_PLATFORM & PLATFORM_HOSTED)
102/* libdl wrappers */
103
104
105#ifdef WIN32
106/* win32 */
107#include <windows.h>
108#define dlopen(_x_, _y_) LoadLibraryW(_x_)
109#define dlsym(_x_, _y_) (void *)GetProcAddress(_x_, _y_)
110#define dlclose(_x_) FreeLibrary(_x_)
111static inline char *_dlerror(void)
112{
113 static char err_buf[64];
114 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
115 err_buf, sizeof(err_buf), NULL);
116 return err_buf;
117}
118#define dlerror _dlerror
119#else
120/* unix */
121#include <dlfcn.h>
122#endif
123#include <stdio.h>
124#include "rbpaths.h"
125#include "general.h"
126
127void * _lc_open(const _lc_open_char *filename, unsigned char *buf, size_t buf_size)
128{
129 (void)buf;
130 (void)buf_size;
131 return dlopen(filename, RTLD_NOW);
132}
133
134void *lc_open_from_mem(void *addr, size_t blob_size)
135{
136#ifndef SIMULATOR
137 (void)addr;
138 (void)blob_size;
139 /* we don't support loading code from memory on application builds,
140 * it doesn't make sense (since it means writing the blob to disk again and
141 * then falling back to load from disk) and requires the ability to write
142 * to an executable directory */
143 return NULL;
144#else
145 /* support it in the sim for the sake of simulating */
146 int fd, i;
147 char temp_filename[MAX_PATH];
148
149 /* We have to create the dynamic link library file from ram so we
150 can simulate the codec loading. With voice and crossfade,
151 multiple codecs may be loaded at the same time, so we need
152 to find an unused filename */
153 for (i = 0; i < 10; i++)
154 {
155 snprintf(temp_filename, sizeof(temp_filename),
156 ROCKBOX_DIR "/libtemp_binary_%d.dll", i);
157 fd = open(temp_filename, O_WRONLY|O_CREAT|O_TRUNC, 0700);
158 if (fd >= 0)
159 break; /* Created a file ok */
160 }
161
162 if (fd < 0)
163 {
164 DEBUGF("open failed\n");
165 return NULL;
166 }
167
168 if (write(fd, addr, blob_size) < (ssize_t)blob_size)
169 {
170 DEBUGF("Write failed\n");
171 close(fd);
172 remove(temp_filename);
173 return NULL;
174 }
175
176 close(fd);
177 return lc_open(temp_filename, NULL, 0);
178#endif
179}
180
181
182void *_lc_get_header(void *handle)
183{
184 char *ret = dlsym(handle, "__header");
185 if (ret == NULL)
186 ret = dlsym(handle, "___header");
187
188 return ret;
189}
190
191void _lc_close(void *handle)
192{
193 if (handle)
194 dlclose(handle);
195}
196
197const char *lc_last_error(void)
198{
199 return dlerror();
200}
201#endif