forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Kernel mode malloc library

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Tue Nov 11, 2008 3:26 am    Post subject: Kernel mode malloc library Reply with quote

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
Back to top
View user's profile Send private message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Wed Nov 12, 2008 7:06 am    Post subject: Reply with quote

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 ?
Back to top
View user's profile Send private message Send e-mail MSN Messenger
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Thu Nov 13, 2008 4:11 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Thu Nov 13, 2008 4:21 am    Post subject: Reply with quote

I'm rewriting the library to resolve this "array overflow" problem!
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Thu Nov 13, 2008 5:21 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Thu Nov 13, 2008 8:13 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Thu Nov 13, 2008 1:51 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Nov 14, 2008 12:24 am    Post subject: Reply with quote

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... "!
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Nov 14, 2008 1:14 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Sat Nov 15, 2008 2:16 am    Post subject: Reply with quote

You have absolut reason torch. memory fragmentation is a hell look at this site
http://www.cs.umass.edu/~emery/hoard/
Back to top
View user's profile Send private message Send e-mail MSN Messenger
PosX100



Joined: 15 Aug 2007
Posts: 98

PostPosted: Sat Nov 15, 2008 4:15 am    Post subject: Reply with quote

Lets start with the basics , first ...

Your code looks like you have messed up linked lists with dynamic arrays ...mixed together , somehow...
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Sat Nov 15, 2008 5:07 am    Post subject: Reply with quote

Everyone can correct the code...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group