0

ok i will just make things simple , how could i send and receive data from my user mode app to my kernel driver using shared memory . with an actual mutex to indicate whether my request is finished or not. and how could i call read memory function without adding it to Major_irp function because i don't want to add any IOCTL code

Frankoo
  • 13
  • 4

1 Answers1

0

The following assumes a *nix style kernel, but the same concepts also translate to Windows. Other OS kernels may employ different concepts, though:

Either implement mmap syscall in your code to map kernel side allocated memory into user space. Or just implement read and write syscalls read/write directly from/to userspace memory.

Specifically to Linux: If you want access userspace memory asynchronously, use vmsplice with flag SPLICE_F_GIFT. Synchronization primitives like mutexes or semaphores usually don't cross the userspace/kernelspace boundary, if you want to operate asynchronously, you'll have to implement the poll file operation, to signal to userspace, when the "file" operation is done.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • am trying to do it with windows . also i have seen that i could do everything with writefile , readfile but i really want to see an example on how that works with shared memory but i can't find , also copying stuff with memcpy – Frankoo Mar 08 '19 at 12:09
  • @Frankoo: Whenever you cross the userspace/kernelspace boundary some precautions have to be made to assure safety. In essence when in kernel space, you're still in the same address space of the process which context you're in, with the addition, that you can also legally access kernel space addresses. So the whole concept of "shared memory" is kind of unneccessary. You just "access" it, albeit through helper functions/macros that the particular access is safe (i.e. goes into a mapped region, with read/write page flags set, and that memory domain fences (NUMA) are respected). – datenwolf Mar 08 '19 at 12:50
  • what i want to do basically is reading/writing memory from kernel driver and sending the data back to my usermode app so here is what i want to do 1- copy the read or write struct buffer from my usermode using memcpy to my shared section and from there i can read it from kernel using my readsharedmemory function but what am having problem is i can't think of a way of implementing it without IOCTL code. i will give you an example and if you can tell me how could that be implemented without the need of IOCTL code https://github.com/Zer0Mem0ry/KernelBhop this driver – Frankoo Mar 08 '19 at 15:54
  • any hints ? forgot to tag you up there ^^ – Frankoo Mar 09 '19 at 00:30
  • @Frankoo: Not trying to get off track here, but I wonder what it really is, you want to do in the first place. Right now we're discussing data transfer (i.e. solving problem X), but most likely you want to do the data transfer to solve another problem Y. What is that problem "Y", exactly? Because there might be an even more elegant way to address it. – datenwolf Mar 09 '19 at 11:44
  • i figured out what i really want as of now , i want to communicate with my driver but without any IOCTL code or DeviceIoControl. i have seen that i could use ReadFile or WriteFile but i haven't found any example about it using kernel and user mode . i want to send the data from my kernel driver to my user mode and from my user mode to kernel back and forth . – Frankoo Mar 09 '19 at 14:34