Skip to content

Commit 50cb67e

Browse files
committed
mmap: move doc to README
1 parent ad55d48 commit 50cb67e

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

README.adoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,44 @@ Bibliography:
34423442
* https://stackoverflow.com/questions/2264384/how-do-i-use-ioctl-to-manipulate-my-kernel-module/44613896#44613896
34433443
* https://askubuntu.com/questions/54239/problem-with-ioctl-in-a-simple-kernel-module/926675#926675
34443444

3445+
==== mmap
3446+
3447+
In guest:
3448+
3449+
....
3450+
/mmap.sh
3451+
echo $?
3452+
....
3453+
3454+
Outcome: the test passes:
3455+
3456+
....
3457+
0
3458+
....
3459+
3460+
Sources:
3461+
3462+
* link:kernel_module/mmap.c[]
3463+
* link:kernel_module/user/mmap.c[]
3464+
* link:rootfs_overlay/mmap.sh[]
3465+
3466+
The `mmap` system call allows us to share memory between user and kernel space without copying.
3467+
3468+
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.
3469+
3470+
`mmap`, like most more complex <<file-operations>>, does not work with <<debugfs>> as of 4.9, so we use a <<procfs>> file for it.
3471+
3472+
Example adapted from: https://coherentmusings.wordpress.com/2014/06/10/implementing-mmap-for-transferring-data-from-user-space-to-kernel-space/
3473+
3474+
Bibliography:
3475+
3476+
* https://stackoverflow.com/questions/10760479/mmap-kernel-buffer-to-user-space/10770582#10770582
3477+
* https://stackoverflow.com/questions/1623008/allocating-memory-for-user-space-from-kernel-thread
3478+
* https://stackoverflow.com/questions/6967933/mmap-mapping-in-user-space-a-kernel-buffer-allocated-with-kmalloc
3479+
* https://github.com/jeremytrimble/ezdma
3480+
* https://github.com/simonjhall/dma
3481+
* https://github.com/ikwzm/udmabuf
3482+
34453483
==== Character devices
34463484

34473485
In guest:

kernel_module/README.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
.. Module dependencies
1919
... link:dep.c[]
2020
... link:dep2.c[]
21-
. Pseudo filesystems
22-
.. link:mmap.c[]
2321
. Asynchronous
2422
.. link:irq.c[]
2523
.. link:schedule.c[]

kernel_module/mmap.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
/*
2-
Remember: mmap, like most fops, does not work with debugfs as of 4.9! https://patchwork.kernel.org/patch/9252557/
3-
4-
Adapted from:
5-
https://coherentmusings.wordpress.com/2014/06/10/implementing-mmap-for-transferring-data-from-user-space-to-kernel-space/
6-
7-
Related:
8-
9-
- https://stackoverflow.com/questions/10760479/mmap-kernel-buffer-to-user-space/10770582#10770582
10-
- https://stackoverflow.com/questions/1623008/allocating-memory-for-user-space-from-kernel-thread
11-
- https://stackoverflow.com/questions/6967933/mmap-mapping-in-user-space-a-kernel-buffer-allocated-with-kmalloc
12-
- https://github.com/jeremytrimble/ezdma
13-
- https://github.com/simonjhall/dma
14-
- https://github.com/ikwzm/udmabuf
15-
*/
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#kthreads */
162

173
#include <linux/fs.h>
184
#include <linux/init.h>

rootfs_overlay/mmap.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
set -ex
2+
set -e
33
insmod /mmap.ko
4-
/mmap.out /proc/lkmc_mmap
4+
/mmap.out /proc/lkmc_mmap 2>&1 1>/dev/null
55
rmmod /mmap.ko

rootfs_overlay/test_all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ for test in \
66
/debugfs.sh \
77
/fops.sh \
88
/ioctl.sh \
9+
/mmap.sh \
910
/procfs.sh \
1011
/seq_file.sh \
1112
/seq_file_single_open.sh \

0 commit comments

Comments
 (0)