diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-06-03 09:31:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-03 09:31:01 +0200 |
| commit | 6511afbf405c31513bc88ab06bca58218610a994 (patch) | |
| tree | e2509b7f9b59643b2a97773604aa383a2fd2e2f3 /dev/libSystem | |
| parent | 5c0bb7ee7b1b0fee02cc179fb21f4c57a61d6c2d (diff) | |
| parent | bebcbe04c2b47b3b4fcdc093b1736cc0295109fe (diff) | |
Merge pull request #36 from nekernel-org/dev
0.0.3 — NeKernel
Diffstat (limited to 'dev/libSystem')
| -rw-r--r-- | dev/libSystem/AsmProc.h | 15 | ||||
| -rw-r--r-- | dev/libSystem/SecurityPolicy.h | 12 | ||||
| -rw-r--r-- | dev/libSystem/SystemKit/Err.h (renamed from dev/libSystem/Codes.h) | 4 | ||||
| -rw-r--r-- | dev/libSystem/SystemKit/Jail.h | 22 | ||||
| -rw-r--r-- | dev/libSystem/SystemKit/Macros.h (renamed from dev/libSystem/Macros.h) | 14 | ||||
| -rw-r--r-- | dev/libSystem/SystemKit/Syscall.h | 19 | ||||
| -rw-r--r-- | dev/libSystem/SystemKit/System.h (renamed from dev/libSystem/System.h) | 16 | ||||
| -rw-r--r-- | dev/libSystem/src/Makefile (renamed from dev/libSystem/src/GNUmakefile) | 8 | ||||
| -rw-r--r-- | dev/libSystem/src/SystemImpl.cc (renamed from dev/libSystem/src/System.cc) | 34 | ||||
| -rw-r--r-- | dev/libSystem/src/SystemProc.asm (renamed from dev/libSystem/src/SystemCalls+IO.asm) | 29 |
10 files changed, 96 insertions, 77 deletions
diff --git a/dev/libSystem/AsmProc.h b/dev/libSystem/AsmProc.h deleted file mode 100644 index b707d533..00000000 --- a/dev/libSystem/AsmProc.h +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include <libSystem/System.h> -#include <cstdarg> - -IMPORT_C VoidPtr sci_syscall_arg_1(SizeT id); -IMPORT_C VoidPtr sci_syscall_arg_2(SizeT id, VoidPtr arg1); -IMPORT_C VoidPtr sci_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); -IMPORT_C VoidPtr sci_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); diff --git a/dev/libSystem/SecurityPolicy.h b/dev/libSystem/SecurityPolicy.h deleted file mode 100644 index 812f52e2..00000000 --- a/dev/libSystem/SecurityPolicy.h +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include <libSystem/System.h> - -/// @file SecurityPolicy.h -/// @brief Hardened Security Policy, used to restrict access to certain system calls.
\ No newline at end of file diff --git a/dev/libSystem/Codes.h b/dev/libSystem/SystemKit/Err.h index 0451df64..c0a2282b 100644 --- a/dev/libSystem/Codes.h +++ b/dev/libSystem/SystemKit/Err.h @@ -6,9 +6,9 @@ #pragma once -#include <libSystem/Macros.h> +#include <libSystem/SystemKit/Macros.h> -/// @file Codes.h +/// @file Err.h /// @brief Process Codes type and values. /// @author Amlal El Mahrouss (amlal@nekernel.org) diff --git a/dev/libSystem/SystemKit/Jail.h b/dev/libSystem/SystemKit/Jail.h new file mode 100644 index 00000000..998173f9 --- /dev/null +++ b/dev/libSystem/SystemKit/Jail.h @@ -0,0 +1,22 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <libSystem/SystemKit/System.h> + +/// @file Jail.h +/// @brief NeKernel Jail System + +struct JAIL_INFO; +struct JAIL; + +/// @brief Jail information (client side struct) +struct JAIL_INFO { + SInt32 fParentID; + SInt32 fJailHash; + SInt64 fACL; +};
\ No newline at end of file diff --git a/dev/libSystem/Macros.h b/dev/libSystem/SystemKit/Macros.h index 52dc904c..2bdeff9d 100644 --- a/dev/libSystem/Macros.h +++ b/dev/libSystem/SystemKit/Macros.h @@ -64,26 +64,24 @@ typedef char Char; typedef decltype(nullptr) nullPtr; typedef nullPtr NullPtr; -#define SCI_COPY_DELETE(KLASS) \ +#define LIBSYS_COPY_DELETE(KLASS) \ KLASS& operator=(const KLASS&) = delete; \ KLASS(const KLASS&) = delete; -#define SCI_COPY_DEFAULT(KLASS) \ +#define LIBSYS_COPY_DEFAULT(KLASS) \ KLASS& operator=(const KLASS&) = default; \ KLASS(const KLASS&) = default; -#define SCI_MOVE_DELETE(KLASS) \ +#define LIBSYS_MOVE_DELETE(KLASS) \ KLASS& operator=(KLASS&&) = delete; \ KLASS(KLASS&&) = delete; -#define SCI_MOVE_DEFAULT(KLASS) \ +#define LIBSYS_MOVE_DEFAULT(KLASS) \ KLASS& operator=(KLASS&&) = default; \ KLASS(KLASS&&) = default; #endif -IMPORT_C void _rtl_assert(Bool expr, const Char* origin); - #define MUST_PASS(X) _rtl_assert(X, __FILE__) #ifndef ARRAY_SIZE @@ -123,4 +121,6 @@ IMPORT_C void _rtl_assert(Bool expr, const Char* origin); #define tib_cast(X) ((UInt64) gib_cast(X) * 1024) #endif -#define SCI_UNUSED(X) ((void) X) +#define LIBSYS_UNUSED(X) ((void) X) + +IMPORT_C void _rtl_assert(Bool expr, const Char* origin); diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h new file mode 100644 index 00000000..436665ae --- /dev/null +++ b/dev/libSystem/SystemKit/Syscall.h @@ -0,0 +1,19 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <libSystem/SystemKit/System.h> +#include <cstdarg> + +#ifndef SYSCALL_HASH +#define SYSCALL_HASH(str) (UInt64) str +#endif // !SYSCALL_HASH + +IMPORT_C VoidPtr libsys_syscall_arg_1(SizeT id); +IMPORT_C VoidPtr libsys_syscall_arg_2(SizeT id, VoidPtr arg1); +IMPORT_C VoidPtr libsys_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); +IMPORT_C VoidPtr libsys_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); diff --git a/dev/libSystem/System.h b/dev/libSystem/SystemKit/System.h index 920ea2b2..91899efe 100644 --- a/dev/libSystem/System.h +++ b/dev/libSystem/SystemKit/System.h @@ -7,21 +7,21 @@ Purpose: System Call Interface. ------------------------------------------- */
-#ifndef SCI_SYSTEM_CALLS_H
-#define SCI_SYSTEM_CALLS_H
+#ifndef LIBSYS_SYSTEM_CALLS_H
+#define LIBSYS_SYSTEM_CALLS_H
-#include <libSystem/Macros.h>
+#include <libSystem/SystemKit/Macros.h>
// ------------------------------------------------------------------------------------------ //
/// @brief Types API.
// ------------------------------------------------------------------------------------------ //
-struct RefType {
- UInt32 __hash;
- VoidPtr __self;
+struct REF_TYPE {
+ UInt64 __hash; /// @brief Hash of the syscall
+ VoidPtr __self; /// @brief Syscall self value.
};
-typedef RefType* Ref;
+typedef REF_TYPE* Ref;
typedef Ref IORef;
typedef Ref FSRef;
@@ -382,4 +382,4 @@ IMPORT_C Char* StrFmt(const Char* fmt, ...); IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base);
-#endif // ifndef SCI_SYSTEM_CALLS_H
+#endif // ifndef LIBSYS_SYSTEM_CALLS_H
diff --git a/dev/libSystem/src/GNUmakefile b/dev/libSystem/src/Makefile index 9b901f9f..39af446b 100644 --- a/dev/libSystem/src/GNUmakefile +++ b/dev/libSystem/src/Makefile @@ -9,8 +9,8 @@ FLAGS=-f win64 .PHONY: error error: @echo "==> Invalid rule." - @echo "==> Use sci_asm_io_<arch> instead." + @echo "==> Use libsys_asm_io_<arch> instead." -.PHONY: sci_asm_io_x64 -sci_asm_io_x64: - $(ASM) $(FLAGS) SystemCalls+IO.asm -o SystemCalls+IO.stub.obj +.PHONY: libsys_asm_io_x64 +libsys_asm_io_x64: + $(ASM) $(FLAGS) SystemProc.asm -o SystemProc.stub.obj diff --git a/dev/libSystem/src/System.cc b/dev/libSystem/src/SystemImpl.cc index 1c28303d..d0682830 100644 --- a/dev/libSystem/src/System.cc +++ b/dev/libSystem/src/SystemImpl.cc @@ -4,11 +4,11 @@ ------------------------------------------- */
-#include <libSystem/AsmProc.h>
-#include <libSystem/System.h>
+#include <libSystem/SystemKit/Syscall.h>
+#include <libSystem/SystemKit/System.h>
-/// @file SystemCalls.cc
-/// @brief Source file for the memory functions/syscalls for libSystem.sys
+/// @file SystemAPI.cc
+/// @brief System wide API for NeKernel.
IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) {
if (!len || !dest || !src) {
@@ -46,30 +46,27 @@ IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt return dest;
}
-//-----------------------------------------------------------------------------------------------------------//
-/// @brief Systems Calls implementation.
-/// @internal
-//-----------------------------------------------------------------------------------------------------------//
-
IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) {
- return sci_syscall_arg_3(1, reinterpret_cast<VoidPtr>(const_cast<Char*>(path)),
- reinterpret_cast<VoidPtr>(const_cast<Char*>(drv_letter)));
+ return (Ref) libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'),
+ reinterpret_cast<VoidPtr>(const_cast<Char*>(path)),
+ reinterpret_cast<VoidPtr>(const_cast<Char*>(drv_letter)));
}
IMPORT_C Void IoCloseFile(_Input Ref desc) {
- sci_syscall_arg_2(2, desc);
+ libsys_syscall_arg_2(2, desc);
}
IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) {
- auto ret = (volatile UInt64*) sci_syscall_arg_3(3, reinterpret_cast<VoidPtr>(desc),
- reinterpret_cast<VoidPtr>(&off));
+ auto ret = (volatile UInt64*) libsys_syscall_arg_3(
+ SYSCALL_HASH('IoSeekFile'), reinterpret_cast<VoidPtr>(desc), reinterpret_cast<VoidPtr>(&off));
MUST_PASS((*ret) != ~0UL);
return *ret;
}
IMPORT_C UInt64 IoTellFile(_Input Ref desc) {
- auto ret = (volatile UInt64*) sci_syscall_arg_2(4, reinterpret_cast<VoidPtr>(desc));
+ auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'),
+ reinterpret_cast<VoidPtr>(desc));
return *ret;
}
@@ -78,8 +75,9 @@ IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { va_start(args, fmt);
- auto ret = (volatile UInt64*) sci_syscall_arg_4(
- 5, reinterpret_cast<VoidPtr>(desc), reinterpret_cast<VoidPtr>(const_cast<Char*>(fmt)), args);
+ auto ret = (volatile UInt64*) libsys_syscall_arg_4(
+ SYSCALL_HASH('PrintOut'), reinterpret_cast<VoidPtr>(desc),
+ reinterpret_cast<VoidPtr>(const_cast<Char*>(fmt)), args);
va_end(args);
@@ -90,5 +88,7 @@ IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { if (!expr) {
PrintOut(nullptr, "Assertion failed: %s\r", origin);
PrintOut(nullptr, "Origin: %s\r", origin);
+
+ libsys_syscall_arg_1(SYSCALL_HASH('_rtl_debug_break'));
}
}
diff --git a/dev/libSystem/src/SystemCalls+IO.asm b/dev/libSystem/src/SystemProc.asm index 097046af..299b59f9 100644 --- a/dev/libSystem/src/SystemCalls+IO.asm +++ b/dev/libSystem/src/SystemProc.asm @@ -11,34 +11,37 @@ section .text -global sci_syscall_arg_1 -global sci_syscall_arg_2 -global sci_syscall_arg_3 -global sci_syscall_arg_4 +global libsys_syscall_arg_1 +global libsys_syscall_arg_2 +global libsys_syscall_arg_3 +global libsys_syscall_arg_4 -sci_syscall_arg_1: +libsys_syscall_arg_1: push rbp mov rbp, rsp mov r8, rcx - syscall + + int 50 pop rbp ret -sci_syscall_arg_2: +libsys_syscall_arg_2: push rbp mov rbp, rsp mov r8, rcx mov r9, rdx - syscall + + int 50 + pop rbp ret -sci_syscall_arg_3: +libsys_syscall_arg_3: push rbp mov rbp, rsp @@ -46,12 +49,13 @@ sci_syscall_arg_3: mov r9, rdx mov r10, rbx - syscall + int 50 + pop rbp ret -sci_syscall_arg_4: +libsys_syscall_arg_4: push rbp mov rbp, rsp @@ -60,7 +64,8 @@ sci_syscall_arg_4: mov r10, rbx mov r11, rax - syscall + int 50 + pop rbp ret |
