Kernel mode malloc library

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

Moderators: cheriff, TyRaNiD

Post Reply
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Kernel mode malloc library

Post by ne0h »

Here is a bit modified library to use normally the malloc function in kernel mode!
The library was writed by Hellcat, I've only compiled and a bit modified it!
Maybe anyone can add this or another library to use the malloc functions in kernel mode to svn...
Can be useful!

http://www.megaupload.com/?d=3EEF4F71
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

Great stuff
But MallocList[32] is a table limitted to 32 entry and in the malloc code
there is no code present to handle if more than 32 malloc has been asked
so memory corruption ;)

Another question : what is the purpose of the flag PSP_SMEM_Low ?
reserve memory compatible FAT & SLIM aka < 32 Méga ?
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

PSP_SMEM_Low have no purpose, it search for a free area and allocate the memory from the lowest memory available address, it works for the Slims only if you compile your program with PSP_LARGE_MEMORY = 1!
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

I'm rewriting the library to resolve this "array overflow" problem!
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

I've rewrited it using a dinamical list, I've tryed it and it works, but can anyone try this? I'm not really sure that it works perfect! Is not finished, I've to add some things...
http://www.megaupload.com/?d=4UYQ9TB6

Anyway, how to printf with kernel libc??
There's a way to do it? I won't use formatting...
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

Tested but why are you doing 2 allocations you can per alloc allocated 1 block
the list struct + the memory size asked.
example i do a malloc of 1024 the strucutre of the list is let say 16 bytes
i do one alloc of 16 bytes+1024 in the first bytes i put the next pointer and the id
and i return adrs allocate+16 to the application ;)

And another thing when you do a allocation always check de return code
if you've got a error (like out of memory) return null. Even with a linked list
you must be aware of error that can occur with the OS of the psp
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

I don't mean to bash, but the last thing you need in the kernel partition is a contiguous lump of pre-allocated memory, half of which will probably lie unused by the application.

Either stick to allocating your bytes as an when you need them with the SCE functions, or allocate an intelligently calculated lump of memory and split it up yourself.

Otherwise you'll end with with ppl writing kernel plugins with PSP_HEAP_SIZE_KB(2048) and crap like that.
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

sauron_le_noir, yes, I've to add some check and improve the code, this is because I've writed "Is not finished, I've to add some things... "!
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

Ok, I've improved it to allocate one memory block, it works for me...
Take a look in the src, maybe there's something wrong...
http://www.megaupload.com/?d=EJTU4K1K
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

You have absolut reason torch. memory fragmentation is a hell look at this site
http://www.cs.umass.edu/~emery/hoard/
PosX100
Posts: 98
Joined: Wed Aug 15, 2007 1:02 am

Post by PosX100 »

Lets start with the basics , first ...

Your code looks like you have messed up linked lists with dynamic arrays ...mixed together , somehow...
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

Everyone can correct the code...
Post Reply