1 | /* $Id: VBoxICD.c 75562 2018-11-19 10:01:56Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Windows Guest Mesa3D - OpenGL driver loader.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <VBoxWddmUmHlp.h>
|
---|
19 |
|
---|
20 | #include <common/wddm/VBoxMPIf.h>
|
---|
21 |
|
---|
22 | static const char *g_pszGalliumDll =
|
---|
23 | #ifdef VBOX_WOW64
|
---|
24 | "VBoxGL-x86.dll"
|
---|
25 | #else
|
---|
26 | "VBoxGL.dll"
|
---|
27 | #endif
|
---|
28 | ;
|
---|
29 |
|
---|
30 | static const char *g_pszChromiumDll =
|
---|
31 | #ifdef VBOX_WOW64
|
---|
32 | "VBoxOGL-x86.dll"
|
---|
33 | #else
|
---|
34 | "VBoxOGL.dll"
|
---|
35 | #endif
|
---|
36 | ;
|
---|
37 |
|
---|
38 | extern struct VBOXWDDMDLLPROC aIcdProcs[];
|
---|
39 |
|
---|
40 | HMODULE volatile g_hmodICD = NULL;
|
---|
41 |
|
---|
42 | static NTSTATUS
|
---|
43 | vboxDdiQueryAdapterInfo(D3DKMT_HANDLE hAdapter,
|
---|
44 | VBOXWDDM_QAI *pAdapterInfo,
|
---|
45 | uint32_t cbAdapterInfo)
|
---|
46 | {
|
---|
47 | NTSTATUS Status;
|
---|
48 | D3DKMTFUNCTIONS const *d3dkmt = D3DKMTFunctions();
|
---|
49 |
|
---|
50 | if (d3dkmt->pfnD3DKMTQueryAdapterInfo)
|
---|
51 | {
|
---|
52 | D3DKMT_QUERYADAPTERINFO QAI;
|
---|
53 | memset(&QAI, 0, sizeof(QAI));
|
---|
54 | QAI.hAdapter = hAdapter;
|
---|
55 | QAI.Type = KMTQAITYPE_UMDRIVERPRIVATE;
|
---|
56 | QAI.pPrivateDriverData = pAdapterInfo;
|
---|
57 | QAI.PrivateDriverDataSize = cbAdapterInfo;
|
---|
58 |
|
---|
59 | Status = d3dkmt->pfnD3DKMTQueryAdapterInfo(&QAI);
|
---|
60 | }
|
---|
61 | else
|
---|
62 | {
|
---|
63 | Status = STATUS_NOT_SUPPORTED;
|
---|
64 | }
|
---|
65 |
|
---|
66 | return Status;
|
---|
67 | }
|
---|
68 |
|
---|
69 | void VBoxLoadICD(void)
|
---|
70 | {
|
---|
71 | NTSTATUS Status;
|
---|
72 | D3DKMT_HANDLE hAdapter = 0;
|
---|
73 |
|
---|
74 | D3DKMTLoad();
|
---|
75 |
|
---|
76 | Status = vboxDispKmtOpenAdapter(&hAdapter);
|
---|
77 | if (Status == STATUS_SUCCESS)
|
---|
78 | {
|
---|
79 | VBOXWDDM_QAI adapterInfo;
|
---|
80 | Status = vboxDdiQueryAdapterInfo(hAdapter, &adapterInfo, sizeof(adapterInfo));
|
---|
81 | if (Status == STATUS_SUCCESS)
|
---|
82 | {
|
---|
83 | const char *pszDll = NULL;
|
---|
84 | switch (adapterInfo.enmHwType)
|
---|
85 | {
|
---|
86 | case VBOXVIDEO_HWTYPE_VBOX: pszDll = g_pszChromiumDll; break;
|
---|
87 | default:
|
---|
88 | case VBOXVIDEO_HWTYPE_VMSVGA: pszDll = g_pszGalliumDll; break;
|
---|
89 | }
|
---|
90 |
|
---|
91 | if (pszDll)
|
---|
92 | {
|
---|
93 | g_hmodICD = VBoxWddmLoadSystemDll(pszDll);
|
---|
94 | if (g_hmodICD)
|
---|
95 | {
|
---|
96 | VBoxWddmLoadAdresses(g_hmodICD, aIcdProcs);
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | vboxDispKmtCloseAdapter(hAdapter);
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * MSDN says:
|
---|
107 | * "You should never perform the following tasks from within DllMain:
|
---|
108 | * Call LoadLibrary or LoadLibraryEx (either directly or indirectly)."
|
---|
109 | *
|
---|
110 | * However it turned out that loading the real ICD from DLL_PROCESS_ATTACH works,
|
---|
111 | * and loading it in a lazy way fails for unknown reason on 64 bit Windows.
|
---|
112 | *
|
---|
113 | * So just call VBoxLoadICD from DLL_PROCESS_ATTACH.
|
---|
114 | */
|
---|
115 | BOOL WINAPI DllMain(HINSTANCE hDLLInst,
|
---|
116 | DWORD fdwReason,
|
---|
117 | LPVOID lpvReserved)
|
---|
118 | {
|
---|
119 | RT_NOREF(hDLLInst);
|
---|
120 |
|
---|
121 | switch (fdwReason)
|
---|
122 | {
|
---|
123 | case DLL_PROCESS_ATTACH:
|
---|
124 | VBoxLoadICD();
|
---|
125 | break;
|
---|
126 |
|
---|
127 | case DLL_PROCESS_DETACH:
|
---|
128 | if (lpvReserved == NULL)
|
---|
129 | {
|
---|
130 | /* "The DLL is being unloaded because of a call to FreeLibrary." */
|
---|
131 | if (g_hmodICD)
|
---|
132 | {
|
---|
133 | FreeLibrary(g_hmodICD);
|
---|
134 | g_hmodICD = NULL;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | else
|
---|
138 | {
|
---|
139 | /* "The DLL is being unloaded due to process termination." */
|
---|
140 | /* Do not bother. */
|
---|
141 | }
|
---|
142 | break;
|
---|
143 |
|
---|
144 | case DLL_THREAD_ATTACH:
|
---|
145 | break;
|
---|
146 |
|
---|
147 | case DLL_THREAD_DETACH:
|
---|
148 | break;
|
---|
149 |
|
---|
150 | default:
|
---|
151 | break;
|
---|
152 | }
|
---|
153 |
|
---|
154 | return TRUE;
|
---|
155 | }
|
---|