PageRenderTime 62ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/mozilla/mozilla/dist/include/nspr/md/_macos.h

#
C Header | 725 lines | 419 code | 159 blank | 147 comment | 5 complexity | 3c00e91f6798ee9f0b3207d68f48d96c MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef prmacos_h___
  38. #define prmacos_h___
  39. //
  40. // This file contains all changes and additions which need to be made to the NSPR runtime
  41. // for the Macintosh platform (specifically the Metrowerks environment). This file should
  42. // only be incluced in Macintosh builds.
  43. //
  44. #define PR_DLL_SUFFIX ""
  45. #define _PR_LOCAL_THREADS_ONLY
  46. #define _PR_NO_PREEMPT 1
  47. #define _PR_HAVE_ATOMIC_OPS 1
  48. #include "prinit.h"
  49. #include "prio.h"
  50. #include "prlong.h"
  51. #include "prlock.h"
  52. #include "prcvar.h"
  53. #include "prsem.h"
  54. #include "prthread.h"
  55. #include "prtime.h"
  56. #include "prproces.h"
  57. #if !defined(MAC_NSPR_STANDALONE)
  58. #include "macstdlibextras.h"
  59. #endif
  60. #include <stddef.h>
  61. #include <setjmp.h>
  62. #include <Errors.h>
  63. #include <OpenTransport.h>
  64. #include <DriverServices.h>
  65. #define _PR_HAVE_PEEK_BUFFER
  66. #define _PR_PEEK_BUFFER_MAX (16 * 1024)
  67. #define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) 1
  68. struct _MDProcess {
  69. PRInt8 notused;
  70. };
  71. struct _MDThread {
  72. jmp_buf jb;
  73. int osErrCode;
  74. PRLock * asyncIOLock;
  75. PRCondVar * asyncIOCVar;
  76. PRBool missedIONotify;
  77. PRBool missedAsyncNotify;
  78. PRBool asyncNotifyPending;
  79. };
  80. struct _MDThreadStack {
  81. PRInt8 notused;
  82. };
  83. struct _MDLock {
  84. PRInt8 notused;
  85. };
  86. struct _MDCVar {
  87. PRInt8 notused;
  88. };
  89. struct _MDSemaphore {
  90. PRInt8 notused;
  91. };
  92. struct _MDSegment {
  93. PRInt8 notused;
  94. };
  95. struct _MDCPU {
  96. AbsoluteTime lastThreadSwitch;
  97. AbsoluteTime lastWakeUpProcess;
  98. PRBool trackScheduling;
  99. };
  100. typedef struct _MDSocketCallerInfo {
  101. PRThread * thread;
  102. void * cookie;
  103. } _MDSocketCallerInfo;
  104. struct _MDFileDesc {
  105. PRInt32 osfd;
  106. PRPackedBool orderlyDisconnect;
  107. PRPackedBool readReady;
  108. PRPackedBool writeReady;
  109. PRPackedBool exceptReady;
  110. PRLock * miscLock;
  111. /* Server sockets: listen bit tells the notifier func what to do */
  112. PRBool doListen;
  113. /* stored error for non-blocking connects, as a Unix-style error code */
  114. OTReason disconnectError;
  115. _MDSocketCallerInfo misc;
  116. _MDSocketCallerInfo read;
  117. _MDSocketCallerInfo write;
  118. };
  119. /*
  120. ** Iinitialization Related definitions
  121. */
  122. #define _MD_EARLY_INIT _MD_EarlyInit
  123. #define _MD_FINAL_INIT _MD_FinalInit
  124. /*
  125. ** Interrupts Related definitions
  126. */
  127. #define _MD_GET_INTSOFF() (_pr_intsOff)
  128. #define _MD_INTSOFF(_is) \
  129. PR_BEGIN_MACRO \
  130. ENTER_CRITICAL_REGION(); \
  131. (_is) = _PR_MD_GET_INTSOFF(); \
  132. _PR_MD_SET_INTSOFF(1); \
  133. LEAVE_CRITICAL_REGION(); \
  134. PR_END_MACRO
  135. #if TARGET_CARBON
  136. extern void _MD_SetIntsOff(PRInt32 ints);
  137. #define _MD_SET_INTSOFF(_val) _MD_SetIntsOff(_val)
  138. #else /* not TARGET_CARBON */
  139. #define _MD_SET_INTSOFF(_val) (_pr_intsOff = _val)
  140. #endif /* TARGET_CARBON */
  141. #define _MD_START_INTERRUPTS _MD_StartInterrupts
  142. #define _MD_STOP_INTERRUPTS _MD_StopInterrupts
  143. #define _MD_BLOCK_CLOCK_INTERRUPTS()
  144. #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
  145. #define _MD_DISABLE_CLOCK_INTERRUPTS()
  146. #define _MD_ENABLE_CLOCK_INTERRUPTS()
  147. /*
  148. ** CPU Related definitions
  149. */
  150. #define _MD_PAUSE_CPU _MD_PauseCPU
  151. #define _MD_CLEANUP_BEFORE_EXIT()
  152. #define _MD_EXIT(status) exit(status)
  153. #define _MD_INIT_CPUS()
  154. #define _MD_INIT_RUNNING_CPU(cpu) _MD_InitRunningCPU(cpu)
  155. /*
  156. ** Process Related definitions
  157. */
  158. extern struct PRProcess * _MD_CreateProcess(
  159. const char *path,
  160. char *const *argv,
  161. char *const *envp,
  162. const PRProcessAttr *attr);
  163. #define _MD_CREATE_PROCESS _MD_CreateProcess
  164. extern PRStatus _MD_DetachProcess(PRProcess *process);
  165. #define _MD_DETACH_PROCESS _MD_DetachProcess
  166. extern PRStatus _MD_WaitProcess(PRProcess *process, PRInt32 *exitCode);
  167. #define _MD_WAIT_PROCESS _MD_WaitProcess
  168. extern PRStatus _MD_KillProcess(PRProcess *process);
  169. #define _MD_KILL_PROCESS _MD_KillProcess
  170. /*
  171. ** Memory Segments Related definitions
  172. */
  173. #define _MD_INIT_SEGS()
  174. /*
  175. ** Thread Stacks Debugging Related definitions
  176. */
  177. #define _MD_INIT_STACK _MD_InitStack
  178. #define _MD_CLEAR_STACK _MD_ClearStack
  179. /*
  180. ** Locks Related definitions
  181. */
  182. #define _MD_INIT_LOCKS()
  183. #define _MD_NEW_LOCK(lock) (PR_SUCCESS)
  184. #define _MD_FREE_LOCK(lock)
  185. #define _MD_LOCK(lock)
  186. #define _MD_UNLOCK(lock)
  187. /*
  188. ** Thread Related definitions
  189. */
  190. NSPR_API(PRThread *) PR_GetPrimaryThread();
  191. #if defined(powerc) || defined(__powerc)
  192. #define _MD_GET_PC(_t) (*((PRUint32 *)((_t)->md.jb)))
  193. #define _MD_GET_SP(_t) (*((PRUint32 *)((_t)->md.jb) + 2))
  194. #define _MD_GET_TOC(_t) (*((PRUint32 *)((_t)->md.jb) + 3))
  195. #define INIT_STACKPTR(stackTop) ((unsigned char*)stackTop - 128)
  196. #define PR_NUM_GCREGS 70
  197. #else
  198. #define _MD_GET_PC(_t) (*((PRUint32 *)((_t)->md.jb) + 6))
  199. #define _MD_GET_SP(_t) (*((PRUint32 *)((_t)->md.jb) + 12))
  200. #define INIT_STACKPTR(stackTop) ((unsigned char*)stackTop - 4)
  201. #define PR_NUM_GCREGS 13
  202. #endif
  203. #define _MD_DEFAULT_STACK_SIZE (58 * 1024)
  204. #define _MD_MINIMUM_STACK_SIZE (58 * 1024)
  205. /*
  206. ** Initialize the thread machine dependent data structure
  207. */
  208. extern PRStatus _MD_InitThread(PRThread *thread);
  209. #define _MD_INIT_THREAD _MD_InitThread
  210. /*
  211. ** Clean-up the thread machine dependent data structure
  212. */
  213. #define _MD_CLEAN_THREAD(_thread) \
  214. PR_BEGIN_MACRO \
  215. PR_DestroyCondVar(_thread->md.asyncIOCVar); \
  216. PR_DestroyLock(_thread->md.asyncIOLock); \
  217. PR_END_MACRO
  218. /*
  219. ** Initialize the thread context preparing it to execute _main.
  220. ** *sp = 0 zeros out the sp for the first stack frame so that
  221. ** stack walking code can find the top of the stack.
  222. */
  223. #if defined(powerc) || defined(__powerc)
  224. #define _MD_INIT_CONTEXT(_thread, _sp, _main, _status) \
  225. PR_BEGIN_MACRO \
  226. unsigned char *sp; \
  227. unsigned long *tvect; \
  228. long **jb = (_thread)->md.jb; \
  229. *((PRBool *)_status) = PR_TRUE; \
  230. (void) setjmp(jb); \
  231. sp = INIT_STACKPTR(_sp); \
  232. *sp = 0; \
  233. (_MD_GET_SP(_thread)) = (long) sp; \
  234. tvect = (unsigned long *)_main; \
  235. (_MD_GET_PC(_thread)) = (int) *tvect; \
  236. (_MD_GET_TOC(_thread)) = (int) *(tvect+1); \
  237. _thread->no_sched = 0; \
  238. PR_END_MACRO
  239. #else
  240. #define _MD_INIT_CONTEXT(_thread, _sp, _main, _status) \
  241. PR_BEGIN_MACRO \
  242. unsigned char *sp; \
  243. long **jb = (_thread)->md.jb; \
  244. *((PRBool *)_status) = PR_TRUE; \
  245. (void) setjmp(jb); \
  246. sp = INIT_STACKPTR(_sp); \
  247. (_MD_GET_SP(_thread)) = (long) sp; \
  248. (_MD_GET_PC(_thread)) = (int) _main; \
  249. _thread->no_sched = 0; \
  250. PR_END_MACRO
  251. #endif
  252. /*
  253. ** Switch away from the current thread context by saving its state and
  254. ** calling the thread scheduler. Reload cpu when we come back from the
  255. ** context switch because it might have changed.
  256. */
  257. /* ResetTimer(); before _PR_Schedule() */
  258. #define _MD_SWITCH_CONTEXT(_thread) \
  259. PR_BEGIN_MACRO \
  260. PR_ASSERT(_thread->no_sched); \
  261. if (!setjmp(_thread->md.jb)) { \
  262. _MD_SET_LAST_THREAD(_thread); \
  263. if (_PR_MD_CURRENT_CPU()->md.trackScheduling) \
  264. _PR_MD_CURRENT_CPU()->md.lastThreadSwitch = UpTime(); \
  265. _PR_Schedule(); \
  266. } else { \
  267. PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
  268. _MD_LAST_THREAD()->no_sched = 0; \
  269. } \
  270. PR_END_MACRO
  271. /*
  272. ** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
  273. ** initialized by _MD_INIT_CONTEXT.
  274. */
  275. #define _MD_RESTORE_CONTEXT(_newThread) \
  276. PR_BEGIN_MACRO \
  277. long **jb = (_newThread)->md.jb; \
  278. _MD_SET_CURRENT_THREAD(_newThread); \
  279. _newThread->no_sched = 1; \
  280. longjmp(jb, 1); \
  281. PR_END_MACRO
  282. #define _MD_ERRNO() _MD_CURRENT_THREAD()->md.osErrCode
  283. extern PRStatus _MD_wait(PRThread *thread, PRIntervalTime timeout);
  284. #define _MD_WAIT _MD_wait
  285. /*
  286. ** Combined thread model related definitions
  287. */
  288. #define _MD_CREATE_THREAD(a,b,c,d,e,f) (PR_SUCCESS)
  289. #define _MD_WAKEUP_WAITER(a)
  290. #define _MD_SET_PRIORITY(a,b)
  291. /*
  292. ** File I/O Related definitions
  293. */
  294. extern PRInt32 _PR_MD_WRITE_SYNC(PRFileDesc *fd, void *buf, PRInt32 amount);
  295. #define _PR_MD_WRITE_SYNC _MD_WRITE_SYNC
  296. struct _MDDir {
  297. short ioVRefNum;
  298. long ioDirID;
  299. short ioFDirIndex;
  300. char *currentEntryName;
  301. };
  302. #define PR_DIRECTORY_SEPARATOR '/'
  303. #define PR_DIRECTORY_SEPARATOR_STR "/"
  304. #define PR_PATH_SEPARATOR ':'
  305. #define PR_PATH_SEPARATOR_STR ":"
  306. typedef enum IOOperation {
  307. READ_ASYNC,
  308. WRITE_ASYNC
  309. } IOOperation;
  310. #define _MD_INIT_IO()
  311. #define _MD_OPEN _MD_Open
  312. #define _MD_OPEN_FILE _MD_Open
  313. #define _MD_CLOSE_FILE FSClose
  314. #define _MD_READ(fd,buf,amount) ReadWriteProc(fd,buf,amount,READ_ASYNC)
  315. #define _MD_WRITE(fd,buf,amount) ReadWriteProc(fd,buf,amount,WRITE_ASYNC)
  316. #define _MD_WRITE_SYNC(fd,buf,amount) WriteSyncProc(fd,buf,amount)
  317. #define _MD_GET_FILE_ERROR() _PR_MD_CURRENT_THREAD()->md.osErrCode
  318. #define _MD_LSEEK _MD_LSeek
  319. #define _MD_FSYNC _MD_FSync
  320. /* to be implemented */
  321. #define _MD_LSEEK64(a,b,c) LL_ZERO
  322. #define _MD_GETOPENFILEINFO64(fd,info) -1
  323. #define _MD_GETFILEINFO64(fd,info) -1
  324. #define _MD_IOQ_LOCK()
  325. #define _MD_IOQ_UNLOCK()
  326. /*
  327. ** File Manipulation definitions
  328. */
  329. #define _MD_RENAME _MD_Rename
  330. #define _MD_ACCESS _MD_Access
  331. #define _MD_GETFILEINFO _MD_GetFileInfo
  332. #define _MD_GETOPENFILEINFO _MD_GetOpenFileInfo
  333. #define _MD_STAT _MD_Stat
  334. #define _MD_DELETE _MD_Delete
  335. extern PRStatus _MD_LockFile(PRInt32 osfd);
  336. #define _MD_LOCKFILE _MD_LockFile
  337. extern PRStatus _MD_TLockFile(PRInt32 osfd);
  338. #define _MD_TLOCKFILE _MD_TLockFile
  339. extern PRStatus _MD_UnlockFile(PRInt32 osfd);
  340. #define _MD_UNLOCKFILE _MD_UnlockFile
  341. /*
  342. ** Directory enumeration related definitions
  343. */
  344. extern PRStatus _MD_OpenDir(struct _MDDir *md,const char *name);
  345. #define _MD_OPEN_DIR _MD_OpenDir
  346. extern char* _MD_ReadDir(struct _MDDir *md,PRIntn flags);
  347. #define _MD_READ_DIR _MD_ReadDir
  348. #define _MD_CLOSE_DIR _MD_CloseDir
  349. #define _MD_MKDIR _MD_MkDir
  350. #define _MD_MAKE_DIR _MD_MkDir
  351. #define _MD_RMDIR _MD_Delete
  352. /*
  353. ** Pipe I/O Related definitions (not implemented)
  354. */
  355. #define _MD_PIPEAVAILABLE(fd) -1
  356. /*
  357. ** Socket I/O Related definitions
  358. */
  359. #if UNIVERSAL_INTERFACES_VERSION >= 0x0330
  360. /* In Universal Interfaces 3.3 and later, these are enums. */
  361. #define IP_TTL IP_TTL
  362. #define IP_TOS IP_TOS
  363. #define IP_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP
  364. #define IP_DROP_MEMBERSHIP IP_DROP_MEMBERSHIP
  365. #define IP_MULTICAST_IF IP_MULTICAST_IF
  366. #define IP_MULTICAST_TTL IP_MULTICAST_TTL
  367. #define IP_MULTICAST_LOOP IP_MULTICAST_LOOP
  368. #define TCP_NODELAY TCP_NODELAY
  369. #define TCP_MAXSEG TCP_MAXSEG
  370. #endif
  371. #define _MD_SOCKET _MD_socket
  372. #define _MD_BIND _MD_bind
  373. #define _MD_LISTEN _MD_listen
  374. #define _MD_GETSOCKNAME _MD_getsockname
  375. extern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval, PRInt32* optlen);
  376. #define _MD_GETSOCKOPT _MD_getsockopt
  377. extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level, PRInt32 optname, const char* optval, PRInt32 optlen);
  378. #define _MD_SETSOCKOPT _MD_setsockopt
  379. #define _MD_SOCKETAVAILABLE _MD_socketavailable
  380. #define _MD_ACCEPT _MD_accept
  381. #define _MD_CONNECT _MD_connect
  382. #define _MD_SEND _MD_send
  383. #define _MD_RECV _MD_recv
  384. #define _MD_CLOSE_SOCKET _MD_closesocket
  385. #define _MD_SENDTO _MD_sendto
  386. #define _MD_RECVFROM _MD_recvfrom
  387. #define _MD_PR_POLL _MD_poll
  388. #define _MD_INIT_FILEDESC _MD_initfiledesc
  389. #define _MD_FREE_FILEDESC _MD_freefiledesc
  390. #define _MD_MAKE_NONBLOCK _MD_makenonblock
  391. #define _MD_INIT_FD_INHERITABLE _MD_initfdinheritable
  392. #define _MD_QUERY_FD_INHERITABLE _MD_queryfdinheritable
  393. #define _MD_GET_SOCKET_ERROR() _PR_MD_CURRENT_THREAD()->md.osErrCode
  394. #define _PR_MD_MAP_SELECT_ERROR(x) (x)
  395. /*
  396. ** Netdb Related definitions
  397. */
  398. extern PRStatus _MD_gethostname(char *name, int namelen);
  399. #define _MD_GETHOSTNAME _MD_gethostname
  400. #define _PR_GET_HOST_ADDR_AS_NAME
  401. /*
  402. XXX _MD_WRITEV, _MD_SHUTDOWN & _MD_GETPEERNAME not done yet!!!
  403. */
  404. #define _MD_WRITEV _MD_writev
  405. #define _MD_SHUTDOWN _MD_shutdown
  406. #define _MD_GETPEERNAME _MD_getpeername
  407. #ifdef OLD_MACSOCK_LIBRARY
  408. #define _MD_SOCKET macsock_socket
  409. #define _MD_LISTEN macsock_listen
  410. #define _MD_SEND(fd,buf,amount,flags,timeout) macsock_send(fd->secret->md.osfd,buf,amount,flags)
  411. #define _MD_SENDTO(fd,buf,amount,flags,addr,addrlen,timeout) macsock_sendto(fd->secret->md.osfd,buf,amount,flags,(struct sockaddr *)addr,addrlen)
  412. #define _MD_RECV(fd,buf,amount,flags,timeout) macsock_recv(fd->secret->md.osfd,buf,amount,flags)
  413. #define _MD_RECVFROM(fd,buf,amount,flags,addr,addrlen,timeout) macsock_recvfrom(fd->secret->md.osfd,buf,amount,flags,(struct sockaddr *)addr,addrlen)
  414. #define _MD_CLOSE_SOCKET macsock_close
  415. #define _MD_SHUTDOWN(a,b) (0)
  416. #define _MD_ACCEPT(fd,addr,addrlen,timeout) macsock_accept(fd->secret->md.osfd,(struct sockaddr *)addr,addrlen)
  417. #define _MD_CONNECT(fd,name,namelen,timeout) macsock_connect(fd->secret->md.osfd,(struct sockaddr *)name,namelen)
  418. #define _MD_BIND(fd,name,namelen) macsock_bind(fd->secret->md.osfd,(struct sockaddr *)name,namelen)
  419. #define _MD_GETSOCKNAME(fd,name,namelen) macsock_getsockname(fd->secret->md.osfd,(struct sockaddr *)name,namelen)
  420. #define _MD_GETPEERNAME(fd,name,namelen) macsock_getpeername(fd->secret->md.osfd,(struct sockaddr *)name,namelen)
  421. #define _MD_GETSOCKOPT(fd,level,optname,optval,optlen) macsock_getsockopt(fd->secret->md.osfd,level,optname,optval,optlen)
  422. #define _MD_SETSOCKOPT(fd,level,optname,optval,optlen) macsock_setsockopt(fd->secret->md.osfd,level,optname,optval,optlen)
  423. #define _MD_SOCKETAVAILABLE(fd,bytes) macsock_socketavailable(fd->secret->md.osfd,bytes)
  424. #endif
  425. /*
  426. ** Memory Segements Related definitions
  427. */
  428. #define _MD_INIT_SEGS()
  429. #define _MD_ALLOC_SEGMENT _MD_AllocSegment
  430. #define _MD_FREE_SEGMENT _MD_FreeSegment
  431. /*
  432. ** Time Related definitions
  433. */
  434. #define _MD_GET_INTERVAL _MD_GetInterval
  435. #define _MD_INTERVAL_PER_SEC() PR_MSEC_PER_SEC
  436. #define _MD_INTERVAL_INIT()
  437. /*
  438. ** Environemnt Related definitions
  439. */
  440. extern char *_MD_GetEnv(const char *name);
  441. #define _MD_GET_ENV _MD_GetEnv
  442. extern int _MD_PutEnv(const char *variableCopy);
  443. #define _MD_PUT_ENV _MD_PutEnv
  444. /*
  445. ** Following is old stuff to be looked at.
  446. */
  447. #define GCPTR
  448. #define CALLBACK
  449. typedef int (*FARPROC)();
  450. #define MAX_NON_PRIMARY_TIME_SLICES 6
  451. extern long gTimeSlicesOnNonPrimaryThread;
  452. extern struct PRThread *gPrimaryThread;
  453. // Errors not found in the Mac StdCLib
  454. #define EACCES 13 // Permission denied
  455. #define ENOENT -43 // No such file or directory
  456. #define _OS_INVALID_FD_VALUE -1
  457. #define STDERR_FILENO 2
  458. #if !defined(MAC_NSPR_STANDALONE)
  459. #define PATH_SEPARATOR ':'
  460. #define PATH_SEPARATOR_STR ":"
  461. #define DIRECTORY_SEPARATOR '/'
  462. #define DIRECTORY_SEPARATOR_STR "/"
  463. #endif
  464. #define UNIX_THIS_DIRECTORY_STR "./"
  465. #define UNIX_PARENT_DIRECTORY_STR "../"
  466. // Alias a few names
  467. #define getenv PR_GetEnv
  468. #define putenv _MD_PutEnv
  469. #if defined(MAC_NSPR_STANDALONE)
  470. typedef unsigned char (*MemoryCacheFlusherProc)(size_t size);
  471. typedef void (*PreAllocationHookProc)(void);
  472. extern char *strdup(const char *source);
  473. extern void InstallPreAllocationHook(PreAllocationHookProc newHook);
  474. extern void InstallMemoryCacheFlusher(MemoryCacheFlusherProc newFlusher);
  475. #endif
  476. extern char *PR_GetDLLSearchPath(void);
  477. #if defined(MAC_NSPR_STANDALONE)
  478. extern int strcmp(const char *str1, const char *str2);
  479. extern int strcasecmp(const char *str1, const char *str2);
  480. #endif
  481. extern void MapFullToPartialMacFile(char *);
  482. extern char *MapPartialToFullMacFile(const char *);
  483. extern void ResetTimer(void);
  484. extern void PR_PeriodicIdle(void);
  485. extern void ActivateTimer(void);
  486. extern void DeactivateTimer(void);
  487. extern void PR_InitMemory(void);
  488. extern struct hostent *gethostbyaddr(const void *addr, int addrlen, int type);
  489. extern short GetVolumeRefNumFromName(const char *);
  490. #include <stdio.h> // Needed to get FILE typedef
  491. extern FILE *_OS_FOPEN(const char *filename, const char *mode);
  492. //
  493. // Macintosh only private parts.
  494. //
  495. #define dprintTrace ";dprintf;doTrace"
  496. #define dprintNoTrace ";dprintf"
  497. extern void dprintf(const char *format, ...);
  498. // Entry into the memory system's cache flushing
  499. #if defined(MAC_NSPR_STANDALONE)
  500. extern PRUint8 CallCacheFlushers(size_t blockSize);
  501. #endif
  502. #if defined(MAC_NSPR_STANDALONE)
  503. extern void* reallocSmaller(void* block, size_t newSize);
  504. #endif
  505. /*
  506. ** PR_GetSystemInfo related definitions
  507. */
  508. #define _PR_SI_SYSNAME "MacOS"
  509. #define _PR_SI_ARCHITECTURE "PowerPC"
  510. /*
  511. * Memory-mapped files
  512. */
  513. struct _MDFileMap {
  514. PRInt8 unused;
  515. };
  516. extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
  517. #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
  518. extern PRInt32 _MD_GetMemMapAlignment(void);
  519. #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
  520. extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
  521. PRUint32 len);
  522. #define _MD_MEM_MAP _MD_MemMap
  523. extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
  524. #define _MD_MEM_UNMAP _MD_MemUnmap
  525. extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
  526. #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
  527. extern void SetLogFileTypeCreator(const char *logFile);
  528. extern int _MD_mac_get_nonblocking_connect_error(PRFileDesc* fd);
  529. /*
  530. * Critical section support
  531. */
  532. #define MAC_CRITICAL_REGIONS TARGET_CARBON
  533. #if MAC_CRITICAL_REGIONS
  534. extern void InitCriticalRegion();
  535. extern void TermCriticalRegion();
  536. extern void EnterCritialRegion();
  537. extern void LeaveCritialRegion();
  538. #define INIT_CRITICAL_REGION() InitCriticalRegion()
  539. #define TERM_CRITICAL_REGION() TermCriticalRegion()
  540. #define ENTER_CRITICAL_REGION() EnterCritialRegion()
  541. #define LEAVE_CRITICAL_REGION() LeaveCritialRegion()
  542. #else
  543. #define INIT_CRITICAL_REGION()
  544. #define TERM_CRITICAL_REGION()
  545. #define ENTER_CRITICAL_REGION()
  546. #define LEAVE_CRITICAL_REGION()
  547. #endif
  548. /*
  549. * CPU Idle support
  550. */
  551. extern void InitIdleSemaphore();
  552. extern void TermIdleSemaphore();
  553. extern void WaitOnIdleSemaphore();
  554. extern void SignalIdleSemaphore();
  555. /*
  556. * Atomic operations
  557. */
  558. #ifdef _PR_HAVE_ATOMIC_OPS
  559. extern PRInt32 _MD_AtomicSet(PRInt32 *val, PRInt32 newval);
  560. #define _MD_INIT_ATOMIC()
  561. #define _MD_ATOMIC_INCREMENT(val) OTAtomicAdd32(1, (SInt32 *)val)
  562. #define _MD_ATOMIC_ADD(ptr, val) OTAtomicAdd32(val, (SInt32 *)ptr)
  563. #define _MD_ATOMIC_DECREMENT(val) OTAtomicAdd32(-1, (SInt32 *)val)
  564. #define _MD_ATOMIC_SET(val, newval) _MD_AtomicSet(val, newval)
  565. #endif /* _PR_HAVE_ATOMIC_OPS */
  566. #endif /* prmacos_h___ */