Loading a Kernl Mod. in Buffer from Kernel Module FAILS??!

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

Moderators: cheriff, TyRaNiD

Post Reply
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Loading a Kernl Mod. in Buffer from Kernel Module FAILS??!

Post by KickinAezz »

sceKernelLoadModuleBuffer only works from Kernel mode module... That is why I'm trying to load Kernel Module in Buffer From a Kernel Module

This isn't working? Please help. :(

This is the buffer which is passed from User module.

Code: Select all


static unsigned int size_KBUF = 2046;
static unsigned char KBUF[] __attribute__((aligned(64))) = {DATA here };

main()
{
loadMyBufModule(KBUF (also tried &KBUF),size_KBUF,PSP_MEMORY_PARTITION_KERNEL,0,NULL)
}

The following code is an export from a kernel module:

Code: Select all

int loadMyBufModule(char **buf ([i]also tried *buf,*buf[][/i]), int size, int mpid, int argc, char * const argv[])
{
    u32 k1;

    k1 = pspSdkSetK1(0);

        SceKernelLMOption option;
        SceUID modid = 0;
        int retVal = 0, mresult;
        char args[5]; //unused
        int  argpos = 0;
        int  i;

//         memset(args, 0, MAX_ARGS);
//        strcpy(args, buf);
//        argpos += size + 1;
//        for&#40;i = 0; &#40;i < argc&#41; && &#40;argpos < MAX_ARGS&#41;; i++&#41;
//        &#123;
//                int len;
//
//                sprintf&#40;&args&#91;argpos&#93;, "%s", argv&#91;i&#93;&#41;;
//                len = strlen&#40;&args&#91;argpos&#93;&#41;;
//                argpos += len + 1;
//        &#125;
//

        option.size = sizeof&#40;option&#41;;
        option.mpidtext = mpid;
        option.mpiddata = mpid;
        option.position = 0;
        option.access = 1;

        retVal = sceKernelLoadModuleBuffer&#40;buf, size, 0, &option&#41;;
        if&#40;retVal < 0&#41;&#123;
                return retVal;
        &#125;

        modid = retVal;

        retVal = sceKernelStartModule&#40;modid, 0, NULL, &mresult, NULL&#41;;
        if&#40;retVal < 0&#41;&#123;
                return retVal;
        &#125;

         pspSdkSetK1&#40;k1&#41;;
        return modid;
&#125;
When the Export is called:

Code: Select all

host0&#58;/flipxmbauth/> Exception - Address load/inst fetch
Thread ID - 0x00CCD21F
Th Name   - SceKernelModmgrWorker
Module ID - 0x00CC6F2B
Mod Name  - SystemControl
EPC       - 0x880668E8
Cause     - 0x10000010
BadVAddr  - 0x000007FE
Status    - 0x00088603
zr&#58;0x00000000 at&#58;0xDEADBEEF v0&#58;0x00000001 v1&#58;0x00000001
a0&#58;0x000007FE a1&#58;0x882FA690 a2&#58;0x00000000 a3&#58;0x00000000
t0&#58;0x882FA750 t1&#58;0x00000000 t2&#58;0x882FA750 t3&#58;0x00000000
t4&#58;0x00000000 t5&#58;0x00000000 t6&#58;0x00000000 t7&#58;0x00000000
s0&#58;0x882FA690 s1&#58;0x000007FE s2&#58;0x882FA690 s3&#58;0xDEADBEEF
s4&#58;0x88224224 s5&#58;0xDEADBEEF s6&#58;0x882FA7E0 s7&#58;0x00000000
t8&#58;0x00000000 t9&#58;0x88300000 k0&#58;0x00000000 k1&#58;0x00000000
gp&#58;0x8806C6D0 sp&#58;0x882FA420 fp&#58;0x882FA760 ra&#58;0x88067E24
0x880668E8&#58; 0x8C830000 '....' - lw         $v1, 0&#40;$a0&#41;
reset
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

under LMOption, int retVal = 0, mresult; // what is mresult //
10011011 00101010 11010111 10001001 10111010
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

dot_blank wrote:under LMOption, int retVal = 0, mresult; // what is mresult //
it's the modded code from pspSdkLoadStartModule...
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

read that line again and notice comma between two values that would get stored into ONE int ... look really hard
10011011 00101010 11010111 10001001 10111010
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

dot_blank wrote:read that line again and notice comma between two values that would get stored into ONE int ... look really hard
http://psp.jim.sh/svn/filedetails.php?r ... admodule.c

The only use of mresult is to store the result....
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
cory1492
Posts: 216
Joined: Fri Dec 10, 2004 1:49 pm

Post by cory1492 »

dot_blank wrote:read that line again and notice comma between two values that would get stored into ONE int ... look really hard

Code: Select all

int var1 =2, var3, var4 = 0, var5, var6, var7 = 1;
though it's generally bad programming practice to declare uninitialized variables along with initialized ones, it works just fine to declare multiple int variables in such a fashion. Doesn't require hard looking at all...

KickinAezz:
It helps to use the search here and try your exception cause (0x10000010) as the search parameter.
http://forums.ps2dev.org/viewtopic.php? ... 0x10000010
See tyranid's reply towards the bottom of that thread, might help you out (along with the info on using partition alloc.)

On that note, is there any documentation/notes that apply to the exception info that would help decipher the info it gives? More specifically cause and status?
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

cory1492 wrote:
dot_blank wrote:read that line again and notice comma between two values that would get stored into ONE int ... look really hard

Code: Select all

int var1 =2, var3, var4 = 0, var5, var6, var7 = 1;
though it's generally bad programming practice to declare uninitialized variables along with initialized ones, it works just fine to declare multiple int variables in such a fashion. Doesn't require hard looking at all...

KickinAezz:
It helps to use the search here and try your exception cause (0x10000010) as the search parameter.
http://forums.ps2dev.org/viewtopic.php? ... 0x10000010
See tyranid's reply towards the bottom of that thread, might help you out (along with the info on using partition alloc.)

On that note, is there any documentation/notes that apply to the exception info that would help decipher the info it gives? More specifically cause and status?
Will try that at my earliest convenience (size first, then *buf)

--

Why doesn't tyranid upgrade PSPLINK to show CAUSE's Descriptive text? :(
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

"Exception - Address load/inst fetch" wasn't clear enough for you, for fucks sake.

The error says it is a load exception, i.e. you gave a garbage address to something. The faulting instruction is a load word from $a0 and $a0 is set to 0x7FE and obvious garbage address. No doubt you could have then looked at your code and probably found your module was that length and you could have worked this out yourself. Damn if people can't read an exception dump they shouldn't be coding in kernel mode at all....

Find yourself a MIPS manual which should tell you about all the exception stuff you need (they are mostly the same in all MIPS revisions).
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

TyRaNiD wrote:"Exception - Address load/inst fetch" wasn't clear enough for you, for fucks sake.

The error says it is a load exception, i.e. you gave a garbage address to something. The faulting instruction is a load word from $a0 and $a0 is set to 0x7FE and obvious garbage address. No doubt you could have then looked at your code and probably found your module was that length and you could have worked this out yourself. Damn if people can't read an exception dump they shouldn't be coding in kernel mode at all....

Find yourself a MIPS manual which should tell you about all the exception stuff you need (they are mostly the same in all MIPS revisions).
You got too serious. I never thought CAUSE's description was the one shown during an exception, my mistake!
Damn if people can't read an exception dump they shouldn't be coding in kernel mode at all....
I never had to interpret Crash dumps because I code that good. And, they only occur during years that end with a 8 and very Rarely too.

Creating creative applications doesn't need that we have to write bad code (using trial and error) and end up with crashes like most people.

===

And WHY Why is the wrong prototype

Code: Select all

sceKernelLoadExecBufferPlain&#40;SceSize bufsize, void *buf, struct SceKernelLoadExecParam *param&#41;;
still in latest PSPSDK?
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
cory1492
Posts: 216
Joined: Fri Dec 10, 2004 1:49 pm

Post by cory1492 »

The 'wrong' prototype isn't in the SDK - if you are using a different firmware than the one you are using. As far as I can tell, it's still mainly geared towards 1.50 with a bit of 2.71 stuff in there.
TyRaNiD wrote:Find yourself a MIPS manual which should tell you about all the exception stuff you need (they are mostly the same in all MIPS revisions).
Thanks for that TyRaNiD - I was mainly curious as to where you 'enumerated' it from yourself as any such document may well have further background info beyond a 1 liner ("MIPS32 Architecture For Programmers Volume III" - login required - has some great info on exceptions and interrupts.) Aiming for understanding, myself - though my search method mentioned above has gotten me out of a few binds (thanks to ps2dev gurus.)
Post Reply