diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-17 08:16:38 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-10-17 08:20:30 +0200 |
| commit | b5ebbd7406e87d19beee3760ef2417e1444a10d2 (patch) | |
| tree | 19961bbbec929b69a2e0ad1f3734334d05585f72 | |
| parent | 6fbdfddecc9771adb43b7c673a99c93e50c33dbc (diff) | |
FIX/IMP: A set of fixes and new features. (MHR-40, 46 and 47 related)
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
| -rw-r--r-- | compile_flags.txt | 1 | ||||
| -rw-r--r-- | dev/crt/base_exception.hxx | 7 | ||||
| -rw-r--r-- | dev/crt/crtx64.json (renamed from dev/crt/crt.json) | 4 | ||||
| -rw-r--r-- | dev/crt/defines.hxx | 1 | ||||
| -rw-r--r-- | dev/crt/src/hal/x86/base_alloc.cxx | 55 | ||||
| -rw-r--r-- | dev/crt/src/hal/x86/exit.cxx | 19 | ||||
| -rw-r--r-- | dev/crt/src/new+delete.cxx | 52 | ||||
| -rw-r--r-- | dev/zba/amd64-efi.make | 2 | ||||
| -rw-r--r-- | tools/common_zka.hxx | 7 | ||||
| -rw-r--r-- | tools/framework.hxx | 13 | ||||
| -rw-r--r-- | tools/make_framework.json | 13 | ||||
| -rw-r--r-- | tools/make_zxd.json | 13 | ||||
| -rw-r--r-- | tools/src/make_framework.cxx | 42 | ||||
| -rw-r--r-- | tools/src/make_zxd.cxx (renamed from tools/src/zxdmake.cxx) | 4 | ||||
| -rw-r--r-- | tools/zxd.hxx | 10 | ||||
| -rw-r--r-- | tools/zxdmake.json | 19 |
16 files changed, 177 insertions, 85 deletions
diff --git a/compile_flags.txt b/compile_flags.txt index 0aa5a0d8..4bd4474d 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,6 +1,7 @@ -Idev/zka -Idev/ -Idev/zba/ +-Itools -Idev/zba/BootKit -Idev/base/ -std=c++20 diff --git a/dev/crt/base_exception.hxx b/dev/crt/base_exception.hxx index e73ac11b..e4ee3487 100644 --- a/dev/crt/base_exception.hxx +++ b/dev/crt/base_exception.hxx @@ -9,7 +9,6 @@ #include <crt/defines.hxx> #include <crt/exit.hxx> -/// @brief Standard C++ namespace namespace std { inline void __throw_general(void) @@ -23,6 +22,12 @@ namespace std __builtin_unreachable(); // prevent from continuing. } + inline void __throw_bad_alloc(void) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } + inline void __throw_bad_array_new_length(void) { __throw_general(); diff --git a/dev/crt/crt.json b/dev/crt/crtx64.json index fbd54bf8..3e321e5d 100644 --- a/dev/crt/crt.json +++ b/dev/crt/crtx64.json @@ -2,8 +2,8 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["../", "./"], - "sources_path": ["src/*.cxx"], - "output_name": "crt.dll", + "sources_path": ["src/*.cxx", "src/hal/x86/*.cxx"], + "output_name": "crtx64.dll", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/dev/crt/defines.hxx b/dev/crt/defines.hxx index 5636c337..73422165 100644 --- a/dev/crt/defines.hxx +++ b/dev/crt/defines.hxx @@ -79,6 +79,7 @@ typedef union double_cast { #endif // ifdef __STD_CXX__ +/// @brief Standard C++ namespace. namespace std { /// @brief Forward object. diff --git a/dev/crt/src/hal/x86/base_alloc.cxx b/dev/crt/src/hal/x86/base_alloc.cxx new file mode 100644 index 00000000..effb6c94 --- /dev/null +++ b/dev/crt/src/hal/x86/base_alloc.cxx @@ -0,0 +1,55 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <crt/base_alloc.hxx> +#include <crt/base_exception.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)); + + if (!ptr) + std::__throw_bad_alloc(); + + 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)); + + if (!ptr) + std::__throw_bad_alloc(); + + 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)); +} diff --git a/dev/crt/src/hal/x86/exit.cxx b/dev/crt/src/hal/x86/exit.cxx new file mode 100644 index 00000000..d593adf9 --- /dev/null +++ b/dev/crt/src/hal/x86/exit.cxx @@ -0,0 +1,19 @@ +/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <crt/exit.hxx>
+
+#define kAllocSyscallId "mov $12, %%r9\n\t"
+
+/// @note Just here for building.
+extern "C" int exit(int code)
+{
+ asm("mov 0, %%r8\n\t" kAllocSyscallId
+ "syscall"
+ : "=r"(code));
+
+ return 1;
+}
diff --git a/dev/crt/src/new+delete.cxx b/dev/crt/src/new+delete.cxx deleted file mode 100644 index 1241bf66..00000000 --- a/dev/crt/src/new+delete.cxx +++ /dev/null @@ -1,52 +0,0 @@ -/* ------------------------------------------- - - 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)); -} diff --git a/dev/zba/amd64-efi.make b/dev/zba/amd64-efi.make index 7bf3ceaa..e1a212ef 100644 --- a/dev/zba/amd64-efi.make +++ b/dev/zba/amd64-efi.make @@ -55,7 +55,7 @@ BOOT_LOADER=newosldr.exe KERNEL=minoskrnl.exe DDK=ddk.dll SCI=sci.dll -CRT=crt.dll +CRT=crtx64.dll SYS_CHK=syschk.sys STARTUP=startup.sys diff --git a/tools/common_zka.hxx b/tools/common_zka.hxx new file mode 100644 index 00000000..3b7a1b19 --- /dev/null +++ b/tools/common_zka.hxx @@ -0,0 +1,7 @@ +#include <cstdint> +#include <iostream> +#include <fstream> +#include <string> +#include <cstring> +#include <sstream> +#include <filesystem> diff --git a/tools/framework.hxx b/tools/framework.hxx new file mode 100644 index 00000000..555f7aae --- /dev/null +++ b/tools/framework.hxx @@ -0,0 +1,13 @@ +/** + Thu Oct 17 07:57:43 CEST 2024 + (C) ZKA Technologies. +*/ + +#pragma once + +#include <common_zka.hxx> + +#define kFKDLLDirectory "ZKA/DLL/" +#define kFKManifestDirectory "ZKA/Manifests/" +#define kFKRootDirectory "ZKA/" +#define kFKExtension ".framework" diff --git a/tools/make_framework.json b/tools/make_framework.json new file mode 100644 index 00000000..c597e5d6 --- /dev/null +++ b/tools/make_framework.json @@ -0,0 +1,13 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": ["./"], + "sources_path": ["src/make_framework.cxx"], + "output_name": "make_framework.exe", + "cpp_macros": [ + "__MKF_AMD64__", + "cMKFVersion=0x0100", + "cMKFVersionHighest=0x0100", + "cMKFVersionLowest=0x0100" + ] +} diff --git a/tools/make_zxd.json b/tools/make_zxd.json new file mode 100644 index 00000000..1c25c1a2 --- /dev/null +++ b/tools/make_zxd.json @@ -0,0 +1,13 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": ["./"], + "sources_path": ["src/make_zxd.cxx"], + "output_name": "make_zxd.exe", + "cpp_macros": [ + "__DRVSIGN_AMD64__", + "cDSVersion=0x0100", + "cDSVersionHighest=0x0100", + "cDSVersionLowest=0x0100" + ] +} diff --git a/tools/src/make_framework.cxx b/tools/src/make_framework.cxx new file mode 100644 index 00000000..3d719529 --- /dev/null +++ b/tools/src/make_framework.cxx @@ -0,0 +1,42 @@ +/* + * Created on Thu Oct 17 08:00:42 CEST 2024 + * + * Copyright (c) 2024 ZKA Technologies + */ + +#include <filesystem> +#include <framework.hxx> + +/// @brief This program converts a PE32+ driver, into a custom format, the ZXD. +/// @note ZXD is a format for ZKA signed drivers. +int main(int argc, char* argv[]) +{ + for (size_t i = 1ul; i < argc; ++i) + { + if (strcmp(argv[i], "/?") == 0) + { + std::cout << "make_framework: Framework Tool.\n"; + std::cout << "make_framework: © ZKA Technologies, all rights reserved.\n"; + + return 0; + } + } + + auto path = std::string(argv[1]); + + if (!path.ends_with(kFKExtension)) + return 1; + + std::filesystem::path path_arg = path; + + if (std::filesystem::create_directory(path_arg)) + { + std::filesystem::create_directory(path_arg / kFKRootDirectory); + std::filesystem::create_directory(path_arg / kFKManifestDirectory); + std::filesystem::create_directory(path_arg / kFKDLLDirectory); + + return 0; + } + + return 1; +} diff --git a/tools/src/zxdmake.cxx b/tools/src/make_zxd.cxx index 8a3276ff..2a456e28 100644 --- a/tools/src/zxdmake.cxx +++ b/tools/src/make_zxd.cxx @@ -14,8 +14,8 @@ int main(int argc, char* argv[]) { if (strcmp(argv[i], "/?") == 0) { - std::cout << "zxdmake: ZKA ZXD Driver Tool.\n"; - std::cout << "zxdmake: © ZKA Technologies, all rights reserved.\n"; + std::cout << "make_zxd: ZXD Tool.\n"; + std::cout << "make_zxd: © ZKA Technologies, all rights reserved.\n"; return 0; } diff --git a/tools/zxd.hxx b/tools/zxd.hxx index 123c9124..bf942241 100644 --- a/tools/zxd.hxx +++ b/tools/zxd.hxx @@ -6,13 +6,7 @@ #pragma once -#include <cstdint> -#include <iostream> -#include <fstream> -#include <string> -#include <cstring> -#include <sstream> -#include <filesystem> +#include <common_zka.hxx> #define kDriverSignedExt ".zxd" #define kDriverExt ".sys" @@ -53,4 +47,4 @@ namespace ZXD return mz_blob[0] == 'M' && mz_blob[1] == 'Z'; } -} // namespace ZXD
\ No newline at end of file +} // namespace ZXD diff --git a/tools/zxdmake.json b/tools/zxdmake.json deleted file mode 100644 index d24a5de9..00000000 --- a/tools/zxdmake.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compiler_path": "x86_64-w64-mingw32-g++.exe", - "compiler_std": "c++20", - "headers_path": [ "../", "./", "../../" ], - "sources_path": [ "src/zxdmake.cxx" ], - "output_name": "zxdmake.exe", - "compiler_flags": [ - "-ffreestanding", - "-fno-rtti", - "-fno-exceptions", - "-Wl,--subsystem=17" - ], - "cpp_macros": [ - "__DRVSIGN_AMD64__", - "cDSVersion=0x0100", - "cDSVersionHighest=0x0100", - "cDSVersionLowest=0x0100" - ] -} |
