OpenOrbis / OpenOrbis-PS4-Toolchain

The OpenOrbis PS4 custom toolchain. Allows developers to build homebrew for the PS4 without the official SDK.
GNU General Public License v3.0
474 stars 86 forks source link

System module function NID not resolved while loaded #116

Closed dmemarko closed 1 year ago

dmemarko commented 3 years ago

App built with libSceAppContent linked crashes when sceAppContentInitialize being called. It's function NID cannot be resolved from module which is actually loaded, as seen from the crash log.

build.bat has lib added:

set libraries=-lc -lkernel -lc++ -lSceVideoOut -lSceSysmodule -lSceAppContent

Actual code:

void initialize_app_content() {
    int ret = 0;
    (void)ret;

    ret = sceSysmoduleLoadModule(SCE_SYSMODULE_APP_CONTENT);
    DEBUGLOG << "sceSysmoduleLoadModule(SCE_SYSMODULE_APP_CONTENT) " << ((ret == ORBIS_OK) ? "ok" : "failed");

    SceAppContentInitParam initParam;
    SceAppContentBootParam bootParam;
    memset(&initParam, 0, sizeof(SceAppContentInitParam));
    memset(&bootParam, 0, sizeof(SceAppContentBootParam));
    ret = sceAppContentInitialize(&initParam, &bootParam);
    DEBUGLOG << "sceAppContentInitialize(&initParam, &bootParam) " << ((ret == ORBIS_OK) ? "ok" : "failed");
}

Extended prototypes in orbis/AppContent.h:

#define SCE_SYSMODULE_APP_CONTENT 0x00b4

typedef uint32_t SceAppContentBootAttribute;

typedef struct SceAppContentInitParam {
    char reserved[32];
} SceAppContentInitParam;

typedef struct SceAppContentBootParam {
    char reserved1[4];
    SceAppContentBootAttribute attr;
    char reserved2[32];
} SceAppContentBootParam;

int32_t sceAppContentInitialize(
    SceAppContentInitParam *initParam, 
    SceAppContentBootParam *bootParam
);

Crash log (stripped):

<118>**** Base Mode ****
<118>main: Creating a scene
<118>main: Initializing font (/app0/Gontserrat-Regular.ttf)
<118>main: Initializing AppContent
<118>initialize_app_content: sceSysmoduleLoadModule(SCE_SYSMODULE_APP_CONTENT) ok
#
# A user thread receives a fatal signal
#
# exception: 0xa0020101 (PRX_NOT_RESOLVED_FUNCTION)
# thread ID: 100758
# thread name: eboot.bin
# proc ID: 72
# proc name: eboot.bin
# proxied exception (Check generated coredump)
...
# backtrace:
copyin: eboot.bin has nonsleeping lock
# 0000000007251a65
#
...
# /xtDpWojOBT/common/lib/libSceAppContent.sprx
#  text: 0000000826edc000:0000000826ee4000 r-x
#  data: 00000008272dc000:00000008272e4000 rw-
#  fingerprint: 9059700a180b33b9f5da883c367f10b400000000
#
# === Call to unpatched function is detected!!! ===
# Module Path     : /app0/eboot.bin
# Caller Address : 0x00000000072cff70
# Required Module Name    : libSceAppContent
# Required Library Name   : libSceAppContent
# Required Function NID   : 0x47D940F363AB68DB

crash.log elfs.zip

ChendoChap commented 3 years ago

extra info: this happens because the converter does not take into account that prx/lib/module name can all be different. In this case the module is libSceAppContentUtil not libSceAppContent. furthermore a single module can contain multiple libraries. and a nid can have several implementations over multiple libraries in the same module. handling this might be somewhat annoying...

Cryptogenic commented 3 years ago

extra info: this happens because the converter does not take into account that prx/lib/module name can all be different. In this case the module is libSceAppContentUtil not libSceAppContent. furthermore a single module can contain multiple libraries. and a nid can have several implementations over multiple libraries in the same module. handling this might be somewhat annoying...

The issue of the module and PRX name being different can be handled, in fact I think we do already handle a few of these cases (though we're missing a few for sure). The case of multiple libraries, yeah this is a royal pain and it's going to be tough to handle :(

ghost commented 1 year ago

create-fself repo contains a fix in the master branch.