Re: cross-bounday memory communication b/w user app and the Kernel.How?
Re: cross-bounday memory communication b/w user app and the Kernel.How?
- Subject: Re: cross-bounday memory communication b/w user app and the Kernel.How?
- From: "rohit dhamija" <email@hidden>
- Date: Sat, 3 Jun 2006 00:09:18 +0530
Hi Michael,
I shall try to explain my doubt again:
I need to send various command packets to the device and get the
corresponding response packet. My command consists of
[a]. command identifier i.e. command_id
[b] command payload: This command payload differs from command to
command. The maximum size of command payload is:
"unsigned char Commandpayload[257];"
My output response packet again varies from command to command. The
maximum size of response packet can be
"unsigned char ResponseData[256];"
So, one way is to make the shared structure (the structure to
communicate with user kernel space) can be:
typedef struct _mypacket{
int command_id;
union {
unsigned char Commandpayload[257];
unsigned char ResponseData[256]
} MY_PACKET, *PMY_PACKET;
But this type of structure will consume the maximum memory. So In
order to avoid it, can we have pointers instead of static memory
allocation ?
The command packet the structure will be
struct command_packet{
int command_id
unsigned char* cmd_payload;
int size_of_command;
}
Similary for response_packet. Is this possible ?
Rohit
On 6/2/06, Michael Smith <email@hidden> wrote:
On Jun 2, 2006, at 12:28 AM, rohit dhamija wrote:
> Thanks for your suggestion, but i need to tell you two things :
>
> 1. I am sure that you did not get my question right.
That's entirely possible.
> Regarding my query,
>> You don't. The descriptor refers to the buffer that already exists
>> in the user-space process' address space. You don't need to copy
>> anything.
>
> I know that the descriptor refers to the buffer only. But say for
> example I wish to set this data to all zero's.
I'm not sure why you would want to do this. If you want a buffer
full of zeroes, you would create an IOBufferMemoryDescriptor, since
that will have private memory associated with it, already mapped into
your address space.
In your example, you want to send the command buffer that the user
has supplied, so you need a descriptor that refers to it.
> So in this case: (a)
> will I give address of the structure OR (b) address of
> IOMemoryDescriptor,, as the first parameter to memset ?
Neither. The IOMemoryDescriptor is a class instance, and the
structure pointer in your example just points to a couple of
pointers. You can't use the pointers inside the structure, because
they are not valid in your address space.
Why do you want to change the contents of the command buffer? In the
typical interface model, the caller is not going to expect you to do
anything to it. Mapping it so that you can write into it will be
expensive, too.
> Similarly what if I want to copy the data AGAIN in my driver side ?
> Do I need to send the address of structure to the memcpy ? Or do i
> need to pass
> address of IOMemoryDescriptor as the first parameter to memcpy.
You don't want to copy the data at all, unless you are going to
modify it before you send it out.
> I hope I am able to clarify my query. Please comment.
Not really. I don't yet understand why you are obsessed with copying
this data...
= Mike
--
Rohit Dhamija(M) 9818446545
_______________________________________________
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