• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: cross-bounday memory communication b/w user app and the Kernel.(Solved)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cross-bounday memory communication b/w user app and the Kernel.(Solved)


  • Subject: Re: cross-bounday memory communication b/w user app and the Kernel.(Solved)
  • From: "rohit dhamija" <email@hidden>
  • Date: Mon, 5 Jun 2006 22:13:42 +0530

Hi,
Thanks for your reply. With help of the experts, I have finally able
to do cross boundary communication successfully. Below is the code
snippet for your review.

As per Terrys and Michael comments, I have allocated the Command
packet memory dynamically and the response packet is kept statically
allocated.


Shared Structure: =================

typedef struct
{
   unsigned long   CmdSize;		// Size of command parameters
   unsigned char   InstCode;       // Opcode part of CmdCode (set by driver)

} CMD_HEAD, *PCMD_HEAD;

typedef struct
{
   unsigned long   RspSize;		// Size of data returned
   unsigned char   ErrorInfo;		// Error information
} RSP_HEAD, *PRSP_HEAD;

typedef union _IOCTL_COMMAND
{
	PCMD_HEAD     pApiCmd;//  Pointer to Command head
	RSP_HEAD      ApiRsp;   //  Response head buffer
} IOCTL_COMMAND , *PIOCTL_COMMAND;


typedef struct { unsigned long pIndex; //the index required by GetDeviceInfo unsigned long iBufferSz; //The command Sz unsigned long oBufferSz; //the expected output Buffer size IOCTL_COMMAND IOCmd; } COMMAND_EXCHANGE, *PCOMMAND_EXCHANGE;


At Application Layer: =====================

// assign the input buffer to structIn
structIn.IOCmd.pApiCmd = iBuffer; // iBuffer is the void* buffer		

// Struct Input and Structure output
kernReturn = IOConnectMethodStructureIStructureO(*dataPort,
			myDriverAPICommand,
			inBuffSize,
			&outBuffSize,
			&structIn,
			&structOut);

// copy the output data in oBuffer
memcpy(oBuffer, &(structOut.IOCmd.ApiRsp) , oBufferSize);


At KEXT Layer: ============= In IOUserClient class:

IOReturn myDriverUserClient::CommonAPICmd( COMMAND_EXCHANGE* inpkt,
COMMAND_EXCHANGE* outpkt){

PCMD_HEAD  pCmd = NULL;
PRSP_HEAD pRsp = NULL;

pCmd = (PCMD_HEAD)IOMalloc(inputSize);
pRsp = (PRSP_HEAD)&(inpkt->IOCmd.ApiRsp);

if( (pCmd == NULL) || (pRsp == NULL))
{
DBLog(("\nMemory could not be allocated\n"));
return kIOReturnNoResources;
}

status = copyin( (user_addr_t) inpkt->IOCmd.pApiCmd, pCmd, inputSize);
..
..
}

Bulk communication Module:
=========================
In IOService:

And then pass the command info to the BULK Communication module:

bulkDeviceCommuncation()
{

IOReturn status;
UInt32 size;

IOMemoryDescriptor *memDescOut = NULL;
IOMemoryDescriptor *memDescIn = NULL;


// Validate and allocate if (myDataStructure->fOutPipe == NULL) { status = kIOReturnNoDevice; goto out; } if ((memDescOut = IOMemoryDescriptor::withAddress(&Command, sizeof(COMMAND), kIODirectionOut) == NULL) { status = kIOReturnNoMemory; goto out; } if ((memDescIn = IOMemoryDescriptor::withAddress(&Response, sizeof(RESPONSE), kIODirectinIn) == NULL) { status = kIOReturnNoMemory; goto out; }


// do outbound command if ((status = memDescOut->prepare()) != kIOReturnSuccess) goto out;


status = myDataStructure->fOutPipe->Write(memDescOut, 1000, 2000, sizeof(COMMAND), NULL); memDescOut->complete();


if (status != kIOReturnSuccess) goto out;


// do inbound response if ((status = memDescIn->prepare()) != kIOReturnSuccess) goto out;


status = myDataStructure->fInPipe->Read(memDescIn, 1000, 2000, size, NULL, &size); memDescIn->complete();


out: if (memDescOut) memDescOut->release(); if (memDescIn) memDescIn->release();


return(status); }

Please send your comments for the same.

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


  • Prev by Date: Re: cross-bounday memory communication b/w user app and the Kernel.How?
  • Next by Date: Re: cross-bounday memory communication b/w user app and the Kernel.How?
  • Previous by thread: Re: GNU-Darwin: missing code in Darwin
  • Next by thread: mbuf data access
  • Index(es):
    • Date
    • Thread