mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-04-11 16:37:45 -04:00
elf_loader: add elf_loadmem() to load file from memory
Change-Id: Ib68b0e8b610d45713a2d5480da015cc4295f2676
This commit is contained in:
parent
843322f898
commit
7868e45edb
2 changed files with 38 additions and 0 deletions
|
|
@ -183,3 +183,29 @@ int elf_loadpath(const char *filename,
|
|||
close(fd);
|
||||
return err;
|
||||
}
|
||||
|
||||
int elf_loadmem(const void *elf_buffer,
|
||||
size_t elf_size,
|
||||
const struct elf_load_context *ctx,
|
||||
void **entrypoint)
|
||||
{
|
||||
struct elf_loadmem_state state = {
|
||||
.buffer = elf_buffer,
|
||||
.size = elf_size,
|
||||
};
|
||||
|
||||
return elf_load(elf_read_mem_callback, (intptr_t)&state, ctx, entrypoint);
|
||||
}
|
||||
|
||||
int elf_read_mem_callback(intptr_t loadmem_state, off_t pos, void *buf, size_t size)
|
||||
{
|
||||
struct elf_loadmem_state *state = (void *)loadmem_state;
|
||||
|
||||
if (pos < 0 || (size_t)pos >= state->size)
|
||||
return -1;
|
||||
if (state->size - (size_t)pos < size)
|
||||
return -1;
|
||||
|
||||
memcpy(buf, state->buffer + pos, size);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,4 +100,16 @@ int elf_loadpath(const char *filename,
|
|||
const struct elf_load_context *ctx,
|
||||
void **entrypoint);
|
||||
|
||||
struct elf_loadmem_state
|
||||
{
|
||||
const void *buffer;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
int elf_loadmem(const void *elf_buffer,
|
||||
size_t elf_size,
|
||||
const struct elf_load_context *ctx,
|
||||
void **entrypoint);
|
||||
int elf_read_mem_callback(intptr_t loadmem_state, off_t pos, void *buf, size_t size);
|
||||
|
||||
#endif /* __ELF_LOADER_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue