Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1171 lines
26 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. basedll.h
  5. Abstract:
  6. This module contains private function prototypes
  7. and types for the 32-bit windows base APIs.
  8. Author:
  9. Mark Lucovsky (markl) 18-Sep-1990
  10. Revision History:
  11. --*/
  12. #ifndef _BASEP_
  13. #define _BASEP_
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #undef UNICODE
  18. //
  19. // Include Common Definitions.
  20. //
  21. #include <base.h>
  22. #include <dbt.h>
  23. #include <sxstypes.h>
  24. //
  25. // Include DLL definitions for CSR
  26. //
  27. #include "ntcsrdll.h"
  28. #include "ntcsrsrv.h"
  29. #define NOEXTAPI
  30. #include <wdbgexts.h>
  31. #include <ntdbg.h>
  32. //
  33. // Include message definitions for communicating between client and server
  34. // portions of the Base portion of the Windows subsystem
  35. //
  36. #include "basemsg.h"
  37. #include "winuserp.h"
  38. #include "basesxs.h"
  39. typedef struct _CMDSHOW {
  40. WORD wMustBe2;
  41. WORD wShowWindowValue;
  42. } CMDSHOW, *PCMDSHOW;
  43. typedef struct _LOAD_MODULE_PARAMS {
  44. LPVOID lpEnvAddress;
  45. LPSTR lpCmdLine;
  46. PCMDSHOW lpCmdShow;
  47. DWORD dwReserved;
  48. } LOAD_MODULE_PARAMS, *PLOAD_MODULE_PARAMS;
  49. typedef struct _RELATIVE_NAME {
  50. STRING RelativeName;
  51. HANDLE ContainingDirectory;
  52. } RELATIVE_NAME, *PRELATIVE_NAME;
  53. HANDLE BaseDllHandle;
  54. HANDLE BaseNamedObjectDirectory;
  55. PVOID BaseHeap;
  56. RTL_HANDLE_TABLE BaseHeapHandleTable;
  57. UNICODE_STRING BaseWindowsDirectory;
  58. UNICODE_STRING BaseWindowsSystemDirectory;
  59. #ifdef WX86
  60. UNICODE_STRING BaseWindowsSys32x86Directory;
  61. #endif
  62. extern UNICODE_STRING BasePathVariableName;
  63. extern UNICODE_STRING BaseTmpVariableName;
  64. extern UNICODE_STRING BaseTempVariableName;
  65. extern UNICODE_STRING BaseUserProfileVariableName;
  66. extern UNICODE_STRING BaseDotVariableName;
  67. extern UNICODE_STRING BaseDotTmpSuffixName;
  68. extern UNICODE_STRING BaseDotComSuffixName;
  69. extern UNICODE_STRING BaseDotPifSuffixName;
  70. extern UNICODE_STRING BaseDotExeSuffixName;
  71. UNICODE_STRING BaseDefaultPath;
  72. UNICODE_STRING BaseDefaultPathAppend;
  73. UNICODE_STRING BaseDllDirectory;
  74. RTL_CRITICAL_SECTION BaseDllDirectoryLock;
  75. PWSTR BaseCSDVersion;
  76. WORD BaseCSDNumber;
  77. WORD BaseRCNumber;
  78. extern UNICODE_STRING BaseConsoleInput;
  79. extern UNICODE_STRING BaseConsoleOutput;
  80. extern UNICODE_STRING BaseConsoleGeneric;
  81. UNICODE_STRING BaseUnicodeCommandLine;
  82. ANSI_STRING BaseAnsiCommandLine;
  83. LPSTARTUPINFOA BaseAnsiStartupInfo;
  84. PBASE_STATIC_SERVER_DATA BaseStaticServerData;
  85. #if defined(BUILD_WOW6432) || defined(_WIN64)
  86. extern SYSTEM_BASIC_INFORMATION SysInfo;
  87. #endif
  88. extern UINT_PTR SystemRangeStart;
  89. extern BOOLEAN BaseRunningInServerProcess;
  90. ULONG BaseIniFileUpdateCount;
  91. #define ROUND_UP_TO_PAGES(SIZE) (((ULONG_PTR)(SIZE) + (ULONG_PTR)BASE_SYSINFO.PageSize - 1) & ~((ULONG_PTR)BASE_SYSINFO.PageSize - 1))
  92. #define ROUND_DOWN_TO_PAGES(SIZE) (((ULONG_PTR)(SIZE)) & ~((ULONG_PTR)BASE_SYSINFO.PageSize - 1))
  93. #define BASE_COPY_FILE_CHUNK (64*1024)
  94. #define BASE_MAX_PATH_STRING 4080
  95. extern BOOLEAN BasepFileApisAreOem;
  96. #define DATA_ATTRIBUTE_NAME L":$DATA"
  97. #define DATA_ATTRIBUTE_LENGTH (sizeof( DATA_ATTRIBUTE_NAME ) - sizeof( WCHAR ))
  98. extern WCHAR BasepDataAttributeType[];
  99. #define CERTAPP_KEY_NAME L"\\Registry\\MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\AppCertDlls"
  100. #define CERTAPP_ENTRYPOINT_NAME "CreateProcessNotify"
  101. #define CERTAPP_EMBEDDED_DLL_NAME L"EmbdTrst.DLL"
  102. #define CERTAPP_EMBEDDED_DLL_EP "ImageOkToRunOnEmbeddedNT"
  103. RTL_CRITICAL_SECTION gcsAppCert;
  104. LIST_ENTRY BasepAppCertDllsList;
  105. RTL_CRITICAL_SECTION gcsAppCompat;
  106. NTSTATUS
  107. BasepConfigureAppCertDlls(
  108. IN PWSTR ValueName,
  109. IN ULONG ValueType,
  110. IN PVOID ValueData,
  111. IN ULONG ValueLength,
  112. IN PVOID Context,
  113. IN PVOID EntryContext
  114. );
  115. NTSTATUS
  116. BasepSaveAppCertRegistryValue(
  117. IN OUT PLIST_ENTRY ListHead,
  118. IN PWSTR Name,
  119. IN PWSTR Value OPTIONAL
  120. );
  121. typedef struct _BASEP_APPCERT_ENTRY {
  122. LIST_ENTRY Entry;
  123. UNICODE_STRING Name;
  124. NTSTATUS (WINAPI *fPluginCertFunc)(LPCWSTR lpApplicationName,ULONG Reason);
  125. } BASEP_APPCERT_ENTRY, *PBASEP_APPCERT_ENTRY;
  126. extern RTL_QUERY_REGISTRY_TABLE BasepAppCertTable[];
  127. #define APPCERT_IMAGE_OK_TO_RUN 1
  128. #define APPCERT_CREATION_ALLOWED 2
  129. #define APPCERT_CREATION_DENIED 3
  130. __inline
  131. BOOL
  132. BasepIsDataAttribute(
  133. ULONG Count,
  134. const WCHAR *Name
  135. )
  136. {
  137. return Count > DATA_ATTRIBUTE_LENGTH &&
  138. !_wcsnicmp( &Name[(Count - DATA_ATTRIBUTE_LENGTH) / sizeof( WCHAR )],
  139. BasepDataAttributeType,
  140. DATA_ATTRIBUTE_LENGTH / sizeof( WCHAR ));
  141. }
  142. PUNICODE_STRING
  143. Basep8BitStringToStaticUnicodeString(
  144. IN LPCSTR SourceString
  145. );
  146. BOOL
  147. Basep8BitStringToDynamicUnicodeString(
  148. OUT PUNICODE_STRING UnicodeString,
  149. IN LPCSTR lpSourceString
  150. );
  151. NTSTATUS
  152. (*Basep8BitStringToUnicodeString)(
  153. PUNICODE_STRING DestinationString,
  154. PANSI_STRING SourceString,
  155. BOOLEAN AllocateDestinationString
  156. );
  157. NTSTATUS
  158. (*BasepUnicodeStringTo8BitString)(
  159. PANSI_STRING DestinationString,
  160. PUNICODE_STRING SourceString,
  161. BOOLEAN AllocateDestinationString
  162. );
  163. ULONG
  164. (*BasepUnicodeStringTo8BitSize)(
  165. PUNICODE_STRING UnicodeString
  166. );
  167. ULONG
  168. BasepUnicodeStringToAnsiSize(
  169. PUNICODE_STRING UnicodeString
  170. );
  171. ULONG
  172. BasepUnicodeStringToOemSize(
  173. PUNICODE_STRING UnicodeString
  174. );
  175. ULONG
  176. (*Basep8BitStringToUnicodeSize)(
  177. PANSI_STRING AnsiString
  178. );
  179. ULONG
  180. BasepAnsiStringToUnicodeSize(
  181. PANSI_STRING AnsiString
  182. );
  183. ULONG
  184. BasepOemStringToUnicodeSize(
  185. PANSI_STRING OemString
  186. );
  187. HANDLE
  188. BaseGetNamedObjectDirectory(
  189. VOID
  190. );
  191. void
  192. BaseDllInitializeMemoryManager( VOID );
  193. typedef
  194. NTSTATUS
  195. (*BASECLIENTCONNECTROUTINE)(
  196. PVOID MustBeNull,
  197. PVOID ConnectionInformation,
  198. PULONG ConnectionInformationLength
  199. );
  200. POBJECT_ATTRIBUTES
  201. BaseFormatObjectAttributes(
  202. POBJECT_ATTRIBUTES ObjectAttributes,
  203. PSECURITY_ATTRIBUTES SecurityAttributes,
  204. PUNICODE_STRING ObjectName
  205. );
  206. PLARGE_INTEGER
  207. BaseFormatTimeOut(
  208. PLARGE_INTEGER TimeOut,
  209. DWORD Milliseconds
  210. );
  211. ULONG
  212. BaseSetLastNTError(
  213. NTSTATUS Status
  214. );
  215. VOID
  216. BaseSwitchStackThenTerminate(
  217. PVOID CurrentStack,
  218. PVOID NewStack,
  219. DWORD ExitCode
  220. );
  221. VOID
  222. BaseFreeStackAndTerminate(
  223. PVOID OldStack,
  224. DWORD ExitCode
  225. );
  226. NTSTATUS
  227. BaseCreateStack(
  228. HANDLE Process,
  229. SIZE_T StackSize,
  230. SIZE_T MaximumStackSize,
  231. PINITIAL_TEB InitialTeb
  232. );
  233. VOID
  234. BasepSwitchToFiber(
  235. PFIBER CurrentFiber,
  236. PFIBER NewFiber
  237. );
  238. VOID
  239. BaseFiberStart(
  240. VOID
  241. );
  242. VOID
  243. BaseThreadStart(
  244. LPTHREAD_START_ROUTINE lpStartAddress,
  245. LPVOID lpParameter
  246. );
  247. typedef DWORD (WINAPI *PPROCESS_START_ROUTINE)(
  248. VOID
  249. );
  250. VOID
  251. BaseProcessStart(
  252. PPROCESS_START_ROUTINE lpStartAddress
  253. );
  254. VOID
  255. BaseThreadStartThunk(
  256. LPTHREAD_START_ROUTINE lpStartAddress,
  257. LPVOID lpParameter
  258. );
  259. VOID
  260. BaseProcessStartThunk(
  261. LPVOID lpProcessStartAddress,
  262. LPVOID lpParameter
  263. );
  264. typedef enum _BASE_CONTEXT_TYPE {
  265. BaseContextTypeProcess,
  266. BaseContextTypeThread,
  267. BaseContextTypeFiber
  268. } BASE_CONTEXT_TYPE, *PBASE_CONTEXT_TYPE;
  269. VOID
  270. BaseInitializeContext(
  271. PCONTEXT Context,
  272. PVOID Parameter,
  273. PVOID InitialPc,
  274. PVOID InitialSp,
  275. BASE_CONTEXT_TYPE ContextType
  276. );
  277. #if defined(WX86) || defined(_AXP64_)
  278. NTSTATUS
  279. BaseCreateWx86Tib(
  280. HANDLE Process,
  281. HANDLE Thread,
  282. ULONG InitialPc,
  283. ULONG CommittedStackSize,
  284. ULONG MaximumStackSize,
  285. BOOLEAN EmulateInitialPc
  286. );
  287. #endif
  288. VOID
  289. BaseFreeThreadStack(
  290. HANDLE hProcess,
  291. HANDLE hThread,
  292. PINITIAL_TEB InitialTeb
  293. );
  294. #define BASE_PUSH_PROCESS_PARAMETERS_FLAG_APP_MANIFEST_PRESENT (0x00000001)
  295. BOOL
  296. BasePushProcessParameters(
  297. DWORD dwFlags,
  298. HANDLE Process,
  299. PPEB Peb,
  300. LPCWSTR ApplicationPathName,
  301. LPCWSTR CurrentDirectory,
  302. LPCWSTR CommandLine,
  303. LPVOID Environment,
  304. LPSTARTUPINFOW lpStartupInfo,
  305. DWORD dwCreationFlags,
  306. BOOL bInheritHandles,
  307. DWORD dwSubsystem,
  308. PVOID pAppCompatData,
  309. DWORD cbAppCompatData
  310. );
  311. LPWSTR
  312. BaseComputeProcessDllPath(
  313. LPCWSTR AppName,
  314. LPVOID Environment
  315. );
  316. LPWSTR
  317. BaseComputeProcessSearchPath(
  318. VOID
  319. );
  320. extern PCLDR_DATA_TABLE_ENTRY BasepExeLdrEntry;
  321. VOID
  322. BasepLocateExeLdrEntry(
  323. IN PCLDR_DATA_TABLE_ENTRY Entry,
  324. IN PVOID Context,
  325. IN OUT BOOLEAN *StopEnumeration
  326. );
  327. FORCEINLINE
  328. VOID
  329. BasepCheckExeLdrEntry(
  330. VOID
  331. )
  332. {
  333. if (! BasepExeLdrEntry) {
  334. LdrEnumerateLoadedModules(0,
  335. &BasepLocateExeLdrEntry,
  336. NtCurrentPeb()->ImageBaseAddress);
  337. }
  338. }
  339. LPCWSTR
  340. BasepEndOfDirName(
  341. IN LPCWSTR FileName
  342. );
  343. DWORD
  344. BaseDebugAttachThread(
  345. LPVOID ThreadParameter
  346. );
  347. HANDLE
  348. BaseFindFirstDevice(
  349. PCUNICODE_STRING FileName,
  350. LPWIN32_FIND_DATAW lpFindFileData
  351. );
  352. PUNICODE_STRING
  353. BaseIsThisAConsoleName(
  354. PCUNICODE_STRING FileNameString,
  355. DWORD dwDesiredAccess
  356. );
  357. typedef ULONG (FAR WINAPI *CSRREMOTEPROCPROC)(HANDLE, CLIENT_ID *);
  358. #if DBG
  359. VOID
  360. BaseHeapBreakPoint( VOID );
  361. #endif
  362. ULONG
  363. BasepOfShareToWin32Share(
  364. IN ULONG OfShare
  365. );
  366. //
  367. // Data structure for CopyFileEx context
  368. //
  369. typedef struct _COPYFILE_CONTEXT {
  370. LARGE_INTEGER TotalFileSize;
  371. LARGE_INTEGER TotalBytesTransferred;
  372. DWORD dwStreamNumber;
  373. LPBOOL lpCancel;
  374. LPVOID lpData;
  375. LPPROGRESS_ROUTINE lpProgressRoutine;
  376. } COPYFILE_CONTEXT, *LPCOPYFILE_CONTEXT;
  377. //
  378. // Data structure for tracking restart state
  379. //
  380. typedef struct _RESTART_STATE {
  381. CSHORT Type;
  382. CSHORT Size;
  383. DWORD NumberOfStreams;
  384. LARGE_INTEGER CreationTime;
  385. LARGE_INTEGER WriteTime;
  386. LARGE_INTEGER EndOfFile;
  387. LARGE_INTEGER FileSize;
  388. LARGE_INTEGER LastKnownGoodOffset;
  389. DWORD CurrentStream;
  390. DWORD Checksum;
  391. } RESTART_STATE, *PRESTART_STATE, *LPRESTART_STATE;
  392. #define SUCCESS_RETURNED_STATE 2
  393. DWORD
  394. BaseCopyStream(
  395. LPCWSTR lpExistingFileName,
  396. HANDLE hSourceFile,
  397. ACCESS_MASK SourceFileAccess OPTIONAL,
  398. LPCWSTR lpNewFileName,
  399. HANDLE hTargetFile OPTIONAL,
  400. LARGE_INTEGER *lpFileSize,
  401. LPDWORD lpCopyFlags,
  402. LPHANDLE lpDestFile,
  403. LPDWORD lpCopySize,
  404. LPCOPYFILE_CONTEXT *lpCopyFileContext,
  405. LPRESTART_STATE lpRestartState OPTIONAL,
  406. BOOL OpenFileAsReparsePoint,
  407. DWORD dwReparseTag,
  408. PDWORD DestFileFsAttributes
  409. );
  410. BOOL
  411. BasepCopyFileExW(
  412. LPCWSTR lpExistingFileName,
  413. LPCWSTR lpNewFileName,
  414. LPPROGRESS_ROUTINE lpProgressRoutine OPTIONAL,
  415. LPVOID lpData OPTIONAL,
  416. LPBOOL pbCancel OPTIONAL,
  417. DWORD dwCopyFlags,
  418. DWORD dwPrivCopyFlags,
  419. LPHANDLE phSource OPTIONAL,
  420. LPHANDLE phDest OPTIONAL
  421. );
  422. VOID
  423. BaseMarkFileForDelete(
  424. HANDLE File,
  425. DWORD FileAttributes
  426. );
  427. PVOID
  428. BasepMapModuleHandle(
  429. IN HMODULE hModule,
  430. IN BOOLEAN bResourcesOnly
  431. );
  432. ULONG_PTR
  433. BaseDllMapResourceIdA(
  434. PCSTR lpId
  435. );
  436. ULONG_PTR
  437. BaseDllMapResourceIdW(
  438. PCWSTR lpId
  439. );
  440. VOID
  441. BaseDllFreeResourceId(
  442. ULONG_PTR Id
  443. );
  444. //
  445. // Data structures and interfaces used by dllini.c
  446. //
  447. typedef struct _INIFILE_CACHE {
  448. struct _INIFILE_CACHE *Next;
  449. ULONG EnvironmentUpdateCount;
  450. UNICODE_STRING NtFileName;
  451. PINIFILE_MAPPING_FILENAME FileMapping;
  452. HANDLE FileHandle;
  453. BOOLEAN WriteAccess;
  454. BOOLEAN UnicodeFile;
  455. BOOLEAN LockedFile;
  456. ULONG EndOfFile;
  457. PVOID BaseAddress;
  458. SIZE_T CommitSize;
  459. SIZE_T RegionSize;
  460. ULONG UpdateOffset;
  461. ULONG UpdateEndOffset;
  462. ULONG DirectoryInformationLength;
  463. FILE_BASIC_INFORMATION BasicInformation;
  464. FILE_STANDARD_INFORMATION StandardInformation;
  465. } INIFILE_CACHE, *PINIFILE_CACHE;
  466. typedef enum _INIFILE_OPERATION {
  467. FlushProfiles,
  468. ReadKeyValue,
  469. WriteKeyValue,
  470. DeleteKey,
  471. ReadKeyNames,
  472. ReadSectionNames,
  473. ReadSection,
  474. WriteSection,
  475. DeleteSection,
  476. RefreshIniFileMapping
  477. } INIFILE_OPERATION;
  478. typedef struct _INIFILE_PARAMETERS {
  479. INIFILE_OPERATION Operation;
  480. BOOLEAN WriteOperation;
  481. BOOLEAN Unicode;
  482. BOOLEAN ValueBufferAllocated;
  483. PINIFILE_MAPPING_FILENAME IniFileNameMapping;
  484. PINIFILE_CACHE IniFile;
  485. UNICODE_STRING BaseFileName;
  486. UNICODE_STRING FileName;
  487. UNICODE_STRING NtFileName;
  488. ANSI_STRING ApplicationName;
  489. ANSI_STRING VariableName;
  490. UNICODE_STRING ApplicationNameU;
  491. UNICODE_STRING VariableNameU;
  492. BOOLEAN MultiValueStrings;
  493. union {
  494. //
  495. // This structure filled in for write operations
  496. //
  497. struct {
  498. LPSTR ValueBuffer;
  499. ULONG ValueLength;
  500. PWSTR ValueBufferU;
  501. ULONG ValueLengthU;
  502. };
  503. //
  504. // This structure filled in for read operations
  505. //
  506. struct {
  507. ULONG ResultChars;
  508. ULONG ResultMaxChars;
  509. LPSTR ResultBuffer;
  510. PWSTR ResultBufferU;
  511. };
  512. };
  513. //
  514. // Remaining fields only valid when parsing an on disk .INI file mapped into
  515. // memory.
  516. //
  517. PVOID TextCurrent;
  518. PVOID TextStart;
  519. PVOID TextEnd;
  520. ANSI_STRING SectionName;
  521. ANSI_STRING KeywordName;
  522. ANSI_STRING KeywordValue;
  523. PANSI_STRING AnsiSectionName;
  524. PANSI_STRING AnsiKeywordName;
  525. PANSI_STRING AnsiKeywordValue;
  526. UNICODE_STRING SectionNameU;
  527. UNICODE_STRING KeywordNameU;
  528. UNICODE_STRING KeywordValueU;
  529. PUNICODE_STRING UnicodeSectionName;
  530. PUNICODE_STRING UnicodeKeywordName;
  531. PUNICODE_STRING UnicodeKeywordValue;
  532. } INIFILE_PARAMETERS, *PINIFILE_PARAMETERS;
  533. NTSTATUS
  534. BaseDllInitializeIniFileMappings(
  535. PBASE_STATIC_SERVER_DATA StaticServerData
  536. );
  537. NTSTATUS
  538. BasepAcquirePrivilege(
  539. ULONG Privilege,
  540. PVOID *ReturnedState
  541. );
  542. NTSTATUS
  543. BasepAcquirePrivilegeEx(
  544. ULONG Privilege,
  545. PVOID *ReturnedState
  546. );
  547. VOID
  548. BasepReleasePrivilege(
  549. PVOID StatePointer
  550. );
  551. NTSTATUS
  552. NTAPI
  553. BaseCreateThreadPoolThread(
  554. PUSER_THREAD_START_ROUTINE Function,
  555. PVOID Parameter,
  556. HANDLE * ThreadHandle
  557. );
  558. NTSTATUS
  559. NTAPI
  560. BaseExitThreadPoolThread(
  561. NTSTATUS Status
  562. );
  563. //
  564. // Function for returning the volume name from a reparse point.
  565. //
  566. BOOL
  567. BasepGetVolumeNameFromReparsePoint(
  568. LPCWSTR lpszVolumeMountPoint,
  569. LPWSTR lpszVolumeName,
  570. DWORD cchBufferLength,
  571. PBOOL ResultOfOpen
  572. );
  573. #if defined(_WIN64) || defined(BUILD_WOW6432)
  574. //
  575. // COM+ Support routines
  576. //
  577. NTSTATUS
  578. BasepIsComplusILImage(
  579. IN HANDLE SectionImageHandle,
  580. IN PSECTION_IMAGE_INFORMATION SectionImageInformation,
  581. OUT BOOLEAN *IsComplusILImage
  582. );
  583. #endif
  584. //
  585. // Definitions for memory handles used by Local/GlobalAlloc functions
  586. //
  587. typedef struct _BASE_HANDLE_TABLE_ENTRY {
  588. USHORT Flags;
  589. USHORT LockCount;
  590. union {
  591. PVOID Object; // Allocated handle
  592. ULONG Size; // Handle to discarded obj.
  593. };
  594. } BASE_HANDLE_TABLE_ENTRY, *PBASE_HANDLE_TABLE_ENTRY;
  595. #define BASE_HANDLE_MOVEABLE (USHORT)0x0002
  596. #define BASE_HANDLE_DISCARDABLE (USHORT)0x0004
  597. #define BASE_HANDLE_DISCARDED (USHORT)0x0008
  598. #define BASE_HANDLE_SHARED (USHORT)0x8000
  599. //
  600. // Handles are 32-bit pointers to the u.Object field of a
  601. // BASE_HANDLE_TABLE_ENTRY. Since this field is 4 bytes into the
  602. // structure and the structures are always on 8 byte boundaries, we can
  603. // test the 0x4 bit to see if it is a handle.
  604. //
  605. // In Sundown, these handles are 64-bit pointers to the u.Object field
  606. // which is 8 bytes into the structure. Therefore, we should test the
  607. // 0x8 bit to see if it is a handle.
  608. //
  609. //on sundown
  610. // #define BASE_HANDLE_MARK_BIT (ULONG_PTR)0x00000008
  611. //on 32 bit systems
  612. // #define BASE_HANDLE_MARK_BIT (ULONG_PTR)0x00000004
  613. //
  614. #define BASE_HANDLE_MARK_BIT (ULONG_PTR)FIELD_OFFSET(BASE_HANDLE_TABLE_ENTRY,Object)
  615. #define BASE_HEAP_FLAG_MOVEABLE HEAP_SETTABLE_USER_FLAG1
  616. #define BASE_HEAP_FLAG_DDESHARE HEAP_SETTABLE_USER_FLAG2
  617. ULONG BaseDllTag;
  618. #define MAKE_TAG( t ) (RTL_HEAP_MAKE_TAG( BaseDllTag, t ))
  619. #define TMP_TAG 0
  620. #define BACKUP_TAG 1
  621. #define INI_TAG 2
  622. #define FIND_TAG 3
  623. #define GMEM_TAG 4
  624. #define LMEM_TAG 5
  625. #define ENV_TAG 6
  626. #define RES_TAG 7
  627. #define VDM_TAG 8
  628. #include <vdmapi.h>
  629. #include "vdm.h"
  630. #include "basevdm.h"
  631. #include "stdlib.h" // for atol
  632. #include "stdio.h" // for atol
  633. #include <objidl.h> // needs nturtl.h
  634. #include <propset.h> // needs objidl.h
  635. #include <tsappcmp.h>
  636. //
  637. // Hydra function for supporting beeps on remote sessions
  638. //
  639. typedef HANDLE (WINAPI * PWINSTATIONBEEPOPEN)(ULONG);
  640. HANDLE WINAPI
  641. _WinStationBeepOpen(
  642. ULONG SessionId
  643. );
  644. PWINSTATIONBEEPOPEN pWinStationBeepOpen;
  645. //
  646. // Private functions for communication with CSR.
  647. //
  648. VOID
  649. CsrBasepSoundSentryNotification(
  650. ULONG VideoMode
  651. );
  652. NTSTATUS
  653. CsrBaseClientConnectToServer(
  654. PWSTR szSessionDir,
  655. PHANDLE phMutant,
  656. PBOOLEAN pServerProcess
  657. );
  658. NTSTATUS
  659. CsrBasepRefreshIniFileMapping(
  660. PUNICODE_STRING BaseFileName
  661. );
  662. NTSTATUS
  663. CsrBasepDefineDosDevice(
  664. DWORD dwFlags,
  665. PUNICODE_STRING pDeviceName,
  666. PUNICODE_STRING pTargetPath
  667. );
  668. UINT
  669. CsrBasepGetTempFile(
  670. VOID
  671. );
  672. NTSTATUS
  673. CsrBasepCreateProcess(
  674. PBASE_CREATEPROCESS_MSG a
  675. );
  676. VOID
  677. CsrBasepExitProcess(
  678. UINT uExitCode
  679. );
  680. NTSTATUS
  681. CsrBasepSetProcessShutdownParam(
  682. DWORD dwLevel,
  683. DWORD dwFlags
  684. );
  685. NTSTATUS
  686. CsrBasepGetProcessShutdownParam(
  687. LPDWORD lpdwLevel,
  688. LPDWORD lpdwFlags
  689. );
  690. NTSTATUS
  691. CsrBasepSetTermsrvAppInstallMode(
  692. BOOL bState
  693. );
  694. NTSTATUS
  695. CsrBasepSetClientTimeZoneInformation(
  696. IN PBASE_SET_TERMSRVCLIENTTIMEZONE c
  697. );
  698. NTSTATUS
  699. CsrBasepCreateThread(
  700. HANDLE ThreadHandle,
  701. CLIENT_ID ClientId
  702. );
  703. //
  704. // This should be merged with BasepCreateActCtx, its only caller.
  705. //
  706. #define BASEP_CREATE_ACTCTX_FLAG_NO_ADMIN_OVERRIDE 0x00000001
  707. NTSTATUS
  708. BasepCreateActCtx(
  709. ULONG Flags,
  710. IN PCACTCTXW ActParams,
  711. OUT PVOID* ActivationContextData
  712. );
  713. NTSTATUS
  714. CsrBasepCreateActCtx(
  715. IN PBASE_SXS_CREATE_ACTIVATION_CONTEXT_MSG Message
  716. );
  717. #if defined(BUILD_WOW6432)
  718. #include "ntwow64b.h"
  719. #endif
  720. BOOL TermsrvSyncUserIniFile(PINIFILE_PARAMETERS a);
  721. BOOL TermsrvLogInstallIniFile(PINIFILE_PARAMETERS a);
  722. PTERMSRVFORMATOBJECTNAME gpTermsrvFormatObjectName;
  723. PTERMSRVGETCOMPUTERNAME gpTermsrvGetComputerName;
  724. PTERMSRVADJUSTPHYMEMLIMITS gpTermsrvAdjustPhyMemLimits;
  725. PTERMSRVGETWINDOWSDIRECTORYA gpTermsrvGetWindowsDirectoryA;
  726. PTERMSRVGETWINDOWSDIRECTORYW gpTermsrvGetWindowsDirectoryW;
  727. PTERMSRVCONVERTSYSROOTTOUSERDIR gpTermsrvConvertSysRootToUserDir;
  728. PTERMSRVBUILDINIFILENAME gpTermsrvBuildIniFileName;
  729. PTERMSRVCORINIFILE gpTermsrvCORIniFile;
  730. PTERMSRVUPDATEALLUSERMENU gpTermsrvUpdateAllUserMenu;
  731. PGETTERMSRCOMPATFLAGS gpGetTermsrCompatFlags;
  732. PTERMSRVBUILDSYSINIPATH gpTermsrvBuildSysIniPath;
  733. PTERMSRVCOPYINIFILE gpTermsrvCopyIniFile;
  734. PTERMSRVGETSTRING gpTermsrvGetString;
  735. PTERMSRVLOGINSTALLINIFILE gpTermsrvLogInstallIniFile;
  736. //
  737. // For periodic timers that fire APCs set when a non-default activation context is active
  738. // we leak this structure.
  739. //
  740. #define BASE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK_FLAG_DO_NOT_FREE_AFTER_CALLBACK (0x00000001)
  741. typedef struct _BASE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK {
  742. DWORD Flags;
  743. PVOID CallbackFunction;
  744. PVOID CallbackContext;
  745. PACTIVATION_CONTEXT ActivationContext;
  746. } BASE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK, *PBASE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK;
  747. #define BASEP_ALLOCATE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK_FLAG_DO_NOT_FREE_AFTER_CALLBACK (0x00000001)
  748. #define BASEP_ALLOCATE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK_FLAG_DO_NOT_ALLOCATE_IF_PROCESS_DEFAULT (0x00000002)
  749. NTSTATUS
  750. BasepAllocateActivationContextActivationBlock(
  751. IN DWORD Flags,
  752. IN PVOID CallbackFunction,
  753. IN PVOID CallbackContext,
  754. OUT PBASE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK *ActivationBlock
  755. );
  756. VOID
  757. BasepFreeActivationContextActivationBlock(
  758. IN PBASE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK ActivationBlock
  759. );
  760. VOID
  761. WINAPI
  762. BasepActivationContextActivationIoCompletion(
  763. IN PVOID ApcContext, // actually PBASE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK
  764. PIO_STATUS_BLOCK IoStatusBlock,
  765. DWORD Reserved
  766. );
  767. VOID
  768. CALLBACK
  769. BasepTimerAPCProc(
  770. IN PVOID ApcContext, // actually PBASE_ACTIVATION_CONTEXT_ACTIVATION_BLOCK
  771. IN ULONG TimerLowValue,
  772. IN LONG TimerHighValue
  773. );
  774. #define BASE_FILE_PATH_ISOLATION_ALLOCATE_PATH (0x00000001)
  775. NTSTATUS
  776. BasepApplyFilePathIsolationRedirection(
  777. IN DWORD Flags,
  778. IN PCUNICODE_STRING FileName,
  779. IN OUT PUNICODE_STRING FullyQualifiedPath
  780. );
  781. #define SXS_POLICY_SUFFIX L".Config"
  782. #define SXS_MANIFEST_SUFFIX L".Manifest"
  783. extern const UNICODE_STRING SxsPolicySuffix;
  784. typedef struct _SXS_CONSTANT_WIN32_NT_PATH_PAIR
  785. {
  786. PCUNICODE_STRING Win32;
  787. PCUNICODE_STRING Nt;
  788. } SXS_CONSTANT_WIN32_NT_PATH_PAIR;
  789. typedef SXS_CONSTANT_WIN32_NT_PATH_PAIR* PSXS_CONSTANT_WIN32_NT_PATH_PAIR;
  790. typedef CONST SXS_CONSTANT_WIN32_NT_PATH_PAIR* PCSXS_CONSTANT_WIN32_NT_PATH_PAIR;
  791. typedef struct _SXS_WIN32_NT_PATH_PAIR
  792. {
  793. PRTL_UNICODE_STRING_BUFFER Win32;
  794. PRTL_UNICODE_STRING_BUFFER Nt;
  795. } SXS_WIN32_NT_PATH_PAIR;
  796. typedef SXS_WIN32_NT_PATH_PAIR* PSXS_WIN32_NT_PATH_PAIR;
  797. typedef CONST SXS_WIN32_NT_PATH_PAIR* PCSXS_WIN32_NT_PATH_PAIR;
  798. NTSTATUS
  799. BasepSxsCreateResourceStream(
  800. IN ULONG LdrCreateOutOfProcessImageFlags,
  801. PCSXS_CONSTANT_WIN32_NT_PATH_PAIR Win32NtPathPair,
  802. IN OUT PBASE_MSG_SXS_HANDLES Handles,
  803. IN ULONG_PTR MappedResourceName,
  804. OUT PBASE_MSG_SXS_STREAM MessageStream
  805. );
  806. NTSTATUS
  807. BasepSxsCreateFileStream(
  808. IN ACCESS_MASK AccessMask,
  809. PCSXS_CONSTANT_WIN32_NT_PATH_PAIR Win32NtPathPair,
  810. IN OUT PBASE_MSG_SXS_HANDLES Handles,
  811. OUT PBASE_MSG_SXS_STREAM MessageStream
  812. );
  813. // Pass the address of this to force policy to be empty.
  814. // It doesn't have a special address, just the right values.
  815. extern const SXS_OVERRIDE_STREAM SxsForceEmptyPolicy;
  816. VOID
  817. BasepSxsOverrideStreamToMessageStream(
  818. IN PCSXS_OVERRIDE_STREAM OverrideStream,
  819. OUT PBASE_MSG_SXS_STREAM MessageStream
  820. );
  821. #define BASEP_SXS_CREATESTREAMS_FLAG_LIKE_CREATEPROCESS 0x00000001
  822. NTSTATUS
  823. BasepSxsCreateStreams(
  824. IN ULONG Flags,
  825. IN ULONG LdrCreateOutOfProcessImageFlags,
  826. IN ACCESS_MASK AccessMask,
  827. IN PCSXS_OVERRIDE_STREAM OverrideManifest OPTIONAL,
  828. IN PCSXS_OVERRIDE_STREAM OverridePolicy OPTIONAL,
  829. IN PCSXS_CONSTANT_WIN32_NT_PATH_PAIR ManifestFilePathPair,
  830. IN OUT PBASE_MSG_SXS_HANDLES ManifestFileHandles,
  831. IN PCSXS_CONSTANT_WIN32_NT_PATH_PAIR ManifestImagePathPair,
  832. IN OUT PBASE_MSG_SXS_HANDLES ManifestImageHandles,
  833. // If none of the optional parameters are passed, then you could have directly
  834. // called a simpler function.
  835. IN ULONG_PTR MappedManifestResourceName OPTIONAL,
  836. IN PCSXS_CONSTANT_WIN32_NT_PATH_PAIR PolicyPathPair OPTIONAL,
  837. IN OUT PBASE_MSG_SXS_HANDLES PolicyHandles OPTIONAL,
  838. OUT PULONG MessageFlags,
  839. OUT PBASE_MSG_SXS_STREAM ManifestMessageStream,
  840. OUT PBASE_MSG_SXS_STREAM PolicyMessageStream OPTIONAL
  841. );
  842. BOOL
  843. BasepSxsIsStatusFileNotFoundEtc(
  844. NTSTATUS Status
  845. );
  846. BOOL
  847. BasepSxsIsStatusResourceNotFound(
  848. NTSTATUS Status
  849. );
  850. NTSTATUS
  851. BasepSxsCreateProcessCsrMessage(
  852. IN PCSXS_OVERRIDE_STREAM OverrideManifest OPTIONAL,
  853. IN PCSXS_OVERRIDE_STREAM OverridePolicy OPTIONAL,
  854. IN OUT PCSXS_WIN32_NT_PATH_PAIR ManifestFilePathPair,
  855. IN OUT PBASE_MSG_SXS_HANDLES ManifestFileHandles,
  856. IN PCSXS_CONSTANT_WIN32_NT_PATH_PAIR ManifestImagePathPair,
  857. IN OUT PBASE_MSG_SXS_HANDLES ManifestImageHandles,
  858. IN OUT PCSXS_WIN32_NT_PATH_PAIR PolicyPathPair,
  859. IN OUT PBASE_MSG_SXS_HANDLES PolicyHandles,
  860. IN OUT PRTL_UNICODE_STRING_BUFFER Win32AssemblyDirectoryBuffer,
  861. OUT PBASE_SXS_CREATEPROCESS_MSG Message
  862. );
  863. NTSTATUS
  864. BasepSxsGetProcessImageBaseAddress(
  865. HANDLE Process,
  866. PVOID* ImageBaseAddress
  867. );
  868. VOID
  869. NTAPI
  870. BasepSxsActivationContextNotification(
  871. IN ULONG NotificationType,
  872. IN PACTIVATION_CONTEXT ActivationContext,
  873. IN const VOID *ActivationContextData,
  874. IN PVOID NotificationContext,
  875. IN PVOID NotificationData,
  876. IN OUT PBOOLEAN DisableNotification
  877. );
  878. VOID
  879. BasepSxsDbgPrintMessageStream(
  880. PCSTR Function,
  881. PCSTR StreamName,
  882. PBASE_MSG_SXS_STREAM MessageStream
  883. );
  884. extern const UNICODE_STRING SxsManifestSuffix;
  885. extern const UNICODE_STRING SxsPolicySuffix;
  886. VOID
  887. BasepSxsCloseHandles(
  888. IN PCBASE_MSG_SXS_HANDLES Handles
  889. );
  890. extern const WCHAR AdvapiDllString[];
  891. //
  892. // These functions implement apphelp cache functionality (ahcache.c)
  893. //
  894. //
  895. // Routines in ahcache.c
  896. //
  897. BOOL
  898. WINAPI
  899. BaseCheckAppcompatCache(
  900. LPCWSTR pwszPath,
  901. HANDLE hFile,
  902. PVOID pEnvironment,
  903. DWORD* dwReason
  904. );
  905. //
  906. // function that we call from winlogon
  907. //
  908. BOOL
  909. WINAPI
  910. BaseInitAppcompatCacheSupport(
  911. VOID
  912. );
  913. VOID
  914. WINAPI
  915. BaseCleanupAppcompatCache(
  916. VOID
  917. );
  918. BOOL
  919. WINAPI
  920. BaseCleanupAppcompatCacheSupport(
  921. BOOL bWrite
  922. );
  923. NTSTATUS
  924. NTAPI
  925. BasepProbeForDllManifest(
  926. IN PVOID DllBase,
  927. IN PCWSTR FullDllPath,
  928. OUT PVOID *ActivationContext
  929. );
  930. #define BASEP_GET_MODULE_HANDLE_EX_NO_LOCK (0x00000001)
  931. BOOL
  932. BasepGetModuleHandleExW(
  933. IN DWORD dwPrivateFlags,
  934. IN DWORD dwPublicFlags,
  935. IN LPCWSTR lpModuleName,
  936. OUT HMODULE* phModule
  937. );
  938. #define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_ERROR 1
  939. #define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_SUCCESS 2
  940. #define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_CONTINUE 3
  941. ULONG
  942. BasepGetModuleHandleExParameterValidation(
  943. IN DWORD dwFlags,
  944. IN CONST VOID* lpModuleName,
  945. OUT HMODULE* phModule
  946. );
  947. #define BASEP_GET_TEMP_PATH_PRESERVE_TEB (0x00000001)
  948. DWORD
  949. BasepGetTempPathW(
  950. ULONG Flags,
  951. DWORD nBufferLength,
  952. LPWSTR lpBuffer
  953. );
  954. #endif // _BASEP_