crossing user-kernel boundary (using copyin/copyout or mmap?)
I am writing an application that uses an NKE (Network Kernel Extension) and a user space client. I would like to share approximately 1KB of information between the NKE and the user-space client. According to Apple's "Inside Mac OSX: Kernel Programming" document chapter entitled "Boundary Crossings": "For one, memory allocated in the kernel cannot be written to by applications, including those running as root" and "In the Mac OS X kernel, data is most easily copied into kernel space with the BSD copyin function, and back out to user space with the copyout function." So I have attempted the following to get information from the kernel to the user-space client (I will also want to send information the other direction): A) allocate memory in the user space using malloc() B) pass the allocated user space void * ptr to the NKE via sysctl of an int C) in the NKE, call copyout() like this: ret = copyout(k_addr, u_addr, shareSize); This results in the copyout returning EFAULT (bad address). I checked the pointers and believe I am dereferencing all the addresses correctly, but it still doesn't work. My questions are: 1) Are the copyout() and copyin() functions the best way to do this (i.e. share memory across the user-kernel boundary)? 2) Should I be using mmap() or something else instead? 3) What do I need to do to get the copyout() working? 4) Do I need to wire the memory to get the copyout() to work? 5) Where can I find a well commented example of an NKE (or similar) sharing memory across the user-kernel boundary? Any help is greatly appreciated! Thanks! -Nate Lim _______________________________________________ darwin-kernel mailing list | darwin-kernel@lists.apple.com Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-kernel Do not post admin requests to the list. They will be ignored.
participants (1)
-
Nathan Lim