Skip to content

Commit

Permalink
[modules] Support ET_SCE_EXEC
Browse files Browse the repository at this point in the history
This elf segment type requires loading of segments at p_vaddr
  • Loading branch information
frangarcj committed May 2, 2018
1 parent 8b41f68 commit 3137d1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/emulator/kernel/src/load_self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#undef SCE_ELF_DEFS_TARGET
#include <self.h>

#define ET_SCE_EXEC 0xFE00

#define NID_MODULE_STOP 0x79F8E492
#define NID_MODULE_EXIT 0x913482A9
#define NID_MODULE_START 0x935CD196
Expand Down Expand Up @@ -279,7 +281,13 @@ SceUID load_self(Ptr<const void> &entry_point, KernelState &kernel, MemState &me

assert(segment_infos[segment_index].encryption == 2);
if (src.p_type == PT_LOAD) {
const Ptr<void> address(alloc(mem, src.p_memsz, path));
Address segment_address = 0;
if (elf.e_type == ET_SCE_EXEC) {
segment_address = alloc_at(mem, src.p_vaddr, src.p_memsz, path);
} else {
segment_address = alloc(mem, src.p_memsz, path);
}
const Ptr<void> address(segment_address);
if (!address) {
LOG_ERROR("Failed to allocate memory for segment.");
return -1;
Expand Down
1 change: 1 addition & 0 deletions src/emulator/mem/include/mem/mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ constexpr size_t GB(size_t gb) {

bool init(MemState &state);
Address alloc(MemState &state, size_t size, const char *name);
Address alloc_at(MemState &state, Address address, size_t size, const char *name);
void free(MemState &state, Address address);
const char *mem_name(Address address, const MemState &state);
9 changes: 9 additions & 0 deletions src/emulator/mem/src/mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ Address alloc(MemState &state, size_t size, const char *name) {
return address;
}

Address alloc_at(MemState &state, Address address, size_t size, const char *name) {
const size_t page_count = (size + (state.page_size - 1)) / state.page_size;
const Allocated::iterator block = state.allocated_pages.begin() + (address / state.page_size);

alloc_inner(state, address, page_count, block, name);

return address;
}

void free(MemState &state, Address address) {
const size_t page = address / state.page_size;
assert(page >= 0);
Expand Down

0 comments on commit 3137d1f

Please sign in to comment.