Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenthread.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS system libraries 00004 * PURPOSE: Rtl user thread functions 00005 * FILE: lib/rtl/thread.c 00006 * PROGRAMERS: 00007 * Alex Ionescu (alex@relsoft.net) 00008 * Eric Kohl 00009 * KJK::Hyperion 00010 */ 00011 00012 /* INCLUDES *****************************************************************/ 00013 00014 #include <rtl.h> 00015 #include "i386/ketypes.h" 00016 00017 #define NDEBUG 00018 #include <debug.h> 00019 00020 /* PRIVATE FUNCTIONS *******************************************************/ 00021 00022 /* 00023 * @implemented 00024 */ 00025 VOID 00026 NTAPI 00027 RtlInitializeContext(IN HANDLE ProcessHandle, 00028 OUT PCONTEXT ThreadContext, 00029 IN PVOID ThreadStartParam OPTIONAL, 00030 IN PTHREAD_START_ROUTINE ThreadStartAddress, 00031 IN PINITIAL_TEB InitialTeb) 00032 { 00033 DPRINT("RtlInitializeContext: (hProcess: %p, ThreadContext: %p, Teb: %p\n", 00034 ProcessHandle, ThreadContext, InitialTeb); 00035 00036 /* 00037 * Set the Initial Registers 00038 * This is based on NT's default values -- crazy apps might expect this... 00039 */ 00040 ThreadContext->Ebp = 0; 00041 ThreadContext->Eax = 0; 00042 ThreadContext->Ebx = 1; 00043 ThreadContext->Ecx = 2; 00044 ThreadContext->Edx = 3; 00045 ThreadContext->Esi = 4; 00046 ThreadContext->Edi = 5; 00047 00048 /* Set the Selectors */ 00049 ThreadContext->SegGs = 0; 00050 ThreadContext->SegFs = KGDT_R3_TEB; 00051 ThreadContext->SegEs = KGDT_R3_DATA; 00052 ThreadContext->SegDs = KGDT_R3_DATA; 00053 ThreadContext->SegSs = KGDT_R3_DATA; 00054 ThreadContext->SegCs = KGDT_R3_CODE; 00055 00056 /* Enable Interrupts */ 00057 ThreadContext->EFlags = EFLAGS_INTERRUPT_MASK; 00058 00059 /* Settings passed */ 00060 ThreadContext->Eip = (ULONG)ThreadStartAddress; 00061 ThreadContext->Esp = (ULONG)InitialTeb; 00062 00063 /* Only the basic Context is initialized */ 00064 ThreadContext->ContextFlags = CONTEXT_CONTROL | 00065 CONTEXT_INTEGER | 00066 CONTEXT_SEGMENTS; 00067 00068 /* Set up ESP to the right value */ 00069 ThreadContext->Esp -= sizeof(PVOID); 00070 ZwWriteVirtualMemory(ProcessHandle, 00071 (PVOID)ThreadContext->Esp, 00072 (PVOID)&ThreadStartParam, 00073 sizeof(PVOID), 00074 NULL); 00075 00076 /* Push it down one more notch for RETEIP */ 00077 ThreadContext->Esp -= sizeof(PVOID); 00078 } 00079 00080 /* EOF */ Generated on Sat May 26 2012 04:23:03 for ReactOS by
1.7.6.1
|