Kernel Module Can't be Started

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
hrimfaxi
Posts: 20
Joined: Thu Nov 23, 2006 5:40 pm

Kernel Module Can't be Started

Post by hrimfaxi »

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include "MyModule.h"

PSP_MODULE_INFO&#40;"MyModule", 0x1000, 0, 1&#41;;
PSP_NO_CREATE_MAIN_THREAD&#40;&#41;;

int mymoduleGetVersionNumber&#40;void&#41;
&#123;
	return 123;
&#125;

int dummyFixupImport&#40;&#41;
&#123;
//	sceKernelDelayThread&#40;1000000&#41;;
&#125;

int module_start&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	return 0;
&#125;

int module_stop&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	return 0;
&#125;

if i comment out the sceKernelDelayThread line, the module can't be started, returning error code 0x8002013c.

client code:

Code: Select all

	ret = kuKernelLoadModule&#40;prx_path, 0, 0&#41;;
	if&#40;ret >= 0&#41; &#123;
		ret = sceKernelStartModule&#40;ret, 0, 0, &status, 0&#41;;
		if&#40;ret >= 0&#41; &#123;
			printf&#40;"Start Module Successfully.\n"&#41;;
		&#125;
		else &#123;
			printf&#40;"Start Module Fail&#91;%08X&#93;\n", ret&#41;;
		&#125;
	&#125;
	else &#123;
		printf&#40;"Load Module Fail&#91;%08x&#93;\n", ret&#41;;
	&#125;
Look like kuKernelLoadModule successully load the module, but i can't start it.
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Make sure you have in the makefile USE_KERNEL_LIBS = 1
hrimfaxi
Posts: 20
Joined: Thu Nov 23, 2006 5:40 pm

Post by hrimfaxi »

that's fixed, thx.
And then, i tried to make a wrapper to let user library to use the kernel only function...:

Code: Select all

int mymoduleKernelModuleCount&#40;void&#41;
&#123;
	return sceKernelModuleCount&#40;&#41;;
&#125;
And the user client:

Code: Select all

printf&#40;"mymoduleGetVersion returns %08X\n", mymoduleGetVersion&#40;&#41;&#41;;
printf&#40;"mymoduleKernelModuleCount returns %08X\n", mymoduleKernelModuleCount&#40;&#41;&#41;;
This time, mymoduleGetVersion is OK now, and the library seems to be loaded OK, but mymoduleKernelModuleCount returns 0x8002013A(SCE_KERNEL_ERROR_LIBRARY_NOT_YET_LINKED). What happend?
jas0nuk
Posts: 137
Joined: Thu Apr 27, 2006 8:00 am

Post by jas0nuk »

Do it like this (in the kernel PRX)

int sceKernelBlahBlah_(u8 *foo) {
int k1 = pspSdkSetK1(0);
int blah = sceKernelBlahBlah(foo);
pspSdkSetK1(k1);

return 0;
}

In other words, set k1 to 0, call kernel functions, then set it to the original value which was stored in k1.
hrimfaxi
Posts: 20
Joined: Thu Nov 23, 2006 5:40 pm

Post by hrimfaxi »

Code: Select all

int mymoduleKernelModuleCount&#40;void&#41;
&#123;
	int k1 = pspSdkSetK1&#40;0&#41;;
	int ret = sceKernelModuleCount&#40;&#41;;
	pspSdkSetK1&#40;k1&#41;;
	return ret;
&#125;
The problem remains, and here is my export.exp for the module:

Code: Select all

# Define the exports for the prx
PSP_BEGIN_EXPORTS

# These four lines are mandatory &#40;although you can add other functions like module_stop&#41;
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;
PSP_EXPORT_FUNC_HASH&#40;module_start&#41;
PSP_EXPORT_VAR_HASH&#40;module_info&#41;
PSP_EXPORT_END

PSP_EXPORT_START&#40;MyModule, 0, 0x4001&#41;
PSP_EXPORT_FUNC_HASH&#40;mymoduleGetVersionNumber&#41;
PSP_EXPORT_FUNC_HASH&#40;mymoduleKernelModuleCount&#41;
PSP_EXPORT_END

PSP_END_EXPORTS
I am on a PSP Slim 3.71M-2 version
cooleyes
Posts: 123
Joined: Thu May 18, 2006 3:30 pm

Re: Kernel Module Can't be Started

Post by cooleyes »

