diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index b35caa7..0f004cb 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,15 +1,17 @@ set(APPS user_tty init + gui ) add_subdirectory(user_tty) add_subdirectory(init) +add_subdirectory(gui) set(APP_FILES ${APPS}) list(TRANSFORM APP_FILES PREPEND "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/") add_custom_target(copy_apps - DEPENDS ${APPS} COMMAND cp ${APP_FILES} ${CMAKE_BINARY_DIR}/sysroot USES_TERMINAL VERBATIM ) +add_dependencies(copy_apps ${APPS}) diff --git a/apps/gui/CMakeLists.txt b/apps/gui/CMakeLists.txt new file mode 100644 index 0000000..c320f48 --- /dev/null +++ b/apps/gui/CMakeLists.txt @@ -0,0 +1,7 @@ +project(gui) + +set(CMAKE_C_STANDARD 23) + +add_executable(gui main.c) + +target_link_libraries(gui PRIVATE common) diff --git a/apps/gui/main.c b/apps/gui/main.c new file mode 100644 index 0000000..b47d1eb --- /dev/null +++ b/apps/gui/main.c @@ -0,0 +1,5 @@ +#include "sys.h" + +int main() { + sys_dprint("hello\n", sizeof("hello\n") - 1); +} diff --git a/apps/init/init.c b/apps/init/init.c index 970e150..910932d 100644 --- a/apps/init/init.c +++ b/apps/init/init.c @@ -1,4 +1,6 @@ +#include "sys.h" int main() { - + Handle gui_handle; + int status = sys_create_process("posix_rootfs/gui", sizeof("posix_rootfs/gui") - 1, &gui_handle); } diff --git a/image.cmake b/image.cmake index c8d2a01..5c4ee9c 100644 --- a/image.cmake +++ b/image.cmake @@ -68,6 +68,8 @@ find_program(GUESTMOUNT guestmount) add_custom_command(OUTPUT initramfs.tar COMMAND tar -cf initramfs.tar -C ${PROJECT_BINARY_DIR}/sysroot/ . + DEPENDS copy_apps + USES_TERMINAL VERBATIM ) if(GUESTMOUNT) diff --git a/kernel/src/dev/fb.c b/kernel/src/dev/fb.c index 5a5208c..e6ad338 100644 --- a/kernel/src/dev/fb.c +++ b/kernel/src/dev/fb.c @@ -1,10 +1,11 @@ #include "fb.h" -#include "assert.h" -#include "sys/utils.h" -#include "mem/vm.h" #include "arch/cpu.h" -#include "mem/utils.h" +#include "assert.h" +#include "fbcon.h" #include "mem/page.h" +#include "mem/utils.h" +#include "mem/vm.h" +#include "sys/utils.h" int fbdev_devmsg(FbDev* self, DevMsgFb msg, __user void* data) { switch (msg) { @@ -42,6 +43,8 @@ int fbdev_devmsg(FbDev* self, DevMsgFb msg, __user void* data) { vm_user_dealloc(task->process, mem, ALIGNUP(size, PAGE_SIZE) / PAGE_SIZE, true); return ERR_FAULT; } + + default_fblog_deinit(); return 0; } default: diff --git a/kernel/src/dev/fbcon.c b/kernel/src/dev/fbcon.c index 5fda41e..e540b05 100644 --- a/kernel/src/dev/fbcon.c +++ b/kernel/src/dev/fbcon.c @@ -93,3 +93,7 @@ void fbcon_init(FbDev* fb, const void* font) { FBLOG.font = (const PsfFont*) font; log_register_sink(&FBLOG.common, false); } + +void default_fblog_deinit() { + log_unregister_sink(&FBLOG.common); +} diff --git a/kernel/src/dev/fbcon.h b/kernel/src/dev/fbcon.h index 17ee915..860665b 100644 --- a/kernel/src/dev/fbcon.h +++ b/kernel/src/dev/fbcon.h @@ -2,4 +2,5 @@ typedef struct FbDev FbDev; -void fbcon_init(FbDev* fb, const void* font); \ No newline at end of file +void fbcon_init(FbDev* fb, const void* font); +void default_fblog_deinit(); diff --git a/kernel/src/main.c b/kernel/src/main.c index ada6dab..05ca26a 100644 --- a/kernel/src/main.c +++ b/kernel/src/main.c @@ -135,7 +135,7 @@ static int stderr_vnode_write(VNode* self, const void* data, usize off, usize si assert(fd_table_insert(&init_process->fd_table, stderr_vnode) == 2); ACTIVE_INPUT_TASK = init_task; - ThreadHandle* h = kmalloc(sizeof(ThreadHandle)); + ThreadHandle* h = kcalloc(sizeof(ThreadHandle)); assert(h); h->refcount = 1; h->task = init_task; diff --git a/kernel/src/sys/syscalls.c b/kernel/src/sys/syscalls.c index a8e0c15..b07b016 100644 --- a/kernel/src/sys/syscalls.c +++ b/kernel/src/sys/syscalls.c @@ -313,7 +313,7 @@ int sys_create_process(__user const char* path, size_t path_len, __user Handle* } const char* process_name = buf + path_len - 1; - for (; process_name > buf && *process_name != '/'; --process_name); + for (; process_name > buf && process_name[-1] != '/'; --process_name); Task* thread = arch_create_user_task(process, process_name, NULL, NULL); kfree(buf, path_len + 1); @@ -336,14 +336,24 @@ int sys_create_process(__user const char* path, size_t path_len, __user Handle* void (*user_fn)(void*) = (void (*)(void*)) res.entry; arch_set_user_task_fn(thread, user_fn); - ProcessHandle* h = kmalloc(sizeof(ProcessHandle)); + ProcessHandle* h = kcalloc(sizeof(ProcessHandle)); if (!h) { arch_destroy_task(thread); return ERR_NO_MEM; } + + ThreadHandle* thread_h = kcalloc(sizeof(ThreadHandle)); + if (!thread_h) { + arch_destroy_task(thread); + kfree(h, sizeof(ProcessHandle)); + return ERR_NO_MEM; + } + thread_h->refcount = 1; + thread_h->task = thread; + thread_h->exited = false; + h->process = process; h->exited = false; - memset(&h->lock, 0, sizeof(Mutex)); Task* task = arch_get_cur_task(); Handle handle = handle_tab_insert(&task->process->handle_table, h, HANDLE_TYPE_PROCESS); @@ -355,6 +365,7 @@ int sys_create_process(__user const char* path, size_t path_len, __user Handle* } process_add_thread(process, thread); + thread->tid = handle_tab_insert(&process->handle_table, thread_h, HANDLE_TYPE_THREAD); Ipl old = arch_ipl_set(IPL_CRITICAL); sched_queue_task(thread); diff --git a/libs/common/CMakeLists.txt b/libs/common/CMakeLists.txt index 9f7ecdb..d478ccd 100644 --- a/libs/common/CMakeLists.txt +++ b/libs/common/CMakeLists.txt @@ -7,6 +7,6 @@ add_library(common STATIC sys.c ) -target_include_directories(common PUBLIC ${CMAKE_SOURCE_DIR}/kernel/include) +target_include_directories(common PUBLIC ${CMAKE_SOURCE_DIR}/kernel/include .) target_compile_options(common PUBLIC -fno-stack-protector -Wall -Wextra) target_link_options(common PUBLIC -nostdlib -Wl,--fatal-warnings)