diff --git a/xtoskrnl/includes/ob/devmap.hh b/xtoskrnl/includes/ob/devmap.hh index a03a6d5..3f59e41 100644 --- a/xtoskrnl/includes/ob/devmap.hh +++ b/xtoskrnl/includes/ob/devmap.hh @@ -19,11 +19,14 @@ namespace OB { private: STATIC KPUSH_LOCK DeviceMapLock; + STATIC PDEVICE_MAP SystemDeviceMap; STATIC BOOLEAN UniqueDeviceMaps; public: STATIC XTAPI POBJECT_DIRECTORY GetGlobalDevicesDirectory(IN POBJECT_DIRECTORY Directory); STATIC XTAPI BOOLEAN GetUniqueDeviceMaps(VOID); + STATIC VOID InheritDeviceMap(IN PEPROCESS NewProcess, + IN PEPROCESS ParentProcess); STATIC XTAPI XTSTATUS InitializeDeviceMap(VOID); }; } diff --git a/xtoskrnl/ob/data.cc b/xtoskrnl/ob/data.cc index 01e9a26..cd8cea5 100644 --- a/xtoskrnl/ob/data.cc +++ b/xtoskrnl/ob/data.cc @@ -12,6 +12,9 @@ /* Synchronizes shared read and exclusive write access to system device map structures */ KPUSH_LOCK OB::DeviceMap::DeviceMapLock; +/* Pointer to the system device map */ +PDEVICE_MAP OB::DeviceMap::SystemDeviceMap = NULLPTR; + /* Indicates whether the system employs unique device maps */ BOOLEAN OB::DeviceMap::UniqueDeviceMaps; diff --git a/xtoskrnl/ob/devmap.cc b/xtoskrnl/ob/devmap.cc index 47d751b..7e8bfe4 100644 --- a/xtoskrnl/ob/devmap.cc +++ b/xtoskrnl/ob/devmap.cc @@ -58,6 +58,51 @@ OB::DeviceMap::GetUniqueDeviceMaps(VOID) return UniqueDeviceMaps; } +/** + * Inherits the device map from a parent process or assigns the system default. + * + * @param NewProcess + * Supplies the newly created process that will inherit the device map. + * + * @param ParentProcess + * Supplies the optional parent process to inherit the device map from. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +VOID +OB::DeviceMap::InheritDeviceMap(IN PEPROCESS NewProcess, + IN PEPROCESS ParentProcess) +{ + PDEVICE_MAP TargetDeviceMap; + + /* Acquire the device map lock */ + KE::PushLockExclusiveGuard PushLock(&DeviceMapLock); + + /* Determine the source of the device map */ + if(ParentProcess) + { + /* Inherit the device map from the provided parent process */ + TargetDeviceMap = (PDEVICE_MAP)ParentProcess->DeviceMap; + } + else + { + /* No parent process provided, use system device map */ + TargetDeviceMap = SystemDeviceMap; + } + + /* Check if a valid device map was resolved */ + if(TargetDeviceMap) + { + /* Increment the reference count of the target device map */ + TargetDeviceMap->ReferenceCount++; + + /* Assign the device map to the process */ + NewProcess->DeviceMap = TargetDeviceMap; + } +} + /** * Initializes the Object Manager's device map subsystem. *