hrimfaxi wrote:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include "MyModule.h"

PSP_MODULE_INFO&#40;"MyModule", 0x1000, 0, 1&#41;;
PSP_NO_CREATE_MAIN_THREAD&#40;&#41;;

int mymoduleGetVersionNumber&#40;void&#41;
&#123;
	return 123;
&#125;

int dummyFixupImport&#40;&#41;
&#123;
//	sceKernelDelayThread&#40;1000000&#41;;
&#125;

int module_start&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	return 0;
&#125;

int module_stop&#40;int argc, char* argv&#91;&#93;&#41;
&#123;
	return 0;
&#125;

if i comment out the sceKernelDelayThread line, the module can't be started, returning error code 0x8002013c.

client code:

Code: Select all

	ret = kuKernelLoadModule&#40;prx_path, 0, 0&#41;;
	if&#40;ret >= 0&#41; &#123;
		ret = sceKernelStartModule&#40;ret, 0, 0, &status, 0&#41;;
		if&#40;ret >= 0&#41; &#123;
			printf&#40;"Start Module Successfully.\n"&#41;;
		&#125;
		else &#123;
			printf&#40;"Start Module Fail&#91;%08X&#93;\n", ret&#41;;
		&#125;
	&#125;
	else &#123;
		printf&#40;"Load Module Fail&#91;%08x&#93;\n", ret&#41;;
	&#125;
Look like kuKernelLoadModule successully load the module, but i can't start it.

PSP_NO_CREATE_MAIN_THREAD();

?????????
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

That function doesn't exist... since 1.50!

http://moonlight.lan.st/1.00/kd/loadcore.html
http://moonlight.lan.st/1.5x/kd/loadcore.html

No surprise it returns that error.

The reason of Sony deleting this function is probably the introducion of sceKernelGetModuleListWithAlloc in 1.50. Maybe before the "user" of the function used sceKernelModuleCount to allocate a buffer with enough size, and then sceKernelGetModuleList to get the module list. Then they just make a function to do all at same time, making sceKernelModuleCount useless for them.
hrimfaxi
Posts: 20
Joined: Thu Nov 23, 2006 5:40 pm

Post by hrimfaxi »

Thanks a lot, it works now
User avatar
Aura
Posts: 37
Joined: Tue Jul 24, 2007 4:30 am

Post by Aura »

I've been having this problem also, but I've not been able to find my error, I'm not sure whats causing it, but I'm 99% sure its the actual kmode plugin and not the loader.

KMode main:

Code: Select all

#include <pspkernel.h>
#include <pspmodulemgr_kernel.h>
#include <pspsdk.h>
#include <pspdebug.h>

PSP_MODULE_INFO&#40;"KMode", 0x1006, 1, 1&#41;; 
//PSP_HEAP_SIZE_KB&#40;3000&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int unloadmod&#40;const char *module&#41;
&#123;
    u32 k1;
    
    k1 = pspSdkSetK1&#40;0&#41;;
    SceModule *mod;
    
    while&#40;&#40;mod = sceKernelFindModuleByName&#40;module&#41;&#41;&#41;
    &#123;
               sceKernelStopModule&#40;mod->modid, 0, NULL, NULL, NULL&#41;;
               sceKernelUnloadModule&#40;mod->modid&#41;;
    &#125;
    pspSdkSetK1&#40;k1&#41;;
    return 1;   
&#125;

int module_start&#40;SceSize args, void *argp&#41; 
&#123; 
   return 0; 
&#125; 

int module_stop&#40;&#41; 
&#123; 
   return 0; 
&#125;


KMode exports:

Code: Select all

# Define the exports for the prx 
PSP_BEGIN_EXPORTS 

# These four lines are mandatory &#40;although you can add other functions like module_stop&#41; 
# syslib is a psynonym for the single mandatory export. 
PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41; 
PSP_EXPORT_FUNC_HASH&#40;module_start&#41; 
PSP_EXPORT_VAR_HASH&#40;module_info&#41; 
PSP_EXPORT_END 

PSP_EXPORT_START&#40;KMode, 0, 0x4001&#41; 
PSP_EXPORT_FUNC&#40;unloadmod&#41;
PSP_EXPORT_END 

PSP_END_EXPORTS
This, too, returns the 0x8002013A, and I'm not sure why.

Any help is greatly apprechiated.

-Aura
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

Post your makefile, just in case.
Post Reply