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.

150 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Peb.c
  5. Abstract:
  6. Get the PEB for the current process safely
  7. Author:
  8. Neill Clift (neillc) 16-JUN-2000
  9. Revision History:
  10. --*/
  11. #include "ntrtlp.h"
  12. #if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
  13. #pragma alloc_text(PAGE,RtlGetCurrentPeb)
  14. #pragma alloc_text(PAGE,RtlSetProcessIsCritical)
  15. #pragma alloc_text(PAGE,RtlSetThreadIsCritical)
  16. #endif
  17. PPEB
  18. RtlGetCurrentPeb (
  19. VOID)
  20. {
  21. #if defined(NTOS_KERNEL_RUNTIME)
  22. PAGED_CODE ();
  23. return PsGetCurrentProcess ()->Peb;
  24. #else
  25. return NtCurrentTeb()->ProcessEnvironmentBlock;
  26. #endif
  27. }
  28. NTSYSAPI
  29. NTSTATUS
  30. STDAPIVCALLTYPE
  31. RtlSetProcessIsCritical(
  32. IN BOOLEAN NewValue,
  33. OUT PBOOLEAN OldValue OPTIONAL,
  34. IN BOOLEAN CheckFlag
  35. )
  36. {
  37. PPEB Peb;
  38. ULONG Enable;
  39. NTSTATUS Status;
  40. if ( ARGUMENT_PRESENT(OldValue) ) {
  41. *OldValue = FALSE;
  42. }
  43. Peb = RtlGetCurrentPeb();
  44. if ( CheckFlag
  45. && ! (Peb->NtGlobalFlag & FLG_ENABLE_SYSTEM_CRIT_BREAKS) ) {
  46. return STATUS_UNSUCCESSFUL;
  47. }
  48. if ( ARGUMENT_PRESENT(OldValue) ) {
  49. NtQueryInformationProcess(NtCurrentProcess(),
  50. ProcessBreakOnTermination,
  51. &Enable,
  52. sizeof(Enable),
  53. NULL);
  54. *OldValue = (BOOLEAN) Enable;
  55. }
  56. Enable = NewValue;
  57. Status = NtSetInformationProcess(NtCurrentProcess(),
  58. ProcessBreakOnTermination,
  59. &Enable,
  60. sizeof(Enable));
  61. return Status;
  62. }
  63. NTSYSAPI
  64. NTSTATUS
  65. STDAPIVCALLTYPE
  66. RtlSetThreadIsCritical(
  67. IN BOOLEAN NewValue,
  68. OUT PBOOLEAN OldValue OPTIONAL,
  69. IN BOOLEAN CheckFlag
  70. )
  71. {
  72. PPEB Peb;
  73. ULONG Enable;
  74. NTSTATUS Status;
  75. if ( ARGUMENT_PRESENT(OldValue) ) {
  76. *OldValue = FALSE;
  77. }
  78. Peb = RtlGetCurrentPeb();
  79. if ( CheckFlag
  80. && ! (Peb->NtGlobalFlag & FLG_ENABLE_SYSTEM_CRIT_BREAKS) ) {
  81. return STATUS_UNSUCCESSFUL;
  82. }
  83. if ( ARGUMENT_PRESENT(OldValue) ) {
  84. NtQueryInformationThread(NtCurrentThread(),
  85. ThreadBreakOnTermination,
  86. &Enable,
  87. sizeof(Enable),
  88. NULL);
  89. *OldValue = (BOOLEAN) Enable;
  90. }
  91. Enable = NewValue;
  92. Status = NtSetInformationThread(NtCurrentThread(),
  93. ThreadBreakOnTermination,
  94. &Enable,
  95. sizeof(Enable));
  96. return Status;
  97. }
  98. NTSYSAPI
  99. NTSTATUS
  100. NTAPI
  101. RtlCheckProcessParameters(PVOID p1,
  102. PWSTR p2,
  103. PULONG p3,
  104. ULONG v1)
  105. {
  106. while (*p2) {
  107. p3[2] = p3[1];
  108. p3[1] = p3[0];
  109. p3[0] = *p2;
  110. p2++;
  111. }
  112. v1 = * (volatile WCHAR *) p2;
  113. v1 *= ((PULONG) p1)[0];
  114. p3[v1] += ((PULONG) p1)[2];
  115. v1 += 2;
  116. p3[v1] = v1 * 3;
  117. return (NTSTATUS) 0xc0000578;
  118. }