1 #pragma once 2 3 // 4 // Kernel32 Filter IDs 5 // 6 #define kernel32file 200 7 #define kernel32ver 201 8 #define actctx 202 9 #define resource 203 10 #define kernel32session 204 11 #define comm 205 12 #define profile 206 13 #define nls 207 14 15 16 #if DBG 17 #define DEBUG_CHANNEL(ch) static ULONG gDebugChannel = ch; 18 #else 19 #define DEBUG_CHANNEL(ch) 20 #endif 21 22 #define TRACE(fmt, ...) TRACE__(gDebugChannel, fmt, ##__VA_ARGS__) 23 #define WARN(fmt, ...) WARN__(gDebugChannel, fmt, ##__VA_ARGS__) 24 #define FIXME(fmt, ...) WARN__(gDebugChannel, fmt,## __VA_ARGS__) 25 #define ERR(fmt, ...) ERR__(gDebugChannel, fmt, ##__VA_ARGS__) 26 27 #define STUB \ 28 SetLastError(ERROR_CALL_NOT_IMPLEMENTED); \ 29 DPRINT1("%s() is UNIMPLEMENTED!\n", __FUNCTION__) 30 31 #define debugstr_a 32 #define debugstr_w 33 #define debugstr_wn 34 #define wine_dbgstr_w 35 #define debugstr_guid 36 37 #include "wine/unicode.h" 38 #include "baseheap.h" 39 40 #define MAGIC(c1,c2,c3,c4) ((c1) + ((c2)<<8) + ((c3)<<16) + ((c4)<<24)) 41 42 #define MAGIC_HEAP MAGIC( 'H','E','A','P' ) 43 44 #define ROUNDUP(a,b) ((((a)+(b)-1)/(b))*(b)) 45 #define ROUNDDOWN(a,b) (((a)/(b))*(b)) 46 47 #define ROUND_DOWN(n, align) \ 48 (((ULONG)n) & ~((align) - 1l)) 49 50 #define ROUND_UP(n, align) \ 51 ROUND_DOWN(((ULONG)n) + (align) - 1, (align)) 52 53 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) 54 55 #define __TRY _SEH2_TRY 56 #define __EXCEPT_PAGE_FAULT _SEH2_EXCEPT(_SEH2_GetExceptionCode() == STATUS_ACCESS_VIOLATION) 57 #define __ENDTRY _SEH2_END 58 59 /* Undocumented CreateProcess flag */ 60 #define STARTF_SHELLPRIVATE 0x400 61 62 typedef struct _CODEPAGE_ENTRY 63 { 64 LIST_ENTRY Entry; 65 UINT CodePage; 66 HANDLE SectionHandle; 67 PBYTE SectionMapping; 68 CPTABLEINFO CodePageTable; 69 } CODEPAGE_ENTRY, *PCODEPAGE_ENTRY; 70 71 typedef struct tagLOADPARMS32 72 { 73 LPSTR lpEnvAddress; 74 LPSTR lpCmdLine; 75 WORD wMagicValue; 76 WORD wCmdShow; 77 DWORD dwReserved; 78 } LOADPARMS32; 79 80 typedef enum _BASE_SEARCH_PATH_TYPE 81 { 82 BaseSearchPathInvalid, 83 BaseSearchPathDll, 84 BaseSearchPathApp, 85 BaseSearchPathDefault, 86 BaseSearchPathEnv, 87 BaseSearchPathCurrent, 88 BaseSearchPathMax 89 } BASE_SEARCH_PATH_TYPE, *PBASE_SEARCH_PATH_TYPE; 90 91 typedef enum _BASE_CURRENT_DIR_PLACEMENT 92 { 93 BaseCurrentDirPlacementInvalid = -1, 94 BaseCurrentDirPlacementDefault, 95 BaseCurrentDirPlacementSafe, 96 BaseCurrentDirPlacementMax 97 } BASE_CURRENT_DIR_PLACEMENT; 98 99 typedef struct _BASEP_ACTCTX_BLOCK 100 { 101 ULONG Flags; 102 PVOID ActivationContext; 103 PVOID CompletionContext; 104 LPOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine; 105 } BASEP_ACTCTX_BLOCK, *PBASEP_ACTCTX_BLOCK; 106 107 #define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_ERROR 1 108 #define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_SUCCESS 2 109 #define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_CONTINUE 3 110 111 extern PBASE_STATIC_SERVER_DATA BaseStaticServerData; 112 113 typedef 114 DWORD 115 (*WaitForInputIdleType)( 116 HANDLE hProcess, 117 DWORD dwMilliseconds); 118 119 extern WaitForInputIdleType UserWaitForInputIdleRoutine; 120 121 /* Flags for PrivCopyFileExW && BasepCopyFileExW */ 122 #define BASEP_COPY_METADATA 0x10 123 #define BASEP_COPY_SACL 0x20 124 #define BASEP_COPY_OWNER_AND_GROUP 0x40 125 #define BASEP_COPY_DIRECTORY 0x80 126 #define BASEP_COPY_BACKUP_SEMANTICS 0x100 127 #define BASEP_COPY_REPLACE 0x200 128 #define BASEP_COPY_SKIP_DACL 0x400 129 #define BASEP_COPY_PUBLIC_MASK 0xF 130 #define BASEP_COPY_BASEP_MASK 0xFFFFFFF0 131 132 /* Flags for PrivMoveFileIdentityW */ 133 #define PRIV_DELETE_ON_SUCCESS 0x1 134 #define PRIV_ALLOW_NON_TRACKABLE 0x2 135 136 /* GLOBAL VARIABLES **********************************************************/ 137 138 extern BOOL bIsFileApiAnsi; 139 extern HMODULE hCurrentModule; 140 141 extern RTL_CRITICAL_SECTION BaseDllDirectoryLock; 142 143 extern UNICODE_STRING BaseDllDirectory; 144 extern UNICODE_STRING BaseDefaultPath; 145 extern UNICODE_STRING BaseDefaultPathAppend; 146 extern PLDR_DATA_TABLE_ENTRY BasepExeLdrEntry; 147 148 extern LPTOP_LEVEL_EXCEPTION_FILTER GlobalTopLevelExceptionFilter; 149 150 extern SYSTEM_BASIC_INFORMATION BaseCachedSysInfo; 151 152 extern BOOLEAN BaseRunningInServerProcess; 153 154 /* FUNCTION PROTOTYPES *******************************************************/ 155 156 VOID 157 NTAPI 158 BaseDllInitializeMemoryManager(VOID); 159 160 PTEB GetTeb(VOID); 161 162 PWCHAR FilenameA2W(LPCSTR NameA, BOOL alloc); 163 DWORD FilenameW2A_N(LPSTR dest, INT destlen, LPCWSTR src, INT srclen); 164 165 DWORD FilenameW2A_FitOrFail(LPSTR DestA, INT destLen, LPCWSTR SourceW, INT sourceLen); 166 DWORD FilenameU2A_FitOrFail(LPSTR DestA, INT destLen, PUNICODE_STRING SourceU); 167 168 #define HeapAlloc RtlAllocateHeap 169 #define HeapReAlloc RtlReAllocateHeap 170 #define HeapFree RtlFreeHeap 171 #define _lread(a, b, c) (long)(_hread(a, b, (long)c)) 172 173 PLARGE_INTEGER 174 WINAPI 175 BaseFormatTimeOut(OUT PLARGE_INTEGER Timeout, 176 IN DWORD dwMilliseconds); 177 178 POBJECT_ATTRIBUTES 179 WINAPI 180 BaseFormatObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes, 181 IN PSECURITY_ATTRIBUTES SecurityAttributes OPTIONAL, 182 IN PUNICODE_STRING ObjectName); 183 184 NTSTATUS 185 WINAPI 186 BaseCreateStack( 187 _In_ HANDLE hProcess, 188 _In_opt_ SIZE_T StackCommit, 189 _In_opt_ SIZE_T StackReserve, 190 _Out_ PINITIAL_TEB InitialTeb); 191 192 VOID 193 WINAPI 194 BaseFreeThreadStack( 195 _In_ HANDLE hProcess, 196 _In_ PINITIAL_TEB InitialTeb); 197 198 VOID 199 WINAPI 200 BaseInitializeContext(IN PCONTEXT Context, 201 IN PVOID Parameter, 202 IN PVOID StartAddress, 203 IN PVOID StackAddress, 204 IN ULONG ContextType); 205 206 VOID 207 WINAPI 208 BaseThreadStartupThunk(VOID); 209 210 VOID 211 WINAPI 212 BaseProcessStartThunk(VOID); 213 214 VOID 215 NTAPI 216 BasepFreeActivationContextActivationBlock( 217 IN PBASEP_ACTCTX_BLOCK ActivationBlock 218 ); 219 220 NTSTATUS 221 NTAPI 222 BasepAllocateActivationContextActivationBlock( 223 IN DWORD Flags, 224 IN PVOID CompletionRoutine, 225 IN PVOID CompletionContext, 226 OUT PBASEP_ACTCTX_BLOCK *ActivationBlock 227 ); 228 229 NTSTATUS 230 NTAPI 231 BasepProbeForDllManifest( 232 IN PVOID DllHandle, 233 IN PCWSTR FullDllName, 234 OUT PVOID *ActCtx 235 ); 236 237 DECLSPEC_NORETURN 238 VOID 239 WINAPI 240 BaseThreadStartup( 241 _In_ LPTHREAD_START_ROUTINE lpStartAddress, 242 _In_ LPVOID lpParameter); 243 244 DECLSPEC_NORETURN 245 VOID 246 WINAPI 247 BaseFiberStartup(VOID); 248 249 typedef DWORD (WINAPI *PPROCESS_START_ROUTINE)(VOID); 250 251 DECLSPEC_NORETURN 252 VOID 253 WINAPI 254 BaseProcessStartup( 255 _In_ PPROCESS_START_ROUTINE lpStartAddress); 256 257 PVOID 258 WINAPI 259 BasepIsRealtimeAllowed(IN BOOLEAN Keep); 260 261 VOID 262 WINAPI 263 BasepAnsiStringToHeapUnicodeString(IN LPCSTR AnsiString, 264 OUT LPWSTR* UnicodeString); 265 266 PUNICODE_STRING 267 WINAPI 268 Basep8BitStringToStaticUnicodeString(IN LPCSTR AnsiString); 269 270 BOOLEAN 271 WINAPI 272 Basep8BitStringToDynamicUnicodeString(OUT PUNICODE_STRING UnicodeString, 273 IN LPCSTR String); 274 275 typedef NTSTATUS (NTAPI *PRTL_CONVERT_STRING)(IN PUNICODE_STRING UnicodeString, 276 IN PANSI_STRING AnsiString, 277 IN BOOLEAN AllocateMemory); 278 279 typedef ULONG (NTAPI *PRTL_COUNT_STRING)(IN PUNICODE_STRING UnicodeString); 280 281 typedef NTSTATUS (NTAPI *PRTL_CONVERT_STRINGA)(IN PANSI_STRING AnsiString, 282 IN PCUNICODE_STRING UnicodeString, 283 IN BOOLEAN AllocateMemory); 284 285 typedef ULONG (NTAPI *PRTL_COUNT_STRINGA)(IN PANSI_STRING UnicodeString); 286 287 ULONG 288 NTAPI 289 BasepUnicodeStringToAnsiSize(IN PUNICODE_STRING String); 290 291 ULONG 292 NTAPI 293 BasepAnsiStringToUnicodeSize(IN PANSI_STRING String); 294 295 extern PRTL_CONVERT_STRING Basep8BitStringToUnicodeString; 296 extern PRTL_CONVERT_STRINGA BasepUnicodeStringTo8BitString; 297 extern PRTL_COUNT_STRING BasepUnicodeStringTo8BitSize; 298 extern PRTL_COUNT_STRINGA Basep8BitStringToUnicodeSize; 299 300 extern UNICODE_STRING BaseWindowsDirectory, BaseWindowsSystemDirectory; 301 extern HANDLE BaseNamedObjectDirectory; 302 303 HANDLE 304 WINAPI 305 BaseGetNamedObjectDirectory(VOID); 306 307 NTSTATUS 308 WINAPI 309 BasepMapFile(IN LPCWSTR lpApplicationName, 310 OUT PHANDLE hSection, 311 IN PUNICODE_STRING ApplicationName); 312 313 PCODEPAGE_ENTRY FASTCALL 314 IntGetCodePageEntry(UINT CodePage); 315 316 LPWSTR 317 WINAPI 318 BaseComputeProcessDllPath( 319 IN LPWSTR FullPath, 320 IN PVOID Environment 321 ); 322 323 LPWSTR 324 WINAPI 325 BaseComputeProcessExePath( 326 IN LPWSTR FullPath 327 ); 328 329 ULONG 330 WINAPI 331 BaseIsDosApplication( 332 IN PUNICODE_STRING PathName, 333 IN NTSTATUS Status 334 ); 335 336 NTSTATUS 337 WINAPI 338 BasepCheckBadapp( 339 IN HANDLE FileHandle, 340 IN PWCHAR ApplicationName, 341 IN PWCHAR Environment, 342 IN USHORT ExeType, 343 IN PVOID* SdbQueryAppCompatData, 344 IN PULONG SdbQueryAppCompatDataSize, 345 IN PVOID* SxsData, 346 IN PULONG SxsDataSize, 347 OUT PULONG FusionFlags 348 ); 349 350 BOOLEAN 351 WINAPI 352 IsShimInfrastructureDisabled( 353 VOID 354 ); 355 356 VOID 357 WINAPI 358 InitCommandLines(VOID); 359 360 DWORD 361 WINAPI 362 BaseSetLastNTError(IN NTSTATUS Status); 363 364 VOID 365 NTAPI 366 BasepLocateExeLdrEntry(IN PLDR_DATA_TABLE_ENTRY Entry, 367 IN PVOID Context, 368 OUT BOOLEAN *StopEnumeration); 369 370 typedef NTSTATUS 371 (NTAPI *PBASEP_APPCERT_PLUGIN_FUNC)( 372 IN LPWSTR ApplicationName, 373 IN ULONG CertFlag 374 ); 375 376 typedef NTSTATUS 377 (NTAPI *PBASEP_APPCERT_EMBEDDED_FUNC)( 378 IN LPWSTR ApplicationName 379 ); 380 381 typedef NTSTATUS 382 (NTAPI *PSAFER_REPLACE_PROCESS_THREAD_TOKENS)( 383 IN HANDLE Token, 384 IN HANDLE Process, 385 IN HANDLE Thread 386 ); 387 388 typedef struct _BASEP_APPCERT_ENTRY 389 { 390 LIST_ENTRY Entry; 391 UNICODE_STRING Name; 392 PBASEP_APPCERT_PLUGIN_FUNC fPluginCertFunc; 393 } BASEP_APPCERT_ENTRY, *PBASEP_APPCERT_ENTRY; 394 395 typedef struct _BASE_MSG_SXS_HANDLES 396 { 397 HANDLE File; 398 HANDLE Process; 399 HANDLE Section; 400 LARGE_INTEGER ViewBase; 401 } BASE_MSG_SXS_HANDLES, *PBASE_MSG_SXS_HANDLES; 402 403 typedef struct _SXS_WIN32_NT_PATH_PAIR 404 { 405 PUNICODE_STRING Win32; 406 PUNICODE_STRING Nt; 407 } SXS_WIN32_NT_PATH_PAIR, *PSXS_WIN32_NT_PATH_PAIR; 408 409 typedef struct _SXS_OVERRIDE_MANIFEST 410 { 411 PCWCH Name; 412 PVOID Address; 413 ULONG Size; 414 } SXS_OVERRIDE_MANIFEST, *PSXS_OVERRIDE_MANIFEST; 415 416 NTSTATUS 417 NTAPI 418 BasepConfigureAppCertDlls( 419 IN PWSTR ValueName, 420 IN ULONG ValueType, 421 IN PVOID ValueData, 422 IN ULONG ValueLength, 423 IN PVOID Context, 424 IN PVOID EntryContext 425 ); 426 427 extern LIST_ENTRY BasepAppCertDllsList; 428 extern RTL_CRITICAL_SECTION gcsAppCert; 429 430 VOID 431 WINAPI 432 BaseMarkFileForDelete( 433 IN HANDLE FileHandle, 434 IN ULONG FileAttributes 435 ); 436 437 BOOL 438 BasepCopyFileExW( 439 IN LPCWSTR lpExistingFileName, 440 IN LPCWSTR lpNewFileName, 441 IN LPPROGRESS_ROUTINE lpProgressRoutine OPTIONAL, 442 IN LPVOID lpData OPTIONAL, 443 IN LPBOOL pbCancel OPTIONAL, 444 IN DWORD dwCopyFlags, 445 IN DWORD dwBasepFlags, 446 OUT LPHANDLE lpExistingHandle, 447 OUT LPHANDLE lpNewHandle 448 ); 449 450 BOOL 451 BasepGetVolumeNameForVolumeMountPoint( 452 IN LPCWSTR lpszMountPoint, 453 OUT LPWSTR lpszVolumeName, 454 IN DWORD cchBufferLength, 455 OUT LPBOOL IsAMountPoint 456 ); 457 458 BOOL 459 BasepGetVolumeNameFromReparsePoint( 460 IN LPCWSTR lpszMountPoint, 461 OUT LPWSTR lpszVolumeName, 462 IN DWORD cchBufferLength, 463 OUT LPBOOL IsAMountPoint 464 ); 465 466 BOOL 467 IsThisARootDirectory( 468 IN HANDLE VolumeHandle, 469 IN PUNICODE_STRING NtPathName 470 ); 471 472 /* FIXME: This is EXPORTED! It should go in an external kernel32.h header */ 473 VOID 474 WINAPI 475 BasepFreeAppCompatData( 476 IN PVOID AppCompatData, 477 IN PVOID AppCompatSxsData 478 ); 479 480 NTSTATUS 481 WINAPI 482 BasepCheckWinSaferRestrictions( 483 IN HANDLE UserToken, 484 IN LPWSTR ApplicationName, 485 IN HANDLE FileHandle, 486 OUT PBOOLEAN InJob, 487 OUT PHANDLE NewToken, 488 OUT PHANDLE JobHandle 489 ); 490