mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 19:51:35 +01:00
move doc for inits and sanity checks to README
This commit is contained in:
45
README.adoc
45
README.adoc
@@ -2323,7 +2323,7 @@ Remember that if your init returns, the kernel will panic, there are just two no
|
|||||||
* run forever in a loop or long sleep
|
* run forever in a loop or long sleep
|
||||||
* `poweroff` the machine
|
* `poweroff` the machine
|
||||||
|
|
||||||
==== The kernel panics despite poweroff
|
==== poweroff.out
|
||||||
|
|
||||||
Just using BusyBox' `poweroff` at the end of the `init` does not work and the kernel panics:
|
Just using BusyBox' `poweroff` at the end of the `init` does not work and the kernel panics:
|
||||||
|
|
||||||
@@ -2341,7 +2341,27 @@ But this fails when we are `init` itself!
|
|||||||
./run -E 'poweroff -f'
|
./run -E 'poweroff -f'
|
||||||
....
|
....
|
||||||
|
|
||||||
but why not just use your super simple and effective `/poweroff.out` and be done with it?
|
but why not just use our minimal `/poweroff.out` and be done with it?
|
||||||
|
|
||||||
|
....
|
||||||
|
./run -E '/poweroff.out'
|
||||||
|
....
|
||||||
|
|
||||||
|
Source: link:kernel_module/user/poweroff.c[]
|
||||||
|
|
||||||
|
This also illustrates how to shutdown the computer from C: https://stackoverflow.com/questions/28812514/how-to-shutdown-linux-using-c-or-qt-without-call-to-system
|
||||||
|
|
||||||
|
==== sleep_forever.out
|
||||||
|
|
||||||
|
I dare you to guess what this does:
|
||||||
|
|
||||||
|
....
|
||||||
|
./run -E '/sleep_forever.out'
|
||||||
|
....
|
||||||
|
|
||||||
|
Source: link:kernel_module/user/sleep_forever.c[]
|
||||||
|
|
||||||
|
This executable is a convenient simple init that does not panic and sleeps instead.
|
||||||
|
|
||||||
[[init-busybox]]
|
[[init-busybox]]
|
||||||
=== Run command at the end of BusyBox init
|
=== Run command at the end of BusyBox init
|
||||||
@@ -8711,6 +8731,27 @@ Then proceed to do the following tests:
|
|||||||
* `/count.sh` and `b __x64_sys_write`
|
* `/count.sh` and `b __x64_sys_write`
|
||||||
* `insmod /timer.ko` and `b lkmc_timer_callback`
|
* `insmod /timer.ko` and `b lkmc_timer_callback`
|
||||||
|
|
||||||
|
===== Sanity checks
|
||||||
|
|
||||||
|
Basic C and C++ hello worlds:
|
||||||
|
|
||||||
|
....
|
||||||
|
/hello.out
|
||||||
|
/hello_cpp.out
|
||||||
|
....
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
....
|
||||||
|
hello
|
||||||
|
hello cpp
|
||||||
|
....
|
||||||
|
|
||||||
|
Sources:
|
||||||
|
|
||||||
|
* link:kernel_module/user/hello.c[]
|
||||||
|
* link:kernel_module/user/hello_cpp.c[]
|
||||||
|
|
||||||
=== About
|
=== About
|
||||||
|
|
||||||
This project is for people who want to learn and modify low level system components:
|
This project is for people who want to learn and modify low level system components:
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sanity-checks */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sanity-checks */
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "hello world" << std::endl;
|
std::cout << "hello cpp" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
/* Userspace is for the weak. Die.
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#poweroff-out */
|
||||||
* https://stackoverflow.com/questions/28812514/how-to-shutdown-linux-using-c-or-qt-without-call-to-system
|
|
||||||
**/
|
|
||||||
|
|
||||||
#define _XOPEN_SOURCE 700
|
#define _XOPEN_SOURCE 700
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Sleeping beauty, your prince is called Ctrl + C. */
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sleep_forever-out */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user