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