andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* andre@0: * GC related routines andre@0: * andre@0: */ andre@0: #include andre@0: #include "primpl.h" andre@0: andre@0: PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) andre@0: { andre@0: #if defined(_X86_) andre@0: CONTEXT context; andre@0: context.ContextFlags = CONTEXT_INTEGER; andre@0: andre@0: if (_PR_IS_NATIVE_THREAD(t)) { andre@0: context.ContextFlags |= CONTEXT_CONTROL; andre@0: if (GetThreadContext(t->md.handle, &context)) { andre@0: t->md.gcContext[0] = context.Eax; andre@0: t->md.gcContext[1] = context.Ebx; andre@0: t->md.gcContext[2] = context.Ecx; andre@0: t->md.gcContext[3] = context.Edx; andre@0: t->md.gcContext[4] = context.Esi; andre@0: t->md.gcContext[5] = context.Edi; andre@0: t->md.gcContext[6] = context.Esp; andre@0: t->md.gcContext[7] = context.Ebp; andre@0: *np = PR_NUM_GCREGS; andre@0: } else { andre@0: PR_ASSERT(0);/* XXX */ andre@0: } andre@0: } else { andre@0: /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING andre@0: * andre@0: * This code is extremely machine dependant and completely andre@0: * undocumented by MS. Its only known to work experimentally. andre@0: * Ready for a walk on the wild * side? andre@0: * andre@0: * WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ andre@0: andre@0: #if !defined WIN95 // Win95 does not have fibers andre@0: int *fiberData = t->md.fiber_id; andre@0: andre@0: /* I found these offsets by disassembling SwitchToFiber(). andre@0: * Are your palms sweating yet? andre@0: */ andre@0: andre@0: /* andre@0: ** EAX is on the stack (ESP+0) andre@0: ** EDX is on the stack (ESP+4) andre@0: ** ECX is on the stack (ESP+8) andre@0: */ andre@0: t->md.gcContext[0] = 0; /* context.Eax */ andre@0: t->md.gcContext[1] = fiberData[0x2e]; /* context.Ebx */ andre@0: t->md.gcContext[2] = 0; /* context.Ecx */ andre@0: t->md.gcContext[3] = 0; /* context.Edx */ andre@0: t->md.gcContext[4] = fiberData[0x2d]; /* context.Esi */ andre@0: t->md.gcContext[5] = fiberData[0x2c]; /* context.Edi */ andre@0: t->md.gcContext[6] = fiberData[0x36]; /* context.Esp */ andre@0: t->md.gcContext[7] = fiberData[0x32]; /* context.Ebp */ andre@0: *np = PR_NUM_GCREGS; andre@0: #endif andre@0: } andre@0: return (PRWord *)&t->md.gcContext; andre@0: #else andre@0: PR_NOT_REACHED("not implemented"); andre@0: return NULL; andre@0: #endif /* defined(_X86_) */ andre@0: } andre@0: andre@0: /* This function is not used right now, but is left as a reference. andre@0: * If you ever need to get the fiberID from the currently running fiber, andre@0: * this is it. andre@0: */ andre@0: void * andre@0: GetMyFiberID() andre@0: { andre@0: #if defined(_X86_) && !defined(__MINGW32__) andre@0: void *fiberData; andre@0: andre@0: /* A pointer to our tib entry is found at FS:[18] andre@0: * At offset 10h is the fiberData pointer. The context of the andre@0: * fiber is stored in there. andre@0: */ andre@0: __asm { andre@0: mov EDX, FS:[18h] andre@0: mov EAX, DWORD PTR [EDX+10h] andre@0: mov [fiberData], EAX andre@0: } andre@0: andre@0: return fiberData; andre@0: #else andre@0: PR_NOT_REACHED("not implemented"); andre@0: return NULL; andre@0: #endif /* defined(_X86_) */ andre@0: }