diff options
Diffstat (limited to 'uisimulator/common/load_code-sim.c')
-rw-r--r-- | uisimulator/common/load_code-sim.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/uisimulator/common/load_code-sim.c b/uisimulator/common/load_code-sim.c new file mode 100644 index 0000000000..59ca97a259 --- /dev/null +++ b/uisimulator/common/load_code-sim.c | |||
@@ -0,0 +1,72 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Daniel Stenberg | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #define RB_FILESYSTEM_OS | ||
22 | #include <stdio.h> | ||
23 | #include "config.h" | ||
24 | #include "system.h" | ||
25 | #include "file.h" | ||
26 | #include "load_code.h" | ||
27 | #include "rbpaths.h" | ||
28 | #include "debug.h" | ||
29 | |||
30 | void * lc_open(const char *filename, unsigned char *buf, size_t buf_size) | ||
31 | { | ||
32 | char osfilename[SIM_TMPBUF_MAX_PATH]; | ||
33 | if (sim_get_os_path(osfilename, filename, sizeof (osfilename)) < 0) | ||
34 | return NULL; | ||
35 | |||
36 | return os_lc_open(osfilename); | ||
37 | (void)buf; (void)buf_size; | ||
38 | } | ||
39 | |||
40 | void * lc_open_from_mem(void *addr, size_t blob_size) | ||
41 | { | ||
42 | /* We have to create the dynamic link library file from ram so we can | ||
43 | simulate code loading. Multiple binaries may be loaded at the same | ||
44 | time, so we need to find an unused filename. */ | ||
45 | int fd; | ||
46 | char tempfile[SIM_TMPBUF_MAX_PATH]; | ||
47 | for (unsigned int i = 0; i < 10; i++) | ||
48 | { | ||
49 | snprintf(tempfile, sizeof(tempfile), | ||
50 | ROCKBOX_DIR "/libtemp_binary_%d.dll", i); | ||
51 | fd = sim_open(tempfile, O_WRONLY|O_CREAT|O_TRUNC, 0700); | ||
52 | if (fd >= 0) | ||
53 | break; /* Created a file ok */ | ||
54 | } | ||
55 | |||
56 | if (fd < 0) | ||
57 | { | ||
58 | DEBUGF("open failed\n"); | ||
59 | return NULL; | ||
60 | } | ||
61 | |||
62 | if (sim_write(fd, addr, blob_size) != (ssize_t)blob_size) | ||
63 | { | ||
64 | DEBUGF("Write failed\n"); | ||
65 | sim_close(fd); | ||
66 | sim_remove(tempfile); | ||
67 | return NULL; | ||
68 | } | ||
69 | |||
70 | sim_close(fd); | ||
71 | return lc_open(tempfile, NULL, 0); | ||
72 | } | ||