mdmac.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#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"
// undefine getenv, so that _MD_GetEnv can call the version in NSStdLib::nsEnvironment.cpp.
//
// Local routines
//
extern PRThread *gPrimaryThread;
//##############################################################################
//##############################################################################
#pragma mark -
enum {
| RESULT_SIZE(SIZE_CODE(sizeof(long)))
};
{
char tos;
// 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) ||
}
else {
}
}
static void InstallStackSpacePatch(void)
{
long systemVersion;
return;
// open connection to "InterfaceLib"
return;
// get symbol GetOSTrapAddress
return;
// get symbol SetOSTrapAddress
return;
// get symbol NewRoutineDescriptor
return;
// get symbol CallOSTrapUniversalProc
return;
// get and set trap address for StackSpace (A065)
{
(StackSpacePatchUPP)newRoutineDescriptorProc((ProcPtr)(StackSpacePatch), uppStackSpaceProcInfo, GetCurrentArchitecture());
}
#if DEBUG
StackSpace();
#endif
}
//##############################################################################
//##############################################################################
#pragma mark -
typedef struct EnvVariable EnvVariable;
struct EnvVariable {
char *variable;
char *value;
};
char *_MD_GetEnv(const char *name)
{
while (currentVariable) {
return currentVariable->value;
}
}
PR_IMPLEMENT(int)
_MD_PutEnv(const char *string)
{
char *variableCopy,
*value,
*current;
while (*current != '=')
current++;
*current = 0;
current++;
while (currentVariable) {
break;
}
if (currentVariable == NULL) {
if (currentVariable == NULL) {
return -1;
}
}
else {
/* 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. */
}
return 0;
}
//##############################################################################
//##############################################################################
#pragma mark -
#pragma mark MISCELLANEOUS
{
if (isCurrent) {
}
}
{
}
void _MD_EarlyInit()
{
#if !defined(MAC_NSPR_STANDALONE)
// MacintoshInitializeMemory(); Moved to mdmacmem.c: AllocateRawMemory(Size blockSize)
#else
#endif
// Install resource-controlled environment variables.
if (environmentVariables != NULL) {
char *currentPutEnvString = (char *)*environmentVariables,
while (resourceSize--) {
*currentScanChar = 0;
}
}
}
#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
}
void _MD_FinalInit()
{
}
void PR_InitMemory(void) {
#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.
#endif
}
//##############################################################################
//##############################################################################
#pragma mark -
#pragma mark TERMINATION
// THIS IS *** VERY *** IMPORTANT... our CFM Termination proc.
// This allows us to deactivate our Time Mananger task even
// if we are not totally gracefully exited. If this is not
// done then we will randomly crash at later times when the
// task is called after the app heap is gone.
#if TARGET_CARBON
extern OTClientContextPtr clientContext;
#else
#define CLOSE_OPEN_TRANSPORT() CloseOpenTransport()
#endif /* TARGET_CARBON */
extern pascal void __NSTerminate(void);
void CleanupTermProc(void)
{
_MD_StopInterrupts(); // deactive Time Manager task
}
//##############################################################################
//##############################################################################
#pragma mark -
#if !defined(MAC_NSPR_STANDALONE)
// PStrFromCStr converts the source C string to a destination
// pascal string as it copies. The dest string will
// be truncated to fit into an Str255 if necessary.
// If the C String pointer is NULL, the pascal string's length is set to zero
//
void
{
short length = 0;
// handle case of overlapping strings
{
unsigned char thisChar;
while ( thisChar != '\0' )
{
unsigned char nextChar;
// use nextChar so we don't overwrite what we are about to read
if ( ++length >= 255 )
break;
}
}
{
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.
{
if ( --overflow <= 0 )
break;
}
}
}
{
// Allocates a cString and copies a Pascal string into it.
unsigned int len;
}
}
{
#if DEBUG
#endif /* DEBUG */
}
#else
void debugstr(const char *debuggerMsg)
{
}
{
char *newAllocation;
if (newAllocation == NULL)
return NULL;
return newAllocation;
}
// PStrFromCStr converts the source C string to a destination
// pascal string as it copies. The dest string will
// be truncated to fit into an Str255 if necessary.
// If the C String pointer is NULL, the pascal string's length is set to zero
//
{
short length = 0;
// handle case of overlapping strings
{
unsigned char thisChar;
while ( thisChar != '\0' )
{
unsigned char nextChar;
// use nextChar so we don't overwrite what we are about to read
if ( ++length >= 255 )
break;
}
}
{
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.
{
if ( --overflow <= 0 )
break;
}
}
}
{
// Allocates a cString and copies a Pascal string into it.
unsigned int len;
}
}
{
size_t currentLength = 0;
return currentLength;
while (*source++ != '\0')
return currentLength;
}
{
char currentChar1, currentChar2;
while (1) {
currentChar1 = *str1;
currentChar2 = *str2;
if (!caseSensitive) {
}
if (currentChar1 == '\0')
break;
if (currentChar1 != currentChar2)
return currentChar1 - currentChar2;
str1++;
str2++;
}
return currentChar1 - currentChar2;
}
{
}
{
}
{
if (size != 0) {
#if DEBUG
DebugStr("\pmemcpy has illegal to argument");
DebugStr("\pmemcpy has illegal from argument");
#endif
}
return to;
}
{
char *buffer;
}
void
{
ExitToShell();
}
void abort(void)
{
exit(-1);
}
#endif
//##############################################################################
//##############################################################################
#pragma mark -
#if !defined(MAC_NSPR_STANDALONE)
unsigned char GarbageCollectorCacheFlusher(PRUint32)
{
// If java wasn't completely initialized, then bail
// harmlessly.
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
_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_INTSON(is);
return false;
}
#endif
//##############################################################################
//##############################################################################
#pragma mark -
//
// ***** HACK FIX THESE ****
//
{
long len;
return 0;
}
{
long len;
return 0;
}
{
long len;
#if defined(TARGET_CPU_PPC) && TARGET_CPU_PPC
#else
#endif
return 0;
}