diff options
| -rw-r--r-- | Comm/herror.hxx | 6 | ||||
| -rw-r--r-- | Kernel/FSKit/NewFS.hxx | 2 | ||||
| -rw-r--r-- | Kernel/KernelKit/DriveManager.hxx | 11 | ||||
| -rw-r--r-- | Kernel/KernelKit/HError.hpp | 10 | ||||
| -rw-r--r-- | Kernel/KernelKit/ProcessScheduler.hxx | 16 | ||||
| -rw-r--r-- | Kernel/NetworkKit/IPCEP.hxx | 41 | ||||
| -rw-r--r-- | Kernel/Sources/FS/NewFS.cxx | 27 | ||||
| -rw-r--r-- | Kernel/Sources/Network/IPCEP.cxx | 36 | ||||
| -rw-r--r-- | Kernel/Sources/ProcessScheduler.cxx | 12 | ||||
| -rw-r--r-- | Kernel/Sources/ProcessTeam.cxx | 7 |
10 files changed, 119 insertions, 49 deletions
diff --git a/Comm/herror.hxx b/Comm/herror.hxx index e5042b60..6f6abf6f 100644 --- a/Comm/herror.hxx +++ b/Comm/herror.hxx @@ -8,9 +8,9 @@ #include <Comm/newstd.hxx> -#define DbgOk() (kLastError == kErrorSuccess) -#define DbgFailed() (kLastError != kErrorSuccess) -#define DbgLastError() kLastError +#define ErrLocalIsOk() (kLastError == kErrorSuccess) +#define ErrLocalFailed() (kLastError != kErrorSuccess) +#define ErrLocal() kLastError typedef SInt32 HError; diff --git a/Kernel/FSKit/NewFS.hxx b/Kernel/FSKit/NewFS.hxx index 8b2129da..4c81dc85 100644 --- a/Kernel/FSKit/NewFS.hxx +++ b/Kernel/FSKit/NewFS.hxx @@ -268,7 +268,7 @@ namespace NewOS /// @brief Make a EPM+NewFS drive out of the disk. /// @param drive The drive to write on. - /// @return If it was sucessful, see DbgLastError(). + /// @return If it was sucessful, see ErrLocal(). bool Format(_Input _Output DriveTrait* drive); public: diff --git a/Kernel/KernelKit/DriveManager.hxx b/Kernel/KernelKit/DriveManager.hxx index df7d5f28..d4ccb50f 100644 --- a/Kernel/KernelKit/DriveManager.hxx +++ b/Kernel/KernelKit/DriveManager.hxx @@ -4,9 +4,10 @@ ------------------------------------------- */ -#ifndef __DRIVE_MANAGER__ -#define __DRIVE_MANAGER__ +#ifndef __INC_DRIVE_MANAGER_HXX__ +#define __INC_DRIVE_MANAGER_HXX__ +#include <KernelKit/ProcessScheduler.hxx> #include <CompilerKit/CompilerKit.hxx> #include <KernelKit/DebugOutput.hpp> #include <KernelKit/DeviceManager.hpp> @@ -99,7 +100,7 @@ namespace NewOS DriveTraitPtr GetAddressOf(Int32 index) { - DbgLastError() = kErrorSuccess; + ErrLocal() = kErrorSuccess; switch (index) { @@ -112,7 +113,7 @@ namespace NewOS case 3: return &mD; default: { - DbgLastError() = kErrorNoSuchDisk; + ErrLocal() = kErrorNoSuchDisk; kcout << "newoskrnl: No such disk.\n"; break; @@ -145,4 +146,4 @@ namespace NewOS DriveTrait construct_main_drive(void) noexcept; } // namespace NewOS -#endif /* ifndef __DRIVE_MANAGER__ */ +#endif /* ifndef __INC_DRIVE_MANAGER_HXX__ */ diff --git a/Kernel/KernelKit/HError.hpp b/Kernel/KernelKit/HError.hpp index a160508d..a61d84d4 100644 --- a/Kernel/KernelKit/HError.hpp +++ b/Kernel/KernelKit/HError.hpp @@ -8,9 +8,12 @@ #include <NewKit/Defines.hpp> -#define DbgOk() (kLastError == NewOS::kErrorSuccess) -#define DbgFailed() (kLastError != NewOS::kErrorSuccess) -#define DbgLastError() kLastError +/// @file HError.hpp +/// @brief Local Process Codes. + +#define ErrLocalIsOk() (NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() == NewOS::kErrorSuccess) +#define ErrLocalFailed() (NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() != NewOS::kErrorSuccess) +#define ErrLocal() NewOS::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() namespace NewOS { @@ -48,4 +51,3 @@ namespace NewOS Boolean ke_bug_check(void) noexcept; } // namespace NewOS -inline NewOS::HError kLastError = 0; diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx index 11555b1d..51a1563f 100644 --- a/Kernel/KernelKit/ProcessScheduler.hxx +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -8,7 +8,6 @@ #define _INC_PROCESS_SCHEDULER_HXX_ #include <ArchKit/ArchKit.hpp> -#include <KernelKit/FileManager.hpp> #include <KernelKit/LockDelegate.hpp> #include <KernelKit/PermissionSelector.hxx> #include <KernelKit/UserHeap.hpp> @@ -197,14 +196,19 @@ namespace NewOS // ProcessHeader getters. public: //! @brief ProcessHeader name getter, example: "C RunTime" - const Char* GetName(); + const Char* GetName() noexcept; - const ProcessSelector& GetSelector(); - const ProcessStatus& GetStatus(); - const AffinityKind& GetAffinity(); + //! @brief return local error code of process. + //! @return Int32 local error code. + Int32& GetLocalCode() noexcept; + + const ProcessSelector& GetSelector() noexcept; + const ProcessStatus& GetStatus() noexcept; + const AffinityKind& GetAffinity() noexcept; private: Int32 fLastExitCode{0}; + Int32 fLocalCode{0}; friend ProcessScheduler; friend ProcessHelper; @@ -222,10 +226,12 @@ namespace NewOS MutableArray<Ref<ProcessHeader>>& AsArray(); Ref<ProcessHeader>& AsRef(); + UInt64& Id() noexcept; public: MutableArray<Ref<ProcessHeader>> mProcessList; Ref<ProcessHeader> mCurrentProcess; + UInt64 mTeamId{0}; }; using ProcessHeaderRef = ProcessHeader*; diff --git a/Kernel/NetworkKit/IPCEP.hxx b/Kernel/NetworkKit/IPCEP.hxx index c92f79cd..4725893e 100644 --- a/Kernel/NetworkKit/IPCEP.hxx +++ b/Kernel/NetworkKit/IPCEP.hxx @@ -18,19 +18,32 @@ /// IA separator. #define cRemoteSeparator "." -/// Interchange address, consists of domain:namespace. -#define cRemoteInvalid "00.00.00.00:0000" -#define cRemoteBitWidth (96) /* 96-bit address space. */ +/// Interchange address, consists of PID:TEAM. +#define cRemoteInvalid "00:00" -#define cRemoteHeaderMagic (0x4950434550) +#define cRemoteHeaderMagic (0x4950434) namespace NewOS { - /// @brief 96-bit number to represent the domain and namespace + /// @brief 128-bit IPC address. struct PACKED IPCEPAddress final { - UInt32 RemoteAddress; - UInt64 RemoteNamespace; + UInt64 ProcessID; + UInt64 ProcessTeam; + + //////////////////////////////////// + // some operators. + //////////////////////////////////// + + bool operator==(const IPCEPAddress& addr) noexcept + { + return addr.ProcessID == this->ProcessID && addr.ProcessTeam == this->ProcessTeam; + } + + bool operator==(IPCEPAddress& addr) noexcept + { + return addr.ProcessID == this->ProcessID && addr.ProcessTeam == this->ProcessTeam; + } }; typedef struct IPCEPAddress IPCEPAddressType; @@ -41,12 +54,12 @@ namespace NewOS eIPCEPBigEndian = 1 }; - /// @brief IPCEP connection header, must be the same on - /// user side as well. + constexpr auto cIPCEPMsgSize = 6094U; - typedef struct IPCEPConnectionHeader + /// @brief IPCEP connection header, message cannot be greater than 6K. + typedef struct IPCEPMessageHeader final { - UInt32 IpcHeader; // cRemoteHeaderMagic + UInt32 IpcHeaderMagic; // cRemoteHeaderMagic UInt8 IpcEndianess; // 0 : LE, 1 : BE SizeT IpcPacketSize; IPCEPAddressType IpcFrom; @@ -54,8 +67,10 @@ namespace NewOS UInt32 IpcCRC32; UInt32 IpcMsg; UInt32 IpcMsgSz; - UInt8 IpcData[]; - } PACKED IPCEPConnectionHeader; + UInt8 IpcData[cIPCEPMsgSize]; + } PACKED IPCEPMessageHeader; + + Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt); } // namespace NewOS #endif // _INC_IPC_ENDPOINT_HXX_ diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index 4e212164..33857590 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -16,6 +16,7 @@ #include <NewKit/String.hpp> #include <NewKit/Utils.hpp> #include <FirmwareKit/EPM.hxx> +#include <KernelKit/ProcessScheduler.hxx> using namespace NewOS; @@ -167,12 +168,12 @@ _Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog, switch (res) { case 1: - DbgLastError() = kErrorDiskReadOnly; + ErrLocal() = kErrorDiskReadOnly; break; case 2: - DbgLastError() = kErrorDiskIsFull; + ErrLocal() = kErrorDiskIsFull; break; - DbgLastError() = kErrorNoSuchDisk; + ErrLocal() = kErrorNoSuchDisk; break; default: @@ -241,7 +242,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, if (*parentName == 0) { - DbgLastError() = kErrorFileNotFound; + ErrLocal() = kErrorFileNotFound; return nullptr; } @@ -414,7 +415,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, /// @brief Make a EPM+NewFS drive out of the disk. /// @param drive The drive to write on. -/// @return If it was sucessful, see DbgLastError(). +/// @return If it was sucessful, see ErrLocal(). bool NewFSParser::Format(_Input _Output DriveTrait* drive) { /// verify disk. @@ -426,7 +427,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) /// if disk isn't good, then error out. if (false == drive->fPacket.fPacketGood) { - DbgLastError() = kErrorDiskIsCorrupted; + ErrLocal() = kErrorDiskIsCorrupted; return false; } @@ -565,7 +566,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, /// sanity check the fork. if (forkData->DataOffset <= kNewFSCatalogStartAddress) { - DbgLastError() = kErrorDiskIsCorrupted; + ErrLocal() = kErrorDiskIsCorrupted; kcout << "newoskrnl: Invalid fork offset.\r"; @@ -771,7 +772,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) if (!catalogName || StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) { - DbgLastError() = kErrorInternal; + ErrLocal() = kErrorInternal; return false; } @@ -835,7 +836,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, { if (!catalog) { - DbgLastError() = kErrorFileNotFound; + ErrLocal() = kErrorFileNotFound; return nullptr; } @@ -913,11 +914,11 @@ bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) { if (!catalog) { - DbgLastError() = kErrorFileNotFound; + ErrLocal() = kErrorFileNotFound; return false; } - DbgLastError() = kErrorUnimplemented; + ErrLocal() = kErrorUnimplemented; return false; } @@ -931,11 +932,11 @@ SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) { if (!catalog) { - DbgLastError() = kErrorFileNotFound; + ErrLocal() = kErrorFileNotFound; return 0; } - DbgLastError() = kErrorUnimplemented; + ErrLocal() = kErrorUnimplemented; return 0; } diff --git a/Kernel/Sources/Network/IPCEP.cxx b/Kernel/Sources/Network/IPCEP.cxx index e3a40fb9..0cd9d778 100644 --- a/Kernel/Sources/Network/IPCEP.cxx +++ b/Kernel/Sources/Network/IPCEP.cxx @@ -5,3 +5,39 @@ ------------------------------------------- */ #include <NetworkKit/IPCEP.hxx> + +using namespace NewOS; + +Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt) +{ + if (!pckt) return false; + + auto endian = DEDUCE_ENDIAN(pckt, ((char*)pckt)[0]); + + switch (endian) + { + case Endian::kEndianBig: + { + if (pckt->IpcEndianess == eIPCEPLittleEndian) + return false; + + break; + } + case Endian::kEndianLittle: + { + if (pckt->IpcEndianess == eIPCEPBigEndian) + return false; + + break; + } + case Endian::kEndianMixed: + break; + default: + return false; + } + + if (pckt->IpcFrom == pckt->IpcTo) return false; + if (pckt->IpcPacketSize > cIPCEPMsgSize) return false; + + return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic; +} diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index ca9a3435..ddeff7f2 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -55,6 +55,8 @@ namespace NewOS this->Exit(kErrorProcessFault); } + Int32& ProcessHeader::GetLocalCode() noexcept { return fLocalCode; } + void ProcessHeader::Wake(const bool should_wakeup) { this->Status = @@ -69,7 +71,7 @@ namespace NewOS { if (this->FreeMemory < 1) { - DbgLastError() = kErrorHeapOutOfMemory; + ErrLocal() = kErrorHeapOutOfMemory; /* we're going out of memory */ this->Crash(); @@ -134,19 +136,19 @@ namespace NewOS } /// @brief process name getter. - const Char* ProcessHeader::GetName() + const Char* ProcessHeader::GetName() noexcept { return this->Name; } /// @brief process selector getter. - const ProcessSelector& ProcessHeader::GetSelector() + const ProcessSelector& ProcessHeader::GetSelector() noexcept { return this->Selector; } /// @brief process status getter. - const ProcessStatus& ProcessHeader::GetStatus() + const ProcessStatus& ProcessHeader::GetStatus() noexcept { return this->Status; } @@ -156,7 +158,7 @@ namespace NewOS /** @brief Affinity is the time slot allowed for the process. */ - const AffinityKind& ProcessHeader::GetAffinity() + const AffinityKind& ProcessHeader::GetAffinity() noexcept { return this->Affinity; } diff --git a/Kernel/Sources/ProcessTeam.cxx b/Kernel/Sources/ProcessTeam.cxx index 30c791b2..f01841a6 100644 --- a/Kernel/Sources/ProcessTeam.cxx +++ b/Kernel/Sources/ProcessTeam.cxx @@ -20,6 +20,13 @@ namespace NewOS return mProcessList; } + /// @brief Get team ID. + /// @return The team's ID. + UInt64& ProcessTeam::Id() noexcept + { + return mTeamId; + } + /// @brief Current process getter. /// @return The current process header. Ref<ProcessHeader>& ProcessTeam::AsRef() |
