aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-05-08 03:25:48 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-05-08 03:25:48 -0300
commit4a14379e3fa49714d169b0a3aaa1ed2b38058196 (patch)
tree286e90f21aba80a887d3458a8dfafe667240f352
parent55565f843deb19c6ec46875d58bca33c6338095b (diff)
downloadRNT-4a14379e3fa49714d169b0a3aaa1ed2b38058196.tar.gz
RNT-4a14379e3fa49714d169b0a3aaa1ed2b38058196.zip
handler, object registry, lifecycle and permission stubs
Diffstat (limited to '')
-rw-r--r--.gitignore4
-rw-r--r--Main.vcxproj97
-rw-r--r--Main.vcxproj.filters14
-rw-r--r--Main/Main.cpp11
-rw-r--r--NT.slnx4
-rw-r--r--NT.vcxproj13
-rw-r--r--NT.vcxproj.filters10
-rw-r--r--NtDll.cpp17
-rw-r--r--Runtime/NtContext.cpp10
-rw-r--r--Runtime/NtContext.h182
-rw-r--r--dllmain.cpp19
11 files changed, 355 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore
index a0a00be..f2fd3ed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
.vs
-out \ No newline at end of file
+out
+x64
+*.vcxproj.user
diff --git a/Main.vcxproj b/Main.vcxproj
new file mode 100644
index 0000000..2bfa6bd
--- /dev/null
+++ b/Main.vcxproj
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>18.0</VCProjectVersion>
+ <Keyword>Win32Proj</Keyword>
+ <ProjectGuid>{ea0ab0d0-241f-4bd0-aefe-28d42bd6cf1d}</ProjectGuid>
+ <RootNamespace>Main</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v145</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v145</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v145</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v145</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <ItemDefinitionGroup>
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ <LanguageStandard>stdcpp20</LanguageStandard>
+ <AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="Main\Main.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="NT.vcxproj">
+ <Project>{28338d4e-8618-418d-8728-f71ffaaf5c4e}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
diff --git a/Main.vcxproj.filters b/Main.vcxproj.filters
new file mode 100644
index 0000000..153390a
--- /dev/null
+++ b/Main.vcxproj.filters
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4fc737f1-c7a5-4376-a066-2a32d752a2ff}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="Main\Main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project>
diff --git a/Main/Main.cpp b/Main/Main.cpp
new file mode 100644
index 0000000..5eb314e
--- /dev/null
+++ b/Main/Main.cpp
@@ -0,0 +1,11 @@
+#include <iostream>
+
+#include "Runtime/NtContext.h"
+
+int main()
+{
+ nt::NtContext nt;
+
+ std::cout << "NT context running: " << (nt.IsRunning() ? "yes" : "no") << '\n';
+ return nt.IsRunning() ? 0 : 1;
+}
diff --git a/NT.slnx b/NT.slnx
index 4367f09..b41bc87 100644
--- a/NT.slnx
+++ b/NT.slnx
@@ -3,6 +3,6 @@
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
- <Project Path="../Main/Main.vcxproj" />
- <Project Path="NT.vcxproj" />
+ <Project Path="Main.vcxproj" Id="ea0ab0d0-241f-4bd0-aefe-28d42bd6cf1d" />
+ <Project Path="NT.vcxproj" Id="28338d4e-8618-418d-8728-f71ffaaf5c4e" />
</Solution>
diff --git a/NT.vcxproj b/NT.vcxproj
index e0a063d..5bdceff 100644
--- a/NT.vcxproj
+++ b/NT.vcxproj
@@ -70,10 +70,14 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <TargetName>nt</TargetName>
+ </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;NT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
@@ -92,6 +96,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;NT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
@@ -108,6 +113,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;NT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
@@ -126,6 +132,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
+ <AdditionalIncludeDirectories>$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;NT_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
@@ -141,17 +148,19 @@
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="pch.h" />
+ <ClInclude Include="Runtime\NtContext.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="dllmain.cpp" />
+ <ClCompile Include="NtDll.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
+ <ClCompile Include="Runtime\NtContext.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/NT.vcxproj.filters b/NT.vcxproj.filters
index 1e57c7b..ff46ef1 100644
--- a/NT.vcxproj.filters
+++ b/NT.vcxproj.filters
@@ -21,13 +21,19 @@
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="Runtime\NtContext.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="dllmain.cpp">
+ <ClCompile Include="NtDll.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="Runtime\NtContext.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/NtDll.cpp b/NtDll.cpp
new file mode 100644
index 0000000..160b970
--- /dev/null
+++ b/NtDll.cpp
@@ -0,0 +1,17 @@
+// NtDll.cpp : Defines the entry point for nt.dll.
+#include "pch.h"
+
+BOOL APIENTRY DllMain(HMODULE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved)
+{
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
diff --git a/Runtime/NtContext.cpp b/Runtime/NtContext.cpp
new file mode 100644
index 0000000..248fdaf
--- /dev/null
+++ b/Runtime/NtContext.cpp
@@ -0,0 +1,10 @@
+#include "pch.h"
+#include "Runtime/NtContext.h"
+
+namespace nt
+{
+ bool NtContext::IsRunning() const
+ {
+ return true;
+ }
+}
diff --git a/Runtime/NtContext.h b/Runtime/NtContext.h
new file mode 100644
index 0000000..4e28f9f
--- /dev/null
+++ b/Runtime/NtContext.h
@@ -0,0 +1,182 @@
+#pragma once
+#include <cstdint>
+#include <set>
+#include <vector>
+#include <string>
+
+#ifdef NT_EXPORTS
+#define NT_API __declspec(dllexport)
+#else
+#define NT_API __declspec(dllimport)
+#endif
+
+enum OBJECT_TYPE {
+ MULTIGROUP,
+ RELATION,
+ TUPLE,
+ ATTRIBUTE,
+ TRANSACTION
+};
+
+enum METHOD {
+ OPEN,
+ CLOSE,
+ PARSE, // To plug a secondary namespace
+ SECURITY
+};
+
+enum AUTH_CLAIM {
+ READ,
+ WRITE
+};
+
+enum AUTH_METHOD {
+ CERTIFICATE,
+ PLAIN_TEXT
+};
+
+namespace nt
+{
+ class NT_API ObjectManager
+ {
+ public:
+ class IObject {
+ virtual ~IObject() {}
+ };
+ class Multigroup : IObject {};
+ class Relation : IObject {};
+ class Tuple : IObject {};
+ class Transaction : IObject {};
+ struct object_type {
+ OBJECT_TYPE label;
+ // If the object is not durable. E.g.: TRANSACTION
+ bool disposable;
+ std::set<METHOD> methods;
+ };
+ struct registry_head {
+ uint32_t reference_count;
+ uint32_t handle_count;
+ struct object_type* type;
+ std::vector<std::string> path;
+ //security_descriptor to be added later, maybe also a set of labels
+ };
+ struct registry {
+ struct registry_head* head;
+ IObject object;
+ // TODO: Treat as a list for now, but ideally it's a tree
+ struct registry* next;
+ };
+ struct registry** registry;
+ // Looks into this registry and attempts to retrieve the entry
+ struct registry* Find(const std::vector<std::string> object_path){}
+ };
+
+ class NT_API PermissionsManager
+ {
+ public:
+ // For validating connections at login
+ std::set<AUTH_CLAIM> Firewall(AUTH_METHOD method) {}
+ // For validating permission to an object
+ const bool Access(const std::vector<std::string> object_path, const void* connection_context) {
+ // Checks the security descriptor on the head of the object we find in the ObjectManager::registry
+ // Then additionally check other metadata yet to be defined in the connection_context,
+ // like user group, policy, etc.
+ // Yet to decide if this should be summoned at every attempt to get ahold of an object,
+ // that might produce significant overhead. How can we solve this?
+ }
+ };
+
+ class NT_API NamespaceReferenceManager
+ {
+ };
+
+ class NT_API CursorManager
+ {
+ };
+
+ class NT_API IdentityManager
+ {
+ public:
+ // Looks into the methods of the object type and asserts if it can be opened
+ const bool CanOpen(struct ObjectManager::registry* object) {}
+ };
+
+ class NT_API LifecycleManager
+ {
+ public:
+ // If object is not being monitored already, monitors the lifecycle by updating the handle count.
+ // Maybe also look at the reference count and kill some categories of disposable objects no longer referenced by other objects, like transactions.
+ // Think of other use cases later.
+ void Monitor(struct ObjectManager::registry* object) {}
+ // Serializes contention for the change of a mutable reference.
+ // This can be used in, for example, the HEAD of a branch to serialize the access.
+ // If the object does not causes contention, like a relation (since they are immutable, just like multigroups, all snapshots)
+ // then just approve, as they do not cause any contention. Transactions also do not cause any,
+ // the only things that do are mutable reference states in shared sessions,
+ // for example: the HEAD of a branch, namespace collisions (creating two branches with the same name, or two multigroups with the same name from the same state, etc),
+ // multi-branch atomic commits (which I wish to not have as it damages isolation),
+ // garbage collection of old state (as in, we want to delete an old-enough history to save up space), etc.
+ const bool Contention(struct ObjectManager::registry* object){}
+ // The inverse of `Monitor`, stops monitoring.
+ // Maybe garbage collect here also if the counters goes to zero.
+ void Unmonitor(struct ObjectManager::registry* object) {}
+ };
+
+ class NT_API HandlerManager
+ {
+ public:
+ // This is supposed to represent an authorized access to a certain object in the registry
+ // This increases the handle count in the object manager
+ // We should consider adding on the object manager a vector of all the handles that refer to an object
+ struct handle {};
+ void DeallocateHandle(struct handle* handle) {}
+ struct handle Open(std::vector<std::string> object_path, void* connection_context) {
+ struct ObjectManager::registry* retrieved_object = ObjectManager::Find((const std::vector<std::string>)object_path);
+ if (PermissionsManager::Access(retrieved_object, (const void*)connection_context)
+ && IdentityManager::CanOpen(retrieved_object)
+ && LifecycleManager::Contention(retrieved_object)) {
+ // Starts monitoring this guy
+ LifecycleManager::Monitor(retrieved_object);
+ return {}; // Return a successful handle
+ }
+ else {
+ // Return something more algebraic instead of null or an int
+ return {};
+ };
+ }
+ bool Close(struct handle *handle) {
+ // Somehow grab the object pointer and connection (maybe drop it...) from the handle
+ struct ObjectManager::registry* object = handle->object;
+ void* connection_context = handle->connection_context;
+ // Checking for permissions here may be relevant.
+ // What if we have a handle but no permission? Spooky
+ if (PermissionsManager::Access(object, connection_context)
+ && IdentityManager::CanClose(object)
+ // TODO: I think that in this case we do not need to worry about contention.
+ // But be careful to evaluate this scenario later.
+ //&& LifecycleManager::Contention(retrieved_object)
+ ) {
+ // Stops monitoring this guy
+ LifecycleManager::Unmonitor(object);
+ DeallocateHandle(handle);
+ return true; // Return a successful handle
+ }
+ else {
+ // Return something more algebraic instead of null or an int.
+ // It's kinda bad to not even report what went wrong.
+ return false;
+ };
+ }
+ };
+
+ class NT_API WAM
+ {
+ };
+
+ class NT_API NT
+ {
+ public:
+ bool IsRunning() const;
+ void SimulateEntryCall() {};
+ };
+}
diff --git a/dllmain.cpp b/dllmain.cpp
deleted file mode 100644
index f266597..0000000
--- a/dllmain.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// dllmain.cpp : Defines the entry point for the DLL application.
-#include "pch.h"
-
-BOOL APIENTRY DllMain( HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved
- )
-{
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
-}
-