Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions | Variables
mdmac.c File Reference
#include <Types.h>
#include <Timer.h>
#include <Files.h>
#include <Errors.h>
#include <Folders.h>
#include <Gestalt.h>
#include <Events.h>
#include <Processes.h>
#include <TextUtils.h>
#include <MixedMode.h>
#include <LowMem.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stat.h>
#include <stdarg.h>
#include <unix.h>
#include "MacErrorHandling.h"
#include "primpl.h"
#include "prgc.h"
#include "mactime.h"
#include "mdmac.h"

Go to the source code of this file.

Classes

struct  EnvVariable

Defines

#define CLOSE_OPEN_TRANSPORT()   CloseOpenTransport()

Typedefs

typedef struct EnvVariable

Enumerations

enum  { uppExitToShellProcInfo = kPascalStackBased, uppStackSpaceProcInfo }

Functions

unsigned char GarbageCollectorCacheFlusher (PRUint32 size)
typedef CALLBACK_API (long, StackSpacePatchPtr)
static void InstallStackSpacePatch (void)
char * _MD_GetEnv (const char *name)
 _MD_PutEnv (const char *string)
PRWord_MD_HomeGCRegisters (PRThread *t, int isCurrent, int *np)
void _MD_GetRegisters (PRUint32 *to)
void _MD_EarlyInit ()
void _MD_FinalInit ()
void PR_InitMemory (void)
pascal void __NSTerminate (void)
void CleanupTermProc (void)
void PStrFromCStr (const char *src, Str255 dst)
void CStrFromPStr (ConstStr255Param pString, char **cString)
void dprintf (const char *format,...)
long _MD_GetOSName (char *buf, long count)
long _MD_GetOSVersion (char *buf, long count)
long _MD_GetArchitecture (char *buf, long count)

Variables

PRThreadgPrimaryThread
ProcessSerialNumber gApplicationProcess
EnvVariablegEnvironmentVariables = NULL

Class Documentation

struct EnvVariable

Definition at line 189 of file mdmac.c.

Collaboration diagram for EnvVariable:
Class Members
EnvVariable * next
char * value
char * variable

Define Documentation

#define CLOSE_OPEN_TRANSPORT ( )    CloseOpenTransport()

Definition at line 376 of file mdmac.c.


Typedef Documentation

typedef struct EnvVariable

Definition at line 187 of file mdmac.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
uppExitToShellProcInfo 
uppStackSpaceProcInfo 

Definition at line 85 of file mdmac.c.

     {
       uppExitToShellProcInfo                           = kPascalStackBased,
       uppStackSpaceProcInfo                            = kRegisterBased 
                                                                        | RESULT_SIZE(SIZE_CODE(sizeof(long)))
                                                                        | REGISTER_RESULT_LOCATION(kRegisterD0)
                                                                        | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(UInt16)))
};

Function Documentation

pascal void __NSTerminate ( void  )

Definition at line 291 of file mdmac.c.

{
       Handle                      environmentVariables;

       GetCurrentProcess(&gApplicationProcess);

       INIT_CRITICAL_REGION();
       InitIdleSemaphore();

#if !defined(MAC_NSPR_STANDALONE)
       // MacintoshInitializeMemory();  Moved to mdmacmem.c: AllocateRawMemory(Size blockSize)
#else
       MacintoshInitializeMemory();
#endif
       MacintoshInitializeTime();
       
       //     Install resource-controlled environment variables.
       
       environmentVariables = GetResource('Envi', 128);
       if (environmentVariables != NULL) {
       
              Size   resourceSize;
              char   *currentPutEnvString = (char *)*environmentVariables,
                            *currentScanChar = currentPutEnvString;
                            
              resourceSize = GetHandleSize(environmentVariables);                   
              DetachResource(environmentVariables);
              HLock(environmentVariables);
              
              while (resourceSize--) {
              
                     if ((*currentScanChar == '\n') || (*currentScanChar == '\r')) {
                            *currentScanChar = 0;
                            _MD_PutEnv (currentPutEnvString);
                            currentPutEnvString = currentScanChar + 1;
                     }
              
                     currentScanChar++;
              
              }
              
              DisposeHandle(environmentVariables);

       }

#ifdef PR_INTERNAL_LOGGING
       _MD_PutEnv ("NSPR_LOG_MODULES=clock:6,cmon:6,io:6,mon:6,linker:6,cvar:6,sched:6,thread:6");
#endif

       InstallStackSpacePatch();
}

