1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 Module Name: 6 7 Stub.cpp 8 9 Abstract: 10 11 This is the stub used by UMDF corresponding to the stub used by 12 KMDF. 13 14 It includes definitions of WdfFunctions, WdfBindInfo and WdfDriverGlobals 15 16 On the UMDF side we don't need the thunk for DriverEntry because 17 DriverEntry is invoked by UMDF host. 18 19 For COM API UMDF framework will link the stub in 20 For flat-C API UMDF driver will need to link the stub in 21 (similar to the way KMDF drivers link the stub) 22 23 Environment: 24 25 User mode only 26 27 Revision History: 28 29 --*/ 30 31 #define FX_DYNAMICS_GENERATE_TABLE 1 32 33 #include <ntverp.h> 34 extern "C" { 35 #include "mx.h" 36 } 37 #include "fxmin.hpp" 38 #include "fxldrum.h" 39 #include "fxifr.h" 40 41 #include <strsafe.h> 42 #include <driverspecs.h> 43 44 extern const WDFFUNC *WdfFunctions; 45 46 extern "C" { 47 48 #include "fxdynamics.h" 49 50 #include "..\librarycommon\fxlibrarycommon.h" 51 52 #define KMDF_DEFAULT_NAME "Wdf" ## \ 53 LITERAL(__WDF_MAJOR_VERSION) ## \ 54 "000" //minor version 55 56 57 58 //----------------------------------------------------------------------------- 59 // local prototype definitions 60 //----------------------------------------------------------------------------- 61 62 ULONG WdfLdrDbgPrintOn = 0; 63 64 PCHAR WdfLdrType = KMDF_DEFAULT_NAME; 65 66 } // extern "C" 67 68 #include "umdfstub.h" 69 70 extern "C" 71 NTSTATUS 72 WDF_LIBRARY_COMMISSION( 73 VOID 74 ); 75 76 extern "C" 77 NTSTATUS 78 WDF_LIBRARY_DECOMMISSION( 79 VOID 80 ); 81 82 extern "C" 83 NTSTATUS 84 WDF_LIBRARY_REGISTER_CLIENT( 85 PWDF_BIND_INFO Info, 86 PWDF_DRIVER_GLOBALS * WdfDriverGlobals, 87 PVOID * Context 88 ); 89 90 extern "C" 91 NTSTATUS 92 WDF_LIBRARY_UNREGISTER_CLIENT( 93 PWDF_BIND_INFO Info, 94 PWDF_DRIVER_GLOBALS WdfDriverGlobals 95 ); 96 97 extern "C" { 98 99 WDF_LIBRARY_INFO WdfLibraryInfo = { 100 sizeof(WDF_LIBRARY_INFO), 101 (PFNLIBRARYCOMMISSION) WDF_LIBRARY_COMMISSION, 102 (PFNLIBRARYDECOMMISSION) WDF_LIBRARY_DECOMMISSION, 103 (PFNLIBRARYREGISTERCLIENT) WDF_LIBRARY_REGISTER_CLIENT, 104 (PFNLIBRARYUNREGISTERCLIENT) WDF_LIBRARY_UNREGISTER_CLIENT, 105 { __WUDF_MAJOR_VERSION, __WUDF_MINOR_VERSION, __WUDF_SERVICE_VERSION } 106 }; 107 108 } 109 110 //----------------------------------------------------------------------------- 111 // 112 //----------------------------------------------------------------------------- 113 extern "C" 114 NTSTATUS 115 WDF_LIBRARY_COMMISSION( 116 VOID 117 ) 118 { 119 return FxLibraryCommonCommission(); 120 } 121 122 //----------------------------------------------------------------------------- 123 // 124 //----------------------------------------------------------------------------- 125 extern "C" 126 NTSTATUS 127 WDF_LIBRARY_DECOMMISSION( 128 VOID 129 ) 130 { 131 return FxLibraryCommonDecommission(); 132 } 133 134 #define EVTLOG_MESSAGE_SIZE 70 135 #define RAW_DATA_SIZE 4 136 137 extern "C" 138 NTSTATUS 139 WDF_LIBRARY_REGISTER_CLIENT( 140 PWDF_BIND_INFO Info, 141 PWDF_DRIVER_GLOBALS * WdfDriverGlobals, 142 PVOID * Context 143 ) 144 { 145 NTSTATUS status = STATUS_INVALID_PARAMETER; 146 PFX_DRIVER_GLOBALS pFxDriverGlobals; 147 WCHAR insertString[EVTLOG_MESSAGE_SIZE]; 148 ULONG rawData[RAW_DATA_SIZE]; 149 PCLIENT_INFO clientInfo = NULL; 150 151 __Print((LITERAL(WDF_LIBRARY_REGISTER_CLIENT) ": enter\n")); 152 153 clientInfo = (PCLIENT_INFO)*Context; 154 *Context = NULL; 155 156 ASSERT(Info->Version.Major == WdfLibraryInfo.Version.Major); 157 158 // 159 // NOTE: If the currently loaded library < drivers minor version fail the load 160 // instead of binding to a lower minor version. The reason for that if there 161 // is a newer API or new contract change made the driver shouldn't be using older 162 // API than it was compiled with. 163 // 164 165 if (Info->Version.Minor > WdfLibraryInfo.Version.Minor) { 166 status = StringCchPrintfW(insertString, 167 RTL_NUMBER_OF(insertString), 168 L"Driver Version: %d.%d Umdf Lib. Version: %d.%d", 169 Info->Version.Major, 170 Info->Version.Minor, 171 WdfLibraryInfo.Version.Major, 172 WdfLibraryInfo.Version.Minor); 173 if (!NT_SUCCESS(status)) { 174 __Print(("ERROR: RtlStringCchPrintfW failed with Status 0x%x\n", status)); 175 return status; 176 } 177 rawData[0] = Info->Version.Major; 178 rawData[1] = Info->Version.Minor; 179 rawData[2] = WdfLibraryInfo.Version.Major; 180 rawData[3] = WdfLibraryInfo.Version.Minor; 181 182 183 184 185 186 187 188 189 190 191 192 // 193 // this looks like the best status to return 194 // 195 return STATUS_OBJECT_TYPE_MISMATCH; 196 197 } 198 199 status = FxLibraryCommonRegisterClient(Info, WdfDriverGlobals, clientInfo); 200 201 if (NT_SUCCESS(status)) { 202 // 203 // The context will be a pointer to FX_DRIVER_GLOBALS 204 // 205 *Context = GetFxDriverGlobals(*WdfDriverGlobals); 206 207 // 208 // Set the WDF_BIND_INFO structure pointer in FxDriverGlobals 209 // 210 pFxDriverGlobals = GetFxDriverGlobals(*WdfDriverGlobals); 211 pFxDriverGlobals->WdfBindInfo = Info; 212 } 213 214 return status; 215 } 216 217 extern "C" 218 NTSTATUS 219 WDF_LIBRARY_UNREGISTER_CLIENT( 220 PWDF_BIND_INFO Info, 221 PWDF_DRIVER_GLOBALS WdfDriverGlobals 222 ) 223 { 224 return FxLibraryCommonUnregisterClient(Info, WdfDriverGlobals); 225 } 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 extern "C" { 279 280 //----------------------------------------------------------------------------- 281 // These header files are referenced in order to make internal structures 282 // available in public symbols. Various WDFKD debug commands use these 283 // internal structures to provide information about WDF. 284 //----------------------------------------------------------------------------- 285 286 #ifndef DECLARE_TYPE 287 #define DECLARE_TYPE(Name) Name* _DECL_##Name 288 #endif 289 290 union { 291 292 DECLARE_TYPE (WDF_IFR_HEADER); 293 DECLARE_TYPE (WDF_IFR_RECORD); 294 DECLARE_TYPE (WDF_IFR_OFFSET); 295 DECLARE_TYPE (WDF_BIND_INFO); 296 DECLARE_TYPE (WDF_OBJECT_CONTEXT_TYPE_INFO); 297 DECLARE_TYPE (WDF_POWER_ROUTINE_TIMED_OUT_DATA); 298 DECLARE_TYPE (WDF_BUGCHECK_CODES); 299 DECLARE_TYPE (WDF_REQUEST_FATAL_ERROR_CODES); 300 DECLARE_TYPE (FX_OBJECT_INFO); 301 DECLARE_TYPE (FX_POOL_HEADER); 302 DECLARE_TYPE (FX_POOL); 303 DECLARE_TYPE (FxObject); 304 DECLARE_TYPE (FxContextHeader); 305 // DECLARE_TYPE (FX_DUMP_DRIVER_INFO_ENTRY); // KMDF only 306 DECLARE_TYPE (FxTargetSubmitSyncParams); 307 308 } uAllPublicTypes; 309 310 } // extern "C" end 311 312 //----------------------------------------------------------------------------- 313