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(HANDLE hProcess, 187 SIZE_T StackReserve, 188 SIZE_T StackCommit, 189 PINITIAL_TEB InitialTeb); 190 191 VOID 192 WINAPI 193 BaseInitializeContext(IN PCONTEXT Context, 194 IN PVOID Parameter, 195 IN PVOID StartAddress, 196 IN PVOID StackAddress, 197 IN ULONG ContextType); 198 199 VOID 200 WINAPI 201 BaseThreadStartupThunk(VOID); 202 203 VOID 204 WINAPI 205 BaseProcessStartThunk(VOID); 206 207 VOID 208 NTAPI 209 BasepFreeActivationContextActivationBlock( 210 IN PBASEP_ACTCTX_BLOCK ActivationBlock 211 ); 212 213 NTSTATUS 214 NTAPI 215 BasepAllocateActivationContextActivationBlock( 216 IN DWORD Flags, 217 IN PVOID CompletionRoutine, 218 IN PVOID CompletionContext, 219 OUT PBASEP_ACTCTX_BLOCK *ActivationBlock 220 ); 221 222 NTSTATUS 223 NTAPI 224 BasepProbeForDllManifest( 225 IN PVOID DllHandle, 226 IN PCWSTR FullDllName, 227 OUT PVOID *ActCtx 228 ); 229 230 __declspec(noreturn) 231 VOID 232 WINAPI 233 BaseThreadStartup(LPTHREAD_START_ROUTINE lpStartAddress, 234 LPVOID lpParameter); 235 236 VOID 237 WINAPI 238 BaseFreeThreadStack(IN HANDLE hProcess, 239 IN PINITIAL_TEB InitialTeb); 240 241 __declspec(noreturn) 242 VOID 243 WINAPI 244 BaseFiberStartup(VOID); 245 246 typedef UINT (WINAPI *PPROCESS_START_ROUTINE)(VOID); 247 248 VOID 249 WINAPI 250 BaseProcessStartup(PPROCESS_START_ROUTINE lpStartAddress); 251 252 PVOID 253 WINAPI 254 BasepIsRealtimeAllowed(IN BOOLEAN Keep); 255 256 VOID 257 WINAPI 258 BasepAnsiStringToHeapUnicodeString(IN LPCSTR AnsiString, 259 OUT LPWSTR* UnicodeString); 260 261 PUNICODE_STRING 262 WINAPI 263 Basep8BitStringToStaticUnicodeString(IN LPCSTR AnsiString); 264 265 BOOLEAN 266 WINAPI 267 Basep8BitStringToDynamicUnicodeString(OUT PUNICODE_STRING UnicodeString, 268 IN LPCSTR String); 269 270 typedef NTSTATUS (NTAPI *PRTL_CONVERT_STRING)(IN PUNICODE_STRING UnicodeString, 271 IN PANSI_STRING AnsiString, 272 IN BOOLEAN AllocateMemory); 273 274 typedef ULONG (NTAPI *PRTL_COUNT_STRING)(IN PUNICODE_STRING UnicodeString); 275 276 typedef NTSTATUS (NTAPI *PRTL_CONVERT_STRINGA)(IN PANSI_STRING AnsiString, 277 IN PCUNICODE_STRING UnicodeString, 278 IN BOOLEAN AllocateMemory); 279 280 typedef ULONG (NTAPI *PRTL_COUNT_STRINGA)(IN PANSI_STRING UnicodeString); 281 282 ULONG 283 NTAPI 284 BasepUnicodeStringToAnsiSize(IN PUNICODE_STRING String); 285 286 ULONG 287 NTAPI 288 BasepAnsiStringToUnicodeSize(IN PANSI_STRING String); 289 290 extern PRTL_CONVERT_STRING Basep8BitStringToUnicodeString; 291 extern PRTL_CONVERT_STRINGA BasepUnicodeStringTo8BitString; 292 extern PRTL_COUNT_STRING BasepUnicodeStringTo8BitSize; 293 extern PRTL_COUNT_STRINGA Basep8BitStringToUnicodeSize; 294 295 extern UNICODE_STRING BaseWindowsDirectory, BaseWindowsSystemDirectory; 296 extern HANDLE BaseNamedObjectDirectory; 297 298 HANDLE 299 WINAPI 300 BaseGetNamedObjectDirectory(VOID); 301 302 NTSTATUS 303 WINAPI 304 BasepMapFile(IN LPCWSTR lpApplicationName, 305 OUT PHANDLE hSection, 306 IN PUNICODE_STRING ApplicationName); 307 308 PCODEPAGE_ENTRY FASTCALL 309 IntGetCodePageEntry(UINT CodePage); 310 311 LPWSTR 312 WINAPI 313 BaseComputeProcessDllPath( 314 IN LPWSTR FullPath, 315 IN PVOID Environment 316 ); 317 318 LPWSTR 319 WINAPI 320 BaseComputeProcessExePath( 321 IN LPWSTR FullPath 322 ); 323 324 ULONG 325 WINAPI 326 BaseIsDosApplication( 327 IN PUNICODE_STRING PathName, 328 IN NTSTATUS Status 329 ); 330 331 NTSTATUS 332 WINAPI 333 BasepCheckBadapp( 334 IN HANDLE FileHandle, 335 IN PWCHAR ApplicationName, 336 IN PWCHAR Environment, 337 IN USHORT ExeType, 338 IN PVOID* SdbQueryAppCompatData, 339 IN PULONG SdbQueryAppCompatDataSize, 340 IN PVOID* SxsData, 341 IN PULONG SxsDataSize, 342 OUT PULONG FusionFlags 343 ); 344 345 BOOLEAN 346 WINAPI 347 IsShimInfrastructureDisabled( 348 VOID 349 ); 350 351 VOID 352 WINAPI 353 InitCommandLines(VOID); 354 355 DWORD 356 WINAPI 357 BaseSetLastNTError(IN NTSTATUS Status); 358 359 VOID 360 NTAPI 361 BasepLocateExeLdrEntry(IN PLDR_DATA_TABLE_ENTRY Entry, 362 IN PVOID Context, 363 OUT BOOLEAN *StopEnumeration); 364 365 typedef NTSTATUS 366 (NTAPI *PBASEP_APPCERT_PLUGIN_FUNC)( 367 IN LPWSTR ApplicationName, 368 IN ULONG CertFlag 369 ); 370 371 typedef NTSTATUS 372 (NTAPI *PBASEP_APPCERT_EMBEDDED_FUNC)( 373 IN LPWSTR ApplicationName 374 ); 375 376 typedef NTSTATUS 377 (NTAPI *PSAFER_REPLACE_PROCESS_THREAD_TOKENS)( 378 IN HANDLE Token, 379 IN HANDLE Process, 380 IN HANDLE Thread 381 ); 382 383 typedef struct _BASEP_APPCERT_ENTRY 384 { 385 LIST_ENTRY Entry; 386 UNICODE_STRING Name; 387 PBASEP_APPCERT_PLUGIN_FUNC fPluginCertFunc; 388 } BASEP_APPCERT_ENTRY, *PBASEP_APPCERT_ENTRY; 389 390 typedef struct _BASE_MSG_SXS_HANDLES 391 { 392 HANDLE File; 393 HANDLE Process; 394 HANDLE Section; 395 LARGE_INTEGER ViewBase; 396 } BASE_MSG_SXS_HANDLES, *PBASE_MSG_SXS_HANDLES; 397 398 typedef struct _SXS_WIN32_NT_PATH_PAIR 399 { 400 PUNICODE_STRING Win32; 401 PUNICODE_STRING Nt; 402 } SXS_WIN32_NT_PATH_PAIR, *PSXS_WIN32_NT_PATH_PAIR; 403 404 typedef struct _SXS_OVERRIDE_MANIFEST 405 { 406 PCWCH Name; 407 PVOID Address; 408 ULONG Size; 409 } SXS_OVERRIDE_MANIFEST, *PSXS_OVERRIDE_MANIFEST; 410 411 NTSTATUS 412 NTAPI 413 BasepConfigureAppCertDlls( 414 IN PWSTR ValueName, 415 IN ULONG ValueType, 416 IN PVOID ValueData, 417 IN ULONG ValueLength, 418 IN PVOID Context, 419 IN PVOID EntryContext 420 ); 421 422 extern LIST_ENTRY BasepAppCertDllsList; 423 extern RTL_CRITICAL_SECTION gcsAppCert; 424 425 VOID 426 WINAPI 427 BaseMarkFileForDelete( 428 IN HANDLE FileHandle, 429 IN ULONG FileAttributes 430 ); 431 432 BOOL 433 BasepCopyFileExW( 434 IN LPCWSTR lpExistingFileName, 435 IN LPCWSTR lpNewFileName, 436 IN LPPROGRESS_ROUTINE lpProgressRoutine OPTIONAL, 437 IN LPVOID lpData OPTIONAL, 438 IN LPBOOL pbCancel OPTIONAL, 439 IN DWORD dwCopyFlags, 440 IN DWORD dwBasepFlags, 441 OUT LPHANDLE lpExistingHandle, 442 OUT LPHANDLE lpNewHandle 443 ); 444 445 BOOL 446 BasepGetVolumeNameForVolumeMountPoint( 447 IN LPCWSTR lpszMountPoint, 448 OUT LPWSTR lpszVolumeName, 449 IN DWORD cchBufferLength, 450 OUT LPBOOL IsAMountPoint 451 ); 452 453 BOOL 454 BasepGetVolumeNameFromReparsePoint( 455 IN LPCWSTR lpszMountPoint, 456 OUT LPWSTR lpszVolumeName, 457 IN DWORD cchBufferLength, 458 OUT LPBOOL IsAMountPoint 459 ); 460 461 BOOL 462 IsThisARootDirectory( 463 IN HANDLE VolumeHandle, 464 IN PUNICODE_STRING NtPathName 465 ); 466 467 /* FIXME: This is EXPORTED! It should go in an external kernel32.h header */ 468 VOID 469 WINAPI 470 BasepFreeAppCompatData( 471 IN PVOID AppCompatData, 472 IN PVOID AppCompatSxsData 473 ); 474 475 NTSTATUS 476 WINAPI 477 BasepCheckWinSaferRestrictions( 478 IN HANDLE UserToken, 479 IN LPWSTR ApplicationName, 480 IN HANDLE FileHandle, 481 OUT PBOOLEAN InJob, 482 OUT PHANDLE NewToken, 483 OUT PHANDLE JobHandle 484 ); 485