diff options
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/common/io.c | 113 |
1 files changed, 100 insertions, 13 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index c8d6a8a67d..4c0fa33be5 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c | |||
@@ -58,7 +58,6 @@ | |||
58 | #include "debug.h" | 58 | #include "debug.h" |
59 | #include "ata.h" /* for IF_MV2 et al. */ | 59 | #include "ata.h" /* for IF_MV2 et al. */ |
60 | #include "rbpaths.h" | 60 | #include "rbpaths.h" |
61 | #include "load_code.h" | ||
62 | 61 | ||
63 | /* keep this in sync with file.h! */ | 62 | /* keep this in sync with file.h! */ |
64 | #undef MAX_PATH /* this avoids problems when building simulator */ | 63 | #undef MAX_PATH /* this avoids problems when building simulator */ |
@@ -531,28 +530,116 @@ int sim_fsync(int fd) | |||
531 | #include <dlfcn.h> | 530 | #include <dlfcn.h> |
532 | #endif | 531 | #endif |
533 | 532 | ||
534 | 533 | void *sim_codec_load_ram(char* codecptr, int size, void **pd) | |
535 | void *lc_open(const char *filename, char *buf, size_t buf_size) | ||
536 | { | 534 | { |
537 | const char *sim_path = get_sim_pathname(filename); | 535 | void *hdr; |
538 | void *handle = _lc_open((const char*)UTF8_TO_OS(sim_path), buf, buf_size); | 536 | char path[MAX_PATH]; |
537 | int fd; | ||
538 | int codec_count; | ||
539 | #ifdef WIN32 | ||
540 | char buf[MAX_PATH]; | ||
541 | #endif | ||
539 | 542 | ||
540 | if (handle == NULL) | 543 | *pd = NULL; |
544 | |||
545 | /* We have to create the dynamic link library file from ram so we | ||
546 | can simulate the codec loading. With voice and crossfade, | ||
547 | multiple codecs may be loaded at the same time, so we need | ||
548 | to find an unused filename */ | ||
549 | for (codec_count = 0; codec_count < 10; codec_count++) | ||
541 | { | 550 | { |
542 | DEBUGF("failed to load %s\n", filename); | 551 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) |
543 | DEBUGF("lc_open(%s): %s\n", filename, lc_last_error()); | 552 | /* we need that path fixed, since get_user_file_path() |
553 | * gives us the folder on the sdcard where we cannot load libraries | ||
554 | * from (no exec permissions) | ||
555 | */ | ||
556 | snprintf(path, sizeof(path), | ||
557 | "/data/data/org.rockbox/app_rockbox/libtemp_codec_%d.so", | ||
558 | codec_count); | ||
559 | #else | ||
560 | char name[MAX_PATH]; | ||
561 | const char *_name = get_user_file_path(ROCKBOX_DIR, 0, name, sizeof(name)); | ||
562 | snprintf(path, sizeof(path), "%s/_temp_codec%d.dll", get_sim_pathname(_name), codec_count); | ||
563 | #endif | ||
564 | fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); | ||
565 | if (fd >= 0) | ||
566 | break; /* Created a file ok */ | ||
567 | } | ||
568 | if (fd < 0) | ||
569 | { | ||
570 | DEBUGF("failed to open for write: %s\n", path); | ||
571 | return NULL; | ||
572 | } | ||
573 | |||
574 | if (write(fd, codecptr, size) != size) | ||
575 | { | ||
576 | DEBUGF("write failed"); | ||
577 | return NULL; | ||
578 | } | ||
579 | close(fd); | ||
580 | |||
581 | /* Now load the library. */ | ||
582 | *pd = dlopen(path, RTLD_NOW); | ||
583 | if (*pd == NULL) | ||
584 | { | ||
585 | DEBUGF("failed to load %s\n", path); | ||
586 | #ifdef WIN32 | ||
587 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, | ||
588 | buf, sizeof buf, NULL); | ||
589 | DEBUGF("dlopen(%s): %s\n", path, buf); | ||
590 | #else | ||
591 | DEBUGF("dlopen(%s): %s\n", path, dlerror()); | ||
592 | #endif | ||
593 | return NULL; | ||
544 | } | 594 | } |
545 | return handle; | 595 | |
596 | hdr = dlsym(*pd, "__header"); | ||
597 | if (!hdr) | ||
598 | hdr = dlsym(*pd, "___header"); | ||
599 | |||
600 | return hdr; /* maybe NULL if symbol not present */ | ||
601 | } | ||
602 | |||
603 | void sim_codec_close(void *pd) | ||
604 | { | ||
605 | dlclose(pd); | ||
546 | } | 606 | } |
547 | 607 | ||
548 | void *lc_get_header(void *handle) | 608 | void *sim_plugin_load(char *plugin, void **pd) |
549 | { | 609 | { |
550 | return _lc_get_header(handle); | 610 | void *hdr; |
611 | char path[MAX_PATH]; | ||
612 | #ifdef WIN32 | ||
613 | char buf[MAX_PATH]; | ||
614 | #endif | ||
615 | |||
616 | snprintf(path, sizeof(path), "%s", get_sim_pathname(plugin)); | ||
617 | |||
618 | *pd = NULL; | ||
619 | |||
620 | *pd = dlopen(path, RTLD_NOW); | ||
621 | if (*pd == NULL) { | ||
622 | DEBUGF("failed to load %s\n", plugin); | ||
623 | #ifdef WIN32 | ||
624 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, | ||
625 | buf, sizeof(buf), NULL); | ||
626 | DEBUGF("dlopen(%s): %s\n", path, buf); | ||
627 | #else | ||
628 | DEBUGF("dlopen(%s): %s\n", path, dlerror()); | ||
629 | #endif | ||
630 | return NULL; | ||
631 | } | ||
632 | |||
633 | hdr = dlsym(*pd, "__header"); | ||
634 | if (!hdr) | ||
635 | hdr = dlsym(*pd, "___header"); | ||
636 | |||
637 | return hdr; /* maybe NULL if symbol not present */ | ||
551 | } | 638 | } |
552 | 639 | ||
553 | void lc_close(void *handle) | 640 | void sim_plugin_close(void *pd) |
554 | { | 641 | { |
555 | _lc_close(handle); | 642 | dlclose(pd); |
556 | } | 643 | } |
557 | 644 | ||
558 | #ifdef WIN32 | 645 | #ifdef WIN32 |