mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
baremetal: build userland/ programs using baremetal path property instead of symlinks
Otherwise I'll go crazy with symlink action.
This commit is contained in:
34
userland/c/abort.c
Normal file
34
userland/c/abort.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* # abort
|
||||
*
|
||||
* Raise a SIGABRT, an ANSI C signal which by default kills the program.
|
||||
*
|
||||
* ....
|
||||
* man abort
|
||||
* ....
|
||||
*
|
||||
* Bibliography:
|
||||
*
|
||||
* * http://stackoverflow.com/questions/397075/what-is-the-difference-between-exit-and-abort
|
||||
* * http://stackoverflow.com/questions/3676221/when-abort-is-preferred-over-exit
|
||||
*
|
||||
* Differences from exit: does not run regular program teardown:
|
||||
*
|
||||
* * does not call `atexit` function.
|
||||
* * does not call C++ destructors
|
||||
*
|
||||
* `assert()` exits the program with abort.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void atexit_func() {
|
||||
puts("atexit");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* Will not get called. */
|
||||
atexit(atexit_func);
|
||||
abort();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../../lkmc/c/add.c
|
||||
13
userland/c/add.c
Normal file
13
userland/c/add.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <assert.h>
|
||||
|
||||
int main(void) {
|
||||
int i, j, k;
|
||||
i = 1;
|
||||
/* test-gdb-op1 */
|
||||
j = 2;
|
||||
/* test-gdb-op2 */
|
||||
k = i + j;
|
||||
/* test-gdb-result */
|
||||
if (k != 3)
|
||||
assert(0);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../../lkmc/c/add.py
|
||||
9
userland/c/add.py
Normal file
9
userland/c/add.py
Normal file
@@ -0,0 +1,9 @@
|
||||
def test(self):
|
||||
self.sendline('tbreak main')
|
||||
self.sendline('continue')
|
||||
self.continue_to('op1')
|
||||
assert self.get_int('i') == 1
|
||||
self.continue_to('op2')
|
||||
assert self.get_int('j') == 2
|
||||
self.continue_to('result')
|
||||
assert self.get_int('k') == 3
|
||||
@@ -1 +0,0 @@
|
||||
../../lkmc/c/assert_fail.c
|
||||
18
userland/c/assert_fail.c
Normal file
18
userland/c/assert_fail.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* Let's see what happens when an assert fails.
|
||||
*
|
||||
* Outcome on Ubuntu 19.04 shows the failure line:
|
||||
*
|
||||
* assert_fail.out: /path/to/linux-kernel-module-cheat/userland/c/assert_fail.c:15: main: Assertion `0' failed.
|
||||
*
|
||||
* and exit status 134 == 128 + 6, which corresponds to SIGABORT (6).
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
assert(0);
|
||||
puts("here");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
7
userland/c/exit0.c
Normal file
7
userland/c/exit0.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#magic-failure-string */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
exit(0);
|
||||
}
|
||||
7
userland/c/exit1.c
Normal file
7
userland/c/exit1.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#magic-failure-string */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
exit(1);
|
||||
}
|
||||
7
userland/c/exit2.c
Normal file
7
userland/c/exit2.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#magic-failure-string */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
exit(2);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../../lkmc/c/getchar.c
|
||||
21
userland/c/getchar.c
Normal file
21
userland/c/getchar.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* Get on character from stdin, and then print it back out.
|
||||
*
|
||||
* Same as getc(stdin).
|
||||
*
|
||||
* You have to press enter for the character to go through:
|
||||
* https://stackoverflow.com/questions/1798511/how-to-avoid-pressing-enter-with-getchar
|
||||
*
|
||||
* Used at:
|
||||
* https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1/53937376#53937376
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char c;
|
||||
printf("enter a character: ");
|
||||
c = getchar();
|
||||
printf("you entered: %c\n", c);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../../lkmc/c/hello.c
|
||||
9
userland/c/hello.c
Normal file
9
userland/c/hello.c
Normal file
@@ -0,0 +1,9 @@
|
||||
/* Print hello to stdout ;-) */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
puts("hello");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../../lkmc/c/infinite_loop.c
|
||||
29
userland/c/infinite_loop.c
Normal file
29
userland/c/infinite_loop.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* Loop infinitely. Print an integer whenever a period is reached:
|
||||
*
|
||||
* ....
|
||||
* ./infinite_loop [period]
|
||||
* ....
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uintmax_t i, j, period;
|
||||
if (argc > 1) {
|
||||
period = strtoumax(argv[1], NULL, 10);
|
||||
} else {
|
||||
period = 100000000;
|
||||
}
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (1) {
|
||||
i++;
|
||||
if (i % period == 0) {
|
||||
printf("%ju\n", j);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
userland/c/out_of_memory.c
Normal file
18
userland/c/out_of_memory.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* Let's see how much memory Linux lets us allocate. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char *ptr = NULL;
|
||||
size_t size = 1;
|
||||
while (1) {
|
||||
printf("0x%zx\n", size);
|
||||
ptr = realloc(ptr, size);
|
||||
if (ptr == NULL) {
|
||||
break;
|
||||
} else {
|
||||
size <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
6
userland/c/return0.c
Normal file
6
userland/c/return0.c
Normal file
@@ -0,0 +1,6 @@
|
||||
/* false.c is a superset of this, this is mainly a sanity check for
|
||||
* baremetal where we don't have CLI arguments yet:
|
||||
* https://github.com/cirosantilli/linux-kernel-module-cheat/issues/67
|
||||
*/
|
||||
|
||||
int main(void) { return 0; }
|
||||
2
userland/c/return1.c
Normal file
2
userland/c/return1.c
Normal file
@@ -0,0 +1,2 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#magic-failure-string */
|
||||
int main(void) { return 1; }
|
||||
2
userland/c/return2.c
Normal file
2
userland/c/return2.c
Normal file
@@ -0,0 +1,2 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#magic-failure-string */
|
||||
int main(void) { return 2; }
|
||||
@@ -1 +0,0 @@
|
||||
../../lkmc/c/stderr.c
|
||||
7
userland/c/stderr.c
Normal file
7
userland/c/stderr.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* Print hello to stderr. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
fputs("hello\n", stderr);
|
||||
}
|
||||
Reference in New Issue
Block a user