summaryrefslogtreecommitdiff
path: root/uisimulator/common/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/common/io.c')
-rw-r--r--uisimulator/common/io.c64
1 files changed, 58 insertions, 6 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 6f9f4b2945..fdacc59069 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -584,27 +584,79 @@ int sim_fsync(int fd)
584 584
585#ifndef __PCTOOL__ 585#ifndef __PCTOOL__
586 586
587#include <SDL_loadso.h>
587void *lc_open(const char *filename, unsigned char *buf, size_t buf_size) 588void *lc_open(const char *filename, unsigned char *buf, size_t buf_size)
588{ 589{
589 const char *sim_path = get_sim_pathname(filename); 590 (void)buf;
590 void *handle = _lc_open(UTF8_TO_OS(sim_path), buf, buf_size); 591 (void)buf_size;
591 592 void *handle = SDL_LoadObject(get_sim_pathname(filename));
592 if (handle == NULL) 593 if (handle == NULL)
593 { 594 {
594 DEBUGF("failed to load %s\n", filename); 595 DEBUGF("failed to load %s\n", filename);
595 DEBUGF("lc_open(%s): %s\n", filename, lc_last_error()); 596 DEBUGF("lc_open(%s): %s\n", filename, SDL_GetError());
596 } 597 }
597 return handle; 598 return handle;
598} 599}
599 600
600void *lc_get_header(void *handle) 601void *lc_get_header(void *handle)
601{ 602{
602 return _lc_get_header(handle); 603 char *ret = SDL_LoadFunction(handle, "__header");
604 if (ret == NULL)
605 ret = SDL_LoadFunction(handle, "___header");
606
607 return ret;
603} 608}
604 609
605void lc_close(void *handle) 610void lc_close(void *handle)
606{ 611{
607 _lc_close(handle); 612 SDL_UnloadObject(handle);
613}
614
615void *lc_open_from_mem(void *addr, size_t blob_size)
616{
617#ifndef SIMULATOR
618 (void)addr;
619 (void)blob_size;
620 /* we don't support loading code from memory on application builds,
621 * it doesn't make sense (since it means writing the blob to disk again and
622 * then falling back to load from disk) and requires the ability to write
623 * to an executable directory */
624 return NULL;
625#else
626 /* support it in the sim for the sake of simulating */
627 int fd, i;
628 char temp_filename[MAX_PATH];
629
630 /* We have to create the dynamic link library file from ram so we
631 can simulate the codec loading. With voice and crossfade,
632 multiple codecs may be loaded at the same time, so we need
633 to find an unused filename */
634 for (i = 0; i < 10; i++)
635 {
636 snprintf(temp_filename, sizeof(temp_filename),
637 ROCKBOX_DIR "/libtemp_binary_%d.dll", i);
638 fd = open(temp_filename, O_WRONLY|O_CREAT|O_TRUNC, 0700);
639 if (fd >= 0)
640 break; /* Created a file ok */
641 }
642
643 if (fd < 0)
644 {
645 DEBUGF("open failed\n");
646 return NULL;
647 }
648
649 if (write(fd, addr, blob_size) < (ssize_t)blob_size)
650 {
651 DEBUGF("Write failed\n");
652 close(fd);
653 remove(temp_filename);
654 return NULL;
655 }
656
657 close(fd);
658 return lc_open(temp_filename, NULL, 0);
659#endif
608} 660}
609 661
610#endif /* __PCTOOL__ */ 662#endif /* __PCTOOL__ */