mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
pci negator working, factorial not
This commit is contained in:
8
rootfs_overlay/README.md
Normal file
8
rootfs_overlay/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# rootfs_overlay
|
||||
|
||||
This directory copied into the target filesystem.
|
||||
|
||||
We use it to for things like:
|
||||
|
||||
- customized configuration files
|
||||
- userland module test scripts
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
insmod /character_device.ko
|
||||
major="$(grep lkmc_character_device /proc/devices | cut -d ' ' -f 1)"
|
||||
mknod /character_device.dev c $major 0
|
||||
cat /character_device.dev
|
||||
/mknoddev.sh character_device
|
||||
cat /dev/lkmc_character_device
|
||||
# => abcd
|
||||
rm /dev/lkmc_character_device
|
||||
rmmod character_device
|
||||
|
||||
4
rootfs_overlay/mknoddev.sh
Executable file
4
rootfs_overlay/mknoddev.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
dev="lkmc_$1"
|
||||
major="$(grep "$dev" /proc/devices | cut -d ' ' -f 1)"
|
||||
mknod "/dev/$dev" c "$major" 0
|
||||
30
rootfs_overlay/pci.sh
Executable file
30
rootfs_overlay/pci.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
# Setup.
|
||||
insmod /pci.ko
|
||||
/mknoddev.sh pci
|
||||
|
||||
# Identifiction.
|
||||
dd bs=4 status=none if=/dev/lkmc_pci count=1 skip=0 | od -An -t x1
|
||||
# => 010000ed
|
||||
|
||||
# Negator.
|
||||
dd bs=4 status=none if=/dev/lkmc_pci count=1 skip=1 | od -An -t x1
|
||||
printf '\xF0\xF0\xF0\xF0' | dd bs=4 status=none of=/dev/lkmc_pci count=1 seek=1
|
||||
dd bs=4 status=none if=/dev/lkmc_pci count=1 skip=1 | od -An -t x1
|
||||
# => 0F0F0F0F
|
||||
|
||||
# Factorial calculator.
|
||||
# factorial(0xC) = 0x1c8cfc00
|
||||
printf '\x00\x00\x00\x0C' | dd bs=4 status=none of=/dev/lkmc_pci count=1 seek=2
|
||||
printf '\x00\x00\x00\x00' | dd bs=4 status=none of=/dev/lkmc_pci count=1 seek=8
|
||||
sleep 1
|
||||
dd bs=4 status=none if=/dev/lkmc_pci count=1 skip=2 | od -An -t x1
|
||||
dd bs=4 status=none if=/dev/lkmc_pci count=1 skip=8 | od -An -t x1
|
||||
# => 1c8cfc00
|
||||
|
||||
# Teardown.
|
||||
rm /dev/lkmc_pci
|
||||
rmmod pci
|
||||
Reference in New Issue
Block a user