home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / src / md / windows / ntgc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.6 KB  |  108 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  * GC related routines
  21.  *
  22.  */
  23. #include <windows.h>
  24. #include "primpl.h"
  25.  
  26. PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np) 
  27. {
  28. #if defined(_X86_)
  29.     CONTEXT context;
  30.     context.ContextFlags = CONTEXT_INTEGER;
  31.  
  32.     if (_PR_IS_NATIVE_THREAD(t)) {
  33.         context.ContextFlags |= CONTEXT_CONTROL;
  34.         if (GetThreadContext(t->md.handle, &context)) {
  35.             t->md.gcContext[0] = context.Eax;
  36.             t->md.gcContext[1] = context.Ebx;
  37.             t->md.gcContext[2] = context.Ecx;
  38.             t->md.gcContext[3] = context.Edx;
  39.             t->md.gcContext[4] = context.Esi;
  40.             t->md.gcContext[5] = context.Edi;
  41.             t->md.gcContext[6] = context.Esp;
  42.             t->md.gcContext[7] = context.Ebp;
  43.             *np = PR_NUM_GCREGS;
  44.         } else {
  45.             PR_ASSERT(0);/* XXX */
  46.         }
  47.     } else {
  48.         /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  49.          *
  50.          * This code is extremely machine dependant and completely 
  51.          * undocumented by MS.  Its only known to work experimentally.  
  52.          * Ready for a walk on the wild * side?
  53.          *
  54.          * WARNING WARNING WARNING WARNING WARNING WARNING WARNING */
  55.  
  56. #if !defined WIN95 // Win95 does not have fibers
  57.         int *fiberData = t->md.fiber_id;
  58.  
  59.         /* I found these offsets by disassembling SwitchToFiber().
  60.          * Are your palms sweating yet?
  61.          */
  62.  
  63.         /* 
  64.         ** EAX is on the stack (ESP+0)
  65.         ** EDX is on the stack (ESP+4)
  66.         ** ECX is on the stack (ESP+8)
  67.         */
  68.         t->md.gcContext[0] = 0;                /* context.Eax */
  69.         t->md.gcContext[1] = fiberData[0x2e];  /* context.Ebx */
  70.         t->md.gcContext[2] = 0;                /* context.Ecx */
  71.         t->md.gcContext[2] = 0;                /* context.Edx */
  72.         t->md.gcContext[4] = fiberData[0x2d];  /* context.Esi */
  73.         t->md.gcContext[5] = fiberData[0x2c];  /* context.Edi */
  74.         t->md.gcContext[6] = fiberData[0x36];  /* context.Esp */
  75.         t->md.gcContext[7] = fiberData[0x32];  /* context.Ebp */
  76.         *np = PR_NUM_GCREGS;
  77. #endif
  78.     }
  79.     return (PRWord *)&t->md.gcContext;
  80. #elif defined(_ALPHA_)
  81. #endif /* defined(_X86_) */
  82. }
  83.  
  84. /* This function is not used right now, but is left as a reference.
  85.  * If you ever need to get the fiberID from the currently running fiber, 
  86.  * this is it.
  87.  */
  88. void *
  89. GetMyFiberID()
  90. {
  91. #if defined(_X86_)
  92.     void *fiberData;
  93.  
  94.     /* A pointer to our tib entry is found at FS:[18]
  95.      * At offset 10h is the fiberData pointer.  The context of the 
  96.      * fiber is stored in there.  
  97.      */
  98.     __asm {
  99.         mov    EDX, FS:[18h]
  100.         mov    EAX, DWORD PTR [EDX+10h]
  101.         mov    [fiberData], EAX
  102.     }
  103.   
  104.     return fiberData;
  105. #elif defined(_ALPHA_)
  106. #endif /* defined(_X86_) */
  107. }
  108.