mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Adding handle verification
Change-Id: I46d6bd2dda46ace927cdfea5f47b0e614d5818f4 Signed-off-by: Koska <andrzej.koska@intel.com> Related-To: NEO-4819
This commit is contained in:
@ -75,6 +75,7 @@ class MemoryManager {
|
||||
|
||||
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr);
|
||||
|
||||
virtual bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool) { return true; }
|
||||
virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) = 0;
|
||||
|
||||
virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) = 0;
|
||||
|
@ -604,6 +604,13 @@ bool Wddm::destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationC
|
||||
|
||||
return status == STATUS_SUCCESS;
|
||||
}
|
||||
bool Wddm::verifySharedHandle(D3DKMT_HANDLE osHandle) {
|
||||
D3DKMT_QUERYRESOURCEINFO QueryResourceInfo = {0};
|
||||
QueryResourceInfo.hDevice = device;
|
||||
QueryResourceInfo.hGlobalShare = osHandle;
|
||||
auto status = getGdi()->queryResourceInfo(&QueryResourceInfo);
|
||||
return status == STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
bool Wddm::openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) {
|
||||
D3DKMT_QUERYRESOURCEINFO QueryResourceInfo = {0};
|
||||
@ -646,6 +653,14 @@ bool Wddm::openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Wddm::verifyNTHandle(HANDLE handle) {
|
||||
D3DKMT_QUERYRESOURCEINFOFROMNTHANDLE queryResourceInfoFromNtHandle = {};
|
||||
queryResourceInfoFromNtHandle.hDevice = device;
|
||||
queryResourceInfoFromNtHandle.hNtHandle = handle;
|
||||
auto status = getGdi()->queryResourceInfoFromNtHandle(&queryResourceInfoFromNtHandle);
|
||||
return status == STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
bool Wddm::openNTHandle(HANDLE handle, WddmAllocation *alloc) {
|
||||
D3DKMT_QUERYRESOURCEINFOFROMNTHANDLE queryResourceInfoFromNtHandle = {};
|
||||
queryResourceInfoFromNtHandle.hDevice = device;
|
||||
|
@ -66,7 +66,9 @@ class Wddm {
|
||||
MOCKABLE_VIRTUAL bool createAllocation64k(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);
|
||||
MOCKABLE_VIRTUAL bool verifySharedHandle(D3DKMT_HANDLE osHandle);
|
||||
MOCKABLE_VIRTUAL bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc);
|
||||
MOCKABLE_VIRTUAL bool verifyNTHandle(HANDLE handle);
|
||||
bool openNTHandle(HANDLE handle, WddmAllocation *alloc);
|
||||
MOCKABLE_VIRTUAL void *lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock, size_t size);
|
||||
MOCKABLE_VIRTUAL void unlockResource(const D3DKMT_HANDLE &handle);
|
||||
|
@ -292,6 +292,12 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
|
||||
return wddmAllocation.release();
|
||||
}
|
||||
|
||||
bool WddmMemoryManager::verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool ntHandle) {
|
||||
bool status = ntHandle ? getWddm(rootDeviceIndex).verifyNTHandle(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(handle)))
|
||||
: getWddm(rootDeviceIndex).verifySharedHandle(handle);
|
||||
return status;
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex) {
|
||||
auto allocation = std::make_unique<WddmAllocation>(rootDeviceIndex, allocationType, nullptr, 0, handle, MemoryPool::SystemCpuInaccessible);
|
||||
|
||||
|
@ -63,6 +63,7 @@ class WddmMemoryManager : public MemoryManager {
|
||||
|
||||
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override { return AddressRange{0, 0}; };
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
||||
bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool ntHandle) override;
|
||||
|
||||
protected:
|
||||
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;
|
||||
|
@ -39,4 +39,29 @@ TEST_F(WddmTests, whenInitializingWddmThenSetMinAddressToCorrectValue) {
|
||||
ASSERT_EQ(expectedMinAddress, wddm->getWddmMinAddress());
|
||||
}
|
||||
|
||||
TEST_F(WddmTests, givenWddmWhenPassesCorrectHandleToVerifySharedHandleThenReturnTrue) {
|
||||
init();
|
||||
D3DKMT_HANDLE handle = 1u;
|
||||
EXPECT_TRUE(wddm->verifySharedHandle(handle));
|
||||
}
|
||||
|
||||
TEST_F(WddmTests, givenWddmWhenPassesIncorrectHandleToVerifySharedHandleThenReturnFalse) {
|
||||
init();
|
||||
D3DKMT_HANDLE handle = 0u;
|
||||
EXPECT_FALSE(wddm->verifySharedHandle(handle));
|
||||
}
|
||||
|
||||
TEST_F(WddmTests, givenWddmWhenPassesCorrectHandleToVerifyNTHandleThenReturnTrue) {
|
||||
init();
|
||||
uint32_t temp = 0;
|
||||
HANDLE handle = &temp;
|
||||
EXPECT_TRUE(wddm->verifyNTHandle(handle));
|
||||
}
|
||||
|
||||
TEST_F(WddmTests, givenWddmWhenPassesIncorrectHandleToVerifyNTHandleThenReturnFalse) {
|
||||
init();
|
||||
HANDLE handle = nullptr;
|
||||
EXPECT_FALSE(wddm->verifyNTHandle(handle));
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
Reference in New Issue
Block a user