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 

Unloading modules

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



Joined: 02 Jun 2009
Posts: 226

PostPosted: Sun Mar 21, 2010 1:57 am    Post subject: Unloading modules Reply with quote

I would like to know if it's possible to call sceKernelStopModule and sceKernelUnloadModule over the main game module.

I tried sceKernelStopModule, but it crashes (throws an exception from SceModuleMgrStop thread). Also, I guess this one calls module_stop from the game itself, but unfortunately I don't know what args should be passed to module_stop.

Thus I think it can be stopped, because otherwise the function would just return an error, and also why have module_stop if it can't be stopped?

Also, can I stop a module from its own code or it must be from another module?

Also if you can link me to docs about what module attribute means, that would be great!

Thanks again for your time!
_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Back to top
View user's profile Send private message
Coldbird



Joined: 08 Feb 2007
Posts: 155

PostPosted: Sun Mar 21, 2010 5:45 am    Post subject: Reply with quote

Yes it is possible to unload oneself from memory.

I suggest you check the headers from the PSPSDK, especially the header of the modulemgr module.
_________________
Been gone for some time. Now I'm back. Someone mind getting me up-2-date?
Back to top
View user's profile Send private message MSN Messenger
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Sun Mar 21, 2010 6:44 am    Post subject: Reply with quote

Thanks for the reply. I checked pspmodulemgr.h but there's nothing new there.

I managed to get over the crash, but now it returns an error: SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT.

I'm using this code:

Code:
ret = sceKernelStopModule(id, 0, NULL, &status, NULL);

_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Back to top
View user's profile Send private message
unsigned int



Joined: 13 Aug 2009
Posts: 22

PostPosted: Sun Mar 21, 2010 7:24 am    Post subject: Reply with quote

I have a hard time understanding how a module could be able to stop itself. Even if sceKernelStopModule can stop the calling module, wouldn't this destroy the call stack of that function, so that it must crash when returning?
Back to top
View user's profile Send private message
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Sun Mar 21, 2010 10:43 am    Post subject: Reply with quote

Ok, maybe you're right, so that's why it gives that error about illegal argument (the module ID is wrong). I'll try sceKernelStopUnloadSelfModule

EDIT: this don't work either: SCE_KERNEL_ERROR_CAN_NOT_STOP
_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Back to top
View user's profile Send private message
willow :--)



Joined: 13 Jan 2007
Posts: 126

PostPosted: Sun Mar 21, 2010 11:16 am    Post subject: Reply with quote

m0skit0, this won't answer any of your questions, but it might help others to get a little bit more context:

Other functions using "Self" to unload the module itself apparently just find the modid based on ra, and then the code looks very similar to the other unload functions. So I'm guessing you get the crash/error even if you try with the "self" functions.
(note that for the "self" methods to work, the code that does the call has to be in the Ram boundaries of the module, since this is how the system detects which module you want to unload - and I believe you're not in the boundaries of the module you want to unload, so if you call the "self" methods, the system will not understand which module you are talking about)
By the way why are there 2 "self" unload methods ?
(Edit: in other words, I think the "Self" methods are just here for convenience when a module doesn't know its own id, but won't help much in your case)

Davee's reversed code of the module manager gives a bit of light on the whole process:
http://svn.lan.st/utopia/modulemgr.c

I think you get the error when dealing with the modMgr worker thread (spawning it or killing it ?), so (again looking at Davee's code on utopia, and assuming it's close enough to the real deal) I'd say the error happens somewhere in the "start_exe_thread" method. This method doesn't seem to return SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT directly, but it seems like a "wide" error. Most likely the error comes from threadman.c ?
http://svn.lan.st/utopia/threadman/threadman.c

so I'm thinking the illegal arguments are the ones passed to the ModuleMgr threads, which is weird because all these arguments are pretty much computed for you :/

Anyways, it doesn't answer your questions, however I hope it gives hints at the kind of complexity you're dealing with, so that people don't foolishly reply "use Lua, it's easier". :)
_________________
Wagic. Play that card game against an AI on your PSP
Back to top
View user's profile Send private message
Davee



Joined: 22 Jun 2009
Posts: 59

PostPosted: Sun Mar 21, 2010 9:59 pm    Post subject: Reply with quote

You sure stop_module isn't returning 1? Also it might be worthwhile seeing where selfstop is called in the original code. As it may do some buffer de-allocations and stuff before hand.
Back to top
View user's profile Send private message
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Mon Mar 22, 2010 5:20 am    Post subject: Reply with quote

I think the problem is that I call that function from outside the module space address, so that's why it is crashing/not working. I need to keep my code running but unload the game module.

I got a couple of new ideas I'll try later, thanks for the answers guys, they helped a lot :D
_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Back to top
View user's profile Send private message
Coldbird



Joined: 08 Feb 2007
Posts: 155

PostPosted: Mon Mar 22, 2010 11:07 pm    Post subject: Reply with quote

Tried spawning a new thread for stopping your module already?
_________________
Been gone for some time. Now I'm back. Someone mind getting me up-2-date?
Back to top
View user's profile Send private message MSN Messenger
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Tue Mar 23, 2010 11:07 pm    Post subject: Reply with quote

Well yes, it's a separate thread, but anyway, it is stopped.
_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
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