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 |
|
---|
38 | #ifndef nspr_os2_defs_h___
|
---|
39 | #define nspr_os2_defs_h___
|
---|
40 |
|
---|
41 | #define INCL_DOS
|
---|
42 | #define INCL_DOSPROCESS
|
---|
43 | #define INCL_DOSERRORS
|
---|
44 | #define INCL_WIN
|
---|
45 | #define INCL_WPS
|
---|
46 | #include <os2.h>
|
---|
47 | #include <sys/select.h>
|
---|
48 |
|
---|
49 | #include "prio.h"
|
---|
50 |
|
---|
51 | #include <errno.h>
|
---|
52 |
|
---|
53 | #ifdef XP_OS2_VACPP
|
---|
54 | /* TODO RAMSEMs need to be written for GCC/EMX */
|
---|
55 | #define USE_RAMSEM
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #ifdef USE_RAMSEM
|
---|
59 | #pragma pack(4)
|
---|
60 |
|
---|
61 | #pragma pack(2)
|
---|
62 | typedef struct _RAMSEM
|
---|
63 | {
|
---|
64 | ULONG ulTIDPID;
|
---|
65 | ULONG hevSem;
|
---|
66 | ULONG cLocks;
|
---|
67 | USHORT cWaiting;
|
---|
68 | USHORT cPosts;
|
---|
69 | } RAMSEM, *PRAMSEM;
|
---|
70 |
|
---|
71 | typedef struct _CRITICAL_SECTION
|
---|
72 | {
|
---|
73 | ULONG ulReserved[4]; /* Same size as RAMSEM */
|
---|
74 | } CRITICAL_SECTION, *PCRITICAL_SECTION, *LPCRITICAL_SECTION;
|
---|
75 | #pragma pack(4)
|
---|
76 |
|
---|
77 | APIRET _Optlink SemRequest486(PRAMSEM, ULONG);
|
---|
78 | APIRET _Optlink SemReleasex86(PRAMSEM, ULONG);
|
---|
79 | #endif
|
---|
80 |
|
---|
81 | /*
|
---|
82 | * Internal configuration macros
|
---|
83 | */
|
---|
84 |
|
---|
85 | #define PR_LINKER_ARCH "os2"
|
---|
86 | #define _PR_SI_SYSNAME "OS2"
|
---|
87 | #define _PR_SI_ARCHITECTURE "x86" /* XXXMB hardcode for now */
|
---|
88 |
|
---|
89 | #define HAVE_DLL
|
---|
90 | #define _PR_GLOBAL_THREADS_ONLY
|
---|
91 | #undef HAVE_THREAD_AFFINITY
|
---|
92 | #define _PR_HAVE_THREADSAFE_GETHOST
|
---|
93 | #define _PR_HAVE_ATOMIC_OPS
|
---|
94 | #ifndef TCPV40HDRS /* bird */
|
---|
95 | #define _PR_HAVE_SOCKADDR_LEN /* bird */
|
---|
96 | #endif /* bird */
|
---|
97 |
|
---|
98 | #define HANDLE unsigned long
|
---|
99 | #define HINSTANCE HMODULE
|
---|
100 |
|
---|
101 | /* --- Common User-Thread/Native-Thread Definitions --------------------- */
|
---|
102 |
|
---|
103 | /* --- Globals --- */
|
---|
104 | extern struct PRLock *_pr_schedLock;
|
---|
105 |
|
---|
106 | /* --- Typedefs --- */
|
---|
107 | typedef void (*FiberFunc)(void *);
|
---|
108 |
|
---|
109 | #define PR_NUM_GCREGS 8
|
---|
110 | typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
|
---|
111 | #define GC_VMBASE 0x40000000
|
---|
112 | #define GC_VMLIMIT 0x00FFFFFF
|
---|
113 | typedef int (*FARPROC)();
|
---|
114 |
|
---|
115 | #define _MD_MAGIC_THREAD 0x22222222
|
---|
116 | #define _MD_MAGIC_THREADSTACK 0x33333333
|
---|
117 | #define _MD_MAGIC_SEGMENT 0x44444444
|
---|
118 | #define _MD_MAGIC_DIR 0x55555555
|
---|
119 | #define _MD_MAGIC_CV 0x66666666
|
---|
120 |
|
---|
121 | struct _MDSemaphore {
|
---|
122 | HEV sem;
|
---|
123 | };
|
---|
124 |
|
---|
125 | struct _MDCPU {
|
---|
126 | int unused;
|
---|
127 | };
|
---|
128 |
|
---|
129 | struct _MDThread {
|
---|
130 | HEV blocked_sema; /* Threads block on this when waiting
|
---|
131 | * for IO or CondVar.
|
---|
132 | */
|
---|
133 | PRBool inCVWaitQueue; /* PR_TRUE if the thread is in the
|
---|
134 | * wait queue of some cond var.
|
---|
135 | * PR_FALSE otherwise. */
|
---|
136 | TID handle; /* OS/2 thread handle */
|
---|
137 | void *sp; /* only valid when suspended */
|
---|
138 | PRUint32 magic; /* for debugging */
|
---|
139 | PR_CONTEXT_TYPE gcContext; /* Thread context for GC */
|
---|
140 | struct PRThread *prev, *next; /* used by the cvar wait queue to
|
---|
141 | * chain the PRThread structures
|
---|
142 | * together */
|
---|
143 | };
|
---|
144 |
|
---|
145 | struct _MDThreadStack {
|
---|
146 | PRUint32 magic; /* for debugging */
|
---|
147 | };
|
---|
148 |
|
---|
149 | struct _MDSegment {
|
---|
150 | PRUint32 magic; /* for debugging */
|
---|
151 | };
|
---|
152 |
|
---|
153 | #undef PROFILE_LOCKS
|
---|
154 |
|
---|
155 | struct _MDDir {
|
---|
156 | HDIR d_hdl;
|
---|
157 | FILEFINDBUF3 d_entry;
|
---|
158 | PRBool firstEntry; /* Is this the entry returned
|
---|
159 | * by FindFirstFile()? */
|
---|
160 | PRUint32 magic; /* for debugging */
|
---|
161 | };
|
---|
162 |
|
---|
163 | struct _MDCVar {
|
---|
164 | PRUint32 magic;
|
---|
165 | struct PRThread *waitHead, *waitTail; /* the wait queue: a doubly-
|
---|
166 | * linked list of threads
|
---|
167 | * waiting on this condition
|
---|
168 | * variable */
|
---|
169 | PRIntn nwait; /* number of threads in the
|
---|
170 | * wait queue */
|
---|
171 | };
|
---|
172 |
|
---|
173 | #define _MD_CV_NOTIFIED_LENGTH 6
|
---|
174 | typedef struct _MDNotified _MDNotified;
|
---|
175 | struct _MDNotified {
|
---|
176 | PRIntn length; /* # of used entries in this
|
---|
177 | * structure */
|
---|
178 | struct {
|
---|
179 | struct _MDCVar *cv; /* the condition variable notified */
|
---|
180 | PRIntn times; /* and the number of times notified */
|
---|
181 | struct PRThread *notifyHead; /* list of threads to wake up */
|
---|
182 | } cv[_MD_CV_NOTIFIED_LENGTH];
|
---|
183 | _MDNotified *link; /* link to another of these, or NULL */
|
---|
184 | };
|
---|
185 |
|
---|
186 | struct _MDLock {
|
---|
187 | #ifdef USE_RAMSEM
|
---|
188 | CRITICAL_SECTION mutex; /* this is recursive on NT */
|
---|
189 | #else
|
---|
190 | HMTX mutex; /* this is recursive on NT */
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | /*
|
---|
194 | * When notifying cvars, there is no point in actually
|
---|
195 | * waking up the threads waiting on the cvars until we've
|
---|
196 | * released the lock. So, we temporarily record the cvars.
|
---|
197 | * When doing an unlock, we'll then wake up the waiting threads.
|
---|
198 | */
|
---|
199 | struct _MDNotified notified; /* array of conditions notified */
|
---|
200 | #ifdef PROFILE_LOCKS
|
---|
201 | PRInt32 hitcount;
|
---|
202 | PRInt32 misscount;
|
---|
203 | #endif
|
---|
204 | };
|
---|
205 |
|
---|
206 | struct _MDFileDesc {
|
---|
207 | PRInt32 osfd; /* The osfd can come from one of three spaces:
|
---|
208 | * - For stdin, stdout, and stderr, we are using
|
---|
209 | * the libc file handle (0, 1, 2), which is an int.
|
---|
210 | * - For files and pipes, we are using OS/2 handles,
|
---|
211 | * which is a void*.
|
---|
212 | * - For sockets, we are using int
|
---|
213 | */
|
---|
214 | };
|
---|
215 |
|
---|
216 | struct _MDProcess {
|
---|
217 | PID pid;
|
---|
218 | };
|
---|
219 |
|
---|
220 | /* --- Misc stuff --- */
|
---|
221 | #define _MD_GET_SP(thread) (thread)->md.gcContext[6]
|
---|
222 |
|
---|
223 | /* --- IO stuff --- */
|
---|
224 |
|
---|
225 | #define _MD_OPEN (_PR_MD_OPEN)
|
---|
226 | #define _MD_OPEN_FILE (_PR_MD_OPEN)
|
---|
227 | #define _MD_READ (_PR_MD_READ)
|
---|
228 | #define _MD_WRITE (_PR_MD_WRITE)
|
---|
229 | #define _MD_WRITEV (_PR_MD_WRITEV)
|
---|
230 | #define _MD_LSEEK (_PR_MD_LSEEK)
|
---|
231 | #define _MD_LSEEK64 (_PR_MD_LSEEK64)
|
---|
232 | extern PRInt32 _MD_CloseFile(PRInt32 osfd);
|
---|
233 | #define _MD_CLOSE_FILE _MD_CloseFile
|
---|
234 | #define _MD_GETFILEINFO (_PR_MD_GETFILEINFO)
|
---|
235 | #define _MD_GETFILEINFO64 (_PR_MD_GETFILEINFO64)
|
---|
236 | #define _MD_GETOPENFILEINFO (_PR_MD_GETOPENFILEINFO)
|
---|
237 | #define _MD_GETOPENFILEINFO64 (_PR_MD_GETOPENFILEINFO64)
|
---|
238 | #define _MD_STAT (_PR_MD_STAT)
|
---|
239 | #define _MD_RENAME (_PR_MD_RENAME)
|
---|
240 | #define _MD_ACCESS (_PR_MD_ACCESS)
|
---|
241 | #define _MD_DELETE (_PR_MD_DELETE)
|
---|
242 | #define _MD_MKDIR (_PR_MD_MKDIR)
|
---|
243 | #define _MD_MAKE_DIR (_PR_MD_MKDIR)
|
---|
244 | #define _MD_RMDIR (_PR_MD_RMDIR)
|
---|
245 | #define _MD_LOCKFILE (_PR_MD_LOCKFILE)
|
---|
246 | #define _MD_TLOCKFILE (_PR_MD_TLOCKFILE)
|
---|
247 | #define _MD_UNLOCKFILE (_PR_MD_UNLOCKFILE)
|
---|
248 |
|
---|
249 | /* --- Socket IO stuff --- */
|
---|
250 |
|
---|
251 | /* The ones that don't map directly may need to be re-visited... */
|
---|
252 | #ifdef XP_OS2_VACPP
|
---|
253 | #define EPIPE EBADF
|
---|
254 | #define EIO ECONNREFUSED
|
---|
255 | #endif
|
---|
256 | #define _MD_EACCES EACCES
|
---|
257 | #define _MD_EADDRINUSE EADDRINUSE
|
---|
258 | #define _MD_EADDRNOTAVAIL EADDRNOTAVAIL
|
---|
259 | #define _MD_EAFNOSUPPORT EAFNOSUPPORT
|
---|
260 | #define _MD_EAGAIN EWOULDBLOCK
|
---|
261 | #define _MD_EALREADY EALREADY
|
---|
262 | #define _MD_EBADF EBADF
|
---|
263 | #define _MD_ECONNREFUSED ECONNREFUSED
|
---|
264 | #define _MD_ECONNRESET ECONNRESET
|
---|
265 | #define _MD_EFAULT SOCEFAULT
|
---|
266 | #define _MD_EINPROGRESS EINPROGRESS
|
---|
267 | #define _MD_EINTR EINTR
|
---|
268 | #define _MD_EINVAL EINVAL
|
---|
269 | #define _MD_EISCONN EISCONN
|
---|
270 | #define _MD_ENETUNREACH ENETUNREACH
|
---|
271 | #define _MD_ENOENT ENOENT
|
---|
272 | #define _MD_ENOTCONN ENOTCONN
|
---|
273 | #define _MD_ENOTSOCK ENOTSOCK
|
---|
274 | #define _MD_EOPNOTSUPP EOPNOTSUPP
|
---|
275 | #define _MD_EWOULDBLOCK EWOULDBLOCK
|
---|
276 | #define _MD_GET_SOCKET_ERROR() sock_errno()
|
---|
277 | #ifndef INADDR_LOOPBACK /* For some reason this is not defined in OS2 tcpip */
|
---|
278 | /* #define INADDR_LOOPBACK INADDR_ANY */
|
---|
279 | #endif
|
---|
280 |
|
---|
281 | #define _MD_INIT_FILEDESC(fd)
|
---|
282 | extern void _MD_MakeNonblock(PRFileDesc *f);
|
---|
283 | #define _MD_MAKE_NONBLOCK _MD_MakeNonblock
|
---|
284 | #define _MD_INIT_FD_INHERITABLE (_PR_MD_INIT_FD_INHERITABLE)
|
---|
285 | #define _MD_QUERY_FD_INHERITABLE (_PR_MD_QUERY_FD_INHERITABLE)
|
---|
286 | #define _MD_SHUTDOWN (_PR_MD_SHUTDOWN)
|
---|
287 | #define _MD_LISTEN _PR_MD_LISTEN
|
---|
288 | extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
|
---|
289 | #define _MD_CLOSE_SOCKET _MD_CloseSocket
|
---|
290 | #define _MD_SENDTO (_PR_MD_SENDTO)
|
---|
291 | #define _MD_RECVFROM (_PR_MD_RECVFROM)
|
---|
292 | #ifdef XP_OS2_VACPP
|
---|
293 | #define _MD_SOCKETPAIR(s, type, proto, sv) -1
|
---|
294 | #else
|
---|
295 | #define _MD_SOCKETPAIR (_PR_MD_SOCKETPAIR)
|
---|
296 | #endif
|
---|
297 | #define _MD_GETSOCKNAME (_PR_MD_GETSOCKNAME)
|
---|
298 | #define _MD_GETPEERNAME (_PR_MD_GETPEERNAME)
|
---|
299 | #define _MD_GETSOCKOPT (_PR_MD_GETSOCKOPT)
|
---|
300 | #define _MD_SETSOCKOPT (_PR_MD_SETSOCKOPT)
|
---|
301 |
|
---|
302 | #define _MD_FSYNC _PR_MD_FSYNC
|
---|
303 | #define _MD_SET_FD_INHERITABLE (_PR_MD_SET_FD_INHERITABLE)
|
---|
304 |
|
---|
305 | #ifdef _PR_HAVE_ATOMIC_OPS
|
---|
306 | #define _MD_INIT_ATOMIC()
|
---|
307 | #define _MD_ATOMIC_INCREMENT _PR_MD_ATOMIC_INCREMENT
|
---|
308 | #define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
|
---|
309 | #define _MD_ATOMIC_DECREMENT _PR_MD_ATOMIC_DECREMENT
|
---|
310 | #define _MD_ATOMIC_SET _PR_MD_ATOMIC_SET
|
---|
311 | #endif
|
---|
312 |
|
---|
313 | #define _MD_INIT_IO (_PR_MD_INIT_IO)
|
---|
314 | #define _MD_PR_POLL (_PR_MD_PR_POLL)
|
---|
315 |
|
---|
316 | #define _MD_SOCKET (_PR_MD_SOCKET)
|
---|
317 | extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
|
---|
318 | #define _MD_SOCKETAVAILABLE _MD_SocketAvailable
|
---|
319 | #define _MD_PIPEAVAILABLE _MD_SocketAvailable
|
---|
320 | #define _MD_CONNECT (_PR_MD_CONNECT)
|
---|
321 | extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
|
---|
322 | PRIntervalTime timeout);
|
---|
323 | #define _MD_ACCEPT _MD_Accept
|
---|
324 | #define _MD_BIND (_PR_MD_BIND)
|
---|
325 | #define _MD_RECV (_PR_MD_RECV)
|
---|
326 | #define _MD_SEND (_PR_MD_SEND)
|
---|
327 |
|
---|
328 | /* --- Scheduler stuff --- */
|
---|
329 | /* #define _MD_PAUSE_CPU _PR_MD_PAUSE_CPU */
|
---|
330 | #define _MD_PAUSE_CPU
|
---|
331 |
|
---|
332 | /* --- DIR stuff --- */
|
---|
333 | #define PR_DIRECTORY_SEPARATOR '\\'
|
---|
334 | #define PR_DIRECTORY_SEPARATOR_STR "\\"
|
---|
335 | #define PR_PATH_SEPARATOR ';'
|
---|
336 | #define PR_PATH_SEPARATOR_STR ";"
|
---|
337 | #define _MD_ERRNO() errno
|
---|
338 | #define _MD_OPEN_DIR (_PR_MD_OPEN_DIR)
|
---|
339 | #define _MD_CLOSE_DIR (_PR_MD_CLOSE_DIR)
|
---|
340 | #define _MD_READ_DIR (_PR_MD_READ_DIR)
|
---|
341 |
|
---|
342 | /* --- Segment stuff --- */
|
---|
343 | #define _MD_INIT_SEGS()
|
---|
344 | #define _MD_ALLOC_SEGMENT(seg, size, vaddr) 0
|
---|
345 | #define _MD_FREE_SEGMENT(seg)
|
---|
346 |
|
---|
347 | /* --- Environment Stuff --- */
|
---|
348 | #define _MD_GET_ENV (_PR_MD_GET_ENV)
|
---|
349 | #define _MD_PUT_ENV (_PR_MD_PUT_ENV)
|
---|
350 |
|
---|
351 | /* --- Threading Stuff --- */
|
---|
352 | #define _MD_DEFAULT_STACK_SIZE 65536L
|
---|
353 | #define _MD_INIT_THREAD (_PR_MD_INIT_THREAD)
|
---|
354 | #define _MD_INIT_ATTACHED_THREAD (_PR_MD_INIT_THREAD)
|
---|
355 | #define _MD_CREATE_THREAD (_PR_MD_CREATE_THREAD)
|
---|
356 | #define _MD_YIELD (_PR_MD_YIELD)
|
---|
357 | #define _MD_SET_PRIORITY (_PR_MD_SET_PRIORITY)
|
---|
358 | #define _MD_CLEAN_THREAD (_PR_MD_CLEAN_THREAD)
|
---|
359 | #define _MD_SETTHREADAFFINITYMASK (_PR_MD_SETTHREADAFFINITYMASK)
|
---|
360 | #define _MD_GETTHREADAFFINITYMASK (_PR_MD_GETTHREADAFFINITYMASK)
|
---|
361 | #define _MD_EXIT_THREAD (_PR_MD_EXIT_THREAD)
|
---|
362 | #define _MD_SUSPEND_THREAD (_PR_MD_SUSPEND_THREAD)
|
---|
363 | #define _MD_RESUME_THREAD (_PR_MD_RESUME_THREAD)
|
---|
364 | #define _MD_SUSPEND_CPU (_PR_MD_SUSPEND_CPU)
|
---|
365 | #define _MD_RESUME_CPU (_PR_MD_RESUME_CPU)
|
---|
366 | #define _MD_WAKEUP_CPUS (_PR_MD_WAKEUP_CPUS)
|
---|
367 | #define _MD_BEGIN_SUSPEND_ALL()
|
---|
368 | #define _MD_BEGIN_RESUME_ALL()
|
---|
369 | #define _MD_END_SUSPEND_ALL()
|
---|
370 | #define _MD_END_RESUME_ALL()
|
---|
371 |
|
---|
372 | /* --- Lock stuff --- */
|
---|
373 | #define _PR_LOCK _MD_LOCK
|
---|
374 | #define _PR_UNLOCK _MD_UNLOCK
|
---|
375 | extern void
|
---|
376 | md_UnlockAndPostNotifies(struct _MDLock *lock, PRThread *waitThred, struct _MDCVar *waitCV);
|
---|
377 | #ifdef USE_RAMSEM
|
---|
378 | #define _MD_NEW_LOCK (_PR_MD_NEW_LOCK)
|
---|
379 | #define _MD_FREE_LOCK(lock) (DosCloseEventSem(((PRAMSEM)(&((lock)->mutex)))->hevSem))
|
---|
380 | #define _MD_LOCK(lock) (SemRequest486(&((lock)->mutex), -1))
|
---|
381 | #define _MD_TEST_AND_LOCK(lock) (SemRequest486(&((lock)->mutex), -1),0)
|
---|
382 | #define _MD_UNLOCK(lock) \
|
---|
383 | PR_BEGIN_MACRO \
|
---|
384 | if (0 != (lock)->notified.length) { \
|
---|
385 | md_UnlockAndPostNotifies((lock), NULL, NULL); \
|
---|
386 | } else { \
|
---|
387 | SemReleasex86( &(lock)->mutex, 0 ); \
|
---|
388 | } \
|
---|
389 | PR_END_MACRO
|
---|
390 | #else
|
---|
391 | #define _MD_NEW_LOCK (_PR_MD_NEW_LOCK)
|
---|
392 | #define _MD_FREE_LOCK(lock) (DosCloseMutexSem((lock)->mutex))
|
---|
393 | #define _MD_LOCK(lock) (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT))
|
---|
394 | #define _MD_TEST_AND_LOCK(lock) (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT),0)
|
---|
395 | #define _MD_UNLOCK(lock) \
|
---|
396 | PR_BEGIN_MACRO \
|
---|
397 | if (0 != (lock)->notified.length) { \
|
---|
398 | md_UnlockAndPostNotifies((lock), NULL, NULL); \
|
---|
399 | } else { \
|
---|
400 | DosReleaseMutexSem((lock)->mutex); \
|
---|
401 | } \
|
---|
402 | PR_END_MACRO
|
---|
403 | #endif
|
---|
404 |
|
---|
405 | /* --- lock and cv waiting --- */
|
---|
406 | #define _MD_WAIT (_PR_MD_WAIT)
|
---|
407 | #define _MD_WAKEUP_WAITER (_PR_MD_WAKEUP_WAITER)
|
---|
408 |
|
---|
409 | /* --- CVar ------------------- */
|
---|
410 | #define _MD_WAIT_CV (_PR_MD_WAIT_CV)
|
---|
411 | #define _MD_NEW_CV (_PR_MD_NEW_CV)
|
---|
412 | #define _MD_FREE_CV (_PR_MD_FREE_CV)
|
---|
413 | #define _MD_NOTIFY_CV (_PR_MD_NOTIFY_CV )
|
---|
414 | #define _MD_NOTIFYALL_CV (_PR_MD_NOTIFYALL_CV)
|
---|
415 |
|
---|
416 | /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
|
---|
417 | /* extern struct _MDLock _pr_ioq_lock; */
|
---|
418 | #define _MD_IOQ_LOCK()
|
---|
419 | #define _MD_IOQ_UNLOCK()
|
---|
420 |
|
---|
421 |
|
---|
422 | /* --- Initialization stuff --- */
|
---|
423 | #define _MD_START_INTERRUPTS()
|
---|
424 | #define _MD_STOP_INTERRUPTS()
|
---|
425 | #define _MD_DISABLE_CLOCK_INTERRUPTS()
|
---|
426 | #define _MD_ENABLE_CLOCK_INTERRUPTS()
|
---|
427 | #define _MD_BLOCK_CLOCK_INTERRUPTS()
|
---|
428 | #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
|
---|
429 | #define _MD_EARLY_INIT (_PR_MD_EARLY_INIT)
|
---|
430 | #define _MD_FINAL_INIT()
|
---|
431 | #define _MD_INIT_CPUS()
|
---|
432 | #define _MD_INIT_RUNNING_CPU(cpu)
|
---|
433 |
|
---|
434 | struct PRProcess;
|
---|
435 | struct PRProcessAttr;
|
---|
436 |
|
---|
437 | extern struct PRProcess * _PR_CreateOS2ProcessEx(
|
---|
438 | const char *path,
|
---|
439 | char *const *argv,
|
---|
440 | char *const *envp,
|
---|
441 | const struct PRProcessAttr *attr,
|
---|
442 | PRBool detached
|
---|
443 | );
|
---|
444 |
|
---|
445 | #define _MD_CREATE_PROCESS _PR_CreateOS2Process
|
---|
446 | extern struct PRProcess * _PR_CreateOS2Process(
|
---|
447 | const char *path,
|
---|
448 | char *const *argv,
|
---|
449 | char *const *envp,
|
---|
450 | const struct PRProcessAttr *attr
|
---|
451 | );
|
---|
452 |
|
---|
453 | #define _MD_DETACH_PROCESS _PR_DetachOS2Process
|
---|
454 | extern PRStatus _PR_DetachOS2Process(struct PRProcess *process);
|
---|
455 |
|
---|
456 | /* --- Wait for a child process to terminate --- */
|
---|
457 | #define _MD_WAIT_PROCESS _PR_WaitOS2Process
|
---|
458 | extern PRStatus _PR_WaitOS2Process(struct PRProcess *process,
|
---|
459 | PRInt32 *exitCode);
|
---|
460 |
|
---|
461 | #define _MD_KILL_PROCESS _PR_KillOS2Process
|
---|
462 | extern PRStatus _PR_KillOS2Process(struct PRProcess *process);
|
---|
463 |
|
---|
464 | #define _MD_CLEANUP_BEFORE_EXIT()
|
---|
465 | #define _MD_EXIT (_PR_MD_EXIT)
|
---|
466 | #define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
|
---|
467 | PR_BEGIN_MACRO \
|
---|
468 | *status = PR_TRUE; \
|
---|
469 | PR_END_MACRO
|
---|
470 | #define _MD_SWITCH_CONTEXT
|
---|
471 | #define _MD_RESTORE_CONTEXT
|
---|
472 |
|
---|
473 | /* --- Intervals --- */
|
---|
474 | #define _MD_INTERVAL_INIT (_PR_MD_INTERVAL_INIT)
|
---|
475 | #define _MD_GET_INTERVAL (_PR_MD_GET_INTERVAL)
|
---|
476 | #define _MD_INTERVAL_PER_SEC (_PR_MD_INTERVAL_PER_SEC)
|
---|
477 | #define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000)
|
---|
478 | #define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000)
|
---|
479 |
|
---|
480 | /* --- Native-Thread Specific Definitions ------------------------------- */
|
---|
481 |
|
---|
482 | typedef struct __NSPR_TLS
|
---|
483 | {
|
---|
484 | struct PRThread *_pr_thread_last_run;
|
---|
485 | struct PRThread *_pr_currentThread;
|
---|
486 | struct _PRCPU *_pr_currentCPU;
|
---|
487 | } _NSPR_TLS;
|
---|
488 |
|
---|
489 | extern _NSPR_TLS* pThreadLocalStorage;
|
---|
490 | NSPR_API(void) _PR_MD_ENSURE_TLS(void);
|
---|
491 |
|
---|
492 | #define _MD_GET_ATTACHED_THREAD() pThreadLocalStorage->_pr_currentThread
|
---|
493 | extern struct PRThread * _MD_CURRENT_THREAD(void);
|
---|
494 | #define _MD_SET_CURRENT_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentThread = (_thread)
|
---|
495 |
|
---|
496 | #define _MD_LAST_THREAD() pThreadLocalStorage->_pr_thread_last_run
|
---|
497 | #define _MD_SET_LAST_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_thread_last_run = (_thread)
|
---|
498 |
|
---|
499 | #define _MD_CURRENT_CPU() pThreadLocalStorage->_pr_currentCPU
|
---|
500 | #define _MD_SET_CURRENT_CPU(_cpu) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentCPU = (_cpu)
|
---|
501 |
|
---|
502 | /* lth. #define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val)) */
|
---|
503 | /* lth. #define _MD_GET_INTSOFF() _pr_ints_off */
|
---|
504 | /* lth. #define _MD_INCREMENT_INTSOFF() (_pr_ints_off++) */
|
---|
505 | /* lth. #define _MD_DECREMENT_INTSOFF() (_pr_ints_off--) */
|
---|
506 |
|
---|
507 | /* --- Scheduler stuff --- */
|
---|
508 | #define LOCK_SCHEDULER() 0
|
---|
509 | #define UNLOCK_SCHEDULER() 0
|
---|
510 | #define _PR_LockSched() 0
|
---|
511 | #define _PR_UnlockSched() 0
|
---|
512 |
|
---|
513 | /* --- Initialization stuff --- */
|
---|
514 | #define _MD_INIT_LOCKS()
|
---|
515 |
|
---|
516 | /* --- Stack stuff --- */
|
---|
517 | #define _MD_INIT_STACK(stack, redzone)
|
---|
518 | #define _MD_CLEAR_STACK(stack)
|
---|
519 |
|
---|
520 | /* --- Memory-mapped files stuff --- not implemented on OS/2 */
|
---|
521 |
|
---|
522 | struct _MDFileMap {
|
---|
523 | PRInt8 unused;
|
---|
524 | };
|
---|
525 |
|
---|
526 | extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
|
---|
527 | #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
|
---|
528 |
|
---|
529 | extern PRInt32 _MD_GetMemMapAlignment(void);
|
---|
530 | #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
|
---|
531 |
|
---|
532 | extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
|
---|
533 | PRUint32 len);
|
---|
534 | #define _MD_MEM_MAP _MD_MemMap
|
---|
535 |
|
---|
536 | extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
|
---|
537 | #define _MD_MEM_UNMAP _MD_MemUnmap
|
---|
538 |
|
---|
539 | extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
|
---|
540 | #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
|
---|
541 |
|
---|
542 | /* Some stuff for setting up thread contexts */
|
---|
543 | typedef ULONG DWORD, *PDWORD;
|
---|
544 |
|
---|
545 | /* The following definitions and two structures are new in OS/2 Warp 4.0.
|
---|
546 | */
|
---|
547 | #ifndef CONTEXT_CONTROL
|
---|
548 | #define CONTEXT_CONTROL 0x00000001
|
---|
549 | #define CONTEXT_INTEGER 0x00000002
|
---|
550 | #define CONTEXT_SEGMENTS 0x00000004
|
---|
551 | #define CONTEXT_FLOATING_POINT 0x00000008
|
---|
552 | #define CONTEXT_FULL 0x0000000F
|
---|
553 |
|
---|
554 | #pragma pack(2)
|
---|
555 | typedef struct _FPREG {
|
---|
556 | ULONG losig; /* Low 32-bits of the significand. */
|
---|
557 | ULONG hisig; /* High 32-bits of the significand. */
|
---|
558 | USHORT signexp; /* Sign and exponent. */
|
---|
559 | } FPREG;
|
---|
560 | typedef struct _CONTEXTRECORD {
|
---|
561 | ULONG ContextFlags;
|
---|
562 | ULONG ctx_env[7];
|
---|
563 | FPREG ctx_stack[8];
|
---|
564 | ULONG ctx_SegGs; /* GS register. */
|
---|
565 | ULONG ctx_SegFs; /* FS register. */
|
---|
566 | ULONG ctx_SegEs; /* ES register. */
|
---|
567 | ULONG ctx_SegDs; /* DS register. */
|
---|
568 | ULONG ctx_RegEdi; /* EDI register. */
|
---|
569 | ULONG ctx_RegEsi; /* ESI register. */
|
---|
570 | ULONG ctx_RegEax; /* EAX register. */
|
---|
571 | ULONG ctx_RegEbx; /* EBX register. */
|
---|
572 | ULONG ctx_RegEcx; /* ECX register. */
|
---|
573 | ULONG ctx_RegEdx; /* EDX register. */
|
---|
574 | ULONG ctx_RegEbp; /* EBP register. */
|
---|
575 | ULONG ctx_RegEip; /* EIP register. */
|
---|
576 | ULONG ctx_SegCs; /* CS register. */
|
---|
577 | ULONG ctx_EFlags; /* EFLAGS register. */
|
---|
578 | ULONG ctx_RegEsp; /* ESP register. */
|
---|
579 | ULONG ctx_SegSs; /* SS register. */
|
---|
580 | } CONTEXTRECORD, *PCONTEXTRECORD;
|
---|
581 | #pragma pack()
|
---|
582 | #endif
|
---|
583 |
|
---|
584 | extern APIRET (* APIENTRY QueryThreadContext)(TID, ULONG, PCONTEXTRECORD);
|
---|
585 | unsigned long _System _DLL_InitTerm( unsigned long mod_handle, unsigned long flag);
|
---|
586 |
|
---|
587 | /*
|
---|
588 | #define _pr_tid (((PTIB2)_getTIBvalue(offsetof(TIB, tib_ptib2)))->tib2_ultid)
|
---|
589 | #define _pr_current_Thread (_system_tls[_pr_tid-1].__pr_current_thread)
|
---|
590 | */
|
---|
591 |
|
---|
592 | /* Some simple mappings of Windows API's to OS/2 API's to make our lives a
|
---|
593 | * little bit easier. Only add one here if it is a DIRECT mapping. We are
|
---|
594 | * not emulating anything. Just mapping.
|
---|
595 | */
|
---|
596 | #define FreeLibrary(x) DosFreeModule((HMODULE)x)
|
---|
597 | #define OutputDebugString(x)
|
---|
598 |
|
---|
599 | extern int _MD_os2_get_nonblocking_connect_error(int osfd);
|
---|
600 |
|
---|
601 | #endif /* nspr_os2_defs_h___ */
|
---|