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.

129 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. context.c
  5. Abstract:
  6. This module contains the context management routines for
  7. Win32
  8. Author:
  9. Mark Lucovsky (markl) 28-Sep-1990
  10. Revision History:
  11. Thomas Van Baak (tvb) 22-Jul-1992
  12. Adapted for Alpha AXP.
  13. --*/
  14. #include "basedll.h"
  15. VOID
  16. BaseInitializeContext (
  17. OUT PCONTEXT Context,
  18. IN PVOID Parameter OPTIONAL,
  19. IN PVOID InitialPc OPTIONAL,
  20. IN PVOID InitialSp OPTIONAL,
  21. IN BASE_CONTEXT_TYPE ContextType
  22. )
  23. /*++
  24. Routine Description:
  25. This function initializes a context structure so that it can
  26. be used in a subsequent call to NtCreateThread.
  27. Arguments:
  28. Context - Supplies a context buffer to be initialized by this routine.
  29. Parameter - Supplies the thread's parameter.
  30. InitialPc - Supplies an initial program counter value.
  31. InitialSp - Supplies an initial stack pointer value.
  32. NewThread - Supplies a flag that specifies that this is a new
  33. thread, or a new process.
  34. Return Value:
  35. None.
  36. --*/
  37. {
  38. ULONG temp;
  39. PPEB Peb;
  40. Peb = NtCurrentPeb();
  41. //
  42. // Initialize the control registers.
  43. // So that the thread begins at BaseThreadStart
  44. //
  45. RtlZeroMemory((PVOID)Context, sizeof(CONTEXT));
  46. Context->IntGp = 1;
  47. Context->IntSp = (ULONGLONG)(LONG_PTR)InitialSp;
  48. Context->IntRa = 1;
  49. Context->ContextFlags = CONTEXT_FULL;
  50. if ( ContextType != BaseContextTypeProcess ) {
  51. if ( ContextType == BaseContextTypeThread ) {
  52. Context->Fir = (ULONGLONG)(LONG_PTR)BaseThreadStart;
  53. } else {
  54. Context->Fir = (ULONGLONG)(LONG_PTR)BaseFiberStart;
  55. }
  56. Context->IntA0 = (ULONGLONG)(LONG_PTR)InitialPc;
  57. Context->IntA1 = (ULONGLONG)(LONG_PTR)Parameter;
  58. Context->IntGp = (ULONGLONG)(LONG_PTR)RtlImageDirectoryEntryToData(
  59. Peb->ImageBaseAddress,
  60. TRUE,
  61. IMAGE_DIRECTORY_ENTRY_GLOBALPTR,
  62. &temp
  63. );
  64. }
  65. else {
  66. Context->Fir = (ULONGLONG)(LONG_PTR)BaseProcessStart;
  67. Context->IntA0 = (ULONGLONG)(LONG_PTR)InitialPc;
  68. }
  69. }
  70. VOID
  71. BaseFiberStart(
  72. VOID
  73. )
  74. /*++
  75. Routine Description:
  76. This function is called to start a Win32 fiber. Its purpose
  77. is to call BaseThreadStart, getting the necessary arguments
  78. from the fiber context record.
  79. Arguments:
  80. None.
  81. Return Value:
  82. None.
  83. --*/
  84. {
  85. PFIBER Fiber;
  86. Fiber = GetCurrentFiber();
  87. BaseThreadStart( (LPTHREAD_START_ROUTINE)Fiber->FiberContext.IntA0,
  88. (LPVOID)Fiber->FiberContext.IntA1 );
  89. }