Bug 12627 - register context saved by setjmp is skipped by GC on windows
Summary: register context saved by setjmp is skipped by GC on windows
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 420+
Hardware: PC Windows XP
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-05 21:06 PST by Huan Ren
Modified: 2011-06-13 23:05 PDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Huan Ren 2007-02-05 21:06:33 PST
code snippet in Collector::markCurrentThreadConservatively: 
{
  ...
  // use setjmp to save register context on the stack
  jmp_buf registers;
  setjmp(registers);
  ...
  // get the base of the stack
   NT_TIB *pTib;
   __asm {
       MOV EAX, FS:[18h]
       MOV pTib, EAX
   }
   void *stackBase = (void *)pTib->StackBase;
  ...
  // get the current top of the stack.
  void *dummy;
  void *stackPointer = &dummy;

  markStackObjectsConservatively(stackPointer, stackBase);
  ...
}

If my understanding of the above code is correct, the assumption here is that the address of dummy should be lower than jmp_buf (assuming stack going downawards) so all saved register context will be included. however, this is not the case for windows by examining the stack at run time:

0:000> bp KJS::Collector::markCurrentThreadConservatively
0:000> g
Breakpoint 1 hit
eax=04cb8f40 ebx=00000000 ecx=00000000 edx=00687ee0 esi=04cc8f30 edi=00000030
eip=006833f0 esp=0012f6a8 ebp=7c859d78 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
KJS::Collector::markCurrentThreadConservatively:
006833f0 55              push    ebp
0:000> dv /V
7c859d70 @ebp-0x08           dummy = 0x90007865
7c859d30 @ebp-0x48       registers = int [16]
7c859d74 @ebp-0x04            pTib = 0x90909090

The address of dummy is actually higher than register. Thus all register context saved by setjmp are ignored.

- Anrong
Comment 1 Gavin Barraclough 2011-06-13 23:05:01 PDT
> If my understanding of the above code is correct, the assumption here is that the address of dummy should be lower than jmp_buf (assuming stack going downawards) so all saved register context will be included. however, this is not the case for windows by examining the stack at run time:

I think this analysis was correct, however the code has changed a lot since then.  Looking at MachineThreads::gatherFromCurrentThread now, the jmp_buf is marked separately (there are two calls to conservativeRoots.add).

Looks like this was a bug, but has since been fixed.