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