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
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/
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
15 * The Original Code is the Netscape Portable Runtime (NSPR).
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.
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nspr_os2_defs_h___
39 #define nspr_os2_defs_h___
45 #define INCL_DOSPROCESS
46 #define INCL_DOSERRORS
50 #include <sys/select.h>
57 * Internal configuration macros
60 #define PR_LINKER_ARCH "os2"
61 #define _PR_SI_SYSNAME "OS2"
62 #define _PR_SI_ARCHITECTURE "x86" /* XXXMB hardcode for now */
65 #define _PR_GLOBAL_THREADS_ONLY
66 #undef HAVE_THREAD_AFFINITY
67 #define _PR_HAVE_THREADSAFE_GETHOST
68 #define _PR_HAVE_ATOMIC_OPS
69 #define HAVE_NETINET_TCP_H
71 #define HANDLE unsigned long
72 #define HINSTANCE HMODULE
74 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
77 extern struct PRLock
*_pr_schedLock
;
79 /* --- Typedefs --- */
80 typedef void (*FiberFunc
)(void *);
82 #define PR_NUM_GCREGS 8
83 typedef PRInt32 PR_CONTEXT_TYPE
[PR_NUM_GCREGS
];
84 #define GC_VMBASE 0x40000000
85 #define GC_VMLIMIT 0x00FFFFFF
86 typedef int (*FARPROC
)();
88 #define _MD_MAGIC_THREAD 0x22222222
89 #define _MD_MAGIC_THREADSTACK 0x33333333
90 #define _MD_MAGIC_SEGMENT 0x44444444
91 #define _MD_MAGIC_DIR 0x55555555
92 #define _MD_MAGIC_CV 0x66666666
103 HEV blocked_sema
; /* Threads block on this when waiting
106 PRBool inCVWaitQueue
; /* PR_TRUE if the thread is in the
107 * wait queue of some cond var.
108 * PR_FALSE otherwise. */
109 TID handle
; /* OS/2 thread handle */
110 void *sp
; /* only valid when suspended */
111 PRUint32 magic
; /* for debugging */
112 PR_CONTEXT_TYPE gcContext
; /* Thread context for GC */
113 struct PRThread
*prev
, *next
; /* used by the cvar wait queue to
114 * chain the PRThread structures
118 struct _MDThreadStack
{
119 PRUint32 magic
; /* for debugging */
123 PRUint32 magic
; /* for debugging */
134 PRBool firstEntry
; /* Is this the entry returned
135 * by FindFirstFile()? */
136 PRUint32 magic
; /* for debugging */
141 struct PRThread
*waitHead
, *waitTail
; /* the wait queue: a doubly-
142 * linked list of threads
143 * waiting on this condition
145 PRIntn nwait
; /* number of threads in the
149 #define _MD_CV_NOTIFIED_LENGTH 6
150 typedef struct _MDNotified _MDNotified
;
152 PRIntn length
; /* # of used entries in this
155 struct _MDCVar
*cv
; /* the condition variable notified */
156 PRIntn times
; /* and the number of times notified */
157 struct PRThread
*notifyHead
; /* list of threads to wake up */
158 } cv
[_MD_CV_NOTIFIED_LENGTH
];
159 _MDNotified
*link
; /* link to another of these, or NULL */
163 HMTX mutex
; /* this is recursive on OS/2 */
166 * When notifying cvars, there is no point in actually
167 * waking up the threads waiting on the cvars until we've
168 * released the lock. So, we temporarily record the cvars.
169 * When doing an unlock, we'll then wake up the waiting threads.
171 struct _MDNotified notified
; /* array of conditions notified */
179 PRInt32 osfd
; /* The osfd can come from one of three spaces:
180 * - For stdin, stdout, and stderr, we are using
181 * the libc file handle (0, 1, 2), which is an int.
182 * - For files and pipes, we are using OS/2 handles,
184 * - For sockets, we are using int
192 /* --- Misc stuff --- */
193 #define _MD_GET_SP(thread) (thread)->md.gcContext[6]
195 /* --- IO stuff --- */
197 #define _MD_OPEN (_PR_MD_OPEN)
198 #define _MD_OPEN_FILE (_PR_MD_OPEN)
199 #define _MD_READ (_PR_MD_READ)
200 #define _MD_WRITE (_PR_MD_WRITE)
201 #define _MD_WRITEV (_PR_MD_WRITEV)
202 #define _MD_LSEEK (_PR_MD_LSEEK)
203 #define _MD_LSEEK64 (_PR_MD_LSEEK64)
204 extern PRInt32
_MD_CloseFile(PRInt32 osfd
);
205 #define _MD_CLOSE_FILE _MD_CloseFile
206 #define _MD_GETFILEINFO (_PR_MD_GETFILEINFO)
207 #define _MD_GETFILEINFO64 (_PR_MD_GETFILEINFO64)
208 #define _MD_GETOPENFILEINFO (_PR_MD_GETOPENFILEINFO)
209 #define _MD_GETOPENFILEINFO64 (_PR_MD_GETOPENFILEINFO64)
210 #define _MD_STAT (_PR_MD_STAT)
211 #define _MD_RENAME (_PR_MD_RENAME)
212 #define _MD_ACCESS (_PR_MD_ACCESS)
213 #define _MD_DELETE (_PR_MD_DELETE)
214 #define _MD_MKDIR (_PR_MD_MKDIR)
215 #define _MD_MAKE_DIR (_PR_MD_MKDIR)
216 #define _MD_RMDIR (_PR_MD_RMDIR)
217 #define _MD_LOCKFILE (_PR_MD_LOCKFILE)
218 #define _MD_TLOCKFILE (_PR_MD_TLOCKFILE)
219 #define _MD_UNLOCKFILE (_PR_MD_UNLOCKFILE)
221 /* --- Socket IO stuff --- */
223 /* The ones that don't map directly may need to be re-visited... */
224 #define _MD_EACCES EACCES
225 #define _MD_EADDRINUSE EADDRINUSE
226 #define _MD_EADDRNOTAVAIL EADDRNOTAVAIL
227 #define _MD_EAFNOSUPPORT EAFNOSUPPORT
228 #define _MD_EAGAIN EWOULDBLOCK
229 #define _MD_EALREADY EALREADY
230 #define _MD_EBADF EBADF
231 #define _MD_ECONNREFUSED ECONNREFUSED
232 #define _MD_ECONNRESET ECONNRESET
233 #define _MD_EFAULT SOCEFAULT
234 #define _MD_EINPROGRESS EINPROGRESS
235 #define _MD_EINTR EINTR
236 #define _MD_EINVAL EINVAL
237 #define _MD_EISCONN EISCONN
238 #define _MD_ENETUNREACH ENETUNREACH
239 #define _MD_ENOENT ENOENT
240 #define _MD_ENOTCONN ENOTCONN
241 #define _MD_ENOTSOCK ENOTSOCK
242 #define _MD_EOPNOTSUPP EOPNOTSUPP
243 #define _MD_EWOULDBLOCK EWOULDBLOCK
244 #define _MD_GET_SOCKET_ERROR() sock_errno()
245 #ifndef INADDR_LOOPBACK /* For some reason this is not defined in OS2 tcpip */
246 /* #define INADDR_LOOPBACK INADDR_ANY */
249 #define _MD_INIT_FILEDESC(fd)
250 extern void _MD_MakeNonblock(PRFileDesc
*f
);
251 #define _MD_MAKE_NONBLOCK _MD_MakeNonblock
252 #define _MD_INIT_FD_INHERITABLE (_PR_MD_INIT_FD_INHERITABLE)
253 #define _MD_QUERY_FD_INHERITABLE (_PR_MD_QUERY_FD_INHERITABLE)
254 #define _MD_SHUTDOWN (_PR_MD_SHUTDOWN)
255 #define _MD_LISTEN _PR_MD_LISTEN
256 extern PRInt32
_MD_CloseSocket(PRInt32 osfd
);
257 #define _MD_CLOSE_SOCKET _MD_CloseSocket
258 #define _MD_SENDTO (_PR_MD_SENDTO)
259 #define _MD_RECVFROM (_PR_MD_RECVFROM)
260 #define _MD_SOCKETPAIR (_PR_MD_SOCKETPAIR)
261 #define _MD_GETSOCKNAME (_PR_MD_GETSOCKNAME)
262 #define _MD_GETPEERNAME (_PR_MD_GETPEERNAME)
263 #define _MD_GETSOCKOPT (_PR_MD_GETSOCKOPT)
264 #define _MD_SETSOCKOPT (_PR_MD_SETSOCKOPT)
266 #define _MD_FSYNC _PR_MD_FSYNC
267 #define _MD_SET_FD_INHERITABLE (_PR_MD_SET_FD_INHERITABLE)
269 #ifdef _PR_HAVE_ATOMIC_OPS
270 #define _MD_INIT_ATOMIC()
271 #define _MD_ATOMIC_INCREMENT _PR_MD_ATOMIC_INCREMENT
272 #define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
273 #define _MD_ATOMIC_DECREMENT _PR_MD_ATOMIC_DECREMENT
274 #define _MD_ATOMIC_SET _PR_MD_ATOMIC_SET
277 #define _MD_INIT_IO (_PR_MD_INIT_IO)
278 #define _MD_PR_POLL (_PR_MD_PR_POLL)
280 #define _MD_SOCKET (_PR_MD_SOCKET)
281 extern PRInt32
_MD_SocketAvailable(PRFileDesc
*fd
);
282 #define _MD_SOCKETAVAILABLE _MD_SocketAvailable
283 #define _MD_PIPEAVAILABLE _MD_SocketAvailable
284 #define _MD_CONNECT (_PR_MD_CONNECT)
285 extern PRInt32
_MD_Accept(PRFileDesc
*fd
, PRNetAddr
*raddr
, PRUint32
*rlen
,
286 PRIntervalTime timeout
);
287 #define _MD_ACCEPT _MD_Accept
288 #define _MD_BIND (_PR_MD_BIND)
289 #define _MD_RECV (_PR_MD_RECV)
290 #define _MD_SEND (_PR_MD_SEND)
292 /* --- Scheduler stuff --- */
293 /* #define _MD_PAUSE_CPU _PR_MD_PAUSE_CPU */
294 #define _MD_PAUSE_CPU
296 /* --- DIR stuff --- */
297 #define PR_DIRECTORY_SEPARATOR '\\'
298 #define PR_DIRECTORY_SEPARATOR_STR "\\"
299 #define PR_PATH_SEPARATOR ';'
300 #define PR_PATH_SEPARATOR_STR ";"
301 #define _MD_ERRNO() errno
302 #define _MD_OPEN_DIR (_PR_MD_OPEN_DIR)
303 #define _MD_CLOSE_DIR (_PR_MD_CLOSE_DIR)
304 #define _MD_READ_DIR (_PR_MD_READ_DIR)
306 /* --- Segment stuff --- */
307 #define _MD_INIT_SEGS()
308 #define _MD_ALLOC_SEGMENT(seg, size, vaddr) 0
309 #define _MD_FREE_SEGMENT(seg)
311 /* --- Environment Stuff --- */
312 #define _MD_GET_ENV (_PR_MD_GET_ENV)
313 #define _MD_PUT_ENV (_PR_MD_PUT_ENV)
315 /* --- Threading Stuff --- */
316 #define _MD_DEFAULT_STACK_SIZE 65536L
317 #define _MD_INIT_THREAD (_PR_MD_INIT_THREAD)
318 #define _MD_INIT_ATTACHED_THREAD (_PR_MD_INIT_THREAD)
319 #define _MD_CREATE_THREAD (_PR_MD_CREATE_THREAD)
320 #define _MD_YIELD (_PR_MD_YIELD)
321 #define _MD_SET_PRIORITY (_PR_MD_SET_PRIORITY)
322 #define _MD_CLEAN_THREAD (_PR_MD_CLEAN_THREAD)
323 #define _MD_SETTHREADAFFINITYMASK (_PR_MD_SETTHREADAFFINITYMASK)
324 #define _MD_GETTHREADAFFINITYMASK (_PR_MD_GETTHREADAFFINITYMASK)
325 #define _MD_EXIT_THREAD (_PR_MD_EXIT_THREAD)
326 #define _MD_SUSPEND_THREAD (_PR_MD_SUSPEND_THREAD)
327 #define _MD_RESUME_THREAD (_PR_MD_RESUME_THREAD)
328 #define _MD_SUSPEND_CPU (_PR_MD_SUSPEND_CPU)
329 #define _MD_RESUME_CPU (_PR_MD_RESUME_CPU)
330 #define _MD_WAKEUP_CPUS (_PR_MD_WAKEUP_CPUS)
331 #define _MD_BEGIN_SUSPEND_ALL()
332 #define _MD_BEGIN_RESUME_ALL()
333 #define _MD_END_SUSPEND_ALL()
334 #define _MD_END_RESUME_ALL()
336 /* --- Lock stuff --- */
337 #define _PR_LOCK _MD_LOCK
338 #define _PR_UNLOCK _MD_UNLOCK
340 #define _MD_NEW_LOCK (_PR_MD_NEW_LOCK)
341 #define _MD_FREE_LOCK(lock) (DosCloseMutexSem((lock)->mutex))
342 #define _MD_LOCK(lock) (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT))
343 #define _MD_TEST_AND_LOCK(lock) (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT),0)
344 #define _MD_UNLOCK (_PR_MD_UNLOCK)
346 /* --- lock and cv waiting --- */
347 #define _MD_WAIT (_PR_MD_WAIT)
348 #define _MD_WAKEUP_WAITER (_PR_MD_WAKEUP_WAITER)
350 /* --- CVar ------------------- */
351 #define _MD_WAIT_CV (_PR_MD_WAIT_CV)
352 #define _MD_NEW_CV (_PR_MD_NEW_CV)
353 #define _MD_FREE_CV (_PR_MD_FREE_CV)
354 #define _MD_NOTIFY_CV (_PR_MD_NOTIFY_CV )
355 #define _MD_NOTIFYALL_CV (_PR_MD_NOTIFYALL_CV)
357 /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
358 /* extern struct _MDLock _pr_ioq_lock; */
359 #define _MD_IOQ_LOCK()
360 #define _MD_IOQ_UNLOCK()
363 /* --- Initialization stuff --- */
364 #define _MD_START_INTERRUPTS()
365 #define _MD_STOP_INTERRUPTS()
366 #define _MD_DISABLE_CLOCK_INTERRUPTS()
367 #define _MD_ENABLE_CLOCK_INTERRUPTS()
368 #define _MD_BLOCK_CLOCK_INTERRUPTS()
369 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
370 #define _MD_EARLY_INIT (_PR_MD_EARLY_INIT)
371 #define _MD_FINAL_INIT()
372 #define _MD_INIT_CPUS()
373 #define _MD_INIT_RUNNING_CPU(cpu)
376 struct PRProcessAttr
;
378 #define _MD_CREATE_PROCESS _PR_CreateOS2Process
379 extern struct PRProcess
* _PR_CreateOS2Process(
383 const struct PRProcessAttr
*attr
386 #define _MD_DETACH_PROCESS _PR_DetachOS2Process
387 extern PRStatus
_PR_DetachOS2Process(struct PRProcess
*process
);
389 /* --- Wait for a child process to terminate --- */
390 #define _MD_WAIT_PROCESS _PR_WaitOS2Process
391 extern PRStatus
_PR_WaitOS2Process(struct PRProcess
*process
,
394 #define _MD_KILL_PROCESS _PR_KillOS2Process
395 extern PRStatus
_PR_KillOS2Process(struct PRProcess
*process
);
397 #define _MD_CLEANUP_BEFORE_EXIT()
398 #define _MD_EXIT (_PR_MD_EXIT)
399 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
403 #define _MD_SWITCH_CONTEXT
404 #define _MD_RESTORE_CONTEXT
406 /* --- Intervals --- */
407 #define _MD_INTERVAL_INIT (_PR_MD_INTERVAL_INIT)
408 #define _MD_GET_INTERVAL (_PR_MD_GET_INTERVAL)
409 #define _MD_INTERVAL_PER_SEC (_PR_MD_INTERVAL_PER_SEC)
410 #define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000)
411 #define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000)
413 /* --- Native-Thread Specific Definitions ------------------------------- */
415 typedef struct __NSPR_TLS
417 struct PRThread
*_pr_thread_last_run
;
418 struct PRThread
*_pr_currentThread
;
419 struct _PRCPU
*_pr_currentCPU
;
422 extern _NSPR_TLS
* pThreadLocalStorage
;
423 NSPR_API(void) _PR_MD_ENSURE_TLS(void);
425 #define _MD_GET_ATTACHED_THREAD() pThreadLocalStorage->_pr_currentThread
426 extern struct PRThread
* _MD_CURRENT_THREAD(void);
427 #define _MD_SET_CURRENT_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentThread = (_thread)
429 #define _MD_LAST_THREAD() pThreadLocalStorage->_pr_thread_last_run
430 #define _MD_SET_LAST_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_thread_last_run = (_thread)
432 #define _MD_CURRENT_CPU() pThreadLocalStorage->_pr_currentCPU
433 #define _MD_SET_CURRENT_CPU(_cpu) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentCPU = (_cpu)
435 /* lth. #define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val)) */
436 /* lth. #define _MD_GET_INTSOFF() _pr_ints_off */
437 /* lth. #define _MD_INCREMENT_INTSOFF() (_pr_ints_off++) */
438 /* lth. #define _MD_DECREMENT_INTSOFF() (_pr_ints_off--) */
440 /* --- Scheduler stuff --- */
441 #define LOCK_SCHEDULER() 0
442 #define UNLOCK_SCHEDULER() 0
443 #define _PR_LockSched() 0
444 #define _PR_UnlockSched() 0
446 /* --- Initialization stuff --- */
447 #define _MD_INIT_LOCKS()
449 /* --- Stack stuff --- */
450 #define _MD_INIT_STACK(stack, redzone)
451 #define _MD_CLEAR_STACK(stack)
453 /* --- Memory-mapped files stuff --- not implemented on OS/2 */
459 extern PRStatus
_MD_CreateFileMap(struct PRFileMap
*fmap
, PRInt64 size
);
460 #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
462 extern PRInt32
_MD_GetMemMapAlignment(void);
463 #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
465 extern void * _MD_MemMap(struct PRFileMap
*fmap
, PRInt64 offset
,
467 #define _MD_MEM_MAP _MD_MemMap
469 extern PRStatus
_MD_MemUnmap(void *addr
, PRUint32 size
);
470 #define _MD_MEM_UNMAP _MD_MemUnmap
472 extern PRStatus
_MD_CloseFileMap(struct PRFileMap
*fmap
);
473 #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
475 /* Some stuff for setting up thread contexts */
476 typedef ULONG DWORD
, *PDWORD
;
478 /* The following definitions and two structures are new in OS/2 Warp 4.0.
480 #ifndef CONTEXT_CONTROL
481 #define CONTEXT_CONTROL 0x00000001
482 #define CONTEXT_INTEGER 0x00000002
483 #define CONTEXT_SEGMENTS 0x00000004
484 #define CONTEXT_FLOATING_POINT 0x00000008
485 #define CONTEXT_FULL 0x0000000F
488 typedef struct _FPREG
{
489 ULONG losig
; /* Low 32-bits of the significand. */
490 ULONG hisig
; /* High 32-bits of the significand. */
491 USHORT signexp
; /* Sign and exponent. */
493 typedef struct _CONTEXTRECORD
{
497 ULONG ctx_SegGs
; /* GS register. */
498 ULONG ctx_SegFs
; /* FS register. */
499 ULONG ctx_SegEs
; /* ES register. */
500 ULONG ctx_SegDs
; /* DS register. */
501 ULONG ctx_RegEdi
; /* EDI register. */
502 ULONG ctx_RegEsi
; /* ESI register. */
503 ULONG ctx_RegEax
; /* EAX register. */
504 ULONG ctx_RegEbx
; /* EBX register. */
505 ULONG ctx_RegEcx
; /* ECX register. */
506 ULONG ctx_RegEdx
; /* EDX register. */
507 ULONG ctx_RegEbp
; /* EBP register. */
508 ULONG ctx_RegEip
; /* EIP register. */
509 ULONG ctx_SegCs
; /* CS register. */
510 ULONG ctx_EFlags
; /* EFLAGS register. */
511 ULONG ctx_RegEsp
; /* ESP register. */
512 ULONG ctx_SegSs
; /* SS register. */
513 } CONTEXTRECORD
, *PCONTEXTRECORD
;
517 extern APIRET (* APIENTRY QueryThreadContext
)(TID
, ULONG
, PCONTEXTRECORD
);
520 #define _pr_tid (((PTIB2)_getTIBvalue(offsetof(TIB, tib_ptib2)))->tib2_ultid)
521 #define _pr_current_Thread (_system_tls[_pr_tid-1].__pr_current_thread)
524 /* Some simple mappings of Windows API's to OS/2 API's to make our lives a
525 * little bit easier. Only add one here if it is a DIRECT mapping. We are
526 * not emulating anything. Just mapping.
528 #define FreeLibrary(x) DosFreeModule((HMODULE)x)
529 #define OutputDebugString(x)
531 extern int _MD_os2_get_nonblocking_connect_error(int osfd
);
533 #endif /* nspr_os2_defs_h___ */