Skip to content

Commit

Permalink
Mantis #5754: JclCreateThreadStackTrace fails unpredictably on Win7 6…
Browse files Browse the repository at this point in the history
…4 bit
  • Loading branch information
ahausladen committed Jun 17, 2018
1 parent 267c312 commit bde4549
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions jcl/experts/debug/simdview/JclSIMDUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
JclBase,
JclSysInfo,
JclOtaResources;

Expand Down Expand Up @@ -938,8 +939,9 @@ function GetThreadJclContext(AThread: IOTAThread; out JclContext: TJclContext):
begin
GetMem(ContextMemory, SizeOf(TJclContext) + 15);
try
if (Cardinal(ContextMemory) and 15) <> 0 then
AlignedContext := PJclContext((Cardinal(ContextMemory) + 16) and $FFFFFFF0)
if (TJclAddr(ContextMemory) and 15) <> 0 then
// PAnsiChar: TJclAddr is signed and would cause an int overflow for half the address space
AlignedContext := PContext(TJclAddr(PAnsiChar(ContextMemory) + 16) and -16)
else
AlignedContext := ContextMemory;
AlignedContext^.ScalarContext.ContextFlags := CONTEXT_EXTENDED_REGISTERS;
Expand Down
8 changes: 4 additions & 4 deletions jcl/source/windows/JclDebug.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5292,13 +5292,13 @@ function JclCreateThreadStackTrace(Raw: Boolean; const ThreadHandle: THandle): T
AlignedContext: PContext;
begin
Result := nil;
GetMem(ContextMemory, SizeOf(TContext) + 15);
ContextMemory := AllocMem(SizeOf(TContext) + 15);
try
if (Cardinal(ContextMemory) and 15) <> 0 then
AlignedContext := PContext((Cardinal(ContextMemory) + 16) and $FFFFFFF0)
if (TJclAddr(ContextMemory) and 15) <> 0 then
// PAnsiChar: TJclAddr is signed and would cause an int overflow for half the address space
AlignedContext := PContext(TJclAddr(PAnsiChar(ContextMemory) + 16) and -16)
else
AlignedContext := ContextMemory;
ResetMemory(AlignedContext^, SizeOf(AlignedContext^));
AlignedContext^.ContextFlags := CONTEXT_FULL;
{$IFDEF CPU32}
if GetThreadContext(ThreadHandle, AlignedContext^) then
Expand Down

1 comment on commit bde4549

@PatrickvL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.