--- truecrypt/boot/windows/bootdebug.cpp 2018/04/24 16:49:04 1.1 +++ truecrypt/boot/windows/bootdebug.cpp 2018/04/24 17:05:46 1.1.1.6 @@ -1,7 +1,7 @@ /* Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. - Governed by the TrueCrypt License 2.4 the full text of which is contained + Governed by the TrueCrypt License 2.8 the full text of which is contained in the file License.txt included in TrueCrypt binary and source code distribution packages. */ @@ -9,10 +9,13 @@ #include "Platform.h" #include "Bios.h" #include "BootConsoleIo.h" +#include "BootDefs.h" #include "BootDiskIo.h" #include "BootDebug.h" +#ifdef TC_BOOT_TRACING_ENABLED + void InitDebugPort () { __asm @@ -38,6 +41,10 @@ void WriteDebugPort (byte dataByte) } } +#endif // TC_BOOT_TRACING_ENABLED + + +#ifdef TC_BOOT_DEBUG_ENABLED extern "C" void PrintDebug (uint32 debugVal) { @@ -46,20 +53,6 @@ extern "C" void PrintDebug (uint32 debug } -void PrintAddress (void *addr) -{ - uint16 segment = uint16 (uint32 (addr) >> 16); - uint16 offset = uint16 (addr); - - PrintHex (segment); - PrintChar (':'); - PrintHex (offset); - Print (" ("); - PrintHex (GetLinearAddress (segment, offset)); - Print (")"); -} - - void PrintVal (const char *message, const uint32 value, bool newLine, bool hex) { Print (message); @@ -139,3 +132,46 @@ void PrintHexDump (uint16 memSegment, ui { PrintHexDump ((byte *) memOffset, size, &memSegment); } + +#endif // TC_BOOT_DEBUG_ENABLED + + +#ifdef TC_BOOT_STACK_CHECKING_ENABLED + +extern "C" char end[]; + +static void PrintStackInfo () +{ + uint16 spReg; + __asm mov spReg, sp + + Print ("Stack: "); Print (TC_BOOT_LOADER_STACK_TOP - spReg); + Print ("/"); Print (TC_BOOT_LOADER_STACK_TOP - (uint16) end); +} + + +void CheckStack () +{ + uint16 spReg; + __asm mov spReg, sp + + if (*(uint32 *) end != 0x12345678UL || spReg < (uint16) end) + { + __asm cli + __asm mov sp, TC_BOOT_LOADER_STACK_TOP + + PrintError ("Stack overflow"); + TC_THROW_FATAL_EXCEPTION; + } +} + + +void InitStackChecker () +{ + *(uint32 *) end = 0x12345678UL; + + PrintStackInfo(); + PrintEndl(); +} + +#endif // TC_BOOT_STACK_CHECKING_ENABLED