Here is the call graph for this function:

Definition at line 343 of file mdmac.c.

Here is the call graph for this function:

long _MD_GetArchitecture ( char *  buf,
long  count 
)

Definition at line 765 of file mdmac.c.

{
       long   len;
       
#if defined(TARGET_CPU_PPC) && TARGET_CPU_PPC    
       len = PR_snprintf(buf, count, "PowerPC");
#else
       len = PR_snprintf(buf, count, "Motorola68k");
#endif

       return 0;
}

Here is the call graph for this function:

char* _MD_GetEnv ( const char *  name)

Definition at line 197 of file mdmac.c.

{
       EnvVariable   *currentVariable = gEnvironmentVariables;

       while (currentVariable) {
              if (!strcmp(currentVariable->variable, name))
                     return currentVariable->value;
                     
              currentVariable = currentVariable->next;
       }

       return getenv(name);
}
long _MD_GetOSName ( char *  buf,
long  count 
)

Definition at line 747 of file mdmac.c.

{
       long   len;
       
       len = PR_snprintf(buf, count, "Mac OS");
       
       return 0;
}

Here is the call graph for this function:

long _MD_GetOSVersion ( char *  buf,
long  count 
)

Definition at line 756 of file mdmac.c.

{
       long   len;
       
       len = PR_snprintf(buf, count, "7.5");

       return 0;
}

Here is the call graph for this function:

Definition at line 286 of file mdmac.c.

{
  (void) setjmp((void*) to);
}
PRWord* _MD_HomeGCRegisters ( PRThread t,
int  isCurrent,
int np 
)

Definition at line 277 of file mdmac.c.

{
    if (isCurrent) {
       (void) setjmp(t->md.jb);
    }
    *np = sizeof(t->md.jb) / sizeof(PRUint32);
    return (PRWord*) (t->md.jb);
}
_MD_PutEnv ( const char *  string)

Definition at line 212 of file mdmac.c.

{
       EnvVariable   *currentVariable = gEnvironmentVariables;
       char                 *variableCopy,
                                *value,
                                   *current;
                                   
       variableCopy = strdup(string);
       PR_ASSERT(variableCopy != NULL);

       current = variableCopy;
       while (*current != '=')
              current++;

       *current = 0;
       current++;

       value = current;

       while (currentVariable) {
              if (!strcmp(currentVariable->variable, variableCopy))
                     break;
              
              currentVariable = currentVariable->next;
       }

       if (currentVariable == NULL) {
              currentVariable = PR_NEW(EnvVariable);
              
              if (currentVariable == NULL) {
                     PR_DELETE(variableCopy);
                     return -1;
              }
              
              currentVariable->variable = strdup(variableCopy);
              currentVariable->value = strdup(value);
              currentVariable->next = gEnvironmentVariables;
              gEnvironmentVariables = currentVariable;
       }
       
       else {
              PR_DELETE(currentVariable->value);
              currentVariable->value = strdup(current);

              /* This is a temporary hack.  Working on a real fix, remove this when done. */
              /* OK, there are two ways to access the  */
              /* library path, getenv() and PR_GetLibraryPath().  Take a look at PR_GetLibraryPath(). */
              /* You'll see that we keep the path in a global which is intialized at startup from */
              /* a call to getenv().  From then on, they have nothing in common. */
              /* We need to keep them in synch.  */
              if (strcmp(currentVariable->variable, "LD_LIBRARY_PATH") == 0)
                     PR_SetLibraryPath(currentVariable->value);
       }
       
       PR_DELETE(variableCopy);
       return 0;
}

