mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
mmap: move doc to README
This commit is contained in:
38
README.adoc
38
README.adoc
@@ -3442,6 +3442,44 @@ Bibliography:
|
|||||||
* https://stackoverflow.com/questions/2264384/how-do-i-use-ioctl-to-manipulate-my-kernel-module/44613896#44613896
|
* https://stackoverflow.com/questions/2264384/how-do-i-use-ioctl-to-manipulate-my-kernel-module/44613896#44613896
|
||||||
* https://askubuntu.com/questions/54239/problem-with-ioctl-in-a-simple-kernel-module/926675#926675
|
* https://askubuntu.com/questions/54239/problem-with-ioctl-in-a-simple-kernel-module/926675#926675
|
||||||
|
|
||||||
|
==== mmap
|
||||||
|
|
||||||
|
In guest:
|
||||||
|
|
||||||
|
....
|
||||||
|
/mmap.sh
|
||||||
|
echo $?
|
||||||
|
....
|
||||||
|
|
||||||
|
Outcome: the test passes:
|
||||||
|
|
||||||
|
....
|
||||||
|
0
|
||||||
|
....
|
||||||
|
|
||||||
|
Sources:
|
||||||
|
|
||||||
|
* link:kernel_module/mmap.c[]
|
||||||
|
* link:kernel_module/user/mmap.c[]
|
||||||
|
* link:rootfs_overlay/mmap.sh[]
|
||||||
|
|
||||||
|
The `mmap` system call allows us to share memory between user and kernel space without copying.
|
||||||
|
|
||||||
|
In this example, we make a tiny 4 byte kernel buffer available to user-space, and we then modify it on userspace, and check that the kernel can see the modification.
|
||||||
|
|
||||||
|
`mmap`, like most more complex <<file-operations>>, does not work with <<debugfs>> as of 4.9, so we use a <<procfs>> file for it.
|
||||||
|
|
||||||
|
Example adapted from: https://coherentmusings.wordpress.com/2014/06/10/implementing-mmap-for-transferring-data-from-user-space-to-kernel-space/
|
||||||
|
|
||||||
|
Bibliography:
|
||||||
|
|
||||||
|
* https://stackoverflow.com/questions/10760479/mmap-kernel-buffer-to-user-space/10770582#10770582
|
||||||
|
* https://stackoverflow.com/questions/1623008/allocating-memory-for-user-space-from-kernel-thread
|
||||||
|
* https://stackoverflow.com/questions/6967933/mmap-mapping-in-user-space-a-kernel-buffer-allocated-with-kmalloc
|
||||||
|
* https://github.com/jeremytrimble/ezdma
|
||||||
|
* https://github.com/simonjhall/dma
|
||||||
|
* https://github.com/ikwzm/udmabuf
|
||||||
|
|
||||||
==== Character devices
|
==== Character devices
|
||||||
|
|
||||||
In guest:
|
In guest:
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
.. Module dependencies
|
.. Module dependencies
|
||||||
... link:dep.c[]
|
... link:dep.c[]
|
||||||
... link:dep2.c[]
|
... link:dep2.c[]
|
||||||
. Pseudo filesystems
|
|
||||||
.. link:mmap.c[]
|
|
||||||
. Asynchronous
|
. Asynchronous
|
||||||
.. link:irq.c[]
|
.. link:irq.c[]
|
||||||
.. link:schedule.c[]
|
.. link:schedule.c[]
|
||||||
|
|||||||
@@ -1,18 +1,4 @@
|
|||||||
/*
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#kthreads */
|
||||||
Remember: mmap, like most fops, does not work with debugfs as of 4.9! https://patchwork.kernel.org/patch/9252557/
|
|
||||||
|
|
||||||
Adapted from:
|
|
||||||
https://coherentmusings.wordpress.com/2014/06/10/implementing-mmap-for-transferring-data-from-user-space-to-kernel-space/
|
|
||||||
|
|
||||||
Related:
|
|
||||||
|
|
||||||
- https://stackoverflow.com/questions/10760479/mmap-kernel-buffer-to-user-space/10770582#10770582
|
|
||||||
- https://stackoverflow.com/questions/1623008/allocating-memory-for-user-space-from-kernel-thread
|
|
||||||
- https://stackoverflow.com/questions/6967933/mmap-mapping-in-user-space-a-kernel-buffer-allocated-with-kmalloc
|
|
||||||
- https://github.com/jeremytrimble/ezdma
|
|
||||||
- https://github.com/simonjhall/dma
|
|
||||||
- https://github.com/ikwzm/udmabuf
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -ex
|
set -e
|
||||||
insmod /mmap.ko
|
insmod /mmap.ko
|
||||||
/mmap.out /proc/lkmc_mmap
|
/mmap.out /proc/lkmc_mmap 2>&1 1>/dev/null
|
||||||
rmmod /mmap.ko
|
rmmod /mmap.ko
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ for test in \
|
|||||||
/debugfs.sh \
|
/debugfs.sh \
|
||||||
/fops.sh \
|
/fops.sh \
|
||||||
/ioctl.sh \
|
/ioctl.sh \
|
||||||
|
/mmap.sh \
|
||||||
/procfs.sh \
|
/procfs.sh \
|
||||||
/seq_file.sh \
|
/seq_file.sh \
|
||||||
/seq_file_single_open.sh \
|
/seq_file_single_open.sh \
|
||||||
|
|||||||
Reference in New Issue
Block a user