cross-bounday memory communication b/w user app and the Kernel.How?
cross-bounday memory communication b/w user app and the Kernel.How?
- Subject: cross-bounday memory communication b/w user app and the Kernel.How?
- From: "rohit dhamija" <email@hidden>
- Date: Thu, 1 Jun 2006 22:21:55 +0530
Hi,
Currently developing a KEXT for USB device on Mac OS 10.4 Intel and
powerpc and require your expert inputs on the following:
Query: "How is the user memory mapped with the kernel memory during
communication process"? I have a dynamic structure for communication
b/w user land app and kernel space.
Details:
1) Shared structure
Below is the common structure to be shared by user and kernel
application for communication across user-kernel boundary:
//////
typedef struct _CS {
int cmd; // my command number
void* cmd_payload; // command payload
void* response; // response
} COMMAND_STRUCTURE, *PCOMMAND_STRUCTURE;
//////
Note: The maximum size of command payload was of 4272 bytes , so i
want to send the command with the required bytes (and not the whole
structure, as void* com_payload)
2) User-Application
The user application sends the structure to the kernel space, and
recieve the output in the same structure. So it will be a "Scalar
Input and Scalar output"
/////////
kernReturn = IOConnectMethodStructureIStructureO(*dataPort,
kGnsGetVersion, //cmd
inBuffSize, //insize
&outBuffSize, //outSize
&structIn,
&structOut);
/////////
3) Kernel Level.
At KEXT level, Now, the main point of discussion is ,"how does the
kernel allocate/map the user-level structure in kernel and return back
the data from kernel memory back to user space"?
After studying the apple docs i have come to following conculsion and
wrote the steps for the same. Following steps needs your
review/comments ( i am not sure about these steps, so please correct
me incase i am wrong)
For Sending the data into kernel space from the user-application.
step a) Use IOMemoryDescriptor::withAddress to create and initializes
an IOMemoryDescriptor
///////////
IOMemoryDescriptor *descriptor = NULL;
descriptor = IOMemoryDescriptor::= withAddress(
address_of_CommandStructure,
sizeof(command_structure),
kIODirectionIn, // I am not sure about this , why do we need this ?
kernel_task // since we are passing data into kernel
);
//////////////
b) Now copy data from the memory descriptor's buffer to the buffer
allocated in the kernel space.
///////////////
ret= descriptor ->prepare( kIODirectionOut );
IOByteCount bytecont = descriptor->readBytes(
0, //offset
myBuff,
Ientocopy);
descriptor->complete();
////////////////
c) Now use this myBuff to communicate with the device.(The module works fine)
d) now we have got the data say,in outBuff, and this needs to be sent
back to user space.
Now at this point, do we need to map output data recieved from the
device data in-order to send to user space ? If yes, then how ?
Is the method correct ? Or there is some alternate methods available ?
I also wanted to mention one more thing: In case of my fixed structure
, mentioned below
//////////
typedef struct packet{
unsigned long pid;
unsigned long cmdId;
} packet, *ppacket;
////////
I have not mapped the data into the kernel space, still it works fine
i.e the data is successfully sent to communication module and the
output is successfully sent back to user without any issues.
Is the mapping is required when the data allocation is dynamic ?
Please correct me if I am wrong.
Please send your useful comments/suggestions for the same. also any
study material, docs , links are most welcome!!!
Thanks and regards,
Rohit Dhamija
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden