From 7a097f16eaa9aa6bbd10fc3759169bfe7ede8c8a Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 11 Oct 2022 17:31:06 +0200 Subject: [PATCH] apps: add a new example app which does all kinds of stdio misbehaving >.< --- apps/Makefile | 2 +- apps/src/quota.c | 22 ++++++++++++++++++++++ kernel/src/main.cpp | 6 +++++- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 apps/src/quota.c diff --git a/apps/Makefile b/apps/Makefile index 10d8984a..c95a1265 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -1,4 +1,4 @@ -APPS := init fib leap art memeater +APPS := init fib leap art memeater quota APPS_DIR := $(LUNA_ROOT)/apps APPS_SRC := $(APPS_DIR)/src diff --git a/apps/src/quota.c b/apps/src/quota.c new file mode 100644 index 00000000..670597ec --- /dev/null +++ b/apps/src/quota.c @@ -0,0 +1,22 @@ +#include +#include +#include + +int main() +{ + if (open("/file/that/does/not/exist", O_RDONLY) < 0) { perror("open"); } + int sys = open("/sys", O_RDONLY); + if (sys < 0) { perror("open"); } + if (read(sys, NULL, 20) < 0) { perror("read"); } + char buf[20]; + if (read(sys, buf, 20) < 0) { perror("read"); } + if (close(sys) < 0) { perror("close"); } + for (int i = 0; i < 10; i++) + { + if (open("/", O_RDONLY) < 0) { perror("open"); } + } + int exec; + if ((exec = open("/bin/quota", O_RDONLY)) < 0) { perror("open"); } + if (read(exec, buf, 20) < 0) { perror("read"); } + if (close(exec) < 0) { perror("close"); } +} \ No newline at end of file diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 6b681253..daebe4b2 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -123,7 +123,7 @@ extern "C" void _start() } }); - uint64_t demo = Mersenne::get() % 5; + uint64_t demo = Mersenne::get() % 6; switch (demo) { @@ -147,6 +147,10 @@ extern "C" void _start() kinfoln("Loading demo: memory eating program"); Scheduler::load_user_task("bin/memeater"); break; + case 5: + kinfoln("Loading demo: misbehaving program"); + Scheduler::load_user_task("bin/quota"); + break; default: break; }