Updated init app

This commit is contained in:
Alex 2022-12-15 03:06:22 +02:00
parent d82d725f11
commit 0ce6433311
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 15 additions and 15 deletions

View File

@ -33,7 +33,7 @@ INCLUDE_DIR = ../../../out/system/include
LDFLAGS := -Wl,-Map file.map LDFLAGS := -Wl,-Map file.map
WARNCFLAG = -Wall -Wextra -Wmain WARNCFLAG = -Wall -Wextra -Wno-main
CFLAGS := \ CFLAGS := \
-I$(INCLUDE_DIR) \ -I$(INCLUDE_DIR) \
@ -61,7 +61,7 @@ $(FILENAME): $(OBJ)
%.o: %.cpp $(HEADERS) %.o: %.cpp $(HEADERS)
$(info Compiling $<) $(info Compiling $<)
$(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti $(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -c $< -o $@
%.o: %.S %.o: %.S
$(info Compiling $<) $(info Compiling $<)

View File

@ -1,34 +1,34 @@
#include <stdlib.h> #include <stdlib.h>
#include <init.h> #include <init.h>
#include <aux.h> #include <aux.h>
#include <syslib.h>
#define print(m, ...) init_log(m, ##__VA_ARGS__) #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("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); print("I have %d arguments\n", argc);
for (int i = 0; i < argc; i++) for (int i = 0; i < argc; i++)
print("argv[%d] = (%p) %s\n", i, argv[i], argv[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); print("I have %d environment variables\n", envc);
for (int i = 0; i < envc; i++) for (int i = 0; i < envc; i++)
print("envp[%d] = (%p) %s\n", i, envp[i], envp[i]); print("envp[%d] = (%p) %s\n", i, envp[i], envp[i]);
Elf64_auxv_t *auxv; Elf64_auxv_t *auxv;
while (*envp++ != NULL) char **e = envp;
while (*e++ != NULL)
; ;
int i = 0; for (auxv = (Elf64_auxv_t *)e; auxv->a_type != AT_NULL; auxv++)
for (auxv = (Elf64_auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) print("auxv: %ld %#lx\n", auxv->a_type, auxv->a_un.a_val);
{
print("%lu :%d\n", (auxv->a_type), i++);
}
// 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; return 0;
} }