Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ee3866
feat: added syscall responses
Zffu Aug 3, 2025
3773561
feat: added syscalls
Zffu Aug 3, 2025
97686f4
feat: added syscall func
Zffu Aug 3, 2025
64dee39
feat: added syscall impl
Zffu Aug 3, 2025
92f54aa
feat: added ioports::is_port_allowed
Zffu Aug 3, 2025
0fcc7ad
feat: added IOPORT_REQ interrupt
Zffu Aug 3, 2025
f588114
feat: added TASk_KILL syscall
Zffu Aug 3, 2025
2d0b9d3
feat: added TASK_SPAWN syscall
Zffu Aug 3, 2025
0ac4b7a
feat: added find_task and find_internal_task in taskio header
Zffu Aug 3, 2025
3f9e670
feat: added find_task & find_internal_task impl
Zffu Aug 3, 2025
c325e64
feat: removed find_internal_task and made find_task return a TASKIO_T…
Zffu Aug 3, 2025
38863e1
feat: added the TASKIO_FINDTASK & TASKIO_FINDINTERNALTASk macros to m…
Zffu Aug 3, 2025
fd92f73
feat: added the TASKIO_FINDTASK & TASKIO_FINDINTERNALTASk macros to m…
Zffu Aug 3, 2025
86e1570
feat: added taskio::task_kill_instant declaration
Zffu Aug 3, 2025
d0c7edf
feat: added task_kill_instant
Zffu Aug 3, 2025
014f54b
feat: added taskthis_kill_instant
Zffu Aug 3, 2025
f2d5a2f
feat: added taskio_task_common_t struct
Zffu Aug 3, 2025
75c56b1
feat: changed TASKIO_TASZK_LIKELY_POINTER to use the taskio_task_comm…
Zffu Aug 3, 2025
30a835b
feat: added TASKIO_KILLTASKBYNAME
Zffu Aug 3, 2025
cbed8bf
feat: removed task_kill_instant
Zffu Aug 3, 2025
bc74552
feat: made khandle_syscall return INVALID_SYSCALL by default
Zffu Aug 3, 2025
2191ac4
feat: added get_current_task macro getter
Zffu Aug 3, 2025
e2e57e2
feat: removed macro getter
Zffu Aug 3, 2025
d6aa9f7
feat: added authority field in tasks
Zffu Aug 3, 2025
1d3aa1b
feat: adde authorities
Zffu Aug 3, 2025
f6d5db2
feat: changed authorisation -> type
Zffu Aug 4, 2025
51b170e
chore: renamed syscall func to ksyscall and fixed some naming bugs
Zffu Aug 4, 2025
492b747
chore: removed imports
Zffu Aug 4, 2025
2ad25ea
feat: added permission checks for most syscalls
Zffu Aug 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"types.h": "c",
"pit.h": "c",
"stdlib.h": "c",
"taskio.h": "c"
"taskio.h": "c",
"syscall.h": "c",
"thread": "c"
}
}
91 changes: 91 additions & 0 deletions cstdlib/includes/klib/syscall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Defintions for the kernel system call usage in the Kernel related applications
*/

#pragma once


#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
*/
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,

UNDEFINED
} 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;

/**
* 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 ksyscall(syscall call, SYSCALL_ARGBUFF args);
22 changes: 22 additions & 0 deletions cstdlib/src/klib/syscall.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <klib/syscall.h>
#include <types.h>

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

#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;
}
2 changes: 1 addition & 1 deletion drivers/src/ps2kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <i8042.h>
#include <driver.h>

#include <taskio.h>
#include <taskio/taskio.h>

#include <str.h>

Expand Down
5 changes: 5 additions & 0 deletions kernel/includes/io/ioports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <types.h>

u8 port_is_allowed(u8 port);
5 changes: 5 additions & 0 deletions kernel/includes/syscall/syscall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <klib/syscall.h>

syscall_response khandle_syscall(syscall call, SYSCALL_ARGBUFF argbuff);
55 changes: 0 additions & 55 deletions kernel/includes/taskio.h

This file was deleted.

118 changes: 118 additions & 0 deletions kernel/includes/taskio/taskio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* TaskIO definitions
*/

#pragma once

#include <types.h>

#ifndef TASKIO_PERTASK_STACK_SIZE
#define TASKIO_PERTASK_STACK_SIZE 256
#endif

#define TASKIO_TASK_LIKELY_POINTER taskio_task_common_t*

#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;

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
* trough the CPU timer interrupt
*/
typedef struct taskio_task_t__bundled {
char* name;
task_type type;

struct taskio_task_t__bundled* prev;
struct taskio_task_t__bundled* next;

void *(*detatch)();

} internal_task_t;

/**
* Defines tasks that are ticked in the CPU timer interrupt
*/
typedef struct taskio_task_t {
char* name;
task_type type;

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;
} task_t;

/**
* Common structures between task_t and internal_task_t
*/
typedef struct taskio_task_common_t {
char* name;
task_type type;

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)();

/**
* @name create_task
*
* @param name the name of the task
* @param entry_point the entry point
*/
task_t* create_task(char* name, void (*entry_point)());

/**
* @name create_internal_task
*
* @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)());

/**
* @name find_task
*
* 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.
*/
TASKIO_TASK_LIKELY_POINTER find_task(char* name, TASKIO_TASK_LIKELY_POINTER tree);

/**
* @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 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;
6 changes: 6 additions & 0 deletions kernel/src/io/ioports.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <types.h>

u8 port_is_allowed(u8 port) {
if(port == 0x60 || port == 0x64) return 1;
return 0;
}
2 changes: 1 addition & 1 deletion kernel/src/shell/kshell.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <eventio.h>
#include <taskio.h>
#include <taskio/taskio.h>
#include <keyboard/keyboard.h>
#include <keyboard/layout.h>

Expand Down
Loading
Loading