cross-bounday memory communication b/w user app and the Kernel.How?
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=jzwR3BOw0XVV0izzFkQh9p0VhXpBPPivIbssyNAf2MrrwK8JhNAc4lDpRqnPgPI85tV4wzSPHWLA9XPwlOoKeAPVvPJJtjO/vdCt7VR+4PyfL23vEew0Rd8gYKzeF0pZvqhonurKWDFgZZUhhwvFqZ9bMXJpJi30SPU3/foEVl0= 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 (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
rohit dhamija