From 9fa8f0915ef228c62bacf2f05e1064ea38fc981c Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 4 Feb 2012 18:35:56 +0000 Subject: [PATCH] [RTL] - Fix RtlLengthSecurityDescriptor - Implement amd64 version of Implement RtlInitializeContext - Add unwind info to amd64 debug asm functions - Fix 64 bit HEAP_COMMON_ENTRY structure The resulting version doesn't exactly match the original windows one, but its compatible, as every field, except the dummy fields - which are omitted - is at its correct position. svn path=/trunk/; revision=55415 --- reactos/lib/rtl/amd64/debug_asm.S | 19 ++++++++--- reactos/lib/rtl/amd64/stubs.c | 56 +++++++++++++++++++++++++++++-- reactos/lib/rtl/heap.h | 7 ++++ 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/reactos/lib/rtl/amd64/debug_asm.S b/reactos/lib/rtl/amd64/debug_asm.S index ca09236c566..b89ea57052c 100644 --- a/reactos/lib/rtl/amd64/debug_asm.S +++ b/reactos/lib/rtl/amd64/debug_asm.S @@ -22,20 +22,31 @@ PUBLIC RtlpBreakWithStatusInstruction .code64 -DbgBreakPointNoBugCheck: +.PROC DbgBreakPointNoBugCheck + .endprolog int 3 ret +.ENDP -DbgBreakPoint: DbgUserBreakPoint: +.PROC DbgBreakPoint + .endprolog int 3 ret +.ENDP -DbgBreakPointWithStatus: +.PROC DbgBreakPointWithStatus + .endprolog mov eax, ecx -RtlpBreakWithStatusInstruction: int 3 ret +.ENDP + +.PROC RtlpBreakWithStatusInstruction + .endprolog + int 3 + ret +.ENDP DebugService2: ret diff --git a/reactos/lib/rtl/amd64/stubs.c b/reactos/lib/rtl/amd64/stubs.c index 83060c77619..cd9412db2a0 100644 --- a/reactos/lib/rtl/amd64/stubs.c +++ b/reactos/lib/rtl/amd64/stubs.c @@ -11,6 +11,7 @@ #include #define NDEBUG #include +#include "amd64/ketypes.h" /* PUBLIC FUNCTIONS **********************************************************/ @@ -23,9 +24,60 @@ RtlInitializeContext(IN HANDLE ProcessHandle, OUT PCONTEXT ThreadContext, IN PVOID ThreadStartParam OPTIONAL, IN PTHREAD_START_ROUTINE ThreadStartAddress, - IN PINITIAL_TEB InitialTeb) + IN PINITIAL_TEB StackBase) { - UNIMPLEMENTED; + + ThreadContext->Rax = 0; + ThreadContext->Rbx = 0; + ThreadContext->Rcx = (ULONG64)ThreadStartParam; + ThreadContext->Rdx = 0; + ThreadContext->Rsi = 0; + ThreadContext->Rdi = 0; + ThreadContext->Rbp = 0; + ThreadContext->R8 = 0; + ThreadContext->R9 = 0; + ThreadContext->R10 = 0; + ThreadContext->R11 = 0; + ThreadContext->R12 = 0; + + /* Set the Selectors */ + if ((LONG64)ThreadStartAddress < 0) + { + /* Initialize kernel mode segments */ + ThreadContext->SegCs = KGDT64_R0_CODE; + ThreadContext->SegDs = KGDT64_R3_DATA; + ThreadContext->SegEs = KGDT64_R3_DATA; + ThreadContext->SegFs = KGDT64_R3_CMTEB; + ThreadContext->SegGs = KGDT64_R3_DATA; + ThreadContext->SegSs = KGDT64_R0_DATA; + } + else + { + /* Initialize user mode segments */ + ThreadContext->SegCs = KGDT64_R3_CODE | RPL_MASK; + ThreadContext->SegDs = KGDT64_R3_DATA | RPL_MASK; + ThreadContext->SegEs = KGDT64_R3_DATA | RPL_MASK; + ThreadContext->SegFs = KGDT64_R3_CMTEB | RPL_MASK; + ThreadContext->SegGs = KGDT64_R3_DATA | RPL_MASK; + ThreadContext->SegSs = KGDT64_R3_DATA | RPL_MASK; + } + + /* Enable Interrupts */ + ThreadContext->EFlags = EFLAGS_INTERRUPT_MASK; + + /* Settings passed */ + ThreadContext->Rip = (ULONG64)ThreadStartAddress; + ThreadContext->Rsp = (ULONG64)StackBase - 6 * sizeof(PVOID); + + /* Align stack by 16 and substract 8 (unaligned on function entry) */ + ThreadContext->Rsp &= ~15; + ThreadContext->Rsp -= 8; + + /* Only the basic Context is initialized */ + ThreadContext->ContextFlags = CONTEXT_CONTROL | + CONTEXT_INTEGER | + CONTEXT_SEGMENTS; + return; } diff --git a/reactos/lib/rtl/heap.h b/reactos/lib/rtl/heap.h index dc8892109f0..e76b742e3db 100644 --- a/reactos/lib/rtl/heap.h +++ b/reactos/lib/rtl/heap.h @@ -78,6 +78,9 @@ RtlpHeapIsSpecial(ULONG Flags) /* Heap structures */ struct _HEAP_COMMON_ENTRY { +#ifdef _M_AMD64 + PVOID PreviousBlockPrivateData; +#endif union { struct @@ -88,7 +91,11 @@ struct _HEAP_COMMON_ENTRY }; struct { +#ifndef _M_AMD64 PVOID SubSegmentCode; +#else + ULONG SubSegmentCodeDummy; +#endif USHORT PreviousSize; union {