Archived:Sharing protected kernel resources between processes on Symbian
Article Metadata
Compatibility
Article
Overview
Sharing protected kernel resources between processes
Description
It is a common requirement to share protected kernel resources like RMutex, RChunk, RSemaphore, etc. between different processes. This can be done either in a Parent – Child or Client – Server relationship.
Solution
Parent – Child relationship
One way of sharing the protected kernel resources like RSemaphore, RChunk, RBusLogicalChannel, RSessionBase, and RMutex objects is by using the RProcess::SetParameter() API. Below is a simplified example of how to pass the resource to the child process from the parent:
// In the parent process:
RProcess proc;
// KChildProcess is process to be launched.
User::LeaveIfError( proc.Create( KChildProcess, KNullDesC,EOwnerThread ) );
CleanupClosePushL( proc );
proc.SetParameter( 7, iSch ); // iSch is the handle to be passed
// 7 is the environmental data slot
proc.Resume();
// In the child process:
iSch.Open( 7, EOwnerProcess ); // iSch is the handle to be obtained
Client – Server relationship
Handles to protected kernel resources like RSemaphore, RChunk, RBusLogicalChannel, RSessionBase, and RMutex objects can be passed via client/server communications.
The implementation is as follows:
A client process which has a handle of one of these objects can give a server the use of it by sending the handle as a RHandleBase parameter in a TIpcArgs package. The server can then open this handle by calling the following method on the appropriate resource class:
Open( RMessagePtr2 aMessage, TInt aParam, TOwnerType aType=EOwnerProcess );
where aMessage is the message that the server received from the client, and aParam is a number (0-3) indicating which message parameter holds the client's handle.
A server can return a handle to the client by completing a client message using the resource object as an argument:
RMessagePtr2::Complete( RHandleBase aHandle );
This will create a thread-relative handle to the object and cause the client's request to complete with this value.
The client should check the returned value, a negative value indicates an error value, a positive value is a handle which can be used to initialize the relevant R object by calling RHandleBase::SetHandle.
Alternatively, you can use the following method:
TInt RHandleBase::SetReturnedHandle( TInt aHandleOrError );
where aHandleOrError is the value returned by the server. This method checks if the value is a handle.


(no comments yet)