Here is the caller graph for this function:

typedef CALLBACK_API ( long  ,
StackSpacePatchPtr   
)

Definition at line 93 of file mdmac.c.

{
       char          tos;
       PRThread      *thisThread;
       
       thisThread = PR_CurrentThread();
       
       //     If we are the primary thread, then call through to the
       //     good ol' fashion stack space implementation.  Otherwise,
       //     compute it by hand.
       if ((thisThread == gPrimaryThread) ||     
              (&tos < thisThread->stack->stackBottom) || 
              (&tos > thisThread->stack->stackTop)) {
              return gCallOSTrapUniversalProc(gStackSpacePatchCallThru, uppStackSpaceProcInfo, trapNo);
       }
       else {
              return &tos - thisThread->stack->stackBottom;
       }
}

Definition at line 381 of file mdmac.c.

Here is the call graph for this function:

void CStrFromPStr ( ConstStr255Param  pString,
char **  cString 
)

Definition at line 452 of file mdmac.c.

{
       // Allocates a cString and copies a Pascal string into it.
       unsigned int  len;
       
       len = pString[0];
       *cString = malloc(len+1);
       
       if (*cString != NULL) {
              strncpy(*cString, (char *)&pString[1], len);
              (*cString)[len] = NULL;
       }
}

Here is the caller graph for this function:

void dprintf ( const char *  format,
  ... 
)

Definition at line 467 of file mdmac.c.

{
#if DEBUG
    va_list ap;
       Str255 buffer;
       
       va_start(ap, format);
       buffer[0] = PR_vsnprintf((char *)buffer + 1, sizeof(buffer) - 1, format, ap);
       va_end(ap);
       
       DebugStr(buffer);
#endif /* DEBUG */
}
unsigned char GarbageCollectorCacheFlusher ( PRUint32  size)

Definition at line 679 of file mdmac.c.

{

    PRIntn is;

       UInt32        oldPriority;

       //     If java wasn't completely initialized, then bail 
       //     harmlessly.
       
       if (PR_GetGCInfo()->lock == NULL)
              return false;

#if DEBUG
       if (_MD_GET_INTSOFF() == 1)
              DebugStr("\pGarbageCollectorCacheFlusher at interrupt time!");
#endif

       //     The synchronization here is very tricky.  We really
       //     don't want any other threads to run while we are 
       //     cleaning up the gc heap... they could call malloc,
       //     and then we would be in trouble in a big way.  So,
       //     we jack up our priority and that of the finalizer
       //     so that we won't yield to other threads.
       //     dkc 5/17/96

       oldPriority = PR_GetThreadPriority(PR_GetCurrentThread());
       _PR_INTSOFF(is);
       _PR_SetThreadPriority(PR_GetCurrentThread(), (PRThreadPriority)30);
       _PR_INTSON(is);

       //     Garbage collect twice.  This will finalize any
       //     dangling AWT resources (images, components), and
       //     then free up their GC space, too.
       //     dkc 2/15/96
       //  interrupts must be on during PR_GC
       
       PR_GC();
       
       //     By setting the finalizer priority to 31, then we 
       //     ensure it will run before us.  When it finishes
       //     its list of finalizations, it returns to us
       //     for the second garbage collection.
       
       PR_Yield();

       PR_GC();
       
       //     Restore our old priorities.
       
       _PR_INTSOFF(is);
       _PR_SetThreadPriority(PR_GetCurrentThread(), (PRThreadPriority)oldPriority);
       _PR_INTSON(is);

       return false;
}

Here is the call graph for this function:

static void InstallStackSpacePatch ( void  ) [static]

Definition at line 122 of file mdmac.c.

