Back to index

lightning-sunbird  0.9+nobinonly
_macos.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef prmacos_h___
00039 #define prmacos_h___
00040 
00041 //
00042 // This file contains all changes and additions which need to be made to the NSPR runtime 
00043 // for the Macintosh platform (specifically the Metrowerks environment).  This file should 
00044 // only be incluced in Macintosh builds.
00045 //
00046 
00047 #define PR_DLL_SUFFIX              ""
00048 #define _PR_LOCAL_THREADS_ONLY
00049 #define _PR_NO_PREEMPT      1
00050 #define _PR_HAVE_ATOMIC_OPS 1
00051 
00052 #include "prinit.h"
00053 #include "prio.h"
00054 #include "prlong.h"
00055 #include "prlock.h"
00056 #include "prcvar.h"
00057 #include "prsem.h"
00058 #include "prthread.h"
00059 #include "prtime.h"
00060 #include "prproces.h"
00061 
00062 #if !defined(MAC_NSPR_STANDALONE)
00063 #include "macstdlibextras.h"
00064 #endif
00065 
00066 #include <stddef.h>
00067 #include <setjmp.h>
00068 
00069 #include <Errors.h>
00070 #include <OpenTransport.h>
00071 #include <DriverServices.h>
00072 
00073 #define _PR_HAVE_PEEK_BUFFER
00074 #define _PR_PEEK_BUFFER_MAX (16 * 1024)
00075 #define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) 1
00076 
00077 struct _MDProcess {
00078     PRInt8 notused;
00079 };
00080 
00081 struct _MDThread {
00082     jmp_buf      jb;
00083     int          osErrCode;
00084        PRLock *     asyncIOLock;
00085        PRCondVar *  asyncIOCVar;
00086     PRBool       missedIONotify;
00087     PRBool       missedAsyncNotify;
00088     PRBool       asyncNotifyPending;
00089 };
00090 
00091 struct _MDThreadStack {
00092     PRInt8 notused;
00093 };
00094 
00095 struct _MDLock {
00096     PRInt8 notused;
00097 };
00098 
00099 struct _MDCVar {
00100     PRInt8 notused;
00101 };
00102 
00103 struct _MDSemaphore {
00104     PRInt8 notused;
00105 };
00106 
00107 struct _MDSegment {
00108     PRInt8 notused;
00109 };
00110 
00111 struct _MDCPU {
00112     AbsoluteTime    lastThreadSwitch;
00113     AbsoluteTime    lastWakeUpProcess;
00114     PRBool          trackScheduling;
00115 };
00116 
00117 typedef struct _MDSocketCallerInfo {
00118        PRThread *    thread;
00119        void *        cookie;
00120 } _MDSocketCallerInfo;
00121 
00122 struct _MDFileDesc {
00123     PRInt32         osfd;
00124     PRPackedBool    orderlyDisconnect;
00125     PRPackedBool    readReady;
00126     PRPackedBool    writeReady;
00127     PRPackedBool    exceptReady;
00128     PRLock *        miscLock;
00129 
00130     /* Server sockets: listen bit tells the notifier func what to do */
00131     PRBool          doListen;
00132 
00133     /* stored error for non-blocking connects, as a Unix-style error code */
00134     OTReason        disconnectError;
00135 
00136     _MDSocketCallerInfo  misc;
00137     _MDSocketCallerInfo  read;
00138     _MDSocketCallerInfo  write;
00139 };
00140 
00141 /*
00142 ** Iinitialization Related definitions
00143 */
00144 
00145 #define _MD_EARLY_INIT             _MD_EarlyInit
00146 #define _MD_FINAL_INIT             _MD_FinalInit
00147 
00148 /*
00149 ** Interrupts Related definitions
00150 */
00151 
00152 #define _MD_GET_INTSOFF()               (_pr_intsOff)
00153 
00154 #define _MD_INTSOFF(_is)                                  \
00155     PR_BEGIN_MACRO                                        \
00156         ENTER_CRITICAL_REGION();                          \
00157         (_is) = _PR_MD_GET_INTSOFF();                     \
00158         _PR_MD_SET_INTSOFF(1);                            \
00159         LEAVE_CRITICAL_REGION();                          \
00160     PR_END_MACRO
00161 
00162 #if TARGET_CARBON
00163 extern void _MD_SetIntsOff(PRInt32 ints);
00164 #define _MD_SET_INTSOFF(_val)           _MD_SetIntsOff(_val)
00165 #else /* not TARGET_CARBON */
00166 #define _MD_SET_INTSOFF(_val)           (_pr_intsOff = _val)
00167 #endif /* TARGET_CARBON */
00168 
00169 #define _MD_START_INTERRUPTS                     _MD_StartInterrupts
00170 #define _MD_STOP_INTERRUPTS               _MD_StopInterrupts
00171 #define _MD_BLOCK_CLOCK_INTERRUPTS()
00172 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
00173 #define _MD_DISABLE_CLOCK_INTERRUPTS()
00174 #define _MD_ENABLE_CLOCK_INTERRUPTS()
00175 
00176 /*
00177 ** CPU Related definitions
00178 */
00179 
00180 #define _MD_PAUSE_CPU              _MD_PauseCPU
00181 #define _MD_CLEANUP_BEFORE_EXIT()
00182 #define _MD_EXIT(status)    exit(status)
00183 #define _MD_INIT_CPUS()
00184 #define _MD_INIT_RUNNING_CPU(cpu) _MD_InitRunningCPU(cpu)
00185 
00186 /*
00187 ** Process Related definitions
00188 */
00189 
00190 extern struct PRProcess * _MD_CreateProcess(
00191     const char *path,
00192     char *const *argv,
00193     char *const *envp,
00194     const PRProcessAttr *attr);
00195 #define _MD_CREATE_PROCESS _MD_CreateProcess
00196 
00197 extern PRStatus _MD_DetachProcess(PRProcess *process);
00198 #define _MD_DETACH_PROCESS _MD_DetachProcess
00199 
00200 extern PRStatus _MD_WaitProcess(PRProcess *process, PRInt32 *exitCode);
00201 #define _MD_WAIT_PROCESS _MD_WaitProcess
00202 
00203 extern PRStatus _MD_KillProcess(PRProcess *process);
00204 #define _MD_KILL_PROCESS _MD_KillProcess
00205 
00206 /*
00207 ** Memory Segments Related definitions
00208 */
00209 
00210 #define _MD_INIT_SEGS()
00211 
00212 /*
00213 ** Thread Stacks Debugging Related definitions
00214 */
00215 
00216 #define _MD_INIT_STACK             _MD_InitStack
00217 #define _MD_CLEAR_STACK            _MD_ClearStack
00218 
00219 /*
00220 ** Locks Related definitions
00221 */
00222 
00223 #define _MD_INIT_LOCKS()
00224 #define _MD_NEW_LOCK(lock) (PR_SUCCESS)
00225 #define _MD_FREE_LOCK(lock)
00226 #define _MD_LOCK(lock)
00227 #define _MD_UNLOCK(lock)
00228 
00229 /*
00230 ** Thread Related definitions
00231 */
00232 
00233 NSPR_API(PRThread *) PR_GetPrimaryThread();
00234 
00235 #if defined(powerc) || defined(__powerc)
00236 #define _MD_GET_PC(_t) (*((PRUint32 *)((_t)->md.jb)))
00237 #define _MD_GET_SP(_t) (*((PRUint32 *)((_t)->md.jb) + 2))
00238 #define _MD_GET_TOC(_t) (*((PRUint32 *)((_t)->md.jb) + 3))
00239 #define INIT_STACKPTR(stackTop) ((unsigned char*)stackTop - 128)
00240 #define PR_NUM_GCREGS 70
00241 #else
00242 #define _MD_GET_PC(_t) (*((PRUint32 *)((_t)->md.jb) + 6))
00243 #define _MD_GET_SP(_t) (*((PRUint32 *)((_t)->md.jb) + 12))
00244 #define INIT_STACKPTR(stackTop) ((unsigned char*)stackTop - 4)
00245 #define PR_NUM_GCREGS 13
00246 #endif
00247 
00248 #define _MD_DEFAULT_STACK_SIZE (58 * 1024)
00249 #define _MD_MINIMUM_STACK_SIZE (58 * 1024)
00250 
00251 /*
00252 ** Initialize the thread machine dependent data structure
00253 */
00254 extern PRStatus _MD_InitThread(PRThread *thread);
00255 #define _MD_INIT_THREAD     _MD_InitThread
00256 
00257 /*
00258 ** Clean-up the thread machine dependent data structure
00259 */
00260 #define       _MD_CLEAN_THREAD(_thread)                                      \
00261     PR_BEGIN_MACRO                                                           \
00262        PR_DestroyCondVar(_thread->md.asyncIOCVar);                    \
00263        PR_DestroyLock(_thread->md.asyncIOLock);                \
00264     PR_END_MACRO
00265 
00266 
00267 /*
00268 ** Initialize the thread context preparing it to execute _main.
00269 ** *sp = 0 zeros out the sp for the first stack frame so that
00270 ** stack walking code can find the top of the stack.
00271 */
00272 #if defined(powerc) || defined(__powerc)
00273 #define _MD_INIT_CONTEXT(_thread, _sp, _main, _status)  \
00274     PR_BEGIN_MACRO                                                           \
00275        unsigned char *sp;                                                           \
00276        unsigned long *tvect;                                                        \
00277        long **jb = (_thread)->md.jb;                                  \
00278     *((PRBool *)_status) = PR_TRUE;                            \
00279        (void) setjmp(jb);                                                    \
00280     sp = INIT_STACKPTR(_sp);                                                 \
00281     *sp = 0;                                            \
00282     (_MD_GET_SP(_thread)) = (long) sp;                         \
00283        tvect = (unsigned long *)_main;                                       \
00284     (_MD_GET_PC(_thread)) = (int) *tvect;                      \
00285     (_MD_GET_TOC(_thread)) = (int) *(tvect+1);                 \
00286        _thread->no_sched = 0;                              \
00287     PR_END_MACRO
00288 #else
00289 #define _MD_INIT_CONTEXT(_thread, _sp, _main, _status)  \
00290     PR_BEGIN_MACRO                                                           \
00291        unsigned char *sp;                                                           \
00292        long **jb = (_thread)->md.jb;                                  \
00293     *((PRBool *)_status) = PR_TRUE;                            \
00294        (void) setjmp(jb);                                                    \
00295     sp = INIT_STACKPTR(_sp);                                                 \
00296     (_MD_GET_SP(_thread)) = (long) sp;                         \
00297     (_MD_GET_PC(_thread)) = (int) _main;                              \
00298        _thread->no_sched = 0;                              \
00299     PR_END_MACRO
00300 #endif
00301 
00302 /*
00303 ** Switch away from the current thread context by saving its state and
00304 ** calling the thread scheduler. Reload cpu when we come back from the
00305 ** context switch because it might have changed.
00306 */
00307 /*     ResetTimer(); before _PR_Schedule()                            */
00308 
00309 
00310 #define _MD_SWITCH_CONTEXT(_thread)                                 \
00311     PR_BEGIN_MACRO                                                  \
00312     PR_ASSERT(_thread->no_sched);                                   \
00313     if (!setjmp(_thread->md.jb)) {                                  \
00314         _MD_SET_LAST_THREAD(_thread);                               \
00315         if (_PR_MD_CURRENT_CPU()->md.trackScheduling)               \
00316             _PR_MD_CURRENT_CPU()->md.lastThreadSwitch = UpTime();   \
00317         _PR_Schedule();                                             \
00318     } else {                                                        \
00319         PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD());        \
00320         _MD_LAST_THREAD()->no_sched = 0;                            \
00321     }                                                               \
00322     PR_END_MACRO
00323 
00324 /*
00325 ** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
00326 ** initialized by _MD_INIT_CONTEXT.
00327 */
00328 #define _MD_RESTORE_CONTEXT(_newThread)       \
00329     PR_BEGIN_MACRO                                      \
00330        long **jb = (_newThread)->md.jb;       \
00331        _MD_SET_CURRENT_THREAD(_newThread);       \
00332     _newThread->no_sched = 1;                     \
00333        longjmp(jb, 1);                                         \
00334     PR_END_MACRO
00335 
00336 
00337 #define _MD_ERRNO()   _MD_CURRENT_THREAD()->md.osErrCode
00338 
00339 extern PRStatus _MD_wait(PRThread *thread, PRIntervalTime timeout);
00340 #define _MD_WAIT     _MD_wait
00341 
00342 /*
00343 ** Combined thread model related definitions
00344 */
00345 
00346 #define _MD_CREATE_THREAD(a,b,c,d,e,f) (PR_SUCCESS)
00347 #define _MD_WAKEUP_WAITER(a)
00348 #define _MD_SET_PRIORITY(a,b)
00349 
00350 /*
00351 ** File I/O Related definitions
00352 */
00353 
00354 extern PRInt32 _PR_MD_WRITE_SYNC(PRFileDesc *fd, void *buf, PRInt32 amount);
00355 #define    _PR_MD_WRITE_SYNC _MD_WRITE_SYNC
00356 
00357 struct _MDDir {
00358        short         ioVRefNum;
00359        long          ioDirID;
00360        short         ioFDirIndex;
00361        char          *currentEntryName;
00362 };
00363 
00364 #define PR_DIRECTORY_SEPARATOR            '/'
00365 #define PR_DIRECTORY_SEPARATOR_STR "/"
00366 #define PR_PATH_SEPARATOR          ':'
00367 #define PR_PATH_SEPARATOR_STR             ":"
00368 
00369 typedef enum IOOperation {
00370     READ_ASYNC,
00371     WRITE_ASYNC
00372 } IOOperation;
00373 
00374 
00375 #define _MD_INIT_IO()
00376 
00377 #define _MD_OPEN                                 _MD_Open
00378 #define _MD_OPEN_FILE                            _MD_Open
00379 #define _MD_CLOSE_FILE                           FSClose
00380 #define _MD_READ(fd,buf,amount)    ReadWriteProc(fd,buf,amount,READ_ASYNC)
00381 #define _MD_WRITE(fd,buf,amount)   ReadWriteProc(fd,buf,amount,WRITE_ASYNC)
00382 #define _MD_WRITE_SYNC(fd,buf,amount) WriteSyncProc(fd,buf,amount)
00383 #define _MD_GET_FILE_ERROR()              _PR_MD_CURRENT_THREAD()->md.osErrCode
00384 #define _MD_LSEEK                                _MD_LSeek
00385 #define _MD_FSYNC                                _MD_FSync
00386 
00387 /* to be implemented */
00388 #define _MD_LSEEK64(a,b,c)           LL_ZERO
00389 #define _MD_GETOPENFILEINFO64(fd,info)   -1
00390 #define _MD_GETFILEINFO64(fd,info)   -1
00391 
00392 #define _MD_IOQ_LOCK()
00393 #define _MD_IOQ_UNLOCK()
00394 
00395 /*
00396 ** File Manipulation definitions
00397 */
00398 
00399 #define       _MD_RENAME                  _MD_Rename
00400 #define       _MD_ACCESS                  _MD_Access
00401 
00402 #define       _MD_GETFILEINFO      _MD_GetFileInfo
00403 #define       _MD_GETOPENFILEINFO _MD_GetOpenFileInfo
00404 
00405 #define       _MD_STAT                    _MD_Stat
00406 
00407 #define       _MD_DELETE                  _MD_Delete
00408 
00409 extern PRStatus _MD_LockFile(PRInt32 osfd);
00410 #define       _MD_LOCKFILE         _MD_LockFile
00411 extern PRStatus _MD_TLockFile(PRInt32 osfd);
00412 #define       _MD_TLOCKFILE               _MD_TLockFile
00413 extern PRStatus _MD_UnlockFile(PRInt32 osfd);
00414 #define       _MD_UNLOCKFILE              _MD_UnlockFile
00415 
00416 /* 
00417 ** Directory enumeration related definitions 
00418 */
00419 
00420 extern PRStatus _MD_OpenDir(struct _MDDir *md,const char *name);
00421 #define       _MD_OPEN_DIR         _MD_OpenDir
00422 
00423 extern char* _MD_ReadDir(struct _MDDir *md,PRIntn flags);
00424 #define       _MD_READ_DIR         _MD_ReadDir
00425 
00426 #define       _MD_CLOSE_DIR               _MD_CloseDir
00427 
00428 #define       _MD_MKDIR                   _MD_MkDir
00429 #define       _MD_MAKE_DIR         _MD_MkDir
00430 #define       _MD_RMDIR                   _MD_Delete
00431 
00432 /*
00433 ** Pipe I/O Related definitions (not implemented)
00434 */
00435 
00436 #define _MD_PIPEAVAILABLE(fd) -1
00437 
00438 /*
00439 ** Socket I/O Related definitions
00440 */
00441 
00442 #if UNIVERSAL_INTERFACES_VERSION >= 0x0330
00443 /* In Universal Interfaces 3.3 and later, these are enums. */
00444 #define IP_TTL IP_TTL
00445 #define IP_TOS IP_TOS
00446 #define IP_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP
00447 #define IP_DROP_MEMBERSHIP IP_DROP_MEMBERSHIP
00448 #define IP_MULTICAST_IF IP_MULTICAST_IF
00449 #define IP_MULTICAST_TTL IP_MULTICAST_TTL
00450 #define IP_MULTICAST_LOOP IP_MULTICAST_LOOP
00451 #define TCP_NODELAY TCP_NODELAY
00452 #define TCP_MAXSEG TCP_MAXSEG
00453 #endif
00454 
00455 #define _MD_SOCKET                 _MD_socket
00456 #define _MD_BIND                   _MD_bind
00457 #define _MD_LISTEN                 _MD_listen
00458 #define _MD_GETSOCKNAME            _MD_getsockname
00459 
00460 extern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval, PRInt32* optlen);
00461 #define _MD_GETSOCKOPT             _MD_getsockopt
00462 
00463 extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level, PRInt32 optname, const char* optval, PRInt32 optlen);
00464 #define _MD_SETSOCKOPT             _MD_setsockopt
00465 
00466 #define _MD_SOCKETAVAILABLE _MD_socketavailable
00467 #define _MD_ACCEPT                 _MD_accept
00468 #define _MD_CONNECT                _MD_connect
00469 #define _MD_SEND                   _MD_send
00470 #define _MD_RECV                   _MD_recv
00471 #define _MD_CLOSE_SOCKET    _MD_closesocket
00472 #define _MD_SENDTO                 _MD_sendto
00473 #define _MD_RECVFROM        _MD_recvfrom
00474 #define _MD_PR_POLL                _MD_poll
00475 #define _MD_INIT_FILEDESC   _MD_initfiledesc
00476 #define _MD_FREE_FILEDESC   _MD_freefiledesc
00477 #define _MD_MAKE_NONBLOCK   _MD_makenonblock
00478 #define _MD_INIT_FD_INHERITABLE _MD_initfdinheritable
00479 #define _MD_QUERY_FD_INHERITABLE _MD_queryfdinheritable
00480 
00481 #define _MD_GET_SOCKET_ERROR()            _PR_MD_CURRENT_THREAD()->md.osErrCode
00482 
00483 #define _PR_MD_MAP_SELECT_ERROR(x)        (x)
00484 /*
00485 ** Netdb Related definitions
00486 */
00487 extern PRStatus _MD_gethostname(char *name, int namelen);
00488 #define _MD_GETHOSTNAME            _MD_gethostname
00489 #define _PR_GET_HOST_ADDR_AS_NAME
00490 
00491 /* 
00492        XXX _MD_WRITEV, _MD_SHUTDOWN & _MD_GETPEERNAME not done yet!!!
00493 */
00494 #define _MD_WRITEV                 _MD_writev
00495 #define _MD_SHUTDOWN        _MD_shutdown
00496 #define _MD_GETPEERNAME            _MD_getpeername
00497 
00498 
00499 #ifdef OLD_MACSOCK_LIBRARY
00500 #define _MD_SOCKET                 macsock_socket
00501 #define _MD_LISTEN                 macsock_listen
00502 #define _MD_SEND(fd,buf,amount,flags,timeout)    macsock_send(fd->secret->md.osfd,buf,amount,flags)
00503 #define _MD_SENDTO(fd,buf,amount,flags,addr,addrlen,timeout)   macsock_sendto(fd->secret->md.osfd,buf,amount,flags,(struct sockaddr *)addr,addrlen)
00504 #define _MD_RECV(fd,buf,amount,flags,timeout)    macsock_recv(fd->secret->md.osfd,buf,amount,flags)
00505 #define _MD_RECVFROM(fd,buf,amount,flags,addr,addrlen,timeout) macsock_recvfrom(fd->secret->md.osfd,buf,amount,flags,(struct sockaddr *)addr,addrlen)
00506 #define _MD_CLOSE_SOCKET    macsock_close
00507 #define _MD_SHUTDOWN(a,b)   (0)
00508 
00509 #define _MD_ACCEPT(fd,addr,addrlen,timeout)      macsock_accept(fd->secret->md.osfd,(struct sockaddr *)addr,addrlen)
00510 #define _MD_CONNECT(fd,name,namelen,timeout)     macsock_connect(fd->secret->md.osfd,(struct sockaddr *)name,namelen)
00511 #define _MD_BIND(fd,name,namelen)                       macsock_bind(fd->secret->md.osfd,(struct sockaddr *)name,namelen)
00512 #define _MD_GETSOCKNAME(fd,name,namelen)         macsock_getsockname(fd->secret->md.osfd,(struct sockaddr *)name,namelen)
00513 #define _MD_GETPEERNAME(fd,name,namelen)         macsock_getpeername(fd->secret->md.osfd,(struct sockaddr *)name,namelen)
00514 #define _MD_GETSOCKOPT(fd,level,optname,optval,optlen)         macsock_getsockopt(fd->secret->md.osfd,level,optname,optval,optlen)
00515 #define _MD_SETSOCKOPT(fd,level,optname,optval,optlen)         macsock_setsockopt(fd->secret->md.osfd,level,optname,optval,optlen)
00516 #define _MD_SOCKETAVAILABLE(fd,bytes)            macsock_socketavailable(fd->secret->md.osfd,bytes)
00517 #endif
00518 
00519 /*
00520 ** Memory Segements Related definitions
00521 */
00522 
00523 #define _MD_INIT_SEGS()            
00524 #define _MD_ALLOC_SEGMENT   _MD_AllocSegment
00525 #define _MD_FREE_SEGMENT    _MD_FreeSegment
00526 
00527 /*
00528 ** Time Related definitions
00529 */
00530 
00531 #define _MD_GET_INTERVAL                         _MD_GetInterval
00532 #define _MD_INTERVAL_PER_SEC()                   PR_MSEC_PER_SEC
00533 #define _MD_INTERVAL_INIT()
00534 
00535 /*
00536 ** Environemnt Related definitions
00537 */
00538 
00539 extern char *_MD_GetEnv(const char *name);
00540 #define _MD_GET_ENV                _MD_GetEnv
00541 
00542 extern int _MD_PutEnv(const char *variableCopy);
00543 #define _MD_PUT_ENV                _MD_PutEnv
00544 
00545 /*
00546 ** Following is old stuff to be looked at.
00547 */
00548 
00549 #define GCPTR
00550 #define CALLBACK
00551 typedef int (*FARPROC)();
00552 
00553 
00554 #define MAX_NON_PRIMARY_TIME_SLICES       6
00555 
00556 extern long gTimeSlicesOnNonPrimaryThread;
00557 extern struct PRThread *gPrimaryThread;
00558 
00559 // Errors not found in the Mac StdCLib
00560 #define EACCES              13            // Permission denied
00561 #define ENOENT                     -43                  // No such file or directory
00562 #define _OS_INVALID_FD_VALUE -1
00563 
00564 #define       STDERR_FILENO 2
00565 
00566 #if !defined(MAC_NSPR_STANDALONE)
00567 #define PATH_SEPARATOR                                  ':'
00568 #define PATH_SEPARATOR_STR                 ":"
00569 #define DIRECTORY_SEPARATOR                      '/'
00570 #define DIRECTORY_SEPARATOR_STR                  "/"
00571 #endif
00572 
00573 #define UNIX_THIS_DIRECTORY_STR                  "./"
00574 #define UNIX_PARENT_DIRECTORY_STR         "../"
00575 
00576 
00577 // Alias a few names
00578 #define getenv       PR_GetEnv
00579 #define putenv       _MD_PutEnv
00580 
00581 #if defined(MAC_NSPR_STANDALONE)
00582 typedef unsigned char (*MemoryCacheFlusherProc)(size_t size);
00583 typedef void (*PreAllocationHookProc)(void);
00584 
00585 extern char *strdup(const char *source);
00586 
00587 extern void InstallPreAllocationHook(PreAllocationHookProc newHook);
00588 extern void InstallMemoryCacheFlusher(MemoryCacheFlusherProc newFlusher);
00589 #endif
00590 
00591 extern char *PR_GetDLLSearchPath(void);
00592 
00593 #if defined(MAC_NSPR_STANDALONE)
00594 extern int strcmp(const char *str1, const char *str2);
00595 extern int strcasecmp(const char *str1, const char *str2);
00596 #endif
00597 
00598 extern void MapFullToPartialMacFile(char *);
00599 extern char *MapPartialToFullMacFile(const char *);
00600 
00601 extern void ResetTimer(void);
00602 extern void PR_PeriodicIdle(void);
00603 extern void ActivateTimer(void);
00604 extern void DeactivateTimer(void);
00605 extern void PR_InitMemory(void);
00606 
00607 extern struct hostent *gethostbyaddr(const void *addr, int addrlen, int type);
00608 
00609 extern short GetVolumeRefNumFromName(const char *);
00610 
00611 #include <stdio.h>                 // Needed to get FILE typedef
00612 extern FILE *_OS_FOPEN(const char *filename, const char *mode);
00613 //
00614 //     Macintosh only private parts.
00615 //
00616 
00617 #define       dprintTrace                 ";dprintf;doTrace"
00618 #define       dprintNoTrace        ";dprintf"
00619 extern void dprintf(const char *format, ...);
00620 
00621 
00622 // Entry into the memory system's cache flushing
00623 #if defined(MAC_NSPR_STANDALONE)
00624 extern PRUint8 CallCacheFlushers(size_t blockSize);
00625 #endif
00626 
00627 #if defined(MAC_NSPR_STANDALONE)
00628 extern void* reallocSmaller(void* block, size_t newSize);
00629 #endif
00630 
00631 
00632 /*
00633 ** PR_GetSystemInfo related definitions
00634 */
00635 #define _PR_SI_SYSNAME          "MacOS"
00636 #define _PR_SI_ARCHITECTURE     "PowerPC"
00637 
00638 /*
00639  * Memory-mapped files
00640  */
00641 
00642 struct _MDFileMap {
00643     PRInt8 unused;
00644 };
00645 
00646 extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
00647 #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
00648 
00649 extern PRInt32 _MD_GetMemMapAlignment(void);
00650 #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
00651 
00652 extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
00653         PRUint32 len);
00654 #define _MD_MEM_MAP _MD_MemMap
00655 
00656 extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
00657 #define _MD_MEM_UNMAP _MD_MemUnmap
00658 
00659 extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
00660 #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
00661 
00662 extern void SetLogFileTypeCreator(const char *logFile);
00663 extern int _MD_mac_get_nonblocking_connect_error(PRFileDesc* fd);
00664 
00665 
00666 /*
00667  * Critical section support
00668  */
00669 
00670 #define MAC_CRITICAL_REGIONS  TARGET_CARBON
00671 
00672 #if MAC_CRITICAL_REGIONS
00673 
00674 extern void InitCriticalRegion();
00675 extern void TermCriticalRegion();
00676 
00677 extern void EnterCritialRegion();
00678 extern void LeaveCritialRegion();
00679 
00680 #define INIT_CRITICAL_REGION()     InitCriticalRegion()
00681 #define TERM_CRITICAL_REGION()     TermCriticalRegion()
00682 
00683 #define ENTER_CRITICAL_REGION()     EnterCritialRegion()
00684 #define LEAVE_CRITICAL_REGION()     LeaveCritialRegion()
00685 
00686 #else
00687 
00688 #define INIT_CRITICAL_REGION()
00689 #define TERM_CRITICAL_REGION()
00690 
00691 #define ENTER_CRITICAL_REGION()
00692 #define LEAVE_CRITICAL_REGION()
00693 
00694 #endif
00695 
00696 
00697 
00698 /*
00699  * CPU Idle support
00700  */
00701 
00702 extern void InitIdleSemaphore();
00703 extern void TermIdleSemaphore();
00704 
00705 extern void WaitOnIdleSemaphore();
00706 extern void SignalIdleSemaphore();
00707 
00708 
00709 /*
00710  * Atomic operations
00711  */
00712 #ifdef _PR_HAVE_ATOMIC_OPS
00713 
00714 extern PRInt32 _MD_AtomicSet(PRInt32 *val, PRInt32 newval);
00715 
00716 #define _MD_INIT_ATOMIC()
00717 #define _MD_ATOMIC_INCREMENT(val)   OTAtomicAdd32(1, (SInt32 *)val)
00718 #define _MD_ATOMIC_ADD(ptr, val)    OTAtomicAdd32(val, (SInt32 *)ptr)
00719 #define _MD_ATOMIC_DECREMENT(val)   OTAtomicAdd32(-1, (SInt32 *)val)
00720 #define _MD_ATOMIC_SET(val, newval) _MD_AtomicSet(val, newval)
00721 
00722 #endif /* _PR_HAVE_ATOMIC_OPS */
00723 
00724 
00725 #endif /* prmacos_h___ */