move doc for inits and sanity checks to README

This commit is contained in:
Ciro Santilli
2018-07-09 16:59:13 +01:00
parent f2bf644cfd
commit be6319ab89
5 changed files with 50 additions and 7 deletions

View File

@@ -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
* `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:
@@ -2341,7 +2341,27 @@ But this fails when we are `init` itself!
./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]]
=== 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`
* `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
This project is for people who want to learn and modify low level system components:

View File

@@ -1,3 +1,5 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sanity-checks */
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,5 +1,7 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sanity-checks */
#include <iostream>
int main() {
std::cout << "hello world" << std::endl;
std::cout << "hello cpp" << std::endl;
}

View File

@@ -1,6 +1,4 @@
/* Userspace is for the weak. Die.
* https://stackoverflow.com/questions/28812514/how-to-shutdown-linux-using-c-or-qt-without-call-to-system
**/
/* https://github.com/cirosantilli/linux-kernel-module-cheat#poweroff-out */
#define _XOPEN_SOURCE 700
#include <stdio.h>

View File

@@ -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 <unistd.h>