Reserve 16MiB heap memory for libc

This commit is contained in:
John Törnblom committed 2024-04-14 14:48:42 +02:00
1 parent ddb4fcf0a4
commit 119d4e9be5
3 files changed
+54 -3

No files matched your search

+44 -3
View File
@@ -600,6 +600,36 @@ elfldr_exec(pid_t pid, int stdio, uint8_t* elf) {
}
/**
* Set the heap size for libc.
**/
static int
elfldr_set_heap_size(pid_t pid, size_t size) {
intptr_t sceLibcHeapSize;
intptr_t libc_param;
intptr_t proc_param;
if(!(proc_param=pt_sceKernelGetProcParam(pid))) {
pt_perror(pid, "pt_sceKernelGetProcParam");
return -1;
}
if(mdbg_copyout(pid, proc_param+56, &libc_param,
sizeof(libc_param))) {
perror("mdbg_copyout");
return -1;
}
if(mdbg_copyout(pid, libc_param+16, &sceLibcHeapSize,
sizeof(sceLibcHeapSize))) {
perror("mdbg_copyout");
return -1;
}
return mdbg_setlong(pid, sceLibcHeapSize, size);
}
/**
* Execute an ELF inside a new process.
**/
@@ -616,9 +646,20 @@ elfldr_spawn(const char* progname, int stdio, uint8_t* elf) {
return -1;
}
// The proc is now in the STOP state, with the instruction pointer
// pointing at the libkernel entry.
// Insert a breakpoint at the eboot entry.
// The proc is now in the STOP state, with the instruction pointer pointing
// at the libkernel entry. Let the kernel assign process parameters accessed
// via sceKernelGetProcParam()
if(pt_syscall(pid, 599)) {
puts("sys_dynlib_process_needed_and_relocate failed");
kill(pid, SIGKILL);
pt_detach(pid);
return -1;
}
// Reserve 16MiB heap memory for libc.
elfldr_set_heap_size(pid, 0x1000000);
//Insert a breakpoint at the eboot entry.
if(!(brkpoint=kernel_dynlib_entry_addr(pid, 0))) {
klog_puts("kernel_dynlib_entry_addr failed");
kill(pid, SIGKILL);
+8
View File
@@ -331,3 +331,11 @@ pt_perror(pid_t pid, const char *s) {
strcat(buf, strerror(err));
klog_puts(buf);
}
intptr_t
pt_sceKernelGetProcParam(pid_t pid) {
intptr_t faddr = pt_resolve(pid, "959qrazPIrg");
return pt_call(pid, faddr);
}
+2
View File
@@ -55,3 +55,5 @@ int pt_dup2(pid_t pid, int oldfd, int newfd);
int pt_rdup(pid_t pid, pid_t other_pid, int fd);
int pt_pipe(pid_t pid, intptr_t pipefd);
void pt_perror(pid_t pid, const char *s);
intptr_t pt_sceKernelGetProcParam(pid_t pid);