VOID
RtlInitializeContext(
IN HANDLE Process,
OUT PCONTEXT Context,
IN PVOID Parameter OPTIONAL,
IN PVOID InitialPc OPTIONAL,
IN PVOID InitialSp OPTIONAL
)
/*++
Routine Description:
This function initializes a context structure so that it can
be used in a subsequent call to NtCreateThread.
Arguments:
Context - Supplies a context buffer to be initialized by this routine.
InitialPc - Supplies an initial program counter value.
InitialSp - Supplies an initial stack pointer value.
Return Value:
Raises STATUS_BAD_INITIAL_STACK if the value of InitialSp is not properly
aligned.
Raises STATUS_BAD_INITIAL_PC if the value of InitialPc is not properly
aligned.
--*/
{
RTL_PAGED_CODE();
Context->Eax = 0L;
Context->Ebx = 1L;
Context->Ecx = 2L;
Context->Edx = 3L;
Context->Esi = 4L;
Context->Edi = 5L;
Context->Ebp = 0L;
Context->SegGs = 0;
Context->SegFs = KGDT_R3_TEB;
Context->SegEs = KGDT_R3_DATA;
Context->SegDs = KGDT_R3_DATA;
Context->SegSs = KGDT_R3_DATA;
Context->SegCs = KGDT_R3_CODE;
Context->EFlags = 0x200L; // force interrupts on, clear all else.
//
// Even though these are optional, they are used as is, since NULL
// is what these would have been initialized to anyway
//
Context->Esp = (ULONG) InitialSp;
Context->Eip = (ULONG) InitialPc;
//
// add code to check alignment and raise exception...
//
Context->ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS;
//
// Set the initial context of the thread in a machine specific way.
// ie, pass the initial parameter to the start address
//
Context->Esp -= sizeof(Parameter);
ZwWriteVirtualMemory(Process,
(PVOID)Context->Esp,
(PVOID)&Parameter,
sizeof(Parameter),
NULL);
Context->Esp -= sizeof(Parameter); // Reserve room for ret address
}
VOID
RtlInitializeContext(
IN HANDLE Process,
OUT PCONTEXT Context,
IN PVOID Parameter OPTIONAL,
IN PVOID InitialPc OPTIONAL,
IN PVOID InitialSp OPTIONAL
)
/*++
Routine Description:
This function initializes a context structure so that it can
be used in a subsequent call to NtCreateThread.
Arguments:
Context - Supplies a context buffer to be initialized by this routine.
InitialPc - Supplies an initial program counter value.
InitialSp - Supplies an initial stack pointer value.
Return Value:
Raises STATUS_BAD_INITIAL_STACK if the value of InitialSp is not properly
aligned.
Raises STATUS_BAD_INITIAL_PC if the value of InitialPc is not properly
aligned.
--*/
{
RTL_PAGED_CODE();
Context->Eax = 0L;
Context->Ebx = 1L;
Context->Ecx = 2L;
Context->Edx = 3L;
Context->Esi = 4L;
Context->Edi = 5L;
Context->Ebp = 0L;
Context->SegGs = 0;
Context->SegFs = KGDT_R3_TEB;
Context->SegEs = KGDT_R3_DATA;
Context->SegDs = KGDT_R3_DATA;
Context->SegSs = KGDT_R3_DATA;
Context->SegCs = KGDT_R3_CODE;
Context->EFlags = 0x200L; // force interrupts on, clear all else.
//
// Even though these are optional, they are used as is, since NULL
// is what these would have been initialized to anyway
//
Context->Esp = (ULONG) InitialSp;
Context->Eip = (ULONG) InitialPc;
//
// add code to check alignment and raise exception...
//
Context->ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS;
//
// Set the initial context of the thread in a machine specific way.
// ie, pass the initial parameter to the start address
//
Context->Esp -= sizeof(Parameter);
ZwWriteVirtualMemory(Process,
(PVOID)Context->Esp,
(PVOID)&Parameter,
sizeof(Parameter),
NULL);
Context->Esp -= sizeof(Parameter); // Reserve room for ret address
}
VOID
RtlInitializeContext(
IN HANDLE Process,
OUT PCONTEXT Context,
IN PVOID Parameter OPTIONAL,
IN PVOID InitialPc OPTIONAL,
IN PVOID InitialSp OPTIONAL
)
/*++
Routine Description:
This function initializes a context structure so that it can
be used in a subsequent call to NtCreateThread.
Arguments:
Context - Supplies a context buffer to be initialized by this routine.
InitialPc - Supplies an initial program counter value.
InitialSp - Supplies an initial stack pointer value.
Return Value:
Raises STATUS_BAD_INITIAL_STACK if the value of InitialSp is not properly
aligned.
Raises STATUS_BAD_INITIAL_PC if the value of InitialPc is not properly
aligned.
--*/
{
RTL_PAGED_CODE();
Context->Eax = 0L;
Context->Ebx = 1L;
Context->Ecx = 2L;
Context->Edx = 3L;
Context->Esi = 4L;
Context->Edi = 5L;
Context->Ebp = 0L;
Context->SegGs = 0;
Context->SegFs = KGDT_R3_TEB;
Context->SegEs = KGDT_R3_DATA;
Context->SegDs = KGDT_R3_DATA;
Context->SegSs = KGDT_R3_DATA;
Context->SegCs = KGDT_R3_CODE;
Context->EFlags = 0x200L; // force interrupts on, clear all else.
//
// Even though these are optional, they are used as is, since NULL
// is what these would have been initialized to anyway
//
Context->Esp = (ULONG) InitialSp;
Context->Eip = (ULONG) InitialPc;
//
// add code to check alignment and raise exception...
//
Context->ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS;
//
// Set the initial context of the thread in a machine specific way.
// ie, pass the initial parameter to the start address
//
Context->Esp -= sizeof(Parameter);
ZwWriteVirtualMemory(Process,
(PVOID)Context->Esp,
(PVOID)&Parameter,
sizeof(Parameter),
NULL);
Context->Esp -= sizeof(Parameter); // Reserve room for ret address
}
VOID
RtlInitializeContext(
IN HANDLE Process,
OUT PCONTEXT Context,
IN PVOID Parameter OPTIONAL,
IN PVOID InitialPc OPTIONAL,
IN PVOID InitialSp OPTIONAL
)
/*++
Routine Description:
This function initializes a context structure so that it can
be used in a subsequent call to NtCreateThread.
Arguments:
Context - Supplies a context buffer to be initialized by this routine.
InitialPc - Supplies an initial program counter value.
InitialSp - Supplies an initial stack pointer value.
Return Value:
Raises STATUS_BAD_INITIAL_STACK if the value of InitialSp is not properly
aligned.
Raises STATUS_BAD_INITIAL_PC if the value of InitialPc is not properly
aligned.
--*/
{
RTL_PAGED_CODE();
Context->Eax = 0L;
Context->Ebx = 1L;
Context->Ecx = 2L;
Context->Edx = 3L;
Context->Esi = 4L;
Context->Edi = 5L;
Context->Ebp = 0L;
Context->SegGs = 0;
Context->SegFs = KGDT_R3_TEB;
Context->SegEs = KGDT_R3_DATA;
Context->SegDs = KGDT_R3_DATA;
Context->SegSs = KGDT_R3_DATA;
Context->SegCs = KGDT_R3_CODE;
Context->EFlags = 0x200L; // force interrupts on, clear all else.
//
// Even though these are optional, they are used as is, since NULL
// is what these would have been initialized to anyway
//
Context->Esp = (ULONG) InitialSp;
Context->Eip = (ULONG) InitialPc;
//
// add code to check alignment and raise exception...
//
Context->ContextFlags = CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS;
//
// Set the initial context of the thread in a machine specific way.
// ie, pass the initial parameter to the start address
//
Context->Esp -= sizeof(Parameter);
ZwWriteVirtualMemory(Process,
(PVOID)Context->Esp,
(PVOID)&Parameter,
sizeof(Parameter),
NULL);
Context->Esp -= sizeof(Parameter); // Reserve room for ret address
}