OLD | NEW |
(Empty) | |
| 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_win32_defs_h___ |
| 39 #define nspr_win32_defs_h___ |
| 40 |
| 41 /* Need to force service-pack 3 extensions to be defined by |
| 42 ** setting _WIN32_WINNT to NT 4.0 for winsock.h, winbase.h, winnt.h. |
| 43 */ |
| 44 #ifndef _WIN32_WINNT |
| 45 #define _WIN32_WINNT 0x0400 |
| 46 #elif (_WIN32_WINNT < 0x0400) |
| 47 #undef _WIN32_WINNT |
| 48 #define _WIN32_WINNT 0x0400 |
| 49 #endif /* _WIN32_WINNT */ |
| 50 |
| 51 #include <windows.h> |
| 52 #include <winsock.h> |
| 53 #ifdef __MINGW32__ |
| 54 #include <mswsock.h> |
| 55 #endif |
| 56 #include <errno.h> |
| 57 |
| 58 #include "prio.h" |
| 59 #include "prclist.h" |
| 60 |
| 61 /* |
| 62 * Internal configuration macros |
| 63 */ |
| 64 |
| 65 #define PR_LINKER_ARCH "win32" |
| 66 #define _PR_SI_SYSNAME "WINNT" |
| 67 #define _PR_SI_ARCHITECTURE "x86" /* XXXMB hardcode for now */ |
| 68 |
| 69 #define HAVE_DLL |
| 70 #define HAVE_CUSTOM_USER_THREADS |
| 71 #define HAVE_THREAD_AFFINITY |
| 72 #define _PR_HAVE_GETADDRINFO |
| 73 #define _PR_INET6_PROBE |
| 74 #ifndef _PR_INET6 |
| 75 #define AF_INET6 23 |
| 76 /* newer ws2tcpip.h provides these */ |
| 77 #ifndef AI_CANONNAME |
| 78 #define AI_CANONNAME 0x2 |
| 79 struct addrinfo { |
| 80 int ai_flags; |
| 81 int ai_family; |
| 82 int ai_socktype; |
| 83 int ai_protocol; |
| 84 size_t ai_addrlen; |
| 85 char *ai_canonname; |
| 86 struct sockaddr *ai_addr; |
| 87 struct addrinfo *ai_next; |
| 88 }; |
| 89 #endif |
| 90 #define _PR_HAVE_MD_SOCKADDR_IN6 |
| 91 /* isomorphic to struct in6_addr on Windows */ |
| 92 struct _md_in6_addr { |
| 93 union { |
| 94 PRUint8 _S6_u8[16]; |
| 95 PRUint16 _S6_u16[8]; |
| 96 } _S6_un; |
| 97 }; |
| 98 /* isomorphic to struct sockaddr_in6 on Windows */ |
| 99 struct _md_sockaddr_in6 { |
| 100 PRInt16 sin6_family; |
| 101 PRUint16 sin6_port; |
| 102 PRUint32 sin6_flowinfo; |
| 103 struct _md_in6_addr sin6_addr; |
| 104 PRUint32 sin6_scope_id; |
| 105 }; |
| 106 #endif |
| 107 #define _PR_HAVE_THREADSAFE_GETHOST |
| 108 #define _PR_HAVE_ATOMIC_OPS |
| 109 #define _PR_HAVE_ATOMIC_CAS |
| 110 #define PR_HAVE_WIN32_NAMED_SHARED_MEMORY |
| 111 #define _PR_HAVE_PEEK_BUFFER |
| 112 #define _PR_PEEK_BUFFER_MAX (32 * 1024) |
| 113 #define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) \ |
| 114 (!(fd)->secret->nonblocking && (fd)->secret->inheritable != _PR_TRI_TRUE) |
| 115 |
| 116 /* --- Common User-Thread/Native-Thread Definitions --------------------- */ |
| 117 |
| 118 /* --- Globals --- */ |
| 119 extern struct PRLock *_pr_schedLock; |
| 120 |
| 121 /* --- Typedefs --- */ |
| 122 typedef void (*FiberFunc)(void *); |
| 123 |
| 124 #define PR_NUM_GCREGS 8 |
| 125 typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS]; |
| 126 #define GC_VMBASE 0x40000000 |
| 127 #define GC_VMLIMIT 0x00FFFFFF |
| 128 |
| 129 #define _MD_MAGIC_THREAD 0x22222222 |
| 130 #define _MD_MAGIC_THREADSTACK 0x33333333 |
| 131 #define _MD_MAGIC_SEGMENT 0x44444444 |
| 132 #define _MD_MAGIC_DIR 0x55555555 |
| 133 |
| 134 struct _MDCPU { |
| 135 int unused; |
| 136 }; |
| 137 |
| 138 enum _MDIOModel { |
| 139 _MD_BlockingIO = 0x38, |
| 140 _MD_MultiWaitIO = 0x49 |
| 141 }; |
| 142 |
| 143 typedef struct _MDOverlapped { |
| 144 OVERLAPPED overlapped; /* Used for async I/O */ |
| 145 |
| 146 enum _MDIOModel ioModel; /* The I/O model to implement |
| 147 * using overlapped I/O. |
| 148 */ |
| 149 union { |
| 150 struct _MDThread *mdThread; /* For blocking I/O, this structure |
| 151 * is embedded in the _MDThread |
| 152 * structure. |
| 153 */ |
| 154 struct { |
| 155 PRCList links; /* for group->io_ready list */ |
| 156 struct PRRecvWait *desc; /* For multiwait I/O, this structure |
| 157 * is associated with a PRRecvWait |
| 158 * structure. |
| 159 */ |
| 160 struct PRWaitGroup *group; |
| 161 struct TimerEvent *timer; |
| 162 DWORD error; |
| 163 } mw; |
| 164 } data; |
| 165 } _MDOverlapped; |
| 166 |
| 167 struct _MDThread { |
| 168 /* The overlapped structure must be first! */ |
| 169 struct _MDOverlapped overlapped; /* Used for async IO for this thread */ |
| 170 void *acceptex_buf; /* Used for AcceptEx() */ |
| 171 TRANSMIT_FILE_BUFFERS *xmit_bufs; /* Used for TransmitFile() */ |
| 172 HANDLE blocked_sema; /* Threads block on this when waiting |
| 173 * for IO or CondVar. |
| 174 */ |
| 175 PRInt32 blocked_io_status; /* Status of the completed IO */ |
| 176 PRInt32 blocked_io_bytes; /* Bytes transferred for completed IO */ |
| 177 PRInt32 blocked_io_error; /* Save error if status is FALSE */ |
| 178 HANDLE handle; |
| 179 PRUint32 id; |
| 180 void *sp; /* only valid when suspended */ |
| 181 PRUint32 magic; /* for debugging */ |
| 182 PR_CONTEXT_TYPE gcContext; /* Thread context for GC */ |
| 183 struct _PRCPU *thr_bound_cpu; /* thread bound to cpu *
/ |
| 184 PRBool interrupt_disabled;/* thread cannot be interrup
ted */ |
| 185 HANDLE thr_event; /* For native-th
reads-only support, |
| 186
thread blocks on this event */ |
| 187 |
| 188 /* The following are used only if this is a fiber */ |
| 189 void *fiber_id; /* flag whether or not this is a fiber*/ |
| 190 FiberFunc fiber_fn; /* main fiber routine */ |
| 191 void *fiber_arg; /* arg to main fiber routine */ |
| 192 PRUint32 fiber_stacksize; /* stacksize for fiber */ |
| 193 PRInt32 fiber_last_error; /* last error for the fiber */ |
| 194 void (*start)(void *); /* used by _PR_MD_CREATE_THREAD to |
| 195 * pass its 'start' argument to |
| 196 * pr_root. */ |
| 197 }; |
| 198 |
| 199 struct _MDThreadStack { |
| 200 PRUint32 magic; /* for debugging */ |
| 201 }; |
| 202 |
| 203 struct _MDSegment { |
| 204 PRUint32 magic; /* for debugging */ |
| 205 }; |
| 206 |
| 207 #undef PROFILE_LOCKS |
| 208 |
| 209 struct _MDLock { |
| 210 CRITICAL_SECTION mutex; /* this is recursive on NT */ |
| 211 #ifdef PROFILE_LOCKS |
| 212 PRInt32 hitcount; |
| 213 PRInt32 misscount; |
| 214 #endif |
| 215 }; |
| 216 |
| 217 struct _MDDir { |
| 218 HANDLE d_hdl; |
| 219 WIN32_FIND_DATA d_entry; |
| 220 PRBool firstEntry; /* Is this the entry returned |
| 221 * by FindFirstFile()? */ |
| 222 PRUint32 magic; /* for debugging */ |
| 223 }; |
| 224 |
| 225 struct _MDCVar { |
| 226 PRUint32 unused; |
| 227 }; |
| 228 |
| 229 struct _MDSemaphore { |
| 230 HANDLE sem; |
| 231 }; |
| 232 |
| 233 struct _MDFileDesc { |
| 234 PRInt32 osfd; /* The osfd can come from one of three spaces: |
| 235 * - For stdin, stdout, and stderr, we are using |
| 236 * the libc file handle (0, 1, 2), which is an int. |
| 237 * - For files and pipes, we are using Win32 HANDLE, |
| 238 * which is a void*. |
| 239 * - For sockets, we are using Winsock SOCKET, which |
| 240 * is a u_int. |
| 241 */ |
| 242 PRBool io_model_committed; /* The io model (blocking or nonblocking) |
| 243 * for this osfd has been committed and |
| 244 * cannot be changed. The osfd has been |
| 245 * either associated with the io |
| 246 * completion port or made nonblocking. */ |
| 247 PRBool sync_file_io; /* Use synchronous file I/O on the osfd |
| 248 * (a file handle) */ |
| 249 PRBool accepted_socket; /* Is this an accepted socket (on the |
| 250 * server side)? */ |
| 251 PRNetAddr peer_addr; /* If this is an accepted socket, cache |
| 252 * the peer's address returned by |
| 253 * AcceptEx(). This is to work around |
| 254 * the bug that getpeername() on an |
| 255 * socket accepted by AcceptEx() returns |
| 256 * an all-zero net address. */ |
| 257 }; |
| 258 |
| 259 struct _MDProcess { |
| 260 HANDLE handle; |
| 261 DWORD id; |
| 262 }; |
| 263 |
| 264 |
| 265 /* --- Misc stuff --- */ |
| 266 #define _MD_GET_SP(thread) (thread)->md.gcContext[6] |
| 267 |
| 268 /* --- NT security stuff --- */ |
| 269 |
| 270 extern void _PR_NT_InitSids(void); |
| 271 extern void _PR_NT_FreeSids(void); |
| 272 extern PRStatus _PR_NT_MakeSecurityDescriptorACL( |
| 273 PRIntn mode, |
| 274 DWORD accessTable[], |
| 275 PSECURITY_DESCRIPTOR *resultSD, |
| 276 PACL *resultACL |
| 277 ); |
| 278 extern void _PR_NT_FreeSecurityDescriptorACL( |
| 279 PSECURITY_DESCRIPTOR pSD, PACL pACL); |
| 280 |
| 281 /* --- IO stuff --- */ |
| 282 |
| 283 extern PRInt32 _md_Associate(HANDLE); |
| 284 extern PRInt32 _PR_MD_CLOSE(PRInt32 osfd, PRBool socket); |
| 285 |
| 286 #define _MD_OPEN _PR_MD_OPEN |
| 287 #define _MD_OPEN_FILE _PR_MD_OPEN_FILE |
| 288 #define _MD_READ _PR_MD_READ |
| 289 #define _MD_WRITE _PR_MD_WRITE |
| 290 #define _MD_WRITEV _PR_MD_WRITEV |
| 291 #define _MD_LSEEK _PR_MD_LSEEK |
| 292 #define _MD_LSEEK64 _PR_MD_LSEEK64 |
| 293 #define _MD_CLOSE_FILE(f) _PR_MD_CLOSE(f, PR_FALSE) |
| 294 #define _MD_GETFILEINFO _PR_MD_GETFILEINFO |
| 295 #define _MD_GETFILEINFO64 _PR_MD_GETFILEINFO64 |
| 296 #define _MD_GETOPENFILEINFO _PR_MD_GETOPENFILEINFO |
| 297 #define _MD_GETOPENFILEINFO64 _PR_MD_GETOPENFILEINFO64 |
| 298 #define _MD_STAT _PR_MD_STAT |
| 299 #define _MD_RENAME _PR_MD_RENAME |
| 300 #define _MD_ACCESS _PR_MD_ACCESS |
| 301 #define _MD_DELETE _PR_MD_DELETE |
| 302 #define _MD_MKDIR _PR_MD_MKDIR |
| 303 #define _MD_MAKE_DIR _PR_MD_MAKE_DIR |
| 304 #define _MD_RMDIR _PR_MD_RMDIR |
| 305 #define _MD_LOCKFILE _PR_MD_LOCKFILE |
| 306 #define _MD_TLOCKFILE _PR_MD_TLOCKFILE |
| 307 #define _MD_UNLOCKFILE _PR_MD_UNLOCKFILE |
| 308 |
| 309 /* --- Socket IO stuff --- */ |
| 310 #define _MD_GET_SOCKET_ERROR() WSAGetLastError() |
| 311 #define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err) |
| 312 |
| 313 #define _MD_INIT_FILEDESC(fd) |
| 314 #define _MD_MAKE_NONBLOCK _PR_MD_MAKE_NONBLOCK |
| 315 #define _MD_INIT_FD_INHERITABLE _PR_MD_INIT_FD_INHERITABLE |
| 316 #define _MD_QUERY_FD_INHERITABLE _PR_MD_QUERY_FD_INHERITABLE |
| 317 #define _MD_SHUTDOWN _PR_MD_SHUTDOWN |
| 318 #define _MD_LISTEN _PR_MD_LISTEN |
| 319 #define _MD_CLOSE_SOCKET(s) _PR_MD_CLOSE(s, PR_TRUE) |
| 320 #define _MD_SENDTO _PR_MD_SENDTO |
| 321 #define _MD_RECVFROM _PR_MD_RECVFROM |
| 322 #define _MD_SOCKETPAIR(s, type, proto, sv) -1 |
| 323 #define _MD_GETSOCKNAME _PR_MD_GETSOCKNAME |
| 324 #define _MD_GETPEERNAME _PR_MD_GETPEERNAME |
| 325 #define _MD_GETSOCKOPT _PR_MD_GETSOCKOPT |
| 326 #define _MD_SETSOCKOPT _PR_MD_SETSOCKOPT |
| 327 #define _MD_SELECT select |
| 328 extern int _PR_NTFiberSafeSelect(int, fd_set *, fd_set *, fd_set *, |
| 329 const struct timeval *); |
| 330 #define _MD_FSYNC _PR_MD_FSYNC |
| 331 #define _MD_SOCKETAVAILABLE _PR_MD_SOCKETAVAILABLE |
| 332 #define _MD_PIPEAVAILABLE _PR_MD_PIPEAVAILABLE |
| 333 #define _MD_SET_FD_INHERITABLE _PR_MD_SET_FD_INHERITABLE |
| 334 |
| 335 #define _MD_INIT_ATOMIC() |
| 336 #if defined(_M_IX86) || defined(_X86_) |
| 337 #define _MD_ATOMIC_INCREMENT _PR_MD_ATOMIC_INCREMENT |
| 338 #define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD |
| 339 #define _MD_ATOMIC_DECREMENT _PR_MD_ATOMIC_DECREMENT |
| 340 #else /* non-x86 processors */ |
| 341 #define _MD_ATOMIC_INCREMENT(x) InterlockedIncrement((PLONG)x) |
| 342 #define _MD_ATOMIC_ADD(ptr,val) (InterlockedExchangeAdd((PLONG)ptr, (LONG)val
) + val) |
| 343 #define _MD_ATOMIC_DECREMENT(x) InterlockedDecrement((PLONG)x) |
| 344 #endif /* x86 */ |
| 345 #define _MD_ATOMIC_SET(x,y) InterlockedExchange((PLONG)x, (LONG)y) |
| 346 |
| 347 #define _MD_INIT_IO _PR_MD_INIT_IO |
| 348 #define _MD_SOCKET _PR_MD_SOCKET |
| 349 #define _MD_CONNECT _PR_MD_CONNECT |
| 350 |
| 351 #define _MD_ACCEPT(s, a, l, to) \ |
| 352 _MD_FAST_ACCEPT(s, a, l, to, PR_FALSE, NULL, NULL) |
| 353 #define _MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba) \ |
| 354 _PR_MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba) |
| 355 #define _MD_ACCEPT_READ(s, ns, ra, buf, l, t) \ |
| 356 _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, PR_FALSE, NULL, NULL) |
| 357 #define _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba) \ |
| 358 _PR_MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba) |
| 359 #define _MD_UPDATE_ACCEPT_CONTEXT _PR_MD_UPDATE_ACCEPT_CONTEXT |
| 360 |
| 361 #define _MD_BIND _PR_MD_BIND |
| 362 #define _MD_RECV _PR_MD_RECV |
| 363 #define _MD_SEND _PR_MD_SEND |
| 364 #define _MD_SENDFILE _PR_MD_SENDFILE |
| 365 #define _MD_PR_POLL _PR_MD_PR_POLL |
| 366 |
| 367 /* --- Scheduler stuff --- */ |
| 368 #define _MD_PAUSE_CPU _PR_MD_PAUSE_CPU |
| 369 |
| 370 /* --- DIR stuff --- */ |
| 371 #define PR_DIRECTORY_SEPARATOR '\\' |
| 372 #define PR_DIRECTORY_SEPARATOR_STR "\\" |
| 373 #define PR_PATH_SEPARATOR ';' |
| 374 #define PR_PATH_SEPARATOR_STR ";" |
| 375 #define _MD_ERRNO() GetLastError() |
| 376 #define _MD_OPEN_DIR _PR_MD_OPEN_DIR |
| 377 #define _MD_CLOSE_DIR _PR_MD_CLOSE_DIR |
| 378 #define _MD_READ_DIR _PR_MD_READ_DIR |
| 379 |
| 380 /* --- Segment stuff --- */ |
| 381 #define _MD_INIT_SEGS() |
| 382 #define _MD_ALLOC_SEGMENT(seg, size, vaddr) 0 |
| 383 #define _MD_FREE_SEGMENT(seg) |
| 384 |
| 385 /* --- Environment Stuff --- */ |
| 386 #define _MD_GET_ENV _PR_MD_GET_ENV |
| 387 #define _MD_PUT_ENV _PR_MD_PUT_ENV |
| 388 |
| 389 /* --- Threading Stuff --- */ |
| 390 #define _MD_DEFAULT_STACK_SIZE 0 |
| 391 #define _MD_INIT_THREAD _PR_MD_INIT_THREAD |
| 392 #define _MD_INIT_ATTACHED_THREAD _PR_MD_INIT_THREAD |
| 393 #define _MD_CREATE_THREAD _PR_MD_CREATE_THREAD |
| 394 #define _MD_JOIN_THREAD _PR_MD_JOIN_THREAD |
| 395 #define _MD_END_THREAD _PR_MD_END_THREAD |
| 396 #define _MD_YIELD _PR_MD_YIELD |
| 397 #define _MD_SET_PRIORITY _PR_MD_SET_PRIORITY |
| 398 #define _MD_CLEAN_THREAD _PR_MD_CLEAN_THREAD |
| 399 #define _MD_SETTHREADAFFINITYMASK _PR_MD_SETTHREADAFFINITYMASK |
| 400 #define _MD_GETTHREADAFFINITYMASK _PR_MD_GETTHREADAFFINITYMASK |
| 401 #define _MD_EXIT_THREAD _PR_MD_EXIT_THREAD |
| 402 #define _MD_SUSPEND_THREAD _PR_MD_SUSPEND_THREAD |
| 403 #define _MD_RESUME_THREAD _PR_MD_RESUME_THREAD |
| 404 #define _MD_SUSPEND_CPU _PR_MD_SUSPEND_CPU |
| 405 #define _MD_RESUME_CPU _PR_MD_RESUME_CPU |
| 406 #define _MD_BEGIN_SUSPEND_ALL() |
| 407 #define _MD_BEGIN_RESUME_ALL() |
| 408 #define _MD_END_SUSPEND_ALL() |
| 409 #define _MD_END_RESUME_ALL() |
| 410 |
| 411 extern void _PR_Unblock_IO_Wait(PRThread *thr); |
| 412 |
| 413 /* --- Lock stuff --- */ |
| 414 #define _MD_NEW_LOCK(lock) (InitializeCriticalSection(&((lock)->mutex
)),PR_SUCCESS) |
| 415 #define _MD_FREE_LOCK(lock) DeleteCriticalSection(&((lock)->mutex)) |
| 416 #ifndef PROFILE_LOCKS |
| 417 #define _MD_LOCK(lock) EnterCriticalSection(&((lock)->mutex)) |
| 418 #define _MD_TEST_AND_LOCK(lock) (TryEnterCriticalSection(&((lock)->mutex))
== FALSE) |
| 419 #define _MD_UNLOCK(lock) LeaveCriticalSection(&((lock)->mutex)) |
| 420 #else |
| 421 #define _MD_LOCK(lock) \ |
| 422 PR_BEGIN_MACRO \ |
| 423 BOOL rv = TryEnterCriticalSection(&((lock)->mutex)); \ |
| 424 if (rv == TRUE) { \ |
| 425 InterlockedIncrement(&((lock)->hitcount)); \ |
| 426 } else { \ |
| 427 InterlockedIncrement(&((lock)->misscount)); \ |
| 428 EnterCriticalSection(&((lock)->mutex)); \ |
| 429 } \ |
| 430 PR_END_MACRO |
| 431 #define _MD_TEST_AND_LOCK(lock) 0 /* XXXMB */ |
| 432 #define _MD_UNLOCK(lock) LeaveCriticalSection(&((lock)->mutex)) |
| 433 #endif |
| 434 #define _PR_LOCK _MD_LOCK |
| 435 #define _PR_UNLOCK _MD_UNLOCK |
| 436 |
| 437 /* --- lock and cv waiting --- */ |
| 438 #define _MD_WAIT _PR_MD_WAIT |
| 439 #define _MD_WAKEUP_WAITER _PR_MD_WAKEUP_WAITER |
| 440 |
| 441 /* XXXMB- the IOQ stuff is certainly not working correctly yet. */ |
| 442 extern struct _MDLock _pr_ioq_lock; |
| 443 #define _MD_IOQ_LOCK() _MD_LOCK(&_pr_ioq_lock) |
| 444 #define _MD_IOQ_UNLOCK() _MD_UNLOCK(&_pr_ioq_lock) |
| 445 |
| 446 |
| 447 /* --- Initialization stuff --- */ |
| 448 #define _MD_START_INTERRUPTS() |
| 449 #define _MD_STOP_INTERRUPTS() |
| 450 #define _MD_DISABLE_CLOCK_INTERRUPTS() |
| 451 #define _MD_ENABLE_CLOCK_INTERRUPTS() |
| 452 #define _MD_BLOCK_CLOCK_INTERRUPTS() |
| 453 #define _MD_UNBLOCK_CLOCK_INTERRUPTS() |
| 454 #define _MD_EARLY_INIT _PR_MD_EARLY_INIT |
| 455 #define _MD_FINAL_INIT() |
| 456 #define _MD_INIT_CPUS() |
| 457 #define _MD_INIT_RUNNING_CPU(cpu) |
| 458 |
| 459 struct PRProcess; |
| 460 struct PRProcessAttr; |
| 461 |
| 462 /* --- Create a new process --- */ |
| 463 #define _MD_CREATE_PROCESS _PR_CreateWindowsProcess |
| 464 extern struct PRProcess * _PR_CreateWindowsProcess( |
| 465 const char *path, |
| 466 char *const *argv, |
| 467 char *const *envp, |
| 468 const struct PRProcessAttr *attr |
| 469 ); |
| 470 |
| 471 #define _MD_DETACH_PROCESS _PR_DetachWindowsProcess |
| 472 extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process); |
| 473 |
| 474 /* --- Wait for a child process to terminate --- */ |
| 475 #define _MD_WAIT_PROCESS _PR_WaitWindowsProcess |
| 476 extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process, |
| 477 PRInt32 *exitCode); |
| 478 |
| 479 #define _MD_KILL_PROCESS _PR_KillWindowsProcess |
| 480 extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process); |
| 481 |
| 482 /* --- User Threading stuff --- */ |
| 483 #define HAVE_FIBERS |
| 484 #define _MD_CREATE_USER_THREAD _PR_MD_CREATE_USER_THREAD |
| 485 #define _MD_CREATE_PRIMORDIAL_USER_THREAD _PR_MD_CREATE_PRIMORDIAL_USER_THREAD |
| 486 #define _MD_CLEANUP_BEFORE_EXIT _PR_MD_CLEANUP_BEFORE_EXIT |
| 487 #define _MD_EXIT _PR_MD_EXIT |
| 488 #define _MD_INIT_CONTEXT _PR_MD_INIT_CONTEXT |
| 489 #define _MD_SWITCH_CONTEXT _PR_MD_SWITCH_CONTEXT |
| 490 #define _MD_RESTORE_CONTEXT _PR_MD_RESTORE_CONTEXT |
| 491 |
| 492 /* --- Intervals --- */ |
| 493 #define _MD_INTERVAL_INIT _PR_MD_INTERVAL_INIT |
| 494 #define _MD_GET_INTERVAL _PR_MD_GET_INTERVAL |
| 495 #define _MD_INTERVAL_PER_SEC _PR_MD_INTERVAL_PER_SEC |
| 496 #define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000) |
| 497 #define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000) |
| 498 |
| 499 /* --- Time --- */ |
| 500 extern void _PR_FileTimeToPRTime(const FILETIME *filetime, PRTime *prtm); |
| 501 |
| 502 /* --- Native-Thread Specific Definitions ------------------------------- */ |
| 503 |
| 504 extern BOOL _pr_use_static_tls; |
| 505 |
| 506 extern __declspec(thread) struct PRThread *_pr_current_fiber; |
| 507 extern DWORD _pr_currentFiberIndex; |
| 508 |
| 509 #define _MD_GET_ATTACHED_THREAD() \ |
| 510 (_pr_use_static_tls ? _pr_current_fiber \ |
| 511 : (PRThread *) TlsGetValue(_pr_currentFiberIndex)) |
| 512 |
| 513 extern struct PRThread * _MD_CURRENT_THREAD(void); |
| 514 |
| 515 #define _MD_SET_CURRENT_THREAD(_thread) \ |
| 516 PR_BEGIN_MACRO \ |
| 517 if (_pr_use_static_tls) { \ |
| 518 _pr_current_fiber = (_thread); \ |
| 519 } else { \ |
| 520 TlsSetValue(_pr_currentFiberIndex, (_thread)); \ |
| 521 } \ |
| 522 PR_END_MACRO |
| 523 |
| 524 extern __declspec(thread) struct PRThread *_pr_fiber_last_run; |
| 525 extern DWORD _pr_lastFiberIndex; |
| 526 |
| 527 #define _MD_LAST_THREAD() \ |
| 528 (_pr_use_static_tls ? _pr_fiber_last_run \ |
| 529 : (PRThread *) TlsGetValue(_pr_lastFiberIndex)) |
| 530 |
| 531 #define _MD_SET_LAST_THREAD(_thread) \ |
| 532 PR_BEGIN_MACRO \ |
| 533 if (_pr_use_static_tls) { \ |
| 534 _pr_fiber_last_run = (_thread); \ |
| 535 } else { \ |
| 536 TlsSetValue(_pr_lastFiberIndex, (_thread)); \ |
| 537 } \ |
| 538 PR_END_MACRO |
| 539 |
| 540 extern __declspec(thread) struct _PRCPU *_pr_current_cpu; |
| 541 extern DWORD _pr_currentCPUIndex; |
| 542 |
| 543 #define _MD_CURRENT_CPU() \ |
| 544 (_pr_use_static_tls ? _pr_current_cpu \ |
| 545 : (struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex)) |
| 546 |
| 547 #define _MD_SET_CURRENT_CPU(_cpu) \ |
| 548 PR_BEGIN_MACRO \ |
| 549 if (_pr_use_static_tls) { \ |
| 550 _pr_current_cpu = (_cpu); \ |
| 551 } else { \ |
| 552 TlsSetValue(_pr_currentCPUIndex, (_cpu)); \ |
| 553 } \ |
| 554 PR_END_MACRO |
| 555 |
| 556 extern __declspec(thread) PRUintn _pr_ints_off; |
| 557 extern DWORD _pr_intsOffIndex; |
| 558 |
| 559 #define _MD_GET_INTSOFF() \ |
| 560 (_pr_use_static_tls ? _pr_ints_off \ |
| 561 : (PRUintn) TlsGetValue(_pr_intsOffIndex)) |
| 562 |
| 563 #define _MD_SET_INTSOFF(_val) \ |
| 564 PR_BEGIN_MACRO \ |
| 565 if (_pr_use_static_tls) { \ |
| 566 _pr_ints_off = (_val); \ |
| 567 } else { \ |
| 568 TlsSetValue(_pr_intsOffIndex, (LPVOID) (_val)); \ |
| 569 } \ |
| 570 PR_END_MACRO |
| 571 |
| 572 /* --- Initialization stuff --- */ |
| 573 #define _MD_INIT_LOCKS() |
| 574 |
| 575 /* --- Stack stuff --- */ |
| 576 #define _MD_INIT_STACK(stack, redzone) |
| 577 #define _MD_CLEAR_STACK(stack) |
| 578 |
| 579 /* --- Memory-mapped files stuff --- */ |
| 580 |
| 581 struct _MDFileMap { |
| 582 HANDLE hFileMap; |
| 583 DWORD dwAccess; |
| 584 }; |
| 585 |
| 586 extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size); |
| 587 #define _MD_CREATE_FILE_MAP _MD_CreateFileMap |
| 588 |
| 589 extern PRInt32 _MD_GetMemMapAlignment(void); |
| 590 #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment |
| 591 |
| 592 extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset, |
| 593 PRUint32 len); |
| 594 #define _MD_MEM_MAP _MD_MemMap |
| 595 |
| 596 extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size); |
| 597 #define _MD_MEM_UNMAP _MD_MemUnmap |
| 598 |
| 599 extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap); |
| 600 #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap |
| 601 |
| 602 /* --- Named semaphores stuff --- */ |
| 603 #define _PR_HAVE_NAMED_SEMAPHORES |
| 604 #define _MD_OPEN_SEMAPHORE _PR_MD_OPEN_SEMAPHORE |
| 605 #define _MD_WAIT_SEMAPHORE _PR_MD_WAIT_SEMAPHORE |
| 606 #define _MD_POST_SEMAPHORE _PR_MD_POST_SEMAPHORE |
| 607 #define _MD_CLOSE_SEMAPHORE _PR_MD_CLOSE_SEMAPHORE |
| 608 #define _MD_DELETE_SEMAPHORE(name) PR_SUCCESS /* no op */ |
| 609 |
| 610 #endif /* nspr_win32_defs_h___ */ |
OLD | NEW |