From 0ce6433311c699bbb819dd257dc470765ec734b1 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 15 Dec 2022 03:06:22 +0200 Subject: [PATCH] Updated init app --- apps/system/init/Makefile | 4 ++-- apps/system/init/init.c | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/system/init/Makefile b/apps/system/init/Makefile index 87224c4..f16f0ee 100644 --- a/apps/system/init/Makefile +++ b/apps/system/init/Makefile @@ -33,7 +33,7 @@ INCLUDE_DIR = ../../../out/system/include LDFLAGS := -Wl,-Map file.map -WARNCFLAG = -Wall -Wextra -Wmain +WARNCFLAG = -Wall -Wextra -Wno-main CFLAGS := \ -I$(INCLUDE_DIR) \ @@ -61,7 +61,7 @@ $(FILENAME): $(OBJ) %.o: %.cpp $(HEADERS) $(info Compiling $<) - $(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti + $(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -c $< -o $@ %.o: %.S $(info Compiling $<) diff --git a/apps/system/init/init.c b/apps/system/init/init.c index 55a95a8..083c979 100644 --- a/apps/system/init/init.c +++ b/apps/system/init/init.c @@ -1,34 +1,34 @@ #include #include #include - +#include #define print(m, ...) init_log(m, ##__VA_ARGS__) -int main(int argc, char *argv[], int envc, char *envp[]) +int main(int argc, char *argv[], char *envp[]) { print("Hello World!\n"); - print("%p %p %p %p\n", argc, argv, envc, envp); + print("%p %p %p\n", (void *)(uint64_t)&argc, (void *)&argv, (void *)&envp); print("I have %d arguments\n", argc); for (int i = 0; i < argc; i++) print("argv[%d] = (%p) %s\n", i, argv[i], argv[i]); + int envc = 0; + while (envp[envc] != NULL) + envc++; + print("I have %d environment variables\n", envc); for (int i = 0; i < envc; i++) print("envp[%d] = (%p) %s\n", i, envp[i], envp[i]); + Elf64_auxv_t *auxv; - while (*envp++ != NULL) + char **e = envp; + + while (*e++ != NULL) ; - int i = 0; - for (auxv = (Elf64_auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) - { - print("%lu :%d\n", (auxv->a_type), i++); - } + for (auxv = (Elf64_auxv_t *)e; auxv->a_type != AT_NULL; auxv++) + print("auxv: %ld %#lx\n", auxv->a_type, auxv->a_un.a_val); - // This code somehow breaks the process. How? I can't figure it out if it's a bug in the kernel or in the libc. - void *yes = malloc(0x100); - print("malloc(0x100) = %p\n", yes); - free(yes); return 0; }