File: helper_wddm.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (64 lines) | stat: -rw-r--r-- 2,357 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Copyright (C) 2021-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#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 {

NTSTATUS Wddm::createNTHandle(const D3DKMT_HANDLE *resourceHandle, HANDLE *ntHandle) {
    OBJECT_ATTRIBUTES objAttr = {};
    objAttr.Length = sizeof(OBJECT_ATTRIBUTES);

    return getGdi()->shareObjects(1, resourceHandle, &objAttr, SHARED_ALLOCATION_WRITE, ntHandle);
}

bool Wddm::getReadOnlyFlagValue(const void *cpuPtr) const {
    return !isAligned<MemoryConstants::pageSize>(cpuPtr);
}
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