summaryrefslogtreecommitdiffhomepage
path: root/Private/Source/AppMain.cxx
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-30 11:58:58 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-30 12:04:01 +0200
commit3033b78abc6ff3dad05994fa51bcd92bf3dae542 (patch)
treeef52ada6b602c50f88e25d4624373ced523cc772 /Private/Source/AppMain.cxx
parent88d9199c65191647641bf06fbaa708d40e53c752 (diff)
AppMain.cxx: Add canary file, which prevents data corruption.
TODO: this file must be protected. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/Source/AppMain.cxx')
-rw-r--r--Private/Source/AppMain.cxx46
1 files changed, 18 insertions, 28 deletions
diff --git a/Private/Source/AppMain.cxx b/Private/Source/AppMain.cxx
index d9c02843..ac1cb1ac 100644
--- a/Private/Source/AppMain.cxx
+++ b/Private/Source/AppMain.cxx
@@ -16,6 +16,7 @@
#include <KernelKit/UserHeap.hpp>
#include <NewKit/Json.hpp>
#include <NewKit/Utils.hpp>
+#include <NewKit/KernelCheck.hpp>
/// @file Main microkernel entrypoint.
@@ -25,51 +26,40 @@ EXTERN_C NewOS::Void AppMain(NewOS::Void) {
NewOS::FilesystemManagerInterface::Mount(newFS);
+ constexpr auto cDataSz = 512;
+ NewOS::UInt8 theData[cDataSz] = { "\x48\xC7\xC0\x00\x00\x00\x00\xC3\xC1" };
+
if (newFS->GetImpl()) {
NewCatalog* textCatalog = nullptr;
- if (!newFS->GetImpl()->GetCatalog("/EditableText")) {
- constexpr auto cDataSz = 512;
- NewOS::Char theData[cDataSz] = {
- "About NewKernel...\rNewKernel is the System behind "
- "NewOS.\rFeaturing modern common features, yet innovative.\r"};
+ if (!newFS->GetImpl()->GetCatalog("/System/.NEWFS_SANITIZER")) {
NewFork theFork{0};
- NewOS::rt_copy_memory((NewOS::VoidPtr) "EditableText",
+ NewOS::rt_copy_memory((NewOS::VoidPtr) "RawExecutable",
(NewOS::VoidPtr)theFork.Name,
- NewOS::rt_string_len("EditableText"));
+ NewOS::rt_string_len("RawExecutable"));
theFork.Kind = NewOS::kNewFSDataForkKind;
theFork.DataSize = kNewFSForkSize;
- textCatalog = newFS->GetImpl()->CreateCatalog("/EditableText");
+ newFS->GetImpl()->CreateCatalog("/System/", 0, kNewFSCatalogKindDir);
+ textCatalog = newFS->GetImpl()->CreateCatalog("/System/.NEWFS_SANITIZER");
newFS->GetImpl()->CreateFork(textCatalog, theFork);
- newFS->GetImpl()->WriteCatalog(textCatalog, theData, cDataSz, "EditableText");
-
- NewFork theForkPreview{0};
-
- theForkPreview.Kind = NewOS::kNewFSDataForkKind;
- theForkPreview.DataSize = kNewFSForkSize;
-
- NewOS::rt_copy_memory((NewOS::VoidPtr) "EditableTextPreview",
- (NewOS::VoidPtr)theForkPreview.Name,
- NewOS::rt_string_len("EditableTextPreview"));
-
- NewOS::Char theDataPreview[cDataSz] = { "NewKernel Info:\r\tNewKernel!" };
- newFS->GetImpl()->CreateFork(textCatalog, theForkPreview);
-
- newFS->GetImpl()->WriteCatalog(textCatalog, theDataPreview, cDataSz, "EditableTextPreview");
- } else {
- NewOS::kcout << "Catalog already exists.\r";
+ newFS->GetImpl()->WriteCatalog(textCatalog, theData, cDataSz, "RawExecutable");
}
- char* buf = nullptr;
+ NewOS::UInt8* buf = nullptr;
- buf = (NewOS::Char*)newFS->GetImpl()->ReadCatalog(newFS->GetImpl()->GetCatalog("/EditableText"), 512, "EditableTextPreview");
+ buf = (NewOS::UInt8*)newFS->GetImpl()->ReadCatalog(newFS->GetImpl()->GetCatalog("/System/.NEWFS_SANITIZER"), 512, "RawExecutable");
- NewOS::kcout << buf << NewOS::endl;
+ for (NewOS::SizeT index = 0UL; index < cDataSz; ++index) {
+ if (buf[index] != theData[index]) {
+ NewOS::kcout << "Diff-Detected: " << NewOS::hex_number(buf[index]) << NewOS::endl;
+ NewOS::ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR);
+ }
+ }
}
while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0)