Skip to content

Commit

Permalink
rtld: only load libSceSysmodule when really neeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed May 12, 2024
1 parent 667c887 commit 089231f
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions crt/rtld.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,49 @@ rtld_load(void) {
}


/**
*
**/
static int
rtld_load_sysmodule(payload_args_t *args) {
unsigned long nb_handles = 0;
int handles[256];
int handle;

// get handles for loaded modules
if(syscall(0x250, handles, sizeof(handles), &nb_handles)) {
return -1;
}

// try to load sceSysmoduleLoadModuleInternal from all of the handles
for(int i=0; i<nb_handles; i++) {
handle = handles[i];
if(!args->sceKernelDlsym(handle, "sceSysmoduleLoadModuleInternal",
&sceSysmoduleLoadModuleInternal)) {
return 0;
}
}

// load libSceSysmodule
if((handle=sceKernelLoadStartModule("/system/common/lib/libSceSysmodule.sprx",
0, 0, 0, 0, 0)) <= 0) {
klog_libload_error("libSceSysmodule.sprx");
return -1;
}

// resolve sceSysmoduleLoadModuleInternal
return args->sceKernelDlsym(handle, "sceSysmoduleLoadModuleInternal",
&sceSysmoduleLoadModuleInternal);
}


int
__rtld_init(payload_args_t *args) {
static const unsigned char privcaps[16] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
int pid = syscall(SYS_getpid);
unsigned long rootdir = 0;
unsigned char caps[16];
int handle = 0;
int error = 0;

// determine libkernel handle
Expand Down Expand Up @@ -621,17 +656,10 @@ __rtld_init(payload_args_t *args) {
return -1;
}

// load deps to sysmodule
if((handle=sceKernelLoadStartModule("/system/common/lib/libSceSysmodule.sprx",
0, 0, 0, 0, 0)) <= 0) {
klog_libload_error("libSceSysmodule.sprx");
if(rtld_load_sysmodule(args)) {
klog_puts("load_sysmodule failed");
return -1;
}
if((error=args->sceKernelDlsym(handle, "sceSysmoduleLoadModuleInternal",
&sceSysmoduleLoadModuleInternal))) {
klog_resolve_error("sceSysmoduleLoadModuleInternal");
return error;
}

error = rtld_load();

Expand Down

0 comments on commit 089231f

Please sign in to comment.