mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 07:08:04 +08:00
Revert "feature: Support for opaque IPC handles on Windows and Linux"
This reverts commit 46b1b2783b.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
5fe59104a4
commit
0855219087
@@ -78,7 +78,6 @@ DECLARE_DEBUG_VARIABLE(bool, DisableForceToStateless, false, "Do not force state
|
||||
DECLARE_DEBUG_VARIABLE(bool, ForceTheoreticalMaxWorkGroupCount, false, "Do not apply any limitation to max cooperative/concurrent work-group count queries")
|
||||
DECLARE_DEBUG_VARIABLE(bool, AppendMemoryPrefetchForKmdMigratedSharedAllocations, true, "Allow prefetching shared memory to the device associated with the specified command list")
|
||||
DECLARE_DEBUG_VARIABLE(bool, ForceMemoryPrefetchForKmdMigratedSharedAllocations, false, "Force prefetch of shared memory in command queue execute command lists")
|
||||
DECLARE_DEBUG_VARIABLE(bool, EnableShareableWithoutNTHandle, true, "Enable creating shareable allocations without NT handle on Windows")
|
||||
DECLARE_DEBUG_VARIABLE(bool, ClKhrExternalMemoryExtension, true, "Enable cl_khr_external_memory extension")
|
||||
DECLARE_DEBUG_VARIABLE(bool, WaitForMemoryRelease, false, "Wait for memory release when out of memory")
|
||||
DECLARE_DEBUG_VARIABLE(bool, RemoveRestrictionsOnNumberOfThreadsInGpgpuThreadGroup, 0, "0 - default disabled, 1- remove restrictions on NumberOfThreadsInGpgpuThreadGroup in INTERFACE_DESCRIPTOR_DATA")
|
||||
|
||||
@@ -28,8 +28,7 @@ struct AllocationProperties {
|
||||
uint32_t forceSystemMemory : 1;
|
||||
uint32_t preferCompressed : 1;
|
||||
uint32_t cantBeReadOnly : 1;
|
||||
uint32_t shareableWithoutNTHandle : 1;
|
||||
uint32_t reserved : 16;
|
||||
uint32_t reserved : 18;
|
||||
} flags;
|
||||
uint32_t allFlags = 0;
|
||||
};
|
||||
@@ -113,8 +112,7 @@ struct AllocationData {
|
||||
uint32_t isUSMDeviceMemory : 1;
|
||||
uint32_t zeroMemory : 1;
|
||||
uint32_t cantBeReadOnly : 1;
|
||||
uint32_t shareableWithoutNTHandle : 1;
|
||||
uint32_t reserved : 14;
|
||||
uint32_t reserved : 15;
|
||||
} flags;
|
||||
uint32_t allFlags = 0;
|
||||
};
|
||||
|
||||
@@ -643,7 +643,6 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
|
||||
allocationData.forceKMDAllocation = properties.forceKMDAllocation;
|
||||
allocationData.makeGPUVaDifferentThanCPUPtr = properties.makeGPUVaDifferentThanCPUPtr;
|
||||
allocationData.flags.shareable = properties.flags.shareable;
|
||||
allocationData.flags.shareableWithoutNTHandle = properties.flags.shareableWithoutNTHandle;
|
||||
allocationData.flags.isUSMDeviceMemory = properties.flags.isUSMDeviceAllocation;
|
||||
allocationData.flags.requiresCpuAccess = GraphicsAllocation::isCpuAccessRequired(properties.allocationType);
|
||||
allocationData.flags.allocateMemory = properties.flags.allocateMemory;
|
||||
|
||||
@@ -111,7 +111,6 @@ class MemoryManager {
|
||||
struct OsHandleData {
|
||||
osHandle handle;
|
||||
uint32_t arrayIndex;
|
||||
uint32_t parentProcessId = 0;
|
||||
|
||||
OsHandleData(uint64_t handle, uint32_t arrayIndex = 0) : handle(static_cast<osHandle>(handle)), arrayIndex(arrayIndex){};
|
||||
OsHandleData(void *handle, uint32_t arrayIndex = 0) : handle(toOsHandle(handle)), arrayIndex(arrayIndex){};
|
||||
|
||||
@@ -506,7 +506,6 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size,
|
||||
unifiedMemoryProperties.alignment = alignUpNonZero<size_t>(memoryProperties.alignment, pageSizeForAlignment);
|
||||
unifiedMemoryProperties.flags.isUSMDeviceAllocation = false;
|
||||
unifiedMemoryProperties.flags.shareable = memoryProperties.allocationFlags.flags.shareable;
|
||||
unifiedMemoryProperties.flags.shareableWithoutNTHandle = memoryProperties.allocationFlags.flags.shareableWithoutNTHandle;
|
||||
unifiedMemoryProperties.cacheRegion = MemoryPropertiesHelper::getCacheRegion(memoryProperties.allocationFlags);
|
||||
unifiedMemoryProperties.flags.uncacheable = memoryProperties.allocationFlags.flags.locallyUncachedResource;
|
||||
unifiedMemoryProperties.flags.preferCompressed = compressionEnabled || memoryProperties.allocationFlags.flags.compressedHint;
|
||||
|
||||
@@ -30,7 +30,6 @@ struct MemoryFlags {
|
||||
uint32_t resource48Bit : 1;
|
||||
uint32_t compressedHint : 1;
|
||||
uint32_t uncompressedHint : 1;
|
||||
uint32_t shareableWithoutNTHandle : 1;
|
||||
};
|
||||
|
||||
struct MemoryAllocFlags {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <iostream>
|
||||
#include <poll.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -60,8 +59,6 @@ long sysconf(int name);
|
||||
int mkfifo(const char *pathname, mode_t mode);
|
||||
int pidfdopen(pid_t pid, unsigned int flags);
|
||||
int pidfdgetfd(int pidfd, int targetfd, unsigned int flags);
|
||||
int prctl(int option, unsigned long arg);
|
||||
char **getEnviron();
|
||||
|
||||
} // namespace SysCalls
|
||||
} // namespace NEO
|
||||
|
||||
@@ -205,10 +205,6 @@ int pidfdgetfd(int pidfd, int targetfd, unsigned int flags) {
|
||||
return static_cast<int>(retval);
|
||||
}
|
||||
|
||||
int prctl(int option, unsigned long arg) {
|
||||
return ::prctl(option, arg);
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence) noexcept {
|
||||
return ::lseek(fd, offset, whence);
|
||||
}
|
||||
|
||||
@@ -36,14 +36,6 @@ unsigned int getCurrentProcessId() {
|
||||
return GetCurrentProcessId();
|
||||
}
|
||||
|
||||
BOOL duplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions) {
|
||||
return DuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions);
|
||||
}
|
||||
|
||||
HANDLE openProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) {
|
||||
return OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
|
||||
}
|
||||
|
||||
unsigned long getNumThreads() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,6 @@ BOOL findNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData);
|
||||
BOOL findClose(HANDLE hFindFile);
|
||||
DWORD getFileAttributesA(LPCSTR lpFileName);
|
||||
DWORD setFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
|
||||
BOOL duplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions);
|
||||
HANDLE openProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId);
|
||||
|
||||
void setProcessPowerThrottlingState(ProcessPowerThrottlingState state);
|
||||
void setThreadPriority(ThreadPriority priority);
|
||||
|
||||
@@ -18,8 +18,4 @@ bool Wddm::getReadOnlyFlagValue(const void *cpuPtr) const {
|
||||
bool Wddm::isReadOnlyFlagFallbackSupported() const {
|
||||
return false;
|
||||
}
|
||||
HANDLE Wddm::getSharedHandle(const MemoryManager::OsHandleData &osHandleData) {
|
||||
HANDLE sharedNtHandle = reinterpret_cast<HANDLE>(static_cast<uintptr_t>(osHandleData.handle));
|
||||
return sharedNtHandle;
|
||||
}
|
||||
} // namespace NEO
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/windows/gdi_interface.h"
|
||||
#include "shared/source/os_interface/windows/sys_calls.h"
|
||||
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||
|
||||
namespace NEO {
|
||||
@@ -24,41 +23,4 @@ bool Wddm::getReadOnlyFlagValue(const void *cpuPtr) const {
|
||||
bool Wddm::isReadOnlyFlagFallbackSupported() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
HANDLE Wddm::getSharedHandle(const MemoryManager::OsHandleData &osHandleData) {
|
||||
HANDLE sharedNtHandle = reinterpret_cast<HANDLE>(static_cast<uintptr_t>(osHandleData.handle));
|
||||
if (osHandleData.parentProcessId != 0) {
|
||||
// Open the parent process handle with required access rights
|
||||
HANDLE parentProcessHandle = NEO::SysCalls::openProcess(PROCESS_DUP_HANDLE, FALSE, static_cast<DWORD>(osHandleData.parentProcessId));
|
||||
if (parentProcessHandle == nullptr) {
|
||||
DEBUG_BREAK_IF(true);
|
||||
return sharedNtHandle;
|
||||
}
|
||||
|
||||
// Duplicate the handle from the parent process to the current process
|
||||
// This is necessary to ensure that the handle can be used in the current process context
|
||||
// We use GENERIC_READ | GENERIC_WRITE to ensure we can perform operations on the handle
|
||||
HANDLE duplicatedHandle = nullptr;
|
||||
BOOL duplicateResult = NEO::SysCalls::duplicateHandle(
|
||||
parentProcessHandle,
|
||||
reinterpret_cast<HANDLE>(static_cast<uintptr_t>(osHandleData.handle)),
|
||||
GetCurrentProcess(),
|
||||
&duplicatedHandle,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FALSE,
|
||||
0);
|
||||
|
||||
// Close the parent process handle as we no longer need it
|
||||
// The duplicated handle will be used for further operations
|
||||
NEO::SysCalls::closeHandle(parentProcessHandle);
|
||||
|
||||
if (!duplicateResult) {
|
||||
DEBUG_BREAK_IF(true);
|
||||
return sharedNtHandle;
|
||||
}
|
||||
sharedNtHandle = duplicatedHandle;
|
||||
}
|
||||
return sharedNtHandle;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -664,10 +664,6 @@ bool Wddm::isReadOnlyFlagFallbackAvailable(const D3DKMT_CREATEALLOCATION &create
|
||||
}
|
||||
|
||||
NTSTATUS Wddm::createAllocation(const void *cpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, uint64_t *outSharedHandle) {
|
||||
return createAllocation(cpuPtr, gmm, outHandle, outResourceHandle, outSharedHandle, true);
|
||||
}
|
||||
|
||||
NTSTATUS Wddm::createAllocation(const void *cpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, uint64_t *outSharedHandle, bool createNTHandle) {
|
||||
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||
D3DDDI_ALLOCATIONINFO2 allocationInfo = {};
|
||||
D3DKMT_CREATEALLOCATION createAllocation = {};
|
||||
@@ -708,7 +704,7 @@ NTSTATUS Wddm::createAllocation(const void *cpuPtr, const Gmm *gmm, D3DKMT_HANDL
|
||||
|
||||
outHandle = allocationInfo.hAllocation;
|
||||
outResourceHandle = createAllocation.hResource;
|
||||
if (outSharedHandle && createNTHandle) {
|
||||
if (outSharedHandle) {
|
||||
HANDLE ntSharedHandle = NULL;
|
||||
status = this->createNTHandle(&outResourceHandle, &ntSharedHandle);
|
||||
if (status != STATUS_SUCCESS) {
|
||||
@@ -926,8 +922,7 @@ bool Wddm::verifyNTHandle(HANDLE handle) {
|
||||
bool Wddm::openNTHandle(const MemoryManager::OsHandleData &osHandleData, WddmAllocation *alloc) {
|
||||
D3DKMT_QUERYRESOURCEINFOFROMNTHANDLE queryResourceInfoFromNtHandle = {};
|
||||
queryResourceInfoFromNtHandle.hDevice = device;
|
||||
HANDLE sharedNtHandle = this->getSharedHandle(osHandleData);
|
||||
queryResourceInfoFromNtHandle.hNtHandle = sharedNtHandle;
|
||||
queryResourceInfoFromNtHandle.hNtHandle = reinterpret_cast<HANDLE>(static_cast<uintptr_t>(osHandleData.handle));
|
||||
[[maybe_unused]] auto status = getGdi()->queryResourceInfoFromNtHandle(&queryResourceInfoFromNtHandle);
|
||||
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
||||
|
||||
@@ -943,7 +938,7 @@ bool Wddm::openNTHandle(const MemoryManager::OsHandleData &osHandleData, WddmAll
|
||||
D3DKMT_OPENRESOURCEFROMNTHANDLE openResourceFromNtHandle = {};
|
||||
|
||||
openResourceFromNtHandle.hDevice = device;
|
||||
openResourceFromNtHandle.hNtHandle = sharedNtHandle;
|
||||
openResourceFromNtHandle.hNtHandle = reinterpret_cast<HANDLE>(static_cast<uintptr_t>(osHandleData.handle));
|
||||
openResourceFromNtHandle.NumAllocations = queryResourceInfoFromNtHandle.NumAllocations;
|
||||
openResourceFromNtHandle.pOpenAllocationInfo2 = allocationInfo2.get();
|
||||
openResourceFromNtHandle.pTotalPrivateDriverDataBuffer = allocPrivateData.get();
|
||||
|
||||
@@ -74,7 +74,6 @@ class Wddm : public DriverModel {
|
||||
MOCKABLE_VIRTUAL uint64_t freeGmmGpuVirtualAddress(Gmm *gmm, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size);
|
||||
MOCKABLE_VIRTUAL bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size);
|
||||
MOCKABLE_VIRTUAL NTSTATUS createAllocation(const void *cpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, uint64_t *outSharedHandle);
|
||||
MOCKABLE_VIRTUAL NTSTATUS createAllocation(const void *cpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, uint64_t *outSharedHandle, bool createNTHandle);
|
||||
MOCKABLE_VIRTUAL bool createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle);
|
||||
MOCKABLE_VIRTUAL NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles);
|
||||
MOCKABLE_VIRTUAL bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
|
||||
@@ -92,7 +91,6 @@ class Wddm : public DriverModel {
|
||||
MOCKABLE_VIRTUAL bool destroyContext(D3DKMT_HANDLE context);
|
||||
MOCKABLE_VIRTUAL bool queryAdapterInfo();
|
||||
MOCKABLE_VIRTUAL NTSTATUS createNTHandle(const D3DKMT_HANDLE *resourceHandle, HANDLE *ntHandle);
|
||||
MOCKABLE_VIRTUAL HANDLE getSharedHandle(const MemoryManager::OsHandleData &osHandleData);
|
||||
|
||||
MOCKABLE_VIRTUAL bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, WddmSubmitArguments &submitArguments);
|
||||
MOCKABLE_VIRTUAL bool waitFromCpu(uint64_t lastFenceValue, const MonitoredFence &monitoredFence, bool busyWait);
|
||||
|
||||
@@ -90,9 +90,6 @@ class WddmAllocation : public GraphicsAllocation {
|
||||
void setMakeResidentBeforeLockRequired(bool makeResidentBeforeLockRequired) { this->makeResidentBeforeLockRequired = makeResidentBeforeLockRequired; }
|
||||
bool isAllocInFrontWindowPool() const { return allocInFrontWindowPool; }
|
||||
void setAllocInFrontWindowPool(bool allocInFrontWindowPool) { this->allocInFrontWindowPool = allocInFrontWindowPool; }
|
||||
bool isShareable() const { return shareable; }
|
||||
bool isShareableWithoutNTHandle() const { return shareableWithoutNTHandle; }
|
||||
void setShareableWithoutNTHandle(bool shareableWithoutNTHandle) { this->shareableWithoutNTHandle = shareableWithoutNTHandle; }
|
||||
bool isPhysicalMemoryReservation() const { return physicalMemoryReservation; }
|
||||
void setPhysicalMemoryReservation(bool physicalMemoryReservation) { this->physicalMemoryReservation = physicalMemoryReservation; }
|
||||
bool isMappedPhysicalMemoryReservation() const { return mappedPhysicalMemoryReservation; }
|
||||
@@ -128,6 +125,5 @@ class WddmAllocation : public GraphicsAllocation {
|
||||
bool physicalMemoryReservation = false;
|
||||
bool mappedPhysicalMemoryReservation = false;
|
||||
bool makeResidentBeforeLockRequired = false;
|
||||
bool shareableWithoutNTHandle = false;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -147,7 +147,6 @@ GraphicsAllocation *WddmMemoryManager::allocatePhysicalDeviceMemory(const Alloca
|
||||
1u, // numGmms
|
||||
allocationData.type, nullptr, 0, allocationData.size, nullptr,
|
||||
MemoryPool::systemCpuInaccessible, allocationData.flags.shareable, maxOsContextCount);
|
||||
allocation->setShareableWithoutNTHandle(allocationData.flags.shareableWithoutNTHandle);
|
||||
allocation->setDefaultGmm(gmm.get());
|
||||
if (!createPhysicalAllocation(allocation.get())) {
|
||||
return nullptr;
|
||||
@@ -176,7 +175,6 @@ GraphicsAllocation *WddmMemoryManager::allocateMemoryByKMD(const AllocationData
|
||||
1u, // numGmms
|
||||
allocationData.type, nullptr, 0, allocationData.size, nullptr,
|
||||
MemoryPool::systemCpuInaccessible, allocationData.flags.shareable, maxOsContextCount);
|
||||
allocation->setShareableWithoutNTHandle(allocationData.flags.shareableWithoutNTHandle);
|
||||
allocation->setDefaultGmm(gmm.get());
|
||||
void *requiredGpuVa = nullptr;
|
||||
adjustGpuPtrToHostAddressSpace(*allocation.get(), requiredGpuVa);
|
||||
@@ -618,6 +616,7 @@ bool WddmMemoryManager::isNTHandle(osHandle handle, uint32_t rootDeviceIndex) {
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(const OsHandleData &osHandleData, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) {
|
||||
auto allocation = std::make_unique<WddmAllocation>(properties.rootDeviceIndex, 1u /*num gmms*/, properties.allocationType, nullptr, 0, osHandleData.handle, MemoryPool::systemCpuInaccessible, maxOsContextCount, 0llu);
|
||||
|
||||
bool status;
|
||||
if (verifyHandle(osHandleData.handle, properties.rootDeviceIndex, false))
|
||||
status = getWddm(properties.rootDeviceIndex).openSharedHandle(osHandleData, allocation.get());
|
||||
@@ -1132,11 +1131,10 @@ bool WddmMemoryManager::mapMultiHandleAllocationWithRetry(WddmAllocation *alloca
|
||||
bool WddmMemoryManager::createGpuAllocationsWithRetry(WddmAllocation *allocation) {
|
||||
for (auto handleId = 0u; handleId < allocation->getNumGmms(); handleId++) {
|
||||
auto gmm = allocation->getGmm(handleId);
|
||||
bool createNTHandle = allocation->isShareable() && !allocation->isShareableWithoutNTHandle();
|
||||
auto status = getWddm(allocation->getRootDeviceIndex()).createAllocation(allocation->getUnderlyingBuffer(), gmm, allocation->getHandleToModify(handleId), allocation->getResourceHandleToModify(), allocation->getSharedHandleToModify(), createNTHandle);
|
||||
auto status = getWddm(allocation->getRootDeviceIndex()).createAllocation(allocation->getUnderlyingBuffer(), gmm, allocation->getHandleToModify(handleId), allocation->getResourceHandleToModify(), allocation->getSharedHandleToModify());
|
||||
if (status == STATUS_GRAPHICS_NO_VIDEO_MEMORY && deferredDeleter) {
|
||||
deferredDeleter->drain(true, false);
|
||||
status = getWddm(allocation->getRootDeviceIndex()).createAllocation(allocation->getUnderlyingBuffer(), gmm, allocation->getHandleToModify(handleId), allocation->getResourceHandleToModify(), allocation->getSharedHandleToModify(), createNTHandle);
|
||||
status = getWddm(allocation->getRootDeviceIndex()).createAllocation(allocation->getUnderlyingBuffer(), gmm, allocation->getHandleToModify(handleId), allocation->getResourceHandleToModify(), allocation->getSharedHandleToModify());
|
||||
}
|
||||
if (status != STATUS_SUCCESS) {
|
||||
getWddm(allocation->getRootDeviceIndex()).destroyAllocations(&allocation->getHandles()[0], handleId, allocation->getResourceHandle());
|
||||
@@ -1370,7 +1368,6 @@ GraphicsAllocation *WddmMemoryManager::allocatePhysicalLocalDeviceMemory(const A
|
||||
|
||||
auto wddmAllocation = std::make_unique<WddmAllocation>(allocationData.rootDeviceIndex, singleBankAllocation ? numGmms : numBanks,
|
||||
allocationData.type, nullptr, 0, sizeAligned, nullptr, MemoryPool::localMemory, allocationData.flags.shareable, maxOsContextCount);
|
||||
wddmAllocation->setShareableWithoutNTHandle(allocationData.flags.shareableWithoutNTHandle);
|
||||
if (singleBankAllocation) {
|
||||
if (numGmms > 1) {
|
||||
splitGmmsInAllocation(gmmHelper, wddmAllocation.get(), alignment, chunkSize, const_cast<StorageInfo &>(allocationData.storageInfo));
|
||||
@@ -1466,7 +1463,6 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryInDevicePool(const
|
||||
|
||||
auto wddmAllocation = std::make_unique<WddmAllocation>(allocationData.rootDeviceIndex, singleBankAllocation ? numGmms : numBanks,
|
||||
allocationData.type, nullptr, 0, sizeAligned, nullptr, MemoryPool::localMemory, allocationData.flags.shareable, maxOsContextCount);
|
||||
wddmAllocation->setShareableWithoutNTHandle(allocationData.flags.shareableWithoutNTHandle);
|
||||
if (singleBankAllocation) {
|
||||
if (numGmms > 1) {
|
||||
splitGmmsInAllocation(gmmHelper, wddmAllocation.get(), alignment, chunkSize, const_cast<StorageInfo &>(allocationData.storageInfo));
|
||||
|
||||
@@ -141,30 +141,6 @@ NTSTATUS WddmMock::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D
|
||||
return createAllocationStatus;
|
||||
}
|
||||
|
||||
NTSTATUS WddmMock::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, uint64_t *outSharedHandle, bool createNTHandle) {
|
||||
createAllocationResult.called++;
|
||||
if (failCreateAllocation) {
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
if (callBaseDestroyAllocations) {
|
||||
createAllocationStatus = Wddm::createAllocation(alignedCpuPtr, gmm, outHandle, outResourceHandle, outSharedHandle, createNTHandle);
|
||||
createAllocationResult.success = createAllocationStatus == STATUS_SUCCESS;
|
||||
if (createAllocationStatus != STATUS_SUCCESS) {
|
||||
destroyAllocationResult.called++;
|
||||
}
|
||||
} else {
|
||||
createAllocationResult.success = true;
|
||||
outHandle = ALLOCATION_HANDLE;
|
||||
outResourceHandle = ALLOCATION_HANDLE;
|
||||
if (outSharedHandle && !createNTHandle) {
|
||||
// For shared allocations without NT handle, set a special value
|
||||
*outSharedHandle = 1u;
|
||||
}
|
||||
return createAllocationStatus;
|
||||
}
|
||||
return createAllocationStatus;
|
||||
}
|
||||
|
||||
bool WddmMock::createAllocation64k(WddmAllocation *wddmAllocation) {
|
||||
if (wddmAllocation) {
|
||||
return createAllocation(wddmAllocation->getDefaultGmm(), wddmAllocation->getHandleToModify(0u));
|
||||
|
||||
@@ -82,7 +82,6 @@ class WddmMock : public Wddm {
|
||||
bool mapGpuVirtualAddress(WddmAllocation *allocation);
|
||||
bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) override;
|
||||
NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResource, uint64_t *outSharedHandle) override;
|
||||
NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResource, uint64_t *outSharedHandle, bool createNTHandle) override;
|
||||
bool createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle) override;
|
||||
bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) override;
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ int readdirCalled = 0;
|
||||
int closedirCalled = 0;
|
||||
int pidfdopenCalled = 0;
|
||||
int pidfdgetfdCalled = 0;
|
||||
int prctlCalled = 0;
|
||||
int fsyncCalled = 0;
|
||||
int fsyncArgPassed = 0;
|
||||
int fsyncRetVal = 0;
|
||||
@@ -117,7 +116,6 @@ int (*sysCallsClosedir)(DIR *dir) = nullptr;
|
||||
int (*sysCallsGetDevicePath)(int deviceFd, char *buf, size_t &bufSize) = nullptr;
|
||||
int (*sysCallsPidfdOpen)(pid_t pid, unsigned int flags) = nullptr;
|
||||
int (*sysCallsPidfdGetfd)(int pidfd, int fd, unsigned int flags) = nullptr;
|
||||
int (*sysCallsPrctl)(int option, unsigned long arg) = nullptr;
|
||||
off_t lseekReturn = 4096u;
|
||||
std::atomic<int> lseekCalledCount(0);
|
||||
long sysconfReturn = 1ull << 30;
|
||||
@@ -557,15 +555,6 @@ int pidfdgetfd(int pid, int targetfd, unsigned int flags) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int prctl(int option, unsigned long arg) {
|
||||
prctlCalled++;
|
||||
if (sysCallsPrctl != nullptr) {
|
||||
return sysCallsPrctl(option, arg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char **getEnviron() {
|
||||
return NEO::ULT::getCurrentEnviron();
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ extern int (*sysCallsGetDevicePath)(int deviceFd, char *buf, size_t &bufSize);
|
||||
extern int (*sysCallsClose)(int fileDescriptor);
|
||||
extern int (*sysCallsPidfdOpen)(pid_t pid, unsigned int flags);
|
||||
extern int (*sysCallsPidfdGetfd)(int pidfd, int fd, unsigned int flags);
|
||||
extern int (*sysCallsPrctl)(int option, unsigned long arg);
|
||||
|
||||
extern bool allowFakeDevicePath;
|
||||
extern int flockRetVal;
|
||||
@@ -94,7 +93,6 @@ extern bool failAccess;
|
||||
extern int setErrno;
|
||||
extern int pidfdopenCalled;
|
||||
extern int pidfdgetfdCalled;
|
||||
extern int prctlCalled;
|
||||
|
||||
extern std::vector<void *> mmapVector;
|
||||
extern std::vector<void *> mmapCapturedExtendedPointers;
|
||||
|
||||
@@ -67,8 +67,6 @@ extern CONFIGRET (*sysCallsCmGetDeviceInterfaceListSize)(PULONG pulLen, LPGUID i
|
||||
extern CONFIGRET (*sysCallsCmGetDeviceInterfaceList)(LPGUID interfaceClassGuid, DEVINSTID_W pDeviceID, PZZWSTR buffer, ULONG bufferLen, ULONG ulFlags);
|
||||
extern LPVOID (*sysCallsHeapAlloc)(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
|
||||
extern BOOL (*sysCallsHeapFree)(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
|
||||
extern BOOL (*sysCallsDuplicateHandle)(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions);
|
||||
extern HANDLE (*sysCallsOpenProcess)(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId);
|
||||
|
||||
extern BOOL (*sysCallsGetModuleHandleExW)(DWORD dwFlags, LPCWSTR lpModuleName, HMODULE *phModule);
|
||||
extern DWORD (*sysCallsGetModuleFileNameW)(HMODULE hModule, LPWSTR lpFilename, DWORD nSize);
|
||||
|
||||
@@ -120,12 +120,6 @@ LPVOID(*sysCallsHeapAlloc)
|
||||
BOOL(*sysCallsHeapFree)
|
||||
(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem) = nullptr;
|
||||
|
||||
BOOL(*sysCallsDuplicateHandle)
|
||||
(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions) = nullptr;
|
||||
|
||||
HANDLE(*sysCallsOpenProcess)
|
||||
(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) = nullptr;
|
||||
|
||||
void exit(int code) {
|
||||
}
|
||||
|
||||
@@ -350,20 +344,6 @@ BOOL heapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem) {
|
||||
return HeapFree(hHeap, dwFlags, lpMem);
|
||||
}
|
||||
|
||||
BOOL duplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions) {
|
||||
if (sysCallsDuplicateHandle != nullptr) {
|
||||
return sysCallsDuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
HANDLE openProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) {
|
||||
if (sysCallsOpenProcess != nullptr) {
|
||||
return sysCallsOpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LSTATUS regOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult) {
|
||||
if (regOpenKeySuccessCount > 0) {
|
||||
regOpenKeySuccessCount--;
|
||||
|
||||
@@ -666,5 +666,4 @@ SplitBcsAggregatedEventsMode = -1
|
||||
SplitBcsRequiredTileCount = -1
|
||||
SplitBcsRequiredEnginesCount = -1
|
||||
SplitBcsTransferDirectionMask = -1
|
||||
EnableShareableWithoutNTHandle = -1
|
||||
# Please don't edit below this line
|
||||
|
||||
@@ -73,44 +73,7 @@ TEST_F(WdmmSharedTests, WhenCreatingSharedAllocationAndGetNTHandleFailedThenAllo
|
||||
Gmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), nullptr, 20, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements);
|
||||
|
||||
EXPECT_NE(STATUS_SUCCESS, wddm->createAllocation(nullptr, &gmm, handle, resourceHandle, &ntHandle));
|
||||
EXPECT_EQ(wddm->destroyAllocationResult.called++, 2u);
|
||||
EXPECT_EQ(handle, 0u);
|
||||
EXPECT_EQ(resourceHandle, 0u);
|
||||
}
|
||||
|
||||
TEST_F(WdmmSharedTests, WhenCreatingSharedAllocationWithShareableWithoutNTHandleFlagThenNTHandleIsNotCreated) {
|
||||
init();
|
||||
|
||||
D3DKMT_HANDLE handle = 32u;
|
||||
D3DKMT_HANDLE resourceHandle = 32u;
|
||||
uint64_t ntHandle = 0u;
|
||||
GmmRequirements gmmRequirements{};
|
||||
gmmRequirements.allowLargePages = true;
|
||||
gmmRequirements.preferCompressed = true;
|
||||
Gmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), nullptr, 20, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements);
|
||||
|
||||
// Test with createNTHandle = false (shareableWithoutNTHandle = true)
|
||||
EXPECT_EQ(STATUS_SUCCESS, wddm->createAllocation(nullptr, &gmm, handle, resourceHandle, &ntHandle, false));
|
||||
EXPECT_NE(handle, 0u);
|
||||
EXPECT_NE(resourceHandle, 0u);
|
||||
EXPECT_EQ(ntHandle, 0u); // Should be set to 1 to indicate shared resource without NT handle
|
||||
EXPECT_EQ(wddm->destroyAllocationResult.called, 0u);
|
||||
}
|
||||
|
||||
TEST_F(WdmmSharedTests, WhenCreatingSharedAllocationWithNormalShareableFlagThenNTHandleCreationIsAttempted) {
|
||||
init();
|
||||
|
||||
D3DKMT_HANDLE handle = 32u;
|
||||
D3DKMT_HANDLE resourceHandle = 32u;
|
||||
uint64_t ntHandle = 0u;
|
||||
GmmRequirements gmmRequirements{};
|
||||
gmmRequirements.allowLargePages = true;
|
||||
gmmRequirements.preferCompressed = true;
|
||||
Gmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), nullptr, 20, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements);
|
||||
|
||||
// Test with createNTHandle = true (shareableWithoutNTHandle = false)
|
||||
EXPECT_NE(STATUS_SUCCESS, wddm->createAllocation(nullptr, &gmm, handle, resourceHandle, &ntHandle, true));
|
||||
EXPECT_EQ(wddm->destroyAllocationResult.called, 2u); // Should be called because NT handle creation failed
|
||||
EXPECT_EQ(wddm->destroyAllocationResult.called++, 1u);
|
||||
EXPECT_EQ(handle, 0u);
|
||||
EXPECT_EQ(resourceHandle, 0u);
|
||||
}
|
||||
|
||||
@@ -1200,15 +1200,6 @@ TEST_F(WddmTests, givenPageAlignedReadOnlyMemoryPassedToCreateAllocationsAndMapG
|
||||
EXPECT_FALSE(readWriteExistingSysMemSupportedForTest);
|
||||
}
|
||||
|
||||
TEST_F(WddmTests, givenOsHandleDataWithoutOpaqueInformationWhenGettingSharedHandleThenReturnOriginalHandle) {
|
||||
uint64_t originalHandle = 0x12345678;
|
||||
MemoryManager::OsHandleData osHandleData(originalHandle);
|
||||
|
||||
HANDLE sharedHandle = wddm->getSharedHandle(osHandleData);
|
||||
|
||||
EXPECT_EQ(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(originalHandle)), sharedHandle);
|
||||
}
|
||||
|
||||
TEST_F(WddmTests, whenThereIsNoExisitngSysMemoryThenReadOnlyFallbackIsNotAvailable) {
|
||||
D3DKMT_CREATEALLOCATION createAllocation{};
|
||||
D3DDDI_ALLOCATIONINFO2 allocationInfo2{};
|
||||
@@ -1240,156 +1231,4 @@ TEST_F(WddmTests, givenSysMemoryPointerAndReadOnlyFlagNotSetInCreateAllocationFl
|
||||
auto readOnlyFallbackSupported = wddm->isReadOnlyFlagFallbackSupported();
|
||||
EXPECT_EQ(readOnlyFallbackSupported, wddm->isReadOnlyFlagFallbackAvailable(createAllocation));
|
||||
}
|
||||
|
||||
// Mock class for testing createNTHandle scenarios
|
||||
class WddmCreateNTHandleMock : public WddmMock {
|
||||
public:
|
||||
using WddmMock::WddmMock;
|
||||
|
||||
NTSTATUS createNTHandle(const D3DKMT_HANDLE *resourceHandle, HANDLE *ntHandle) override {
|
||||
createNTHandleCalled = true;
|
||||
lastResourceHandle = resourceHandle ? *resourceHandle : 0;
|
||||
|
||||
if (shouldCreateNTHandleFail) {
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
*ntHandle = reinterpret_cast<HANDLE>(0x12345678);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
bool createNTHandleCalled = false;
|
||||
D3DKMT_HANDLE lastResourceHandle = 0;
|
||||
bool shouldCreateNTHandleFail = false;
|
||||
};
|
||||
|
||||
class WddmCreateAllocationNTHandleTests : public WddmTestWithMockGdiDll {
|
||||
public:
|
||||
void SetUp() override {
|
||||
WddmTestWithMockGdiDll::SetUp();
|
||||
|
||||
// Replace the wddm with our mock
|
||||
mockWddm = new WddmCreateNTHandleMock(*rootDeviceEnvironment);
|
||||
auto wddmMockInterface = new WddmMockInterface20(*mockWddm);
|
||||
mockWddm->wddmInterface.reset(wddmMockInterface);
|
||||
rootDeviceEnvironment->osInterface = std::make_unique<OSInterface>();
|
||||
rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mockWddm));
|
||||
rootDeviceEnvironment->memoryOperationsInterface = std::make_unique<WddmMemoryOperationsHandler>(mockWddm);
|
||||
|
||||
// Initialize the mock WDDM
|
||||
mockWddm->init();
|
||||
}
|
||||
|
||||
void initGmm() {
|
||||
GmmRequirements gmmRequirements{};
|
||||
gmmRequirements.allowLargePages = true;
|
||||
gmmRequirements.preferCompressed = true;
|
||||
gmm = std::make_unique<Gmm>(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(),
|
||||
nullptr, 20, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, StorageInfo{}, gmmRequirements);
|
||||
}
|
||||
|
||||
WddmCreateNTHandleMock *mockWddm = nullptr;
|
||||
std::unique_ptr<Gmm> gmm;
|
||||
};
|
||||
|
||||
TEST_F(WddmCreateAllocationNTHandleTests, givenOutSharedHandleAndCreateNTHandleTrueThenCreateNTHandleIsCalled) {
|
||||
initGmm();
|
||||
|
||||
D3DKMT_HANDLE handle = 0;
|
||||
D3DKMT_HANDLE resourceHandle = 0;
|
||||
uint64_t sharedHandle = 0;
|
||||
|
||||
// Test the condition: outSharedHandle && createNTHandle (both true)
|
||||
auto result = mockWddm->createAllocation(nullptr, gmm.get(), handle, resourceHandle, &sharedHandle, true);
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, result);
|
||||
EXPECT_TRUE(mockWddm->createNTHandleCalled);
|
||||
EXPECT_NE(0u, handle);
|
||||
EXPECT_NE(0u, resourceHandle);
|
||||
EXPECT_NE(0u, sharedHandle);
|
||||
|
||||
// Cleanup
|
||||
EXPECT_TRUE(mockWddm->destroyAllocations(&handle, 1, resourceHandle));
|
||||
}
|
||||
|
||||
TEST_F(WddmCreateAllocationNTHandleTests, givenOutSharedHandleNullAndCreateNTHandleTrueThenCreateNTHandleIsNotCalled) {
|
||||
initGmm();
|
||||
|
||||
D3DKMT_HANDLE handle = 0;
|
||||
D3DKMT_HANDLE resourceHandle = 0;
|
||||
|
||||
// Test the condition: outSharedHandle is null, createNTHandle is true
|
||||
auto result = mockWddm->createAllocation(nullptr, gmm.get(), handle, resourceHandle, nullptr, true);
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, result);
|
||||
EXPECT_FALSE(mockWddm->createNTHandleCalled);
|
||||
EXPECT_NE(0u, handle);
|
||||
// When outSharedHandle is null, CreateResource flag is FALSE, so resourceHandle stays 0
|
||||
EXPECT_EQ(0u, resourceHandle);
|
||||
|
||||
// Cleanup only the handle (no resource handle to clean up)
|
||||
EXPECT_TRUE(mockWddm->destroyAllocations(&handle, 1, 0));
|
||||
}
|
||||
|
||||
TEST_F(WddmCreateAllocationNTHandleTests, givenOutSharedHandleAndCreateNTHandleFalseThenCreateNTHandleIsNotCalled) {
|
||||
initGmm();
|
||||
|
||||
D3DKMT_HANDLE handle = 0;
|
||||
D3DKMT_HANDLE resourceHandle = 0;
|
||||
uint64_t sharedHandle = 0;
|
||||
|
||||
// Test the condition: outSharedHandle is valid, createNTHandle is false
|
||||
auto result = mockWddm->createAllocation(nullptr, gmm.get(), handle, resourceHandle, &sharedHandle, false);
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, result);
|
||||
EXPECT_FALSE(mockWddm->createNTHandleCalled);
|
||||
EXPECT_NE(0u, handle);
|
||||
EXPECT_NE(0u, resourceHandle);
|
||||
EXPECT_EQ(0u, sharedHandle); // Should remain 0 since no NT handle was created
|
||||
|
||||
// Cleanup
|
||||
EXPECT_TRUE(mockWddm->destroyAllocations(&handle, 1, resourceHandle));
|
||||
}
|
||||
|
||||
TEST_F(WddmCreateAllocationNTHandleTests, givenCreateNTHandleFailsThenAllocationIsDestroyedAndHandlesAreReset) {
|
||||
initGmm();
|
||||
|
||||
D3DKMT_HANDLE handle = 0;
|
||||
D3DKMT_HANDLE resourceHandle = 0;
|
||||
uint64_t sharedHandle = 0;
|
||||
|
||||
// Set up the mock to fail createNTHandle
|
||||
mockWddm->shouldCreateNTHandleFail = true;
|
||||
|
||||
// Test the condition: outSharedHandle && createNTHandle (both true) but createNTHandle fails
|
||||
auto result = mockWddm->createAllocation(nullptr, gmm.get(), handle, resourceHandle, &sharedHandle, true);
|
||||
|
||||
EXPECT_NE(STATUS_SUCCESS, result);
|
||||
EXPECT_TRUE(mockWddm->createNTHandleCalled);
|
||||
EXPECT_EQ(0u, handle); // Should be reset to NULL_HANDLE
|
||||
EXPECT_EQ(0u, resourceHandle); // Should be reset to NULL_HANDLE
|
||||
// sharedHandle value is not modified on failure in this path
|
||||
}
|
||||
|
||||
TEST_F(WddmCreateAllocationNTHandleTests, givenCreateNTHandleSucceedsThenSharedHandleIsSet) {
|
||||
initGmm();
|
||||
|
||||
D3DKMT_HANDLE handle = 0;
|
||||
D3DKMT_HANDLE resourceHandle = 0;
|
||||
uint64_t sharedHandle = 0;
|
||||
|
||||
// Test successful createNTHandle path
|
||||
auto result = mockWddm->createAllocation(nullptr, gmm.get(), handle, resourceHandle, &sharedHandle, true);
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, result);
|
||||
EXPECT_TRUE(mockWddm->createNTHandleCalled);
|
||||
EXPECT_EQ(mockWddm->lastResourceHandle, resourceHandle);
|
||||
EXPECT_NE(0u, handle);
|
||||
EXPECT_NE(0u, resourceHandle);
|
||||
EXPECT_EQ(0x12345678u, sharedHandle); // Should be set to the mock handle value
|
||||
|
||||
// Cleanup
|
||||
EXPECT_TRUE(mockWddm->destroyAllocations(&handle, 1, resourceHandle));
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -34,9 +34,6 @@ extern SysCalls::ProcessPowerThrottlingState setProcessPowerThrottlingStateLastV
|
||||
extern size_t setThreadPriorityCalled;
|
||||
extern SysCalls::ThreadPriority setThreadPriorityLastValue;
|
||||
extern MEMORY_BASIC_INFORMATION virtualQueryMemoryBasicInformation;
|
||||
extern size_t closeHandleCalled;
|
||||
extern BOOL (*sysCallsDuplicateHandle)(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions);
|
||||
extern HANDLE (*sysCallsOpenProcess)(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId);
|
||||
} // namespace SysCalls
|
||||
extern uint32_t numRootDevicesToEnum;
|
||||
extern bool gCreateAllocation2FailOnReadOnlyAllocation;
|
||||
@@ -462,99 +459,3 @@ TEST_F(WddmTestWithMockGdiDll, whenGettingReadOnlyFlagThenReturnTrueOnlyForPageM
|
||||
TEST_F(WddmTestWithMockGdiDll, whenGettingReadOnlyFlagFallbackSupportThenTrueIsReturned) {
|
||||
EXPECT_TRUE(wddm->isReadOnlyFlagFallbackSupported());
|
||||
}
|
||||
|
||||
TEST_F(WddmTestWithMockGdiDll, givenOsHandleDataWithoutParentProcessWhenGettingSharedHandleThenReturnOriginalHandle) {
|
||||
uint64_t originalHandle = 0x12345678;
|
||||
MemoryManager::OsHandleData osHandleData(originalHandle);
|
||||
|
||||
HANDLE sharedHandle = wddm->getSharedHandle(osHandleData);
|
||||
|
||||
EXPECT_EQ(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(originalHandle)), sharedHandle);
|
||||
}
|
||||
|
||||
TEST_F(WddmTestWithMockGdiDll, givenOsHandleDataWithParentProcessWhenGettingSharedHandleThenDuplicateHandleFromParentProcess) {
|
||||
uint64_t originalHandle = 0x12345678;
|
||||
uint32_t parentProcessId = 1234;
|
||||
MemoryManager::OsHandleData osHandleData(originalHandle);
|
||||
osHandleData.parentProcessId = parentProcessId;
|
||||
|
||||
HANDLE mockDuplicatedHandle = reinterpret_cast<HANDLE>(0x8888);
|
||||
|
||||
// Mock openProcess to return a valid handle
|
||||
SysCalls::sysCallsOpenProcess = [](DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) -> HANDLE {
|
||||
EXPECT_EQ(static_cast<DWORD>(PROCESS_DUP_HANDLE), dwDesiredAccess);
|
||||
EXPECT_EQ(FALSE, bInheritHandle);
|
||||
EXPECT_EQ(1234u, dwProcessId);
|
||||
return reinterpret_cast<HANDLE>(0x9999);
|
||||
};
|
||||
|
||||
// Mock duplicateHandle to succeed
|
||||
SysCalls::sysCallsDuplicateHandle = [](HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions) -> BOOL {
|
||||
EXPECT_EQ(reinterpret_cast<HANDLE>(0x9999), hSourceProcessHandle);
|
||||
EXPECT_EQ(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(0x12345678)), hSourceHandle);
|
||||
EXPECT_EQ(GetCurrentProcess(), hTargetProcessHandle);
|
||||
EXPECT_EQ(GENERIC_READ | GENERIC_WRITE, dwDesiredAccess);
|
||||
EXPECT_EQ(FALSE, bInheritHandle);
|
||||
EXPECT_EQ(0u, dwOptions);
|
||||
*lpTargetHandle = reinterpret_cast<HANDLE>(0x8888);
|
||||
return TRUE;
|
||||
};
|
||||
|
||||
size_t closeHandleCallsBefore = SysCalls::closeHandleCalled;
|
||||
|
||||
HANDLE sharedHandle = wddm->getSharedHandle(osHandleData);
|
||||
|
||||
EXPECT_EQ(mockDuplicatedHandle, sharedHandle);
|
||||
EXPECT_EQ(closeHandleCallsBefore + 1, SysCalls::closeHandleCalled); // Parent process handle should be closed
|
||||
|
||||
// Cleanup
|
||||
SysCalls::sysCallsOpenProcess = nullptr;
|
||||
SysCalls::sysCallsDuplicateHandle = nullptr;
|
||||
}
|
||||
|
||||
TEST_F(WddmTestWithMockGdiDll, givenOsHandleDataWithParentProcessWhenOpenProcessFailsThenReturnOriginalHandle) {
|
||||
uint64_t originalHandle = 0x12345678;
|
||||
uint32_t parentProcessId = 1234;
|
||||
MemoryManager::OsHandleData osHandleData(originalHandle);
|
||||
osHandleData.parentProcessId = parentProcessId;
|
||||
|
||||
// Mock openProcess to fail
|
||||
SysCalls::sysCallsOpenProcess = [](DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) -> HANDLE {
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
HANDLE sharedHandle = wddm->getSharedHandle(osHandleData);
|
||||
|
||||
EXPECT_EQ(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(originalHandle)), sharedHandle);
|
||||
|
||||
// Cleanup
|
||||
SysCalls::sysCallsOpenProcess = nullptr;
|
||||
}
|
||||
|
||||
TEST_F(WddmTestWithMockGdiDll, givenOsHandleDataWithParentProcessWhenDuplicateHandleFailsThenReturnOriginalHandle) {
|
||||
uint64_t originalHandle = 0x12345678;
|
||||
uint32_t parentProcessId = 1234;
|
||||
MemoryManager::OsHandleData osHandleData(originalHandle);
|
||||
osHandleData.parentProcessId = parentProcessId;
|
||||
|
||||
// Mock openProcess to succeed
|
||||
SysCalls::sysCallsOpenProcess = [](DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) -> HANDLE {
|
||||
return reinterpret_cast<HANDLE>(0x9999);
|
||||
};
|
||||
|
||||
// Mock duplicateHandle to fail
|
||||
SysCalls::sysCallsDuplicateHandle = [](HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions) -> BOOL {
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
size_t closeHandleCallsBefore = SysCalls::closeHandleCalled;
|
||||
|
||||
HANDLE sharedHandle = wddm->getSharedHandle(osHandleData);
|
||||
|
||||
EXPECT_EQ(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(originalHandle)), sharedHandle);
|
||||
EXPECT_EQ(closeHandleCallsBefore + 1, SysCalls::closeHandleCalled); // Parent process handle should still be closed
|
||||
|
||||
// Cleanup
|
||||
SysCalls::sysCallsOpenProcess = nullptr;
|
||||
SysCalls::sysCallsDuplicateHandle = nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user