yifanlu / taiHEN

CFW framework for PS Vita
MIT License
310 stars 46 forks source link

Crash on load kernel module. #60

Closed DavisDev closed 7 years ago

DavisDev commented 7 years ago

I am loading a kernel module from an application in user mode, Using the API taihen, as follows:

SceUID modkernel = taiLoadStartKernelModule("ux0:/mylib.skprx", 0, NULL, 0);

Always the first time I run the application after having installed henkaku, it crashes, the second no longer gives the crash, and works great! It should be mentioned that the user application, it imports prx functions, In the module_start, no action is performed, Could someone help me solve this problem?

Any help will be appreciated.

parkerlreed commented 7 years ago

I don't know exactly but here are a few examples of a user application loading a kernel module

https://github.com/xerpi/hidmouse/tree/master/skprx

https://github.com/TheOfficialFloW/VitaShell/search?utf8=%E2%9C%93&q=startusb&type=Code

DavisDev commented 7 years ago

Hello, I had already tried and reviewed both samples, The difference is that they do not export in the prx, and import in the application. I suppose, some of that is the cause in my particular situation.

yifanlu commented 7 years ago

Importing happens at launch. If the module is not loaded then, the import stubs are not filled.

DavisDev commented 7 years ago

Any idea how to fix it? Maybe get the functions dynamically?

Is there a way to know that a prx kernel was previously loaded? I have a plan, check that the prx kernel is not loaded, load it, reboot eboot.bin, and check that the prx kernel is loaded, and continue.

yifanlu commented 7 years ago

Well one solution is to make a wrapper suprx that imports functions from skprx. Then use the weak import of the suprx. So for example, userprx imports from kernelprx and has wrapper functions to kernelprx

  1. From eboot.bin load kernelprx.skprx
  2. From userprx.suprx export wrapper calls to kernelprx.suprx
  3. From eboot.bin load userprx.suprx
  4. Make calls to imported userprx.suprx wrapper functions

The problem is that kernel modules cannot export weak symbols (that's a Sony limitation I guess) but user modules can.

DavisDev commented 7 years ago

Thank you very much @yifanlu ! It works great, yes, it's a bit more work, but, in the end, what's important is that it works. Thanks again yifan, I proceed to mark this case as solved.