nsprpub/pr/include/md/_winnt.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

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

mercurial