Skip to content

Commit be6319a

Browse files
committed
move doc for inits and sanity checks to README
1 parent f2bf644 commit be6319a

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

README.adoc

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,7 @@ Remember that if your init returns, the kernel will panic, there are just two no
23232323
* run forever in a loop or long sleep
23242324
* `poweroff` the machine
23252325

2326-
==== The kernel panics despite poweroff
2326+
==== poweroff.out
23272327

23282328
Just using BusyBox' `poweroff` at the end of the `init` does not work and the kernel panics:
23292329

@@ -2341,7 +2341,27 @@ But this fails when we are `init` itself!
23412341
./run -E 'poweroff -f'
23422342
....
23432343

2344-
but why not just use your super simple and effective `/poweroff.out` and be done with it?
2344+
but why not just use our minimal `/poweroff.out` and be done with it?
2345+
2346+
....
2347+
./run -E '/poweroff.out'
2348+
....
2349+
2350+
Source: link:kernel_module/user/poweroff.c[]
2351+
2352+
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
2353+
2354+
==== sleep_forever.out
2355+
2356+
I dare you to guess what this does:
2357+
2358+
....
2359+
./run -E '/sleep_forever.out'
2360+
....
2361+
2362+
Source: link:kernel_module/user/sleep_forever.c[]
2363+
2364+
This executable is a convenient simple init that does not panic and sleeps instead.
23452365

23462366
[[init-busybox]]
23472367
=== Run command at the end of BusyBox init
@@ -8711,6 +8731,27 @@ Then proceed to do the following tests:
87118731
* `/count.sh` and `b __x64_sys_write`
87128732
* `insmod /timer.ko` and `b lkmc_timer_callback`
87138733

8734+
===== Sanity checks
8735+
8736+
Basic C and C++ hello worlds:
8737+
8738+
....
8739+
/hello.out
8740+
/hello_cpp.out
8741+
....
8742+
8743+
Output:
8744+
8745+
....
8746+
hello
8747+
hello cpp
8748+
....
8749+
8750+
Sources:
8751+
8752+
* link:kernel_module/user/hello.c[]
8753+
* link:kernel_module/user/hello_cpp.c[]
8754+
87148755
=== About
87158756

87168757
This project is for people who want to learn and modify low level system components:

kernel_module/user/hello.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sanity-checks */
2+
13
#include <stdio.h>
24
#include <stdlib.h>
35

kernel_module/user/hello_cpp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sanity-checks */
2+
13
#include <iostream>
24

35
int main() {
4-
std::cout << "hello world" << std::endl;
6+
std::cout << "hello cpp" << std::endl;
57
}

kernel_module/user/poweroff.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* Userspace is for the weak. Die.
2-
* https://stackoverflow.com/questions/28812514/how-to-shutdown-linux-using-c-or-qt-without-call-to-system
3-
**/
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#poweroff-out */
42

53
#define _XOPEN_SOURCE 700
64
#include <stdio.h>

kernel_module/user/sleep_forever.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Sleeping beauty, your prince is called Ctrl + C. */
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#sleep_forever-out */
22

33
#include <stdio.h>
44
#include <unistd.h>

0 commit comments

Comments
 (0)