diff options
| -rw-r--r-- | Comm/newstd.hxx | 49 | ||||
| -rw-r--r-- | Drv/VideoDrv/VideoDrv.c | 5 | ||||
| -rw-r--r-- | Kernel/KernelKit/FileManager.hpp | 121 | ||||
| -rw-r--r-- | Kernel/KernelKit/PEFCodeManager.hxx | 2 | ||||
| -rw-r--r-- | Kernel/Sources/FileManager.cxx | 38 | ||||
| -rw-r--r-- | Kernel/Sources/PEFCodeManager.cxx | 46 |
6 files changed, 175 insertions, 86 deletions
diff --git a/Comm/newstd.hxx b/Comm/newstd.hxx index 913d2a28..908ea017 100644 --- a/Comm/newstd.hxx +++ b/Comm/newstd.hxx @@ -16,6 +16,11 @@ Purpose: NewOS standard interface. #define IMPORT_CXX extern "C++"
#define IMPORT_C extern "C"
+#define cRestrictR "r"
+#define cRestrictRB "rb"
+#define cRestrictW "w"
+#define cRestrictRW "rw"
+
class NUser; /// @brief User application class.
class NWindow; /// @brief Window class.
class NWindowAlert; /// @brief Window alert object
@@ -23,8 +28,9 @@ class NURL; /// @brief URL object. typedef void(*NWindowCallback)(NWindow*);
-typedef int NOSType;
-typedef bool NOSBool;
+typedef int OSType;
+typedef bool Bool;
+typedef void UInt0;
typedef __UINT64_TYPE__ UInt64;
typedef __UINT32_TYPE__ UInt32;
@@ -42,33 +48,30 @@ typedef __INT8_TYPE__ SInt8; class NUser final
{
public:
- /// THOSE REQUIRES PERMISSIONS FROM THE USER. ///
-
- static void Poweroff();
- static void Reboot();
-
- /// THOSE REQUIRES PERMISSIONS FROM THE USER. ///
+ // THOSE REQUIRES PERMISSIONS FROM THE USER. ///
- static NOSBool IsWokeup();
- static void Terminate();
+ static UInt0 Poweroff();
+ static UInt0 Reboot();
+ static Bool IsWokeup();
- /// THOSE DOESNT REQUIRE PERMISSIONS FROM THE USER. ///
+ // THOSE DOESNT REQUIRE PERMISSIONS FROM THE USER. ///
- static NOSBool Exit(NOSType code);
- static void* New(long long sz);
- static void Delete(void* ptr);
+ static UInt0 Terminate();
+ static Bool Exit(OSType code);
+ static UInt0* New(long long sz);
+ static UInt0 Delete(void* ptr);
- /// ASK FOR ELEVATION ///
+ // ASK FOR ELEVATION ///
- static NOSBool RaiseUAC();
+ static Bool RaiseUAC();
- /// THOSE MAY REQUIRE PERMISSIONS FROM THE USER. ///
+ // THOSE MAY REQUIRE PERMISSIONS FROM THE USER. ///
- static NOSType Open(const char* path);
- static void Close(NOSType fd);
+ static OSType Open(const char* path);
+ static UInt0 Close(OSType fd);
static NURL* Execute(const NURL* command);
- static void* Read(const char* forkName, NOSType fd);
- static void* Write(const char* forkName, NOSType fd);
+ static UInt0* Read(const char* forkName, OSType fd);
+ static UInt0* Write(const char* forkName, OSType fd);
};
/**
@@ -97,7 +100,7 @@ public: virtual NWindowAlert* Collect(const char* resultBuf, long resultBufSz) = 0;
public:
- NOSBool fAsyncOperationMode;
+ Bool fAsyncOperationMode;
NWindowCallback fAsyncOnComplete;
};
@@ -129,7 +132,7 @@ public: NWindowCallback onHover = nullptr) = 0;
public:
- NOSBool fWindowEnabled;
+ Bool fWindowEnabled;
void* fWindowDataPtr;
};
diff --git a/Drv/VideoDrv/VideoDrv.c b/Drv/VideoDrv/VideoDrv.c index fc79d2a0..2e389358 100644 --- a/Drv/VideoDrv/VideoDrv.c +++ b/Drv/VideoDrv/VideoDrv.c @@ -6,17 +6,16 @@ #include <DDK/KernelString.h> #include <DDK/KernelPrint.h> - #include <Builtins/GX/GX> int __at_enter(void) { - kernelPrintStr("VideoDrv: Starting up...\r"); + kernelPrintStr("VideoDrv: Starting up GPU...\r"); return 0; } int __at_exit(void) { - kernelPrintStr("VideoDrv: Shutting down...\r"); + kernelPrintStr("VideoDrv: Shutting down GPU...\r"); return 0; } diff --git a/Kernel/KernelKit/FileManager.hpp b/Kernel/KernelKit/FileManager.hpp index b06b926e..c154438e 100644 --- a/Kernel/KernelKit/FileManager.hpp +++ b/Kernel/KernelKit/FileManager.hpp @@ -26,27 +26,35 @@ /// @brief Filesystem abstraction manager. /// Works like the VFS or IFS. -#define kBootFolder "/Boot" -#define kBinFolder "/Applications" -#define kShLibsFolder "/Library" -#define kMountFolder "/Mount" +#define cRestrictR "r" +#define cRestrictRB "rb" +#define cRestrictW "w" +#define cRestrictRW "rw" /// refer to first enum. -#define kFileOpsCount 4 -#define kFileMimeGeneric "application-type/*" +#define cFileOpsCount 4 +#define cFileMimeGeneric "application-type/*" + +/** @brief invalid position. (n-pos) */ +#define kNPos (SizeT)(-1); namespace NewOS { enum { - kFileWriteAll = 100, - kFileReadAll = 101, - kFileReadChunk = 102, - kFileWriteChunk = 103, - kFileIOCnt = (kFileWriteChunk - kFileWriteAll) + 1, + cFileWriteAll = 100, + cFileReadAll = 101, + cFileReadChunk = 102, + cFileWriteChunk = 103, + cFileIOCnt = (cFileWriteChunk - cFileWriteAll) + 1, + }; + + /// @brief filesystem node generic type. + struct PACKED FMNode final { + VoidPtr _Unused; }; - typedef VoidPtr NodePtr; + typedef FMNode* NodePtr; /** @brief Filesystem Manager Interface class @@ -55,7 +63,7 @@ namespace NewOS class FilesystemManagerInterface { public: - FilesystemManagerInterface() = default; + explicit FilesystemManagerInterface() = default; virtual ~FilesystemManagerInterface() = default; public: @@ -87,9 +95,19 @@ namespace NewOS virtual NodePtr Open(_Input const char* path, _Input const char* r) = 0; public: - virtual Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) = 0; - virtual _Output VoidPtr Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT sz) = 0; - + virtual Void Write(_Input NodePtr node, _Input VoidPtr data, + _Input Int32 flags, _Input SizeT size) = 0; + + virtual _Output VoidPtr Read(_Input NodePtr node, + _Input Int32 flags, _Input SizeT sz) = 0; + + virtual Void Write(_Input const Char* name, + _Input NodePtr node, _Input VoidPtr data, + _Input Int32 flags, _Input SizeT size) = 0; + + virtual _Output VoidPtr Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, _Input SizeT sz) = 0; public: virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0; @@ -98,9 +116,6 @@ namespace NewOS virtual bool Rewind(_Input NodePtr node) = 0; }; -/** @brief invalid position. (n-pos) */ -#define kNPos (SizeT)(-1); - #ifdef __FSKIT_NEWFS__ /** * @brief Based of FilesystemManagerInterface, takes care of managing NewFS @@ -128,7 +143,17 @@ namespace NewOS bool Seek(NodePtr node, SizeT off); SizeT Tell(NodePtr node) override; bool Rewind(NodePtr node) override; - + + Void Write(_Input const Char* name, + _Input NodePtr node, _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) override; + + _Output VoidPtr Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) override; + public: void SetResourceFork(const char* forkName); void SetDataFork(const char* forkName); @@ -170,7 +195,7 @@ namespace NewOS if (man) { - man->Write(fFile, data, kFileWriteAll); + man->Write(fFile, data, cFileWriteAll); return ErrorOr<Int64>(0); } @@ -183,7 +208,36 @@ namespace NewOS if (man) { - VoidPtr ret = man->Read(fFile, kFileReadAll, 0); + VoidPtr ret = man->Read(fFile, cFileReadAll, 0); + return ret; + } + + return nullptr; + } + + ErrorOr<Int64> WriteAll(const char* fName, const VoidPtr data) noexcept + { + if (data == nullptr) + return ErrorOr<Int64>(kErrorInvalidData); + + auto man = FSClass::GetMounted(); + + if (man) + { + man->Write(fName, fFile, data, cFileWriteAll); + return ErrorOr<Int64>(0); + } + + return ErrorOr<Int64>(kErrorInvalidData); + } + + VoidPtr Read(const char* fName) noexcept + { + auto man = FSClass::GetMounted(); + + if (man) + { + VoidPtr ret = man->Read(fName, fFile, cFileReadAll, 0); return ret; } @@ -197,7 +251,7 @@ namespace NewOS if (man) { man->Seek(fFile, offset); - auto ret = man->Read(fFile, kFileReadChunk, sz); + auto ret = man->Read(fFile, cFileReadChunk, sz); return ret; } @@ -212,7 +266,7 @@ namespace NewOS if (man) { man->Seek(fFile, offset); - man->Write(fFile, data, sz, kFileReadChunk); + man->Write(fFile, data, sz, cFileReadChunk); } } @@ -231,28 +285,29 @@ namespace NewOS private: NodePtr fFile; - const Char* fMime{kFileMimeGeneric}; + const Char* fMime{cFileMimeGeneric}; }; -#define kRestrictR "r" -#define kRestrictRB "rb" -#define kRestrictW "w" -#define kRestrictRW "rw" - using FileStreamUTF8 = FileStream<Char>; using FileStreamUTF16 = FileStream<WideChar>; typedef UInt64 CursorType; - + + /// @brief constructor template <typename Encoding, typename Class> FileStream<Encoding, Class>::FileStream(const Encoding* path, const Encoding* restrict_type) : fFile(Class::GetMounted()->Open(path, restrict_type)) { + kcout << "newoskrnl: new file: " << path << ".\r"; } - template <typename Encoding, typename Class> - FileStream<Encoding, Class>::~FileStream() = default; + /// @brief destructor + template<typename Encoding, typename Class> + FileStream<Encoding, Class>::~FileStream() + { + delete fFile; + } } // namespace NewOS #define node_cast(PTR) reinterpret_cast<NewOS::NodePtr>(PTR) diff --git a/Kernel/KernelKit/PEFCodeManager.hxx b/Kernel/KernelKit/PEFCodeManager.hxx index b6f3e160..90e674f8 100644 --- a/Kernel/KernelKit/PEFCodeManager.hxx +++ b/Kernel/KernelKit/PEFCodeManager.hxx @@ -10,6 +10,7 @@ #include <KernelKit/PEF.hpp> #include <NewKit/ErrorOr.hpp> #include <NewKit/String.hpp> +#include <KernelKit/FileManager.hpp> #define kPefApplicationMime "application/x-newos-exec" @@ -45,6 +46,7 @@ namespace NewOS bool IsLoaded() noexcept; private: + OwnPtr<FileStream<Char>> fFile; Ref<StringView> fPath; VoidPtr fCachedBlob; bool fFatBinary; diff --git a/Kernel/Sources/FileManager.cxx b/Kernel/Sources/FileManager.cxx index ee285ae1..9f81c260 100644 --- a/Kernel/Sources/FileManager.cxx +++ b/Kernel/Sources/FileManager.cxx @@ -81,6 +81,26 @@ namespace NewOS /// @return Void NewFilesystemManager::Write(NodePtr node, VoidPtr data, Int32 flags, SizeT size) { + auto dataForkName = kNewFSDataFork; + this->Write(dataForkName, node, data, flags, size); + } + + /// @brief Read from filesystem fork. + /// @param node the catalog node. + /// @param flags the flags with it. + /// @param sz the size to read. + /// @return + VoidPtr NewFilesystemManager::Read(NodePtr node, Int32 flags, SizeT sz) + { + auto dataForkName = kNewFSDataFork; + return this->Read(dataForkName, node, flags, sz); + } + + Void NewFilesystemManager::Write(_Input const Char* name, + _Input NodePtr node, _Input VoidPtr data, + _Input Int32 flags, + _Input SizeT size) + { if (!size || size > kNewFSForkSize) return; @@ -90,19 +110,15 @@ namespace NewOS NEWOS_UNUSED(flags); - auto dataForkName = kNewFSDataFork; - if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) fImpl->WriteCatalog(reinterpret_cast<NewCatalog*>(node), data, size, - dataForkName); + name); } - /// @brief Read from filesystem fork. - /// @param node the catalog node. - /// @param flags the flags with it. - /// @param sz the size to read. - /// @return - VoidPtr NewFilesystemManager::Read(NodePtr node, Int32 flags, SizeT sz) + _Output VoidPtr NewFilesystemManager::Read(_Input const Char* name, + _Input NodePtr node, + _Input Int32 flags, + _Input SizeT sz) { if (sz > kNewFSForkSize) return nullptr; @@ -112,11 +128,9 @@ namespace NewOS NEWOS_UNUSED(flags); - auto dataForkName = kNewFSDataFork; - if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) return fImpl->ReadCatalog(reinterpret_cast<NewCatalog*>(node), sz, - dataForkName); + name); return nullptr; } diff --git a/Kernel/Sources/PEFCodeManager.cxx b/Kernel/Sources/PEFCodeManager.cxx index e259885b..f8b50e56 100644 --- a/Kernel/Sources/PEFCodeManager.cxx +++ b/Kernel/Sources/PEFCodeManager.cxx @@ -5,7 +5,6 @@ ------------------------------------------- */ #include <KernelKit/DebugOutput.hpp> -#include <KernelKit/FileManager.hpp> #include <KernelKit/KernelHeap.hpp> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hxx> @@ -49,15 +48,15 @@ namespace NewOS PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fBad(false), fFatBinary(false) { - OwnPtr<FileStream<Char>> file; + fFile.New(const_cast<Char*>(path), cRestrictRB); - file.New(const_cast<Char*>(path), kRestrictRB); - - if (StringBuilder::Equals(file->MIME(), this->MIME())) + if (StringBuilder::Equals(fFile->MIME(), this->MIME())) { fPath = StringBuilder::Construct(path).Leak(); - fCachedBlob = file->Read(); + auto cPefHeader = "PEFContainer"; + + fCachedBlob = fFile->Read(cPefHeader); PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob); @@ -85,7 +84,7 @@ namespace NewOS fBad = true; ke_delete_ke_heap(fCachedBlob); - + fCachedBlob = nullptr; } } @@ -95,6 +94,8 @@ namespace NewOS { if (fCachedBlob) ke_delete_ke_heap(fCachedBlob); + + fFile.Delete(); } VoidPtr PEFLoader::FindSymbol(const char* name, Int32 kind) @@ -104,8 +105,12 @@ namespace NewOS PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob); - PEFCommandHeader* container_header = reinterpret_cast<PEFCommandHeader*>( - (UIntPtr)fCachedBlob + sizeof(PEFContainer)); + StringView cPefHeaderStr = StringBuilder::Construct("PEFContainerHeader:").Leak().Leak(); + cPefHeaderStr += name; + + auto blob = fFile->Read(cPefHeaderStr.CData()); + + PEFCommandHeader* container_header = reinterpret_cast<PEFCommandHeader*>(blob); constexpr auto cMangleCharacter = '$'; const char* cContainerKinds[] = {".code64", ".data64", ".zero64", nullptr}; @@ -114,15 +119,18 @@ namespace NewOS switch (kind) { - case kPefCode: { + case kPefCode: + { errOrSym = StringBuilder::Construct(cContainerKinds[0]); // code symbol. break; } - case kPefData: { + case kPefData: + { errOrSym = StringBuilder::Construct(cContainerKinds[1]); // data symbol. break; } - case kPefZero: { + case kPefZero: + { errOrSym = StringBuilder::Construct(cContainerKinds[2]); // block starting symbol. break; } @@ -152,15 +160,23 @@ namespace NewOS if (container_header->Cpu != Detail::rt_get_pef_platform()) { if (!this->fFatBinary) + { + ke_delete_ke_heap(blob); return nullptr; + } } - return (VoidPtr)(static_cast<UIntPtr*>(fCachedBlob) + - container_header->Offset); + Char* blobRet = new Char[container_header->Size]; + + rt_copy_memory((VoidPtr)((Char*)blob + sizeof(PEFCommandHeader)), blobRet, container_header->Size); + + ke_delete_ke_heap(blob); + return blobRet; } } } - + + ke_delete_ke_heap(blob); return nullptr; } |
