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