From 5ee386627d1446db73ea1eb7b305a87c6d1eefea Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 19:39:50 +0200 Subject: [PATCH 01/29] feat: added syscall responses --- cstdlib/includes/klib/syscall.h | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cstdlib/includes/klib/syscall.h diff --git a/cstdlib/includes/klib/syscall.h b/cstdlib/includes/klib/syscall.h new file mode 100644 index 0000000..6b364e8 --- /dev/null +++ b/cstdlib/includes/klib/syscall.h @@ -0,0 +1,38 @@ +/** +* Defintions for the kernel system call usage in the Kernel related applications +*/ + +#pragma once + +/** + * The possible responses from a kernel syscall + */ +typedef enum syscall_response { + /** + * The syscall request was denied and wasn't executed. + */ + DENIED, + + /** + * The syscall request was denied and wasn't executed. + * The issuing process also will be killed as a result. + */ + DENIED_STRICT, +* + /** + * The given syscall is invalid / incomplete + */ + INVALID_SYSCALL, + + /** + * The syscall request was accepted but couldn't be executed properly. + */ + ACCEPT_ERR, + + /** + * The syscall request was accepted and was executed sucessfully. + */ */ + ACCEPTED +} syscall_response; + + From 377356157ea167936825e9743353d3c60411ce9c Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 19:47:37 +0200 Subject: [PATCH 02/29] feat: added syscalls --- cstdlib/includes/klib/syscall.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cstdlib/includes/klib/syscall.h b/cstdlib/includes/klib/syscall.h index 6b364e8..27e04b8 100644 --- a/cstdlib/includes/klib/syscall.h +++ b/cstdlib/includes/klib/syscall.h @@ -36,3 +36,36 @@ typedef enum syscall_response { } syscall_response; +/** + * The available system calls. +*/ +typedef enum syscall { + + /** + * Prints a message + */ + PRINT, + + /** + * Asks for either read or write rights on a specific IO port, + * The issuer task has to be considered as a driver task for the request to be considered. + */ + IOPORT_REQ, + + /** + * Requests to apply the driver status to the issuer process. This request will always fail if said task isn't + * internally spun by the kernel. + */ + DRIVERTASK_REQ, + + /** + * Kills a specified task. This request will fail if the permissions of the issuer aren't high enough (if a program tries closing another program and isn't privilleged). + */ + TASK_KILL, + + /** + * Spawns / creates a process. The request will fail if the issuer tries spawning a task that is either internal or requires higher permissions than what the issuer has. + */ + TASK_SPAWN + +} syscall; \ No newline at end of file From 97686f418b61d8cc59d27c3c80edd5eed7ca26bb Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:08:33 +0200 Subject: [PATCH 03/29] feat: added syscall func --- cstdlib/includes/klib/syscall.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cstdlib/includes/klib/syscall.h b/cstdlib/includes/klib/syscall.h index 27e04b8..f0ba68c 100644 --- a/cstdlib/includes/klib/syscall.h +++ b/cstdlib/includes/klib/syscall.h @@ -4,6 +4,10 @@ #pragma once + +#define SYSCALL_ARGBUFF void* +#define SYSCALL_NOARGS ((void*)0) + /** * The possible responses from a kernel syscall */ @@ -68,4 +72,12 @@ typedef enum syscall { */ TASK_SPAWN -} syscall; \ No newline at end of file +} syscall; + +/** + * Requests a syscall to the kernel. + * @param call the systemcall to request + * @param args the syscall arguments, should be SYSCALL_NOARGS if no arguments + * @return a response to your syscall.s +*/ +syscall_response syscall(syscall call, SYSCALL_ARGBUFF args); \ No newline at end of file From 64dee39207c9bf5eb95354240a00accdf9c6d08a Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:23:25 +0200 Subject: [PATCH 04/29] feat: added syscall impl --- cstdlib/includes/klib/syscall.h | 10 +++++++++- cstdlib/src/klib/syscall.c | 22 ++++++++++++++++++++++ kernel/includes/syscall/syscall.h | 2 ++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 cstdlib/src/klib/syscall.c create mode 100644 kernel/includes/syscall/syscall.h diff --git a/cstdlib/includes/klib/syscall.h b/cstdlib/includes/klib/syscall.h index f0ba68c..57b8854 100644 --- a/cstdlib/includes/klib/syscall.h +++ b/cstdlib/includes/klib/syscall.h @@ -8,6 +8,12 @@ #define SYSCALL_ARGBUFF void* #define SYSCALL_NOARGS ((void*)0) +#ifndef SYSCALL_MODERN_INSTRUCTION +#define SYSCALL_INTERRUPT 0x80 +#endif + +#define SYSCALL_RESPONSE_SZ ACCEPTED + /** * The possible responses from a kernel syscall */ @@ -36,7 +42,9 @@ typedef enum syscall_response { /** * The syscall request was accepted and was executed sucessfully. */ */ - ACCEPTED + ACCEPTED, + + UNDEFINED } syscall_response; diff --git a/cstdlib/src/klib/syscall.c b/cstdlib/src/klib/syscall.c new file mode 100644 index 0000000..1f2690a --- /dev/null +++ b/cstdlib/src/klib/syscall.c @@ -0,0 +1,22 @@ +#include +#include + +syscall_response syscall(syscall call, SYSCALL_ARGBUFF args) { + __asm__("mov %%al, al" : : "a" ((u8) call)); + __asm__("mov %%eax, ebx" : : "a" (args)); // MUST BE A POINTER + +#ifdef SYSCALL_MODERN_INSTRUCTION + __asm__("syscall"); +#else + __asm__("int 0x80"); +#endif + + u8 result; + __asm__("mov bl, %%al" : "=a" (result)); + + if(result < DENIED || result > SYSCALL_RESPONSE_SZ) { + return UNDEFINED; + } + + return (syscall_response) result; +} \ No newline at end of file diff --git a/kernel/includes/syscall/syscall.h b/kernel/includes/syscall/syscall.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/kernel/includes/syscall/syscall.h @@ -0,0 +1,2 @@ +#pragma once + From 92f54aa2a27189a78e0945c7ac09ff8a8b7bcb73 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:29:03 +0200 Subject: [PATCH 05/29] feat: added ioports::is_port_allowed --- kernel/includes/io/ioports.h | 5 +++++ kernel/includes/syscall/syscall.h | 3 +++ kernel/src/io/ioports.c | 6 ++++++ kernel/src/syscall/syscall.c | 11 +++++++++++ 4 files changed, 25 insertions(+) create mode 100644 kernel/includes/io/ioports.h create mode 100644 kernel/src/io/ioports.c create mode 100644 kernel/src/syscall/syscall.c diff --git a/kernel/includes/io/ioports.h b/kernel/includes/io/ioports.h new file mode 100644 index 0000000..23221b6 --- /dev/null +++ b/kernel/includes/io/ioports.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +u8 port_is_allowed(u8 port); \ No newline at end of file diff --git a/kernel/includes/syscall/syscall.h b/kernel/includes/syscall/syscall.h index 3f59c93..ecf474f 100644 --- a/kernel/includes/syscall/syscall.h +++ b/kernel/includes/syscall/syscall.h @@ -1,2 +1,5 @@ #pragma once +#include + +syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff); \ No newline at end of file diff --git a/kernel/src/io/ioports.c b/kernel/src/io/ioports.c new file mode 100644 index 0000000..e2155c8 --- /dev/null +++ b/kernel/src/io/ioports.c @@ -0,0 +1,6 @@ +#include + +u8 port_is_allowed(u8 port) { + if(port == 0x60 || port == 0x64) return 1; + return 0; +} \ No newline at end of file diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c new file mode 100644 index 0000000..e67a08b --- /dev/null +++ b/kernel/src/syscall/syscall.c @@ -0,0 +1,11 @@ +#include +#include + +syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { + switch(call) { + case PRINT: + return DENIED_STRICT; + case IOPORT_REQ: + + } +} \ No newline at end of file From 0fcc7ad53dfa3fbe09e6d9d5b10beefb513a468f Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:32:38 +0200 Subject: [PATCH 06/29] feat: added IOPORT_REQ interrupt --- kernel/src/syscall/syscall.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c index e67a08b..04ef31f 100644 --- a/kernel/src/syscall/syscall.c +++ b/kernel/src/syscall/syscall.c @@ -1,11 +1,31 @@ #include #include +#include + +#include syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { switch(call) { case PRINT: return DENIED_STRICT; + case IOPORT_REQ: + if(argbuff == SYSCALL_NOARGS) return INVALID_SYSCALL; + u8* ptr = (u8*) argbuff; + + u8 port = *ptr; + u8 mode = *(ptr + 1); + + if(port < 0) return INVALID_SYSCALL; + if(mode < 0 || mode > 1) return INVALID_SYSCALL; + + if(!port_is_allowed(port)) return DENIED; + + // TODO: check for driver permissions + break; + + + } } \ No newline at end of file From f5881147b10064d44a5febcc068e491f73c2bb49 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:38:55 +0200 Subject: [PATCH 07/29] feat: added TASk_KILL syscall --- kernel/src/syscall/syscall.c | 46 +++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c index 04ef31f..fa84e89 100644 --- a/kernel/src/syscall/syscall.c +++ b/kernel/src/syscall/syscall.c @@ -2,8 +2,15 @@ #include #include +#include + +#include + #include +extern internal_task_t* taskio_internaltask_queue; +extern task_t* taskio_task_queue; + syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { switch(call) { case PRINT: @@ -24,8 +31,45 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { // TODO: check for driver permissions break; - + case TASK_KILL: + if(argbuff == SYSCALL_NOARGS) return INVALID_SYSCALL; + u8* ptr = (u8*) argbuff; + + u8 task_type = *ptr; + char* task_name = (char*) (ptr + 1); + + if(task_type < 0 || task_type > 1) return INVALID_SYSCALL; + if(task_name == 0) return INVALID_SYSCALL; + // Internal + if(task_type == 0x01) { + internal_task_t* node = taskio_internaltask_queue; + + while(node != 0) { + if(strcmp(task_name, node->name)) { + node->detach(); + + return ACCEPTED; + } + + node = node->next; + } + + return ACCEPT_ERR; + } + task_t* node = taskio_task_queue; + + while(node != 0) { + if(strcmp(task_name, node)) { + // TODO: remove node + + return ACCEPTED; + } + + node = node->next; + } + + return ACCEPT_ERR; } } \ No newline at end of file From 2d0b9d36015b649b7595757e5bfc8b225cb63a54 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:47:16 +0200 Subject: [PATCH 08/29] feat: added TASK_SPAWN syscall --- kernel/includes/taskio.h | 3 +++ kernel/src/syscall/syscall.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/kernel/includes/taskio.h b/kernel/includes/taskio.h index 181fcdc..8a41716 100644 --- a/kernel/includes/taskio.h +++ b/kernel/includes/taskio.h @@ -38,6 +38,9 @@ typedef struct taskio_task_t { struct taskio_task_t* next; } task_t; +typedef void (*entry_point_t)(); +typedef void (*detach_point_t)(); + /** * @name create_task * diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c index fa84e89..771d0a1 100644 --- a/kernel/src/syscall/syscall.c +++ b/kernel/src/syscall/syscall.c @@ -71,5 +71,32 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { } return ACCEPT_ERR; + + case TASK_SPAWN: + if(argbuff == SYSCALL_NOARGS) return INVALID_SYSCALL; + u8* ptr = (u8*) argbuff; + + u8 mode = *(ptr); + u8* point = *((u8**)(ptr + 1)); + char* name = *((char**)(ptr + sizeof(u8*) + 1)); + + if(mode < 0 || mode > 1) return INVALID_SYSCALL; + if(point == 0 || name == 0) return INVALID_SYSCALL; + + // TODO: make internal tasks require additional permissions + + if(mode == 0x00) { + task_t* task = create_task(name, (entry_point_t)(point)); + + if(task == 0) return ACCEPT_ERR; + return ACCEPT; + } + + internal_task_t* task = create_internal_task(name, (detach_point_t)(point)); + + if(task == 0) return ACCEPT_ERR; + return ACCEPT; + + } } \ No newline at end of file From 0ac4b7a001feaab515fa5d623f6ba912e537e6d6 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:49:37 +0200 Subject: [PATCH 09/29] feat: added find_task and find_internal_task in taskio header --- kernel/includes/taskio.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kernel/includes/taskio.h b/kernel/includes/taskio.h index 8a41716..e8f3b5e 100644 --- a/kernel/includes/taskio.h +++ b/kernel/includes/taskio.h @@ -55,4 +55,22 @@ task_t* create_task(char* name, void (*entry_point)()); * @param name the name of the internal task * @param detach the function allowing to detach/kill the internal tasks */ -internal_task_t* create_internal_task(char* name, void (*detach)()); \ No newline at end of file +internal_task_t* create_internal_task(char* name, void (*detach)()); + +/** + * @name find_task + * + * Finds a task based on the name of it + * + * @param name the name of the task +*/ +task_t* find_task(char* name); + +/** + * @name find_internal_task + * + * Finds an internal task based on the name of it + * + * @param name the name of the internal task +*/ +internal_task_t* find_internal_task(char* name); \ No newline at end of file From 3f9e670a9de148a682b701512068d6c6dcf0a6a7 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:52:20 +0200 Subject: [PATCH 10/29] feat: added find_task & find_internal_task impl --- kernel/includes/taskio.h | 2 ++ kernel/src/taskio.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/kernel/includes/taskio.h b/kernel/includes/taskio.h index e8f3b5e..8f37611 100644 --- a/kernel/includes/taskio.h +++ b/kernel/includes/taskio.h @@ -10,6 +10,8 @@ #define TASKIO_PERTASK_STACK_SIZE 256 #endif +#define TASKIO_TASK_LIKELY_POINTER u8* + /** * Defines tasks that are fully 'internal', AKA tasks that do NOT need to be ticked * trough the CPU timer interrupt diff --git a/kernel/src/taskio.c b/kernel/src/taskio.c index 30c29b5..8de2b28 100644 --- a/kernel/src/taskio.c +++ b/kernel/src/taskio.c @@ -49,4 +49,30 @@ internal_task_t* create_internal_task(char* name, void (*detach)()) { task->next = taskio_internaltask_queue; taskio_internaltask_queue = task; } +} + +task_t* find_task(char* name) { + task_t* n = taskio_task_queue; + + while(n != 0) { + if(strcmp(n->name, name)) { + return n; + } + n = n->next; + } + + return 0; +} + +internal_task_t* find_internal_task(char* name) { + internal_task_t* n = taskio_internaltask_queue; + + while(n != 0) { + if(strcmp(n->name, name)) { + return n; + } + n = n->next; + } + + return 0; } \ No newline at end of file From c325e6493e47a973c208d009e53398d5d369d58a Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:54:54 +0200 Subject: [PATCH 11/29] feat: removed find_internal_task and made find_task return a TASKIO_TASK_LIKELY_POINTER and require a tree pointer as well --- kernel/includes/taskio.h | 14 +++----------- kernel/src/taskio.c | 19 +++---------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/kernel/includes/taskio.h b/kernel/includes/taskio.h index 8f37611..a36c554 100644 --- a/kernel/includes/taskio.h +++ b/kernel/includes/taskio.h @@ -62,17 +62,9 @@ internal_task_t* create_internal_task(char* name, void (*detach)()); /** * @name find_task * - * Finds a task based on the name of it + * Finds a task based on the name of it. It is recomended to use the FINDTASK macros instead. * * @param name the name of the task + * @param tree the tree pointer of the tasks. */ -task_t* find_task(char* name); - -/** - * @name find_internal_task - * - * Finds an internal task based on the name of it - * - * @param name the name of the internal task -*/ -internal_task_t* find_internal_task(char* name); \ No newline at end of file +TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree); \ No newline at end of file diff --git a/kernel/src/taskio.c b/kernel/src/taskio.c index 8de2b28..a2f6df0 100644 --- a/kernel/src/taskio.c +++ b/kernel/src/taskio.c @@ -51,25 +51,12 @@ internal_task_t* create_internal_task(char* name, void (*detach)()) { } } -task_t* find_task(char* name) { - task_t* n = taskio_task_queue; +TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree); { + task_t* n = tree; while(n != 0) { if(strcmp(n->name, name)) { - return n; - } - n = n->next; - } - - return 0; -} - -internal_task_t* find_internal_task(char* name) { - internal_task_t* n = taskio_internaltask_queue; - - while(n != 0) { - if(strcmp(n->name, name)) { - return n; + return (TASKIO_TASK_LIKELY_POINTER)n; } n = n->next; } From 38863e15412137b915ba475d3d2b004c5b379dd8 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:56:39 +0200 Subject: [PATCH 12/29] feat: added the TASKIO_FINDTASK & TASKIO_FINDINTERNALTASk macros to make it easier --- kernel/includes/taskio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/includes/taskio.h b/kernel/includes/taskio.h index a36c554..f7d88fc 100644 --- a/kernel/includes/taskio.h +++ b/kernel/includes/taskio.h @@ -12,6 +12,12 @@ #define TASKIO_TASK_LIKELY_POINTER u8* +extern task_t* taskio_task_queue; +extern internal_task_t* taskio_internaltask_queue; + +#define TASKIO_FINDTASK(name) find_task(name, taskio_task_queue) +#define TASKIO_FINDINTERNAL(name) find_task(name, taskio_internaltask_queue) + /** * Defines tasks that are fully 'internal', AKA tasks that do NOT need to be ticked * trough the CPU timer interrupt From fd92f73544ce9124a4f7a99f87d640afca7776a0 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 20:56:41 +0200 Subject: [PATCH 13/29] feat: added the TASKIO_FINDTASK & TASKIO_FINDINTERNALTASk macros to make it easier --- kernel/includes/taskio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/includes/taskio.h b/kernel/includes/taskio.h index f7d88fc..982ef56 100644 --- a/kernel/includes/taskio.h +++ b/kernel/includes/taskio.h @@ -16,7 +16,7 @@ extern task_t* taskio_task_queue; extern internal_task_t* taskio_internaltask_queue; #define TASKIO_FINDTASK(name) find_task(name, taskio_task_queue) -#define TASKIO_FINDINTERNAL(name) find_task(name, taskio_internaltask_queue) +#define TASKIO_FINDINTERNALTASK(name) find_task(name, taskio_internaltask_queue) /** * Defines tasks that are fully 'internal', AKA tasks that do NOT need to be ticked From 86e1570d79d9c9f3feb500157b72413d89a3ce96 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:01:46 +0200 Subject: [PATCH 14/29] feat: added taskio::task_kill_instant declaration --- kernel/includes/taskio.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/includes/taskio.h b/kernel/includes/taskio.h index 982ef56..361e509 100644 --- a/kernel/includes/taskio.h +++ b/kernel/includes/taskio.h @@ -73,4 +73,16 @@ internal_task_t* create_internal_task(char* name, void (*detach)()); * @param name the name of the task * @param tree the tree pointer of the tasks. */ -TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree); \ No newline at end of file +TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree); + +/** + * @name task_kill_instant + * + * Kills the task if it exists, skips every permission / authority check when killing the task, doesn't wait for the app to be ready. + * + * @param name the name of the task + * @param tree the tree pointer of the tasks. + * @param mode the mode, 0x00 if normal task, 0x01 if internal + * @return 0x00 if the task couldn't be killed, 0x01 if it was + */ +u8 task_kill_instant(char* name, TASKIO_TASK_LIKELY_POINTER tree, u8 mode); From d0c7edf881a32d02380086c8b0a7e9a8e63b1925 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:05:04 +0200 Subject: [PATCH 15/29] feat: added task_kill_instant --- kernel/src/taskio.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/kernel/src/taskio.c b/kernel/src/taskio.c index a2f6df0..f7c140e 100644 --- a/kernel/src/taskio.c +++ b/kernel/src/taskio.c @@ -52,7 +52,7 @@ internal_task_t* create_internal_task(char* name, void (*detach)()) { } TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree); { - task_t* n = tree; + TASKIO_TASK_LIKELY_POINTER n = tree; while(n != 0) { if(strcmp(n->name, name)) { @@ -62,4 +62,24 @@ TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree } return 0; +} + +u8 task_kill_instant(char* name, TASKIO_TASK_LIKELY_POINTER tree, u8 mode) { + TASKIO_TASK_LIKELY_POINTER n = tree; + + while(n != 0) { + if(strcmp(n->name, name)) { + if(mode = 0x01) ((internal_task_t*)n)->detach(); + + if(n->prev != 0) n->prev->next = n->next; + if(n->next != 0) n->next->prev = n->prev; + + // FREE n + return 0x01; + } + + n = n->next; + } + + return 0x00; } \ No newline at end of file From 014f54b1f0a4456e3f499acc10fc175dc21b6b46 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:18:01 +0200 Subject: [PATCH 16/29] feat: added taskthis_kill_instant --- drivers/src/ps2kbd.c | 2 +- kernel/includes/{ => taskio}/taskio.h | 11 +++++++++ kernel/src/shell/kshell.c | 2 +- kernel/src/syscall/syscall.c | 34 ++++----------------------- kernel/src/{ => taskio}/taskio.c | 15 ++++++++++-- 5 files changed, 30 insertions(+), 34 deletions(-) rename kernel/includes/{ => taskio}/taskio.h (84%) rename kernel/src/{ => taskio}/taskio.c (85%) diff --git a/drivers/src/ps2kbd.c b/drivers/src/ps2kbd.c index 3a8ab7e..cfdaac9 100644 --- a/drivers/src/ps2kbd.c +++ b/drivers/src/ps2kbd.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include diff --git a/kernel/includes/taskio.h b/kernel/includes/taskio/taskio.h similarity index 84% rename from kernel/includes/taskio.h rename to kernel/includes/taskio/taskio.h index 361e509..992d18d 100644 --- a/kernel/includes/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -86,3 +86,14 @@ TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree * @return 0x00 if the task couldn't be killed, 0x01 if it was */ u8 task_kill_instant(char* name, TASKIO_TASK_LIKELY_POINTER tree, u8 mode); + +/** + * @name taskthis_kill_instant + * + * Kills the task, skips every permission / authority check when killing the task, doesn't wait for the app to be ready. + * + * @param task the pointer of the task + * @param mode the mode, 0x00 if normal task, 0x01 if internal + * @return 0x00 if the task couldn't be killed, 0x01 if it was + */ +u8 taskthis_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode); diff --git a/kernel/src/shell/kshell.c b/kernel/src/shell/kshell.c index 9d044ed..82e2665 100644 --- a/kernel/src/shell/kshell.c +++ b/kernel/src/shell/kshell.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c index 771d0a1..5e72d09 100644 --- a/kernel/src/syscall/syscall.c +++ b/kernel/src/syscall/syscall.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include @@ -41,36 +41,10 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { if(task_type < 0 || task_type > 1) return INVALID_SYSCALL; if(task_name == 0) return INVALID_SYSCALL; - // Internal - if(task_type == 0x01) { - internal_task_t* node = taskio_internaltask_queue; + //TODO: check permissions of task before using priviledged function - while(node != 0) { - if(strcmp(task_name, node->name)) { - node->detach(); - - return ACCEPTED; - } - - node = node->next; - } - - return ACCEPT_ERR; - } - - task_t* node = taskio_task_queue; - - while(node != 0) { - if(strcmp(task_name, node)) { - // TODO: remove node - - return ACCEPTED; - } - - node = node->next; - } - - return ACCEPT_ERR; + if(task_kill_instant(task_name, task_type) == 0) return ACCEPT_ERR; + return ACCEPT; case TASK_SPAWN: if(argbuff == SYSCALL_NOARGS) return INVALID_SYSCALL; diff --git a/kernel/src/taskio.c b/kernel/src/taskio/taskio.c similarity index 85% rename from kernel/src/taskio.c rename to kernel/src/taskio/taskio.c index f7c140e..3955dae 100644 --- a/kernel/src/taskio.c +++ b/kernel/src/taskio/taskio.c @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -82,4 +82,15 @@ u8 task_kill_instant(char* name, TASKIO_TASK_LIKELY_POINTER tree, u8 mode) { } return 0x00; -} \ No newline at end of file +} + +u8 taskthis_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode) { + if(task == 0) return 0x00; + + if(mode == 0x01) ((internal_task_t*)task)->detach(); + + if(task->prev != 0) task->prev->next = task->next; + if(task->next != 0) task->next->prev = task->prev; + + return 0x01; +} From f2d5a2f2e4e551c2846f5c7e7f02c184bff14ccd Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:20:03 +0200 Subject: [PATCH 17/29] feat: added taskio_task_common_t struct --- kernel/includes/taskio/taskio.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index 992d18d..b083fb3 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -35,17 +35,28 @@ typedef struct taskio_task_t__bundled { */ typedef struct taskio_task_t { char* name; + + struct taskio_task_t* prev; + struct taskio_task_t* next; + u32* stack; u32 esp, ebp, eip; u32 eax, ebx, ecx, edx; u32 esi, edi; u32 eflags; - - struct taskio_task_t* prev; - struct taskio_task_t* next; } task_t; +/** + * Common structures between task_t and internal_task_t +*/ +typedef struct taskio_task_common_t { + char* name; + + struct taskio_task_common_t* prev; + struct taskio_task_common_t* next; +} taskio_task_common_t; + typedef void (*entry_point_t)(); typedef void (*detach_point_t)(); From 75c56b1e2fde492100451e42d7a14ceb32464c44 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:20:43 +0200 Subject: [PATCH 18/29] feat: changed TASKIO_TASZK_LIKELY_POINTER to use the taskio_task_common_t struct --- kernel/includes/taskio/taskio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index b083fb3..43d89a3 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -10,7 +10,7 @@ #define TASKIO_PERTASK_STACK_SIZE 256 #endif -#define TASKIO_TASK_LIKELY_POINTER u8* +#define TASKIO_TASK_LIKELY_POINTER taskio_task_common_t* extern task_t* taskio_task_queue; extern internal_task_t* taskio_internaltask_queue; From 30a835bdda423f561f193e9207be40567921ef68 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:25:33 +0200 Subject: [PATCH 19/29] feat: added TASKIO_KILLTASKBYNAME --- kernel/includes/taskio/taskio.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index 43d89a3..cbfc65e 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -18,6 +18,14 @@ extern internal_task_t* taskio_internaltask_queue; #define TASKIO_FINDTASK(name) find_task(name, taskio_task_queue) #define TASKIO_FINDINTERNALTASK(name) find_task(name, taskio_internaltask_queue) +#define TASKIO_FINDTASK_0(name) TASKIO_FINDTASK(name) +#define TASKIO_FINDTASK_1(name) TASKIO_FINDINTERNALTASK(name) + +#define TASKIO_KILLTASKBYNAME(name, result, type) \ + TASKIO_TASK_LIKELY_POINTER task = TASKIO_FINDTASK_##type(name); \ + result = (task != 0) ? taskthis_kill_instant(result, type) : 0x00; + + /** * Defines tasks that are fully 'internal', AKA tasks that do NOT need to be ticked * trough the CPU timer interrupt From cbed8bf36cd282c71ada1adb26b5d5adeb525876 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:26:09 +0200 Subject: [PATCH 20/29] feat: removed task_kill_instant --- kernel/includes/taskio/taskio.h | 14 +------------- kernel/src/taskio/taskio.c | 22 +--------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index cbfc65e..58a0efa 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -94,18 +94,6 @@ internal_task_t* create_internal_task(char* name, void (*detach)()); */ TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree); -/** - * @name task_kill_instant - * - * Kills the task if it exists, skips every permission / authority check when killing the task, doesn't wait for the app to be ready. - * - * @param name the name of the task - * @param tree the tree pointer of the tasks. - * @param mode the mode, 0x00 if normal task, 0x01 if internal - * @return 0x00 if the task couldn't be killed, 0x01 if it was - */ -u8 task_kill_instant(char* name, TASKIO_TASK_LIKELY_POINTER tree, u8 mode); - /** * @name taskthis_kill_instant * @@ -115,4 +103,4 @@ u8 task_kill_instant(char* name, TASKIO_TASK_LIKELY_POINTER tree, u8 mode); * @param mode the mode, 0x00 if normal task, 0x01 if internal * @return 0x00 if the task couldn't be killed, 0x01 if it was */ -u8 taskthis_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode); +u8 task_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode); diff --git a/kernel/src/taskio/taskio.c b/kernel/src/taskio/taskio.c index 3955dae..7e12d0f 100644 --- a/kernel/src/taskio/taskio.c +++ b/kernel/src/taskio/taskio.c @@ -64,27 +64,7 @@ TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree return 0; } -u8 task_kill_instant(char* name, TASKIO_TASK_LIKELY_POINTER tree, u8 mode) { - TASKIO_TASK_LIKELY_POINTER n = tree; - - while(n != 0) { - if(strcmp(n->name, name)) { - if(mode = 0x01) ((internal_task_t*)n)->detach(); - - if(n->prev != 0) n->prev->next = n->next; - if(n->next != 0) n->next->prev = n->prev; - - // FREE n - return 0x01; - } - - n = n->next; - } - - return 0x00; -} - -u8 taskthis_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode) { +u8 task_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode) { if(task == 0) return 0x00; if(mode == 0x01) ((internal_task_t*)task)->detach(); From bc7455296e40fb52fe0d4d9be0d22ebd7eff2a4a Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:27:39 +0200 Subject: [PATCH 21/29] feat: made khandle_syscall return INVALID_SYSCALL by default --- kernel/src/syscall/syscall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c index 5e72d09..99510cb 100644 --- a/kernel/src/syscall/syscall.c +++ b/kernel/src/syscall/syscall.c @@ -70,7 +70,8 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { if(task == 0) return ACCEPT_ERR; return ACCEPT; - + default: + return INVALID_SYSCALL; } } \ No newline at end of file From 2191ac44b65128c20a3dec66f33675bf3b48c16f Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:30:03 +0200 Subject: [PATCH 22/29] feat: added get_current_task macro getter --- kernel/includes/taskio/taskio.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index 58a0efa..f0f40d8 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -24,7 +24,6 @@ extern internal_task_t* taskio_internaltask_queue; #define TASKIO_KILLTASKBYNAME(name, result, type) \ TASKIO_TASK_LIKELY_POINTER task = TASKIO_FINDTASK_##type(name); \ result = (task != 0) ? taskthis_kill_instant(result, type) : 0x00; - /** * Defines tasks that are fully 'internal', AKA tasks that do NOT need to be ticked @@ -104,3 +103,9 @@ TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree * @return 0x00 if the task couldn't be killed, 0x01 if it was */ u8 task_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode); + +/** + * @name get_current_task + * @return the current running task +*/ +#define get_current_task() taskio_task_queue; \ No newline at end of file From e2e57e2d71adccb8475bcedb87cdf610bb47dec9 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:30:47 +0200 Subject: [PATCH 23/29] feat: removed macro getter --- kernel/includes/taskio/taskio.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index f0f40d8..fe4992a 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -14,6 +14,7 @@ extern task_t* taskio_task_queue; extern internal_task_t* taskio_internaltask_queue; +extern task_t* current_task; #define TASKIO_FINDTASK(name) find_task(name, taskio_task_queue) #define TASKIO_FINDINTERNALTASK(name) find_task(name, taskio_internaltask_queue) @@ -103,9 +104,3 @@ TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree * @return 0x00 if the task couldn't be killed, 0x01 if it was */ u8 task_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode); - -/** - * @name get_current_task - * @return the current running task -*/ -#define get_current_task() taskio_task_queue; \ No newline at end of file From d6aa9f7a9ea7c0d5d0a00cb07ed6d2251e0ec830 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:33:06 +0200 Subject: [PATCH 24/29] feat: added authority field in tasks --- kernel/includes/taskio/taskio.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index fe4992a..f0422af 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -26,16 +26,21 @@ extern task_t* current_task; TASKIO_TASK_LIKELY_POINTER task = TASKIO_FINDTASK_##type(name); \ result = (task != 0) ? taskthis_kill_instant(result, type) : 0x00; +typedef u8 taskio_task_authority + /** * Defines tasks that are fully 'internal', AKA tasks that do NOT need to be ticked * trough the CPU timer interrupt */ typedef struct taskio_task_t__bundled { char* name; - void *(*detatch)(); + taskio_task_authority authority; struct taskio_task_t__bundled* prev; struct taskio_task_t__bundled* next; + + void *(*detatch)(); + } internal_task_t; /** @@ -43,6 +48,7 @@ typedef struct taskio_task_t__bundled { */ typedef struct taskio_task_t { char* name; + taskio_task_authority authority; struct taskio_task_t* prev; struct taskio_task_t* next; @@ -60,6 +66,7 @@ typedef struct taskio_task_t { */ typedef struct taskio_task_common_t { char* name; + taskio_task_authority authority; struct taskio_task_common_t* prev; struct taskio_task_common_t* next; From 1d3aa1bbedb3188f18b443bb17d343f6a9e8b796 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Sun, 3 Aug 2025 21:34:36 +0200 Subject: [PATCH 25/29] feat: adde authorities --- kernel/includes/taskio/taskio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index f0422af..d379ebf 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -28,6 +28,12 @@ extern task_t* current_task; typedef u8 taskio_task_authority +#define TASK_AUTHORITY_NORMAL 0 +#define TASK_AUTHORITY_INTERNAL 1 +#define TASK_AUTHORITY_DRIVER 2 +#define TASK_AUTHORITY_KERNELSPIN 3 +#define TASK_AUTHORITY_KERNEL 4 + /** * Defines tasks that are fully 'internal', AKA tasks that do NOT need to be ticked * trough the CPU timer interrupt From f6d5db2e4b2d53dbd3d0d4baac4b808762ae6bdc Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:20:00 +0200 Subject: [PATCH 26/29] feat: changed authorisation -> type --- kernel/includes/taskio/taskio.h | 18 ++++++++---------- kernel/src/taskio/taskio.c | 4 ++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index d379ebf..7a3edd9 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -26,13 +26,11 @@ extern task_t* current_task; TASKIO_TASK_LIKELY_POINTER task = TASKIO_FINDTASK_##type(name); \ result = (task != 0) ? taskthis_kill_instant(result, type) : 0x00; -typedef u8 taskio_task_authority - -#define TASK_AUTHORITY_NORMAL 0 -#define TASK_AUTHORITY_INTERNAL 1 -#define TASK_AUTHORITY_DRIVER 2 -#define TASK_AUTHORITY_KERNELSPIN 3 -#define TASK_AUTHORITY_KERNEL 4 +typedef enum task_type { + NORMAL, + DRIVER, + KERNEL_INTEGRATED +} task_type; /** * Defines tasks that are fully 'internal', AKA tasks that do NOT need to be ticked @@ -40,7 +38,7 @@ typedef u8 taskio_task_authority */ typedef struct taskio_task_t__bundled { char* name; - taskio_task_authority authority; + task_type type; struct taskio_task_t__bundled* prev; struct taskio_task_t__bundled* next; @@ -54,7 +52,7 @@ typedef struct taskio_task_t__bundled { */ typedef struct taskio_task_t { char* name; - taskio_task_authority authority; + task_type type; struct taskio_task_t* prev; struct taskio_task_t* next; @@ -72,7 +70,7 @@ typedef struct taskio_task_t { */ typedef struct taskio_task_common_t { char* name; - taskio_task_authority authority; + task_type type; struct taskio_task_common_t* prev; struct taskio_task_common_t* next; diff --git a/kernel/src/taskio/taskio.c b/kernel/src/taskio/taskio.c index 7e12d0f..1dac5ab 100644 --- a/kernel/src/taskio/taskio.c +++ b/kernel/src/taskio/taskio.c @@ -9,6 +9,8 @@ task_t* create_task(char* name, void (*entry_point)()) { task_t* task = kmallocs(sizeof(task_t), 1); task->stack = kmallocs(TASKIO_PERTASK_STACK_SIZE, 1); + task->type = NORMAL; + u32 top = (u32) task->stack + TASKIO_PERTASK_STACK_SIZE; #ifdef TASKIO_EMPTY_STACK @@ -40,6 +42,8 @@ internal_task_t* create_internal_task(char* name, void (*detach)()) { task->next = taskio_internaltask_queue; task->detatch = detach; + task->type = KERNEL_INTEGRATED; + if(!taskio_internaltask_queue) { taskio_internaltask_queue = task; task->next = 0; From 51b170e0c97731b35df08787094e68fb8da9217f Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:35:46 +0200 Subject: [PATCH 27/29] chore: renamed syscall func to ksyscall and fixed some naming bugs --- .vscode/settings.json | 3 ++- cstdlib/includes/klib/syscall.h | 6 +++--- cstdlib/src/klib/syscall.c | 2 +- kernel/src/syscall/syscall.c | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 9ec63be..388aec7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "types.h": "c", "pit.h": "c", "stdlib.h": "c", - "taskio.h": "c" + "taskio.h": "c", + "syscall.h": "c" } } \ No newline at end of file diff --git a/cstdlib/includes/klib/syscall.h b/cstdlib/includes/klib/syscall.h index 57b8854..6824f6c 100644 --- a/cstdlib/includes/klib/syscall.h +++ b/cstdlib/includes/klib/syscall.h @@ -28,7 +28,7 @@ typedef enum syscall_response { * The issuing process also will be killed as a result. */ DENIED_STRICT, -* + /** * The given syscall is invalid / incomplete */ @@ -41,7 +41,7 @@ typedef enum syscall_response { /** * The syscall request was accepted and was executed sucessfully. - */ */ + */ ACCEPTED, UNDEFINED @@ -88,4 +88,4 @@ typedef enum syscall { * @param args the syscall arguments, should be SYSCALL_NOARGS if no arguments * @return a response to your syscall.s */ -syscall_response syscall(syscall call, SYSCALL_ARGBUFF args); \ No newline at end of file +syscall_response ksyscall(syscall call, SYSCALL_ARGBUFF args); \ No newline at end of file diff --git a/cstdlib/src/klib/syscall.c b/cstdlib/src/klib/syscall.c index 1f2690a..d39015c 100644 --- a/cstdlib/src/klib/syscall.c +++ b/cstdlib/src/klib/syscall.c @@ -1,7 +1,7 @@ #include #include -syscall_response syscall(syscall call, SYSCALL_ARGBUFF args) { +syscall_response ksyscall(syscall call, SYSCALL_ARGBUFF args) { __asm__("mov %%al, al" : : "a" ((u8) call)); __asm__("mov %%eax, ebx" : : "a" (args)); // MUST BE A POINTER diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c index 99510cb..adfe0c7 100644 --- a/kernel/src/syscall/syscall.c +++ b/kernel/src/syscall/syscall.c @@ -44,7 +44,7 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { //TODO: check permissions of task before using priviledged function if(task_kill_instant(task_name, task_type) == 0) return ACCEPT_ERR; - return ACCEPT; + return ACCEPTED; case TASK_SPAWN: if(argbuff == SYSCALL_NOARGS) return INVALID_SYSCALL; @@ -63,13 +63,13 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { task_t* task = create_task(name, (entry_point_t)(point)); if(task == 0) return ACCEPT_ERR; - return ACCEPT; + return ACCEPTED; } internal_task_t* task = create_internal_task(name, (detach_point_t)(point)); if(task == 0) return ACCEPT_ERR; - return ACCEPT; + return ACCEPTED; default: return INVALID_SYSCALL; From 492b747adce2398bb5481a4ca92fc5de8663bd3e Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:36:48 +0200 Subject: [PATCH 28/29] chore: removed imports --- kernel/src/syscall/syscall.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c index adfe0c7..34c9d06 100644 --- a/kernel/src/syscall/syscall.c +++ b/kernel/src/syscall/syscall.c @@ -4,13 +4,8 @@ #include -#include - #include -extern internal_task_t* taskio_internaltask_queue; -extern task_t* taskio_task_queue; - syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { switch(call) { case PRINT: @@ -28,7 +23,6 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { if(!port_is_allowed(port)) return DENIED; - // TODO: check for driver permissions break; case TASK_KILL: From 2ad25ea5ddf281697566caa453b936246a524368 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:42:36 +0200 Subject: [PATCH 29/29] feat: added permission checks for most syscalls --- .vscode/settings.json | 3 ++- kernel/includes/taskio/taskio.h | 9 +++++---- kernel/src/syscall/syscall.c | 16 +++++++++++++--- kernel/src/taskio/taskio.c | 4 ++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 388aec7..8b373fc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,6 +9,7 @@ "pit.h": "c", "stdlib.h": "c", "taskio.h": "c", - "syscall.h": "c" + "syscall.h": "c", + "thread": "c" } } \ No newline at end of file diff --git a/kernel/includes/taskio/taskio.h b/kernel/includes/taskio/taskio.h index 7a3edd9..3e55cbb 100644 --- a/kernel/includes/taskio/taskio.h +++ b/kernel/includes/taskio/taskio.h @@ -12,10 +12,6 @@ #define TASKIO_TASK_LIKELY_POINTER taskio_task_common_t* -extern task_t* taskio_task_queue; -extern internal_task_t* taskio_internaltask_queue; -extern task_t* current_task; - #define TASKIO_FINDTASK(name) find_task(name, taskio_task_queue) #define TASKIO_FINDINTERNALTASK(name) find_task(name, taskio_internaltask_queue) @@ -115,3 +111,8 @@ TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree * @return 0x00 if the task couldn't be killed, 0x01 if it was */ u8 task_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode); + + +extern task_t* taskio_task_queue; +extern internal_task_t* taskio_internaltask_queue; +extern task_t* current_task; \ No newline at end of file diff --git a/kernel/src/syscall/syscall.c b/kernel/src/syscall/syscall.c index 34c9d06..9961147 100644 --- a/kernel/src/syscall/syscall.c +++ b/kernel/src/syscall/syscall.c @@ -7,6 +7,11 @@ #include syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { + + if(current_task == 0) { + return DENIED; + } + switch(call) { case PRINT: return DENIED_STRICT; @@ -21,6 +26,11 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { if(port < 0) return INVALID_SYSCALL; if(mode < 0 || mode > 1) return INVALID_SYSCALL; + if(current_task->type < DRIVER) { + task_kill_instant(current_task, 0x00); + return DENIED_STRICT; + } + if(!port_is_allowed(port)) return DENIED; break; @@ -34,8 +44,8 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { if(task_type < 0 || task_type > 1) return INVALID_SYSCALL; if(task_name == 0) return INVALID_SYSCALL; - - //TODO: check permissions of task before using priviledged function + + //TODO: add a permission check here if(task_kill_instant(task_name, task_type) == 0) return ACCEPT_ERR; return ACCEPTED; @@ -51,7 +61,7 @@ syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff) { if(mode < 0 || mode > 1) return INVALID_SYSCALL; if(point == 0 || name == 0) return INVALID_SYSCALL; - // TODO: make internal tasks require additional permissions + if(current_task->type != KERNEL_INTEGRATED) return DENIED; if(mode == 0x00) { task_t* task = create_task(name, (entry_point_t)(point)); diff --git a/kernel/src/taskio/taskio.c b/kernel/src/taskio/taskio.c index 1dac5ab..7984650 100644 --- a/kernel/src/taskio/taskio.c +++ b/kernel/src/taskio/taskio.c @@ -55,7 +55,7 @@ internal_task_t* create_internal_task(char* name, void (*detach)()) { } } -TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree); { +TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree) { TASKIO_TASK_LIKELY_POINTER n = tree; while(n != 0) { @@ -71,7 +71,7 @@ TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree u8 task_kill_instant(TASKIO_TASK_LIKELY_POINTER task, u8 mode) { if(task == 0) return 0x00; - if(mode == 0x01) ((internal_task_t*)task)->detach(); + if(mode == 0x01) ((internal_task_t*)task)->detatch(); if(task->prev != 0) task->prev->next = task->next; if(task->next != 0) task->next->prev = task->prev;