Simulators: Fix pointer size vs. int size problems (64bit hosts) in plugin loader and codec loader.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8880 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jens Arnold 2006-03-02 01:08:38 +00:00
parent e3f155dce2
commit 38b7547ef4
3 changed files with 36 additions and 35 deletions

View file

@ -55,8 +55,8 @@
unsigned char codecbuf[CODEC_SIZE]; unsigned char codecbuf[CODEC_SIZE];
#endif #endif
void *sim_codec_load_ram(char* codecptr, int size, void *sim_codec_load_ram(char* codecptr, int size,
void* ptr2, int bufwrap, int *pd); void* ptr2, int bufwrap, void **pd);
void sim_codec_close(int pd); void sim_codec_close(void *pd);
#else #else
#define sim_codec_close(x) #define sim_codec_close(x)
extern unsigned char codecbuf[]; extern unsigned char codecbuf[];
@ -249,10 +249,10 @@ int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap,
return CODEC_ERROR; return CODEC_ERROR;
} }
#else /* SIMULATOR */ #else /* SIMULATOR */
int pd; void *pd;
hdr = sim_codec_load_ram(codecptr, size, ptr2, bufwrap, &pd); hdr = sim_codec_load_ram(codecptr, size, ptr2, bufwrap, &pd);
if (pd < 0) if (pd == NULL)
return CODEC_ERROR; return CODEC_ERROR;
if (hdr == NULL if (hdr == NULL

View file

@ -70,8 +70,8 @@
#ifdef SIMULATOR #ifdef SIMULATOR
static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE]; static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
void *sim_plugin_load(char *plugin, int *fd); void *sim_plugin_load(char *plugin, void **pd);
void sim_plugin_close(int fd); void sim_plugin_close(void *pd);
void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int)); void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int));
void sim_lcd_ex_update_rect(int x, int y, int width, int height); void sim_lcd_ex_update_rect(int x, int y, int width, int height);
#else #else
@ -411,9 +411,12 @@ static const struct plugin_api rockbox_api = {
int plugin_load(const char* plugin, void* parameter) int plugin_load(const char* plugin, void* parameter)
{ {
int fd, rc; int rc;
struct plugin_header *hdr; struct plugin_header *hdr;
#ifndef SIMULATOR #ifdef SIMULATOR
void *pd;
#else
int fd;
ssize_t readsize; ssize_t readsize;
#endif #endif
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
@ -436,21 +439,21 @@ int plugin_load(const char* plugin, void* parameter)
gui_syncsplash(0, true, str(LANG_WAIT)); gui_syncsplash(0, true, str(LANG_WAIT));
#ifdef SIMULATOR #ifdef SIMULATOR
hdr = sim_plugin_load((char *)plugin, &fd); hdr = sim_plugin_load((char *)plugin, &pd);
if (!fd) { if (pd == NULL) {
gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin); gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_CANT_OPEN), plugin);
return -1; return -1;
} }
if (hdr == NULL if (hdr == NULL
|| hdr->magic != PLUGIN_MAGIC || hdr->magic != PLUGIN_MAGIC
|| hdr->target_id != TARGET_ID) { || hdr->target_id != TARGET_ID) {
sim_plugin_close(fd); sim_plugin_close(pd);
gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL)); gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL));
return -1; return -1;
} }
if (hdr->api_version > PLUGIN_API_VERSION if (hdr->api_version > PLUGIN_API_VERSION
|| hdr->api_version < PLUGIN_MIN_API_VERSION) { || hdr->api_version < PLUGIN_MIN_API_VERSION) {
sim_plugin_close(fd); sim_plugin_close(pd);
gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION)); gui_syncsplash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION));
return -1; return -1;
} }
@ -549,7 +552,7 @@ int plugin_load(const char* plugin, void* parameter)
if (pfn_tsr_exit == NULL) if (pfn_tsr_exit == NULL)
plugin_loaded = false; plugin_loaded = false;
sim_plugin_close(fd); sim_plugin_close(pd);
switch (rc) { switch (rc) {
case PLUGIN_OK: case PLUGIN_OK:

View file

@ -308,9 +308,9 @@ int sim_fsync(int fd)
#endif #endif
void *sim_codec_load_ram(char* codecptr, int size, void *sim_codec_load_ram(char* codecptr, int size,
void* ptr2, int bufwrap, int *pd_fd) void* ptr2, int bufwrap, void **pd)
{ {
void *pd, *hdr; void *hdr;
const char *path = "archos/_temp_codec.dll"; const char *path = "archos/_temp_codec.dll";
int fd; int fd;
int copy_n; int copy_n;
@ -318,7 +318,7 @@ void *sim_codec_load_ram(char* codecptr, int size,
char buf[256]; char buf[256];
#endif #endif
*pd_fd = 0; *pd = NULL;
/* We have to create the dynamic link library file from ram /* We have to create the dynamic link library file from ram
so we could simulate the codec loading. */ so we could simulate the codec loading. */
@ -351,8 +351,8 @@ void *sim_codec_load_ram(char* codecptr, int size,
close(fd); close(fd);
/* Now load the library. */ /* Now load the library. */
pd = dlopen(path, RTLD_NOW); *pd = dlopen(path, RTLD_NOW);
if (!pd) { if (*pd == NULL) {
DEBUGF("failed to load %s\n", path); DEBUGF("failed to load %s\n", path);
#ifdef WIN32 #ifdef WIN32
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
@ -361,26 +361,25 @@ void *sim_codec_load_ram(char* codecptr, int size,
#else #else
DEBUGF("dlopen(%s): %s\n", path, dlerror()); DEBUGF("dlopen(%s): %s\n", path, dlerror());
#endif #endif
dlclose(pd); dlclose(*pd);
return NULL; return NULL;
} }
hdr = dlsym(pd, "__header"); hdr = dlsym(*pd, "__header");
if (!hdr) if (!hdr)
hdr = dlsym(pd, "___header"); hdr = dlsym(*pd, "___header");
*pd_fd = (int)pd;
return hdr; /* maybe NULL if symbol not present */ return hdr; /* maybe NULL if symbol not present */
} }
void sim_codec_close(int pd) void sim_codec_close(void *pd)
{ {
dlclose((void *)pd); dlclose(pd);
} }
void *sim_plugin_load(char *plugin, int *fd) void *sim_plugin_load(char *plugin, void **pd)
{ {
void *pd, *hdr; void *hdr;
char path[256]; char path[256];
#ifdef WIN32 #ifdef WIN32
char buf[256]; char buf[256];
@ -388,10 +387,10 @@ void *sim_plugin_load(char *plugin, int *fd)
snprintf(path, sizeof path, "archos%s", plugin); snprintf(path, sizeof path, "archos%s", plugin);
*fd = 0; *pd = NULL;
pd = dlopen(path, RTLD_NOW); *pd = dlopen(path, RTLD_NOW);
if (!pd) { if (*pd == NULL) {
DEBUGF("failed to load %s\n", plugin); DEBUGF("failed to load %s\n", plugin);
#ifdef WIN32 #ifdef WIN32
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
@ -400,21 +399,20 @@ void *sim_plugin_load(char *plugin, int *fd)
#else #else
DEBUGF("dlopen(%s): %s\n", path, dlerror()); DEBUGF("dlopen(%s): %s\n", path, dlerror());
#endif #endif
dlclose(pd); dlclose(*pd);
return NULL; return NULL;
} }
hdr = dlsym(pd, "__header"); hdr = dlsym(*pd, "__header");
if (!hdr) if (!hdr)
hdr = dlsym(pd, "___header"); hdr = dlsym(*pd, "___header");
*fd = (int)pd; /* success */
return hdr; /* maybe NULL if symbol not present */ return hdr; /* maybe NULL if symbol not present */
} }
void sim_plugin_close(int pd) void sim_plugin_close(void *pd)
{ {
dlclose((void *)pd); dlclose(pd);
} }
#if !defined(WIN32) || defined(SDL) #if !defined(WIN32) || defined(SDL)