diff options
| -rw-r--r-- | src/boot/src/HEL/AMD64/BootEFI.cc | 4 | ||||
| -rw-r--r-- | src/kernel/HALKit/AMD64/HalKernelMain.cc | 3 | ||||
| -rw-r--r-- | src/kernel/KernelKit/FileMgr.h | 40 | ||||
| -rw-r--r-- | src/kernel/KernelKit/PE32CodeMgr.h | 2 | ||||
| -rw-r--r-- | src/kernel/KernelKit/PEFCodeMgr.h | 2 | ||||
| -rw-r--r-- | src/kernel/KernelKit/TraceSrv.h | 4 | ||||
| -rw-r--r-- | src/kernel/NeKit/ErrorOr.h | 2 | ||||
| -rw-r--r-- | src/kernel/NeKit/KString.h | 4 | ||||
| -rw-r--r-- | src/kernel/NeKit/Ref.h | 1 | ||||
| -rw-r--r-- | src/kernel/StorageKit/AHCI.h | 5 | ||||
| -rw-r--r-- | src/kernel/StorageKit/ATA.h | 4 | ||||
| -rw-r--r-- | src/kernel/StorageKit/NVME.h | 4 | ||||
| -rw-r--r-- | src/kernel/StorageKit/SCSI.h | 4 | ||||
| -rw-r--r-- | src/kernel/SwapKit/DiskSwap.h | 7 | ||||
| -rw-r--r-- | src/kernel/src/FS/OpenHeFS+FileMgr.cc | 23 | ||||
| -rw-r--r-- | src/kernel/src/PE32CodeMgr.cc | 29 | ||||
| -rw-r--r-- | src/kernel/src/PEFCodeMgr.cc | 35 | ||||
| -rw-r--r-- | src/kernel/src/Swap/DiskSwap.cc | 19 |
18 files changed, 101 insertions, 91 deletions
diff --git a/src/boot/src/HEL/AMD64/BootEFI.cc b/src/boot/src/HEL/AMD64/BootEFI.cc index d275a13d..27610dd6 100644 --- a/src/boot/src/HEL/AMD64/BootEFI.cc +++ b/src/boot/src/HEL/AMD64/BootEFI.cc @@ -139,7 +139,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa // Calculate initial bitmap size by summing all free memory pages. UInt64 free_pages = 0; - VoidPtr first_free_page = nullptr; + VoidPtr first_free_page = (VoidPtr) 1024; for (UInt32 i = 0; i < size_struct_ptr / sz_desc; ++i) { EfiMemoryDescriptor* desc = (EfiMemoryDescriptor*) ((UInt8*) struct_ptr + (i * sz_desc)); @@ -151,6 +151,8 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa } } + free_pages -= 1024; + // Set bitmap to use the first free page region found. kHandoverHeader->f_BitMapStart = first_free_page; handover_hdr->f_BitMapStart = first_free_page; diff --git a/src/kernel/HALKit/AMD64/HalKernelMain.cc b/src/kernel/HALKit/AMD64/HalKernelMain.cc index 1277dee7..ed82b60f 100644 --- a/src/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/src/kernel/HALKit/AMD64/HalKernelMain.cc @@ -15,6 +15,7 @@ #include <misc/BenchKit/HWChronometer.h> #include <modules/ACPI/ACPIFactoryInterface.h> #include <modules/CoreGfx/TextGfx.h> +#include "KernelKit/FileMgr.h" #ifndef __NE_MODULAR_KERNEL_COMPONENTS__ EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; @@ -134,10 +135,12 @@ EXTERN_C Kernel::Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_h EXTERN_C Kernel::Void hal_real_init(Kernel::Void) { #ifdef __FSKIT_INCLUDES_OPENHEFS__ OpenHeFS::fs_init_openhefs(); + HeFileSystemMgr::Mount(new HeFileSystemMgr()); #endif #ifdef __FSKIT_INCLUDES_NEFS__ NeFS::fs_init_nefs(); + NeFileSystemMgr::Mount(new NeFileSystemMgr()); #endif UserProcessScheduler::The().SwitchTeam(kRTUserTeam); diff --git a/src/kernel/KernelKit/FileMgr.h b/src/kernel/KernelKit/FileMgr.h index 3b6cabe2..df12a65a 100644 --- a/src/kernel/KernelKit/FileMgr.h +++ b/src/kernel/KernelKit/FileMgr.h @@ -261,7 +261,7 @@ class HeFileSystemMgr final : public IFilesystemMgr { template <typename Encoding = Char, typename FSClass = IFilesystemMgr> class FileStream final { public: - explicit FileStream(const Encoding* path, const Encoding* restrict_type); + FileStream(const Encoding* path, const Encoding* restrict_type); ~FileStream(); public: @@ -269,68 +269,68 @@ class FileStream final { FileStream(const FileStream&); public: - ErrorOr<Int64> Write(UIntPtr offset, const VoidPtr data, SizeT len) { + Ref<Int64> Write(UIntPtr offset, const VoidPtr data, SizeT len) { if (this->fFileRestrict != kFileMgrRestrictReadWrite && this->fFileRestrict != kFileMgrRestrictReadWriteBinary && this->fFileRestrict != kFileMgrRestrictWrite && this->fFileRestrict != kFileMgrRestrictWriteBinary) - return ErrorOr<Int64>(kErrorInvalidData); + return Ref<Int64>(0L); - if (data == nullptr) return ErrorOr<Int64>(kErrorInvalidData); + if (data == nullptr) return Ref<Int64>(0L); auto man = FSClass::GetMounted(); if (man) { man->Seek(fFile, offset); man->Write(fFile, data, 0, len); - return ErrorOr<Int64>(kErrorSuccess); + return Ref<Int64>(len); } - return ErrorOr<Int64>(kErrorInvalidData); + return Ref<Int64>(0L); } - ErrorOr<Int64> Write(const Char* name, const VoidPtr data, SizeT len) { + Ref<Int64> Write(const Char* name, const VoidPtr data, SizeT len) { if (this->fFileRestrict != kFileMgrRestrictReadWrite && this->fFileRestrict != kFileMgrRestrictReadWriteBinary && this->fFileRestrict != kFileMgrRestrictWrite && this->fFileRestrict != kFileMgrRestrictWriteBinary) - return ErrorOr<Int64>(kErrorInvalidData); + return Ref<Int64>(0L); - if (data == nullptr) return ErrorOr<Int64>(kErrorInvalidData); + if (data == nullptr) return Ref<Int64>(0L); auto man = FSClass::GetMounted(); if (man) { man->Write(name, fFile, data, 0, len); - return ErrorOr<Int64>(kErrorSuccess); + return Ref<Int64>(len); } - return ErrorOr<Int64>(kErrorInvalidData); + return Ref<Int64>(0L); } - VoidPtr Read(const Char* name, SizeT sz) { + ErrorOrAny Read(const Char* name, SizeT sz) { if (this->fFileRestrict != kFileMgrRestrictReadWrite && this->fFileRestrict != kFileMgrRestrictReadWriteBinary && this->fFileRestrict != kFileMgrRestrictRead && this->fFileRestrict != kFileMgrRestrictReadBinary) - return nullptr; + return ErrorOrAny(kErrorInvalidData); auto man = FSClass::GetMounted(); if (man) { VoidPtr ret = man->Read(name, fFile, kFileReadAll, sz); - return ret; + return ErrorOrAny(ret); } - return nullptr; + return ErrorOrAny(kErrorInvalidData); } - VoidPtr Read(UIntPtr offset, SizeT sz) { + ErrorOrAny Read(UIntPtr offset, SizeT sz) { if (this->fFileRestrict != kFileMgrRestrictReadWrite && this->fFileRestrict != kFileMgrRestrictReadWriteBinary && this->fFileRestrict != kFileMgrRestrictRead && this->fFileRestrict != kFileMgrRestrictReadBinary) - return nullptr; + return ErrorOrAny(kErrorInvalidData); auto man = FSClass::GetMounted(); @@ -338,10 +338,10 @@ class FileStream final { man->Seek(fFile, offset); auto ret = man->Read(fFile, kFileReadChunk, sz); - return ret; + return ErrorOrAny(ret); } - return nullptr; + return ErrorOrAny(kErrorInvalidData); } public: @@ -408,7 +408,7 @@ inline FileStream<Encoding, Class>::FileStream(const Encoding* path, const Encod .fMappedTo = kFileMgrRestrictReadWrite, }}; - for (SizeT index = 0; index < kRestrictCount; ++index) { + for (SizeT index{}; index < kRestrictCount; ++index) { if (rt_string_cmp(restrict_type, kRestrictList[index].fRestrict, rt_string_len(kRestrictList[index].fRestrict)) == 0) { fFileRestrict = kRestrictList[index].fMappedTo; diff --git a/src/kernel/KernelKit/PE32CodeMgr.h b/src/kernel/KernelKit/PE32CodeMgr.h index 9504615d..3a3ea6f3 100644 --- a/src/kernel/KernelKit/PE32CodeMgr.h +++ b/src/kernel/KernelKit/PE32CodeMgr.h @@ -66,7 +66,7 @@ class PE32Loader : public ILoader { #endif // __FSKIT_INCLUDES_NEFS__ Ref<KString> fPath; - RefAny fCachedBlob{}; + ErrorOrAny fCachedBlob{}; BOOL fBad{}; }; diff --git a/src/kernel/KernelKit/PEFCodeMgr.h b/src/kernel/KernelKit/PEFCodeMgr.h index 59b13db7..e5daa4f5 100644 --- a/src/kernel/KernelKit/PEFCodeMgr.h +++ b/src/kernel/KernelKit/PEFCodeMgr.h @@ -60,7 +60,7 @@ class PEFLoader : public ILoader { #endif // __FSKIT_INCLUDES_NEFS__ Ref<KString> fPath; - VoidPtr fCachedBlob; + ErrorOrAny fCachedBlob; BOOL fFatBinary{}; BOOL fBad{}; }; diff --git a/src/kernel/KernelKit/TraceSrv.h b/src/kernel/KernelKit/TraceSrv.h index 25bbc4c8..5a9d365c 100644 --- a/src/kernel/KernelKit/TraceSrv.h +++ b/src/kernel/KernelKit/TraceSrv.h @@ -8,6 +8,7 @@ #include <CompilerKit/CompilerKit.h> namespace Kernel { + namespace Detail { inline constexpr auto kDebugCmdLen = 256U; inline constexpr auto kDebugPort = 51820; @@ -17,6 +18,7 @@ namespace Detail { inline constexpr auto kDebugDelim = ';'; inline constexpr auto kDebugEnd = '\r'; } // namespace Detail + } // namespace Kernel -#endif // !__KERNELKIT_TRACESRV_H__
\ No newline at end of file +#endif // !__KERNELKIT_TRACESRV_H__ diff --git a/src/kernel/NeKit/ErrorOr.h b/src/kernel/NeKit/ErrorOr.h index 87031b75..722d8f84 100644 --- a/src/kernel/NeKit/ErrorOr.h +++ b/src/kernel/NeKit/ErrorOr.h @@ -23,7 +23,7 @@ class ErrorOr final { using Type = T; using TypePtr = T*; - explicit ErrorOr(ErrorT err) : mRef((T*) RTL_ALLOCA(sizeof(T))), mId(err) { + explicit ErrorOr(ErrorT err) : mRef(Type()), mId(err) { // TODO: Invalidate the value of mRef to make computational evaluations false. mRef = nullptr; } diff --git a/src/kernel/NeKit/KString.h b/src/kernel/NeKit/KString.h index fa31a717..99742239 100644 --- a/src/kernel/NeKit/KString.h +++ b/src/kernel/NeKit/KString.h @@ -18,7 +18,7 @@ inline constexpr Int kMinimumStringSize = 8196; template <typename CharKind = Char, Int MinSz = kMinimumStringSize> class KBasicString final { public: - explicit KBasicString() { + KBasicString() { fDataSz = MinSz; fData = new CharKind[fDataSz]; @@ -27,7 +27,7 @@ class KBasicString final { rt_set_memory(fData, 0, fDataSz); } - explicit KBasicString(SizeT Sz) : fDataSz(Sz) { + KBasicString(SizeT Sz) : fDataSz(Sz) { MUST_PASS(Sz > 1); fData = new CharKind[Sz]; diff --git a/src/kernel/NeKit/Ref.h b/src/kernel/NeKit/Ref.h index 8cc20e3e..267fc217 100644 --- a/src/kernel/NeKit/Ref.h +++ b/src/kernel/NeKit/Ref.h @@ -27,7 +27,6 @@ class Ref final { using ConstType = const T&; using RefType = T&; - Ref(Type* cls) : fClass(*cls) {} Ref(Type cls) : fClass(cls) {} Ref& operator=(nullPtr) { return *this; } diff --git a/src/kernel/StorageKit/AHCI.h b/src/kernel/StorageKit/AHCI.h index 2ac0032d..2b2988fc 100644 --- a/src/kernel/StorageKit/AHCI.h +++ b/src/kernel/StorageKit/AHCI.h @@ -15,8 +15,9 @@ namespace Kernel { /// @note The class is derived from the IDevice class. class AHCIDeviceInterface NE_DEVICE<IMountpoint*> { public: - explicit AHCIDeviceInterface(void (*out)(IDevice* self, IMountpoint* out), - void (*in)(IDevice* self, IMountpoint* in)); + AHCIDeviceInterface() = default; + AHCIDeviceInterface(void (*out)(IDevice* self, IMountpoint* out), + void (*in)(IDevice* self, IMountpoint* in)); virtual ~AHCIDeviceInterface() override; diff --git a/src/kernel/StorageKit/ATA.h b/src/kernel/StorageKit/ATA.h index bccf9b3d..04bb9169 100644 --- a/src/kernel/StorageKit/ATA.h +++ b/src/kernel/StorageKit/ATA.h @@ -14,8 +14,8 @@ namespace Kernel { /// @brief ATA device interface class. class ATADeviceInterface : public IDevice<IMountpoint*> { public: - explicit ATADeviceInterface(void (*Out)(IDevice*, IMountpoint* outpacket), - void (*In)(IDevice*, IMountpoint* inpacket)); + ATADeviceInterface(void (*Out)(IDevice*, IMountpoint* outpacket), + void (*In)(IDevice*, IMountpoint* inpacket)); virtual ~ATADeviceInterface(); diff --git a/src/kernel/StorageKit/NVME.h b/src/kernel/StorageKit/NVME.h index d11a2084..69bd7642 100644 --- a/src/kernel/StorageKit/NVME.h +++ b/src/kernel/StorageKit/NVME.h @@ -11,8 +11,8 @@ namespace Kernel { class NVMEDeviceInterface final NE_DEVICE<IMountpoint*> { public: - explicit NVMEDeviceInterface(Void (*out)(IDevice*, IMountpoint* out_packet), - Void (*in)(IDevice*, IMountpoint* in_packet), Void (*cleanup)(Void)); + NVMEDeviceInterface(Void (*out)(IDevice*, IMountpoint* out_packet), + Void (*in)(IDevice*, IMountpoint* in_packet), Void (*cleanup)(Void)); ~NVMEDeviceInterface() override; diff --git a/src/kernel/StorageKit/SCSI.h b/src/kernel/StorageKit/SCSI.h index 61dcfef8..a7eb8423 100644 --- a/src/kernel/StorageKit/SCSI.h +++ b/src/kernel/StorageKit/SCSI.h @@ -12,8 +12,8 @@ namespace Kernel { class SCSIDeviceInterface final NE_DEVICE<IMountpoint*> { public: - explicit SCSIDeviceInterface(Void (*out)(IDevice*, IMountpoint* out_packet), - Void (*in)(IDevice*, IMountpoint* in_packet), Void (*cleanup)(Void)); + SCSIDeviceInterface(Void (*out)(IDevice*, IMountpoint* out_packet), + Void (*in)(IDevice*, IMountpoint* in_packet), Void (*cleanup)(Void)); ~SCSIDeviceInterface() override; diff --git a/src/kernel/SwapKit/DiskSwap.h b/src/kernel/SwapKit/DiskSwap.h index 9804afa6..a66b86dc 100644 --- a/src/kernel/SwapKit/DiskSwap.h +++ b/src/kernel/SwapKit/DiskSwap.h @@ -9,7 +9,6 @@ #include <NeKit/Config.h> #include <hint/CompilerHint.h> -#define kSwapBlockMaxSize (mib_cast(16)) #define kSwapPageFilePath "/boot/pagefile.sys" #define kSwapPageFilePathU8 u8"/boot/pagefile.sys" @@ -17,6 +16,7 @@ /// @brief Virtual memory swap disk. namespace Kernel { + struct SwapDiskHdr; class IDiskSwap; @@ -34,9 +34,9 @@ class IDiskSwap final { /***********************************************************************************/ /// @brief Write memory chunk onto disk. /// @param data the data packet. - /// @return Whether the swap was written to disk, or not. + /// @return Number of bytes written to swap. /***********************************************************************************/ - BOOL Write(SwapDiskHdr* data); + _Output Int64 Write(SwapDiskHdr* data); /***********************************************************************************/ /// @brief Read memory chunk from disk. @@ -64,6 +64,7 @@ typedef struct SwapDiskHdr { SizeT fBlobSz; UInt8 fBlob[1]; } PACKED ALIGN(8) SwapDiskHdr; + } // namespace Kernel #endif diff --git a/src/kernel/src/FS/OpenHeFS+FileMgr.cc b/src/kernel/src/FS/OpenHeFS+FileMgr.cc index 69930d35..48482551 100644 --- a/src/kernel/src/FS/OpenHeFS+FileMgr.cc +++ b/src/kernel/src/FS/OpenHeFS+FileMgr.cc @@ -17,12 +17,12 @@ HeFileSystemMgr::HeFileSystemMgr() { mParser = new HeFileSystemParser(); MUST_PASS(mParser); - kout << "We are done allocating HeFileSystemParser...\n"; + kout << "We are done allocating HeFileSystemParser...\r"; } HeFileSystemMgr::~HeFileSystemMgr() { if (mParser) { - kout << "Destroying HeFileSystemParser...\n"; + kout << "Destroying HeFileSystemParser...\r"; delete mParser; mParser = nullptr; } @@ -33,8 +33,8 @@ HeFileSystemMgr::~HeFileSystemMgr() { /// @return If it was deleted or not. bool HeFileSystemMgr::Remove(_Input const Char* path) { if (path == nullptr || *path == 0) { - kout << "OpenHeFS: Remove called with null or empty path\n"; - return false; + kout << "OpenHeFS: Remove called with null or empty path\r"; + return NO; } return NO; @@ -45,7 +45,7 @@ bool HeFileSystemMgr::Remove(_Input const Char* path) { /// @return The Node pointer. NodePtr HeFileSystemMgr::Create(_Input const Char* path) { if (!path || *path == 0) { - kout << "OpenHeFS: Create called with null or empty path\n"; + kout << "OpenHeFS: Create called with null or empty path\r"; return nullptr; } @@ -74,7 +74,7 @@ NodePtr HeFileSystemMgr::Create(_Input const Char* path) { /// @return The Node pointer. NodePtr HeFileSystemMgr::CreateDirectory(const Char* path) { if (!path || *path == 0) { - kout << "OpenHeFS: CreateDirectory called with null or empty path\n"; + kout << "OpenHeFS: CreateDirectory called with null or empty path\r"; return nullptr; } return nullptr; @@ -85,7 +85,7 @@ NodePtr HeFileSystemMgr::CreateDirectory(const Char* path) { /// @return The Node pointer. NodePtr HeFileSystemMgr::CreateAlias(const Char* path) { if (!path || *path == 0) { - kout << "OpenHeFS: CreateAlias called with null or empty path\n"; + kout << "OpenHeFS: CreateAlias called with null or empty path\r"; return nullptr; } return nullptr; @@ -93,7 +93,7 @@ NodePtr HeFileSystemMgr::CreateAlias(const Char* path) { NodePtr HeFileSystemMgr::CreateSwapFile(const Char* path) { if (!path || *path == 0) { - kout << "OpenHeFS: CreateSwapFile called with null or empty path\n"; + kout << "OpenHeFS: CreateSwapFile called with null or empty path\r"; return nullptr; } return nullptr; @@ -129,13 +129,16 @@ Char NeFileSystemHelper::MetaFile() { /// @return _Output NodePtr HeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) { if (!path || *path == 0) { - kout << "OpenHeFS: Open called with null or empty path\n"; + kout << "OpenHeFS: Open called with null or empty path\r"; return nullptr; } if (!r || *r == 0) { - kout << "OpenHeFS: Open called with null or empty mode string\n"; + kout << "OpenHeFS: Open called with null or empty mode string\r"; return nullptr; } + + kout << "Unimplemented.\r"; + return nullptr; } diff --git a/src/kernel/src/PE32CodeMgr.cc b/src/kernel/src/PE32CodeMgr.cc index df66d21e..a7b1057e 100644 --- a/src/kernel/src/PE32CodeMgr.cc +++ b/src/kernel/src/PE32CodeMgr.cc @@ -39,7 +39,6 @@ namespace Detail { /***********************************************************************************/ PE32Loader::PE32Loader(const VoidPtr blob) : fCachedBlob(blob) { - (Void) fCachedBlob.TryLeak(); fBad = false; } @@ -55,7 +54,7 @@ PE32Loader::PE32Loader(const Char* path) : fCachedBlob(static_cast<VoidPtr>(null auto kPefHeader = "PE32_BLOB"; fCachedBlob = fFile->Read(kPefHeader, 0); - if (!fCachedBlob) fBad = YES; + if (fCachedBlob.HasError()) fBad = YES; } /***********************************************************************************/ @@ -63,7 +62,7 @@ PE32Loader::PE32Loader(const Char* path) : fCachedBlob(static_cast<VoidPtr>(null /***********************************************************************************/ PE32Loader::~PE32Loader() { - if (fCachedBlob) mm_free_ptr(fCachedBlob.Leak()); + if (fCachedBlob) mm_free_ptr(fCachedBlob.Leak().Leak()); fFile.Reset(); } @@ -76,9 +75,10 @@ PE32Loader::~PE32Loader() { ErrorOr<VoidPtr> PE32Loader::FindSectionByName(const Char* name) { if (!fCachedBlob || fBad || !name) return ErrorOr<VoidPtr>{kErrorInvalidData}; - LDR_EXEC_HEADER_PTR header_ptr = CF::ldr_find_exec_header((const Char*) fCachedBlob.Leak()); + LDR_EXEC_HEADER_PTR header_ptr = + CF::ldr_find_exec_header((const Char*) fCachedBlob.Leak().Leak()); LDR_OPTIONAL_HEADER_PTR opt_header_ptr = - CF::ldr_find_opt_exec_header((const Char*) fCachedBlob.Leak()); + CF::ldr_find_opt_exec_header((const Char*) fCachedBlob.Leak().Leak()); if (!header_ptr || !opt_header_ptr) return ErrorOr<VoidPtr>{kErrorInvalidData}; @@ -142,7 +142,7 @@ ErrorOr<VoidPtr> PE32Loader::FindSymbol(const Char* name, Int32 kind) { if (!sec_ptr || !*sec_ptr) return ErrorOr<VoidPtr>{kErrorInvalidData}; LDR_OPTIONAL_HEADER_PTR opt_header_ptr = - CF::ldr_find_opt_exec_header((const Char*) fCachedBlob.Leak()); + CF::ldr_find_opt_exec_header((const Char*) fCachedBlob.Leak().Leak()); if (opt_header_ptr) { LDR_DATA_DIRECTORY_PTR data_dirs = @@ -154,22 +154,25 @@ ErrorOr<VoidPtr> PE32Loader::FindSymbol(const Char* name, Int32 kind) { return ErrorOr<VoidPtr>{kErrorInvalidData}; LDR_EXPORT_DIRECTORY* export_dir = - (LDR_EXPORT_DIRECTORY*) ((UIntPtr) fCachedBlob.Leak() + export_dir_entry->VirtualAddress); + (LDR_EXPORT_DIRECTORY*) ((UIntPtr) fCachedBlob.Leak().Leak() + + export_dir_entry->VirtualAddress); - UInt32* name_table = (UInt32*) ((UIntPtr) fCachedBlob.Leak() + export_dir->AddressOfNames); + UInt32* name_table = + (UInt32*) ((UIntPtr) fCachedBlob.Leak().Leak() + export_dir->AddressOfNames); UInt16* ordinal_table = - (UInt16*) ((UIntPtr) fCachedBlob.Leak() + export_dir->AddressOfNameOrdinal); + (UInt16*) ((UIntPtr) fCachedBlob.Leak().Leak() + export_dir->AddressOfNameOrdinal); UInt32* function_table = - (UInt32*) ((UIntPtr) fCachedBlob.Leak() + export_dir->AddressOfFunctions); + (UInt32*) ((UIntPtr) fCachedBlob.Leak().Leak() + export_dir->AddressOfFunctions); for (UInt32 i = 0; i < export_dir->NumberOfNames; ++i) { - const char* exported_name = (const char*) ((UIntPtr) fCachedBlob.Leak() + name_table[i]); + const char* exported_name = + (const char*) ((UIntPtr) fCachedBlob.Leak().Leak() + name_table[i]); if (KStringBuilder::Equals(exported_name, name)) { UInt16 ordinal = ordinal_table[i]; UInt32 rva = function_table[ordinal]; - VoidPtr symbol_addr = (VoidPtr) ((UIntPtr) fCachedBlob.Leak() + rva); + VoidPtr symbol_addr = (VoidPtr) ((UIntPtr) fCachedBlob.Leak().Leak() + rva); return ErrorOr<VoidPtr>{symbol_addr}; } @@ -218,7 +221,7 @@ const Char* PE32Loader::MIME() { } ErrorOr<VoidPtr> PE32Loader::GetBlob() { - return ErrorOr<VoidPtr>{this->fCachedBlob.TryLeak()}; + return ErrorOr<VoidPtr>{this->fCachedBlob.Leak().Leak()}; } namespace Utils { diff --git a/src/kernel/src/PEFCodeMgr.cc b/src/kernel/src/PEFCodeMgr.cc index 0b180427..7585b553 100644 --- a/src/kernel/src/PEFCodeMgr.cc +++ b/src/kernel/src/PEFCodeMgr.cc @@ -49,14 +49,12 @@ namespace Detail { /// @param blob file blob. /***********************************************************************************/ PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(blob) { - MUST_PASS(fCachedBlob); - - if (!fCachedBlob) { + if (fCachedBlob.HasError()) { this->fBad = YES; return; } - PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob); + PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob.Leak().Leak()); if (container->Abi == kPefAbi && container->Count >= @@ -79,8 +77,8 @@ PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(blob) { this->fFatBinary = NO; this->fBad = YES; - if (this->fCachedBlob) mm_free_ptr(this->fCachedBlob); - this->fCachedBlob = nullptr; + if (this->fCachedBlob) mm_free_ptr(this->fCachedBlob.Leak().Leak()); + this->fCachedBlob.Leak().Leak() = nullptr; } /***********************************************************************************/ @@ -101,7 +99,7 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false) return; } - PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob); + PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob.Leak().Leak()); if (container->Abi == kPefAbi && container->Count >= @@ -124,16 +122,15 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false) this->fFatBinary = NO; this->fBad = YES; - if (this->fCachedBlob) mm_free_ptr(this->fCachedBlob); - this->fCachedBlob = nullptr; + if (this->fCachedBlob) mm_free_ptr(this->fCachedBlob.Leak().Leak()); + this->fCachedBlob.Leak().Leak() = nullptr; } /***********************************************************************************/ /// @brief PEF destructor. /***********************************************************************************/ PEFLoader::~PEFLoader() { - if (fCachedBlob) mm_free_ptr(fCachedBlob); - + if (fCachedBlob) mm_free_ptr(fCachedBlob.Leak().Leak()); fFile.Reset(); } @@ -149,11 +146,11 @@ ErrorOr<VoidPtr> PEFLoader::FindSymbol(const Char* name, Int32 kind) { if (!blob) return ErrorOr<VoidPtr>{kErrorInvalidData}; - PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob); + PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob.Leak().Leak()); if (!container) return ErrorOr<VoidPtr>{kErrorInvalidData}; - PEFCommandHeader* command_header = reinterpret_cast<PEFCommandHeader*>(blob); + PEFCommandHeader* command_header = reinterpret_cast<PEFCommandHeader*>(blob.Leak().Leak()); if (command_header->VMSize < 1 || command_header->VMAddress == 0) return ErrorOr<VoidPtr>{kErrorInvalidData}; @@ -200,8 +197,8 @@ ErrorOr<VoidPtr> PEFLoader::FindSymbol(const Char* name, Int32 kind) { if (command_header->Kind == kind) { if (command_header->Cpu != Detail::ldr_get_platform()) { if (!this->fFatBinary) { - mm_free_ptr(blob); - blob = nullptr; + mm_free_ptr(blob.Leak().Leak()); + blob.Leak().Leak() = nullptr; return ErrorOr<VoidPtr>{kErrorInvalidData}; } @@ -209,10 +206,10 @@ ErrorOr<VoidPtr> PEFLoader::FindSymbol(const Char* name, Int32 kind) { Char* container_blob_value = new Char[command_header->VMSize]; - rt_copy_memory_safe((VoidPtr) ((Char*) blob + sizeof(PEFCommandHeader)), container_blob_value, - command_header->VMSize, command_header->VMSize); + rt_copy_memory_safe((VoidPtr) ((Char*) blob.Leak().Leak() + sizeof(PEFCommandHeader)), + container_blob_value, command_header->VMSize, command_header->VMSize); - mm_free_ptr(blob); + mm_free_ptr(blob.Leak().Leak()); kout << "PEFLoader: info: Load stub: " << command_header->Name << "!\r"; @@ -243,7 +240,7 @@ ErrorOr<VoidPtr> PEFLoader::FindSymbol(const Char* name, Int32 kind) { } } - mm_free_ptr(blob); + mm_free_ptr(blob.Leak().Leak()); return ErrorOr<VoidPtr>{kErrorInvalidData}; } diff --git a/src/kernel/src/Swap/DiskSwap.cc b/src/kernel/src/Swap/DiskSwap.cc index bd428040..944463fa 100644 --- a/src/kernel/src/Swap/DiskSwap.cc +++ b/src/kernel/src/Swap/DiskSwap.cc @@ -11,16 +11,15 @@ static constexpr UInt32 kSwapDiskHeaderMagic = 0x44535750; // 'DSWP' /***********************************************************************************/ /// @brief Write memory chunk onto disk. /// @param data the data packet. -/// @return Whether the swap was written to disk, or not. /***********************************************************************************/ -BOOL IDiskSwap::Write(SwapDiskHdr* data) { - if (!data || data->fMagic != kSwapDiskHeaderMagic) return NO; +Int64 IDiskSwap::Write(SwapDiskHdr* data) { + if (!data || data->fMagic != kSwapDiskHeaderMagic) return 0UL; FileStream file(kSwapPageFilePath, kRestrictWRB); - ErrorOr<Int64> ret = file.Write(data->fOffset, data, sizeof(SwapDiskHdr) + data->fBlobSz); + Ref<Int64> ret = file.Write(data->fOffset, data, sizeof(SwapDiskHdr) + data->fBlobSz); - return ret.Value() < kErrorSuccess; + return ret.Leak(); } /***********************************************************************************/ @@ -29,18 +28,18 @@ BOOL IDiskSwap::Write(SwapDiskHdr* data) { /// @return Whether the swap was fetched to disk, or not. /***********************************************************************************/ SwapDiskHdr* IDiskSwap::Read(const UIntPtr offset, SizeT data_len) { - if (data_len > kSwapBlockMaxSize) return nullptr; if (data_len == 0) return nullptr; FileStream file(kSwapPageFilePath, kRestrictRB); - VoidPtr blob = file.Read(offset, sizeof(SwapDiskHdr) + data_len); + ErrorOrAny blob = file.Read(offset, sizeof(SwapDiskHdr) + data_len); - if (!blob || (static_cast<SwapDiskHdr*>(blob))->fMagic != kSwapDiskHeaderMagic) { - if (blob) mm_free_ptr(blob); + if (blob.HasError() || + (static_cast<SwapDiskHdr*>(blob.Leak().Leak()))->fMagic != kSwapDiskHeaderMagic) { + if (!blob.HasError()) mm_free_ptr(blob.Leak().Leak()); return nullptr; } - return reinterpret_cast<SwapDiskHdr*>(blob); + return reinterpret_cast<SwapDiskHdr*>(blob.Leak().Leak()); } } // namespace Kernel |