{
       long                        systemVersion;
       OSErr                       err;
       CFragConnectionID    connID;
       Str255                      errMessage;
       Ptr                                interfaceLibAddr;
       CFragSymbolClass     symClass;
       UniversalProcPtr     (*getOSTrapAddressProc)(UInt16);
       void                        (*setOSTrapAddressProc)(StackSpacePatchUPP, UInt16);
       UniversalProcPtr     (*newRoutineDescriptorProc)(ProcPtr,ProcInfoType,ISAType);
       

       err = Gestalt(gestaltSystemVersion,&systemVersion);
       if (systemVersion >= 0x00000A00)   // we don't need to patch StackSpace()
              return;

       // open connection to "InterfaceLib"
       err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
                                                                             &connID, &interfaceLibAddr, errMessage);
       PR_ASSERT(err == noErr);
       if (err != noErr)
              return;

       // get symbol GetOSTrapAddress
       err = FindSymbol(connID, "\pGetOSTrapAddress", &(Ptr)getOSTrapAddressProc, &symClass);
       if (err != noErr)
              return;

       // get symbol SetOSTrapAddress
       err = FindSymbol(connID, "\pSetOSTrapAddress", &(Ptr)setOSTrapAddressProc, &symClass);
       if (err != noErr)
              return;
       
       // get symbol NewRoutineDescriptor
       err = FindSymbol(connID, "\pNewRoutineDescriptor", &(Ptr)newRoutineDescriptorProc, &symClass);
       if (err != noErr)
              return;
       
       // get symbol CallOSTrapUniversalProc
       err = FindSymbol(connID, "\pCallOSTrapUniversalProc", &(Ptr)gCallOSTrapUniversalProc, &symClass);
       if (err != noErr)
              return;

       // get and set trap address for StackSpace (A065)
       gStackSpacePatchCallThru = getOSTrapAddressProc(0x0065);
       if (gStackSpacePatchCallThru)
       {
              gStackSpacePatchUPP =
                     (StackSpacePatchUPP)newRoutineDescriptorProc((ProcPtr)(StackSpacePatch), uppStackSpaceProcInfo, GetCurrentArchitecture());
              setOSTrapAddressProc(gStackSpacePatchUPP, 0x0065);
       }

#if DEBUG
       StackSpace();
#endif
}

Here is the caller graph for this function:

Definition at line 348 of file mdmac.c.

                         {
#ifndef NSPR_AS_SHARED_LIB
       //     Needed for Mac browsers without Java.  We don't want them calling PR_INIT, since it
       //     brings in all of the thread support.  But we do need to allow them to initialize
       //     the NSPR memory package.
       //     This should go away when all clients of the NSPR want threads AND memory.
       MacintoshInitializeMemory();
#endif
}
void PStrFromCStr ( const char *  src,
Str255  dst 
)

Definition at line 407 of file mdmac.c.

{
       short  length  = 0;
       
       // handle case of overlapping strings
       if ( (void*)src == (void*)dst )
       {
              unsigned char*              curdst = &dst[1];
              unsigned char        thisChar;
                            
              thisChar = *(const unsigned char*)src++;
              while ( thisChar != '\0' ) 
              {
                     unsigned char nextChar;
                     
                     // use nextChar so we don't overwrite what we are about to read
                     nextChar = *(const unsigned char*)src++;
                     *curdst++ = thisChar;
                     thisChar = nextChar;
                     
                     if ( ++length >= 255 )
                            break;
              }
       }
       else if ( src != NULL )
       {
              unsigned char*              curdst = &dst[1];
              short                       overflow = 255;             // count down so test it loop is faster
              register char        temp;
       
              // Can't do the K&R C thing of "while (*s++ = *t++)" because it will copy trailing zero
              // which might overrun pascal buffer.  Instead we use a temp variable.
              while ( (temp = *src++) != 0 ) 
              {
                     *(char*)curdst++ = temp;
                            
                     if ( --overflow <= 0 )
                            break;
              }
              length = 255 - overflow;
       }
       dst[0] = length;
}

Here is the caller graph for this function:


Variable Documentation

ProcessSerialNumber gApplicationProcess

Definition at line 55 of file macthr.c.

Definition at line 195 of file mdmac.c.

Definition at line 53 of file macthr.c.