diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-13 15:29:55 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-13 15:29:55 +0200 |
| commit | 7477a0f942c374b652da4f80cdb36d4661aac3c8 (patch) | |
| tree | d06627de4689b5661f4b95c4fa15f932b004ad13 /dev/crt | |
| parent | 182f2baa4d38a286d3453cc0da90ebec5fb25266 (diff) | |
IMP: Delete the memory list when exiting process.
IMP: Add Allocation (and delete) of MemoryList.
IMP: BitMap allocator must now allocate directories as well.
IMP: Add Handover arch to check if executable is an AMD64 executable or
ARM64 executable.
FIX: Add ::EFI::Stop, when a thread doesn't load correctly.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/crt')
| -rw-r--r-- | dev/crt/crt.json | 2 | ||||
| -rw-r--r-- | dev/crt/defines.hxx | 22 | ||||
| -rw-r--r-- | dev/crt/exit.hxx | 4 | ||||
| -rw-r--r-- | dev/crt/src/alloca.cxx | 9 | ||||
| -rw-r--r-- | dev/crt/src/base_exception.cxx (renamed from dev/crt/src/crt_lib.cxx) | 4 | ||||
| -rw-r--r-- | dev/crt/src/new+delete.cxx | 52 |
6 files changed, 65 insertions, 28 deletions
diff --git a/dev/crt/crt.json b/dev/crt/crt.json index 07368550..fbd54bf8 100644 --- a/dev/crt/crt.json +++ b/dev/crt/crt.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../", "./"], "sources_path": ["src/*.cxx"], - "output_name": "zka-crt-cxx.dll", + "output_name": "crt.dll", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/dev/crt/defines.hxx b/dev/crt/defines.hxx index d9670ac1..5636c337 100644 --- a/dev/crt/defines.hxx +++ b/dev/crt/defines.hxx @@ -10,21 +10,11 @@ #include <stdint.h> #include <stddef.h> -#ifndef __GNUC__ - -typedef __SIZE_TYPE__ size_t; - -#ifdef __LP64__ -typedef long int ssize_t; -#else -typedef int ssize_t; -#endif // __LP64__ +#ifdef __GNUC__ typedef void* ptr_type; typedef __SIZE_TYPE__ size_type; -typedef size_t ptrdiff_t; -typedef size_t uintptr_t; typedef void* voidptr_t; typedef void* any_t; typedef char* caddr_t; @@ -53,16 +43,6 @@ typedef char* caddr_t; #define __fini_decl() #endif -#if __has_builtin(__builtin_alloca) -#define alloca(sz) __builtin_alloca(sz) -#ifdef __alloca -#undef __alloca -#endif -#define __alloca alloca -#else -#warning ! alloca not detected ! -#endif - typedef long long off_t; typedef unsigned long long uoff_t; diff --git a/dev/crt/exit.hxx b/dev/crt/exit.hxx index a699cacd..7f64ebd5 100644 --- a/dev/crt/exit.hxx +++ b/dev/crt/exit.hxx @@ -13,6 +13,6 @@ namespace std { inline int exit(int code) { - exit(code); + return exit(code); } -} // namespace std
\ No newline at end of file +} // namespace std diff --git a/dev/crt/src/alloca.cxx b/dev/crt/src/alloca.cxx new file mode 100644 index 00000000..d2f684b3 --- /dev/null +++ b/dev/crt/src/alloca.cxx @@ -0,0 +1,9 @@ +/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <crt/alloca.hxx>
+
+/// @note Just here for building.
diff --git a/dev/crt/src/crt_lib.cxx b/dev/crt/src/base_exception.cxx index 530e40db..a8a43ac7 100644 --- a/dev/crt/src/crt_lib.cxx +++ b/dev/crt/src/base_exception.cxx @@ -4,10 +4,6 @@ ------------------------------------------- */
-#include <crt/alloca.hxx>
-#include <crt/defines.hxx>
#include <crt/base_exception.hxx>
-#include <crt/math.hxx>
-#include <crt/base_alloc.hxx>
/// @note Just here for building.
diff --git a/dev/crt/src/new+delete.cxx b/dev/crt/src/new+delete.cxx new file mode 100644 index 00000000..1241bf66 --- /dev/null +++ b/dev/crt/src/new+delete.cxx @@ -0,0 +1,52 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <crt/base_alloc.hxx> + +#define kAllocSyscallId "mov $10, %%r9\n\t" +#define kFreeSyscallId "mov $11, %%r9\n\t" + +void* operator new(size_t length) +{ + void* ptr = nullptr; + + // do syscall according to PEF convention. + asm ("mov %0, %%r8\n\t" + kAllocSyscallId + "syscall" + : "=r" (ptr)); + + return ptr; +} + +void* operator new[](size_t length) +{ + ptr_type ptr = nullptr; + + // do syscall according to PEF convention. + asm ("mov %0, %%r8\n\t" + kAllocSyscallId + "syscall" + : "=r" (ptr)); + + return ptr; +} + +void operator delete(void* ptr) noexcept +{ + asm ("mov %0, %%r8\n\t" + kFreeSyscallId + "syscall" + : "=r" (ptr)); +} + +void operator delete[](void* ptr) noexcept +{ + asm ("mov %0, %%r8\n\t" + kFreeSyscallId + "syscall" + : "=r" (ptr)); +} |
