Back to index

lightning-sunbird  0.9+nobinonly
_winnt.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nspr_win32_defs_h___
00039 #define nspr_win32_defs_h___
00040 
00041 /* Need to force service-pack 3 extensions to be defined by
00042 ** setting _WIN32_WINNT to NT 4.0 for winsock.h, winbase.h, winnt.h.
00043 */ 
00044 #ifndef  _WIN32_WINNT
00045     #define _WIN32_WINNT 0x0400
00046 #elif   (_WIN32_WINNT < 0x0400)
00047     #undef  _WIN32_WINNT
00048     #define _WIN32_WINNT 0x0400
00049 #endif /* _WIN32_WINNT */
00050 
00051 #include <windows.h>
00052 #include <winsock.h>
00053 #ifdef __MINGW32__
00054 #include <mswsock.h>
00055 #endif
00056 #include <errno.h>
00057 
00058 #include "prio.h"
00059 #include "prclist.h"
00060 
00061 /*
00062  * Internal configuration macros
00063  */
00064 
00065 #define PR_LINKER_ARCH      "win32"
00066 #define _PR_SI_SYSNAME        "WINNT"
00067 #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
00068 
00069 #define HAVE_DLL
00070 #define HAVE_CUSTOM_USER_THREADS
00071 #define HAVE_THREAD_AFFINITY
00072 #define _PR_HAVE_GETADDRINFO
00073 #define _PR_INET6_PROBE
00074 #ifndef _PR_INET6
00075 #define AF_INET6 23
00076 /* newer ws2tcpip.h provides these */
00077 #ifndef AI_CANONNAME
00078 #define AI_CANONNAME 0x2
00079 struct addrinfo {
00080     int ai_flags;
00081     int ai_family;
00082     int ai_socktype;
00083     int ai_protocol;
00084     size_t ai_addrlen;
00085     char *ai_canonname;
00086     struct sockaddr *ai_addr;
00087     struct addrinfo *ai_next;
00088 };
00089 #endif
00090 #define _PR_HAVE_MD_SOCKADDR_IN6
00091 /* isomorphic to struct in6_addr on Windows */
00092 struct _md_in6_addr {
00093     union {
00094         PRUint8  _S6_u8[16];
00095         PRUint16 _S6_u16[8];
00096     } _S6_un;
00097 };
00098 /* isomorphic to struct sockaddr_in6 on Windows */
00099 struct _md_sockaddr_in6 {
00100     PRInt16 sin6_family;
00101     PRUint16 sin6_port;
00102     PRUint32 sin6_flowinfo;
00103     struct _md_in6_addr sin6_addr;
00104     PRUint32 sin6_scope_id;
00105 };
00106 #endif
00107 #define _PR_HAVE_THREADSAFE_GETHOST
00108 #define _PR_HAVE_ATOMIC_OPS
00109 #define _PR_HAVE_ATOMIC_CAS
00110 #define PR_HAVE_WIN32_NAMED_SHARED_MEMORY
00111 #define _PR_HAVE_PEEK_BUFFER
00112 #define _PR_PEEK_BUFFER_MAX (32 * 1024)
00113 #define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) \
00114     (!(fd)->secret->nonblocking && (fd)->secret->inheritable != _PR_TRI_TRUE)
00115 #define _PR_NEED_SECRET_AF
00116 
00117 /* --- Common User-Thread/Native-Thread Definitions --------------------- */
00118 
00119 /* --- Globals --- */
00120 extern struct PRLock                      *_pr_schedLock;
00121 
00122 /* --- Typedefs --- */
00123 typedef void (*FiberFunc)(void *);
00124 
00125 #define PR_NUM_GCREGS           8
00126 typedef PRInt32                      PR_CONTEXT_TYPE[PR_NUM_GCREGS];
00127 #define GC_VMBASE               0x40000000
00128 #define GC_VMLIMIT              0x00FFFFFF
00129 
00130 #define _MD_MAGIC_THREAD    0x22222222
00131 #define _MD_MAGIC_THREADSTACK      0x33333333
00132 #define _MD_MAGIC_SEGMENT   0x44444444
00133 #define _MD_MAGIC_DIR              0x55555555
00134 
00135 struct _MDCPU {
00136     int              unused;
00137 };
00138 
00139 enum _MDIOModel {
00140     _MD_BlockingIO = 0x38,
00141     _MD_MultiWaitIO = 0x49
00142 };
00143 
00144 typedef struct _MDOverlapped {
00145     OVERLAPPED overlapped;              /* Used for async I/O */
00146 
00147     enum _MDIOModel ioModel;            /* The I/O model to implement
00148                                          * using overlapped I/O.
00149                                          */
00150     union {
00151         struct _MDThread *mdThread;     /* For blocking I/O, this structure
00152                                          * is embedded in the _MDThread
00153                                          * structure.
00154                                          */
00155         struct {
00156             PRCList links;              /* for group->io_ready list */
00157             struct PRRecvWait *desc;    /* For multiwait I/O, this structure
00158                                          * is associated with a PRRecvWait
00159                                          * structure.
00160                                          */
00161             struct PRWaitGroup *group;
00162             struct TimerEvent *timer;
00163             DWORD error;
00164         } mw;
00165     } data;
00166 } _MDOverlapped;
00167 
00168 struct _MDThread {
00169         /* The overlapped structure must be first! */
00170     struct _MDOverlapped overlapped;    /* Used for async IO for this thread */
00171     void            *acceptex_buf;      /* Used for AcceptEx() */
00172     TRANSMIT_FILE_BUFFERS *xmit_bufs;   /* Used for TransmitFile() */
00173     HANDLE           blocked_sema;      /* Threads block on this when waiting
00174                                          * for IO or CondVar.
00175                                          */
00176     PRInt32          blocked_io_status; /* Status of the completed IO */
00177     PRInt32          blocked_io_bytes;  /* Bytes transferred for completed IO */
00178     PRInt32          blocked_io_error;  /* Save error if status is FALSE */
00179     HANDLE           handle;
00180     PRUint32         id;
00181     void            *sp;                /* only valid when suspended */
00182     PRUint32         magic;             /* for debugging */
00183     PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
00184        struct _PRCPU    *thr_bound_cpu;          /* thread bound to cpu */
00185        PRBool                interrupt_disabled;/* thread cannot be interrupted */
00186        HANDLE                       thr_event;                 /* For native-threads-only support,
00187                                                                              thread blocks on this event        */
00188 
00189     /* The following are used only if this is a fiber */
00190     void            *fiber_id;          /* flag whether or not this is a fiber*/
00191     FiberFunc        fiber_fn;          /* main fiber routine */
00192     void            *fiber_arg;         /* arg to main fiber routine */
00193     PRUint32         fiber_stacksize;   /* stacksize for fiber */
00194     PRInt32          fiber_last_error;  /* last error for the fiber */
00195     void (*start)(void *);              /* used by _PR_MD_CREATE_THREAD to
00196                                          * pass its 'start' argument to
00197                                          * pr_root. */
00198 };
00199 
00200 struct _MDThreadStack {
00201     PRUint32           magic;          /* for debugging */
00202 };
00203 
00204 struct _MDSegment {
00205     PRUint32           magic;          /* for debugging */
00206 };
00207 
00208 #undef PROFILE_LOCKS
00209 
00210 struct _MDLock {
00211     CRITICAL_SECTION mutex;          /* this is recursive on NT */
00212 #ifdef PROFILE_LOCKS
00213     PRInt32 hitcount;
00214     PRInt32 misscount;
00215 #endif
00216 };
00217 
00218 struct _MDDir {
00219     HANDLE           d_hdl;
00220     WIN32_FIND_DATA  d_entry;
00221     PRBool           firstEntry;     /* Is this the entry returned
00222                                       * by FindFirstFile()? */
00223     PRUint32         magic;          /* for debugging */
00224 };
00225 
00226 struct _MDCVar {
00227     PRUint32         unused;
00228 };
00229 
00230 struct _MDSemaphore {
00231     HANDLE           sem;
00232 };
00233 
00234 struct _MDFileDesc {
00235     PRInt32 osfd;    /* The osfd can come from one of three spaces:
00236                       * - For stdin, stdout, and stderr, we are using
00237                       *   the libc file handle (0, 1, 2), which is an int.
00238                       * - For files and pipes, we are using Win32 HANDLE,
00239                       *   which is a void*.
00240                       * - For sockets, we are using Winsock SOCKET, which
00241                       *   is a u_int.
00242                       */
00243     PRBool io_model_committed;  /* The io model (blocking or nonblocking)
00244                                  * for this osfd has been committed and
00245                                  * cannot be changed.  The osfd has been
00246                                  * either associated with the io
00247                                  * completion port or made nonblocking. */
00248     PRBool sync_file_io;        /* Use synchronous file I/O on the osfd
00249                                  * (a file handle) */
00250     PRBool accepted_socket;     /* Is this an accepted socket (on the
00251                                  * server side)? */
00252     PRNetAddr peer_addr;        /* If this is an accepted socket, cache
00253                                  * the peer's address returned by
00254                                  * AcceptEx().  This is to work around
00255                                  * the bug that getpeername() on an
00256                                  * socket accepted by AcceptEx() returns
00257                                  * an all-zero net address. */
00258 };
00259 
00260 struct _MDProcess {
00261     HANDLE handle;
00262     DWORD id;
00263 };
00264 
00265 
00266 /* --- Misc stuff --- */
00267 #define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
00268 
00269 /* --- NT security stuff --- */
00270 
00271 extern void _PR_NT_InitSids(void);
00272 extern void _PR_NT_FreeSids(void);
00273 extern PRStatus _PR_NT_MakeSecurityDescriptorACL(
00274     PRIntn mode,
00275     DWORD accessTable[],
00276     PSECURITY_DESCRIPTOR *resultSD,
00277     PACL *resultACL
00278 );
00279 extern void _PR_NT_FreeSecurityDescriptorACL(
00280     PSECURITY_DESCRIPTOR pSD, PACL pACL);
00281 
00282 /* --- IO stuff --- */
00283 
00284 extern PRInt32 _md_Associate(HANDLE);
00285 extern PRInt32 _PR_MD_CLOSE(PRInt32 osfd, PRBool socket);
00286 
00287 #define _MD_OPEN                      _PR_MD_OPEN
00288 #define _MD_OPEN_FILE                 _PR_MD_OPEN_FILE
00289 #define _MD_READ                      _PR_MD_READ
00290 #define _MD_WRITE                     _PR_MD_WRITE
00291 #define _MD_WRITEV                    _PR_MD_WRITEV
00292 #define _MD_LSEEK                     _PR_MD_LSEEK
00293 #define _MD_LSEEK64                   _PR_MD_LSEEK64
00294 #define _MD_CLOSE_FILE(f)             _PR_MD_CLOSE(f, PR_FALSE)
00295 #define _MD_GETFILEINFO               _PR_MD_GETFILEINFO
00296 #define _MD_GETFILEINFO64             _PR_MD_GETFILEINFO64
00297 #define _MD_GETOPENFILEINFO           _PR_MD_GETOPENFILEINFO
00298 #define _MD_GETOPENFILEINFO64         _PR_MD_GETOPENFILEINFO64
00299 #define _MD_STAT                      _PR_MD_STAT
00300 #define _MD_RENAME                    _PR_MD_RENAME     
00301 #define _MD_ACCESS                    _PR_MD_ACCESS     
00302 #define _MD_DELETE                    _PR_MD_DELETE     
00303 #define _MD_MKDIR                     _PR_MD_MKDIR      
00304 #define _MD_MAKE_DIR                  _PR_MD_MAKE_DIR
00305 #define _MD_RMDIR                     _PR_MD_RMDIR      
00306 #define _MD_LOCKFILE                  _PR_MD_LOCKFILE
00307 #define _MD_TLOCKFILE                 _PR_MD_TLOCKFILE
00308 #define _MD_UNLOCKFILE                _PR_MD_UNLOCKFILE
00309 
00310 /* --- Socket IO stuff --- */
00311 #define _MD_GET_SOCKET_ERROR()    WSAGetLastError()
00312 #define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
00313 
00314 #define _MD_INIT_FILEDESC(fd)
00315 #define _MD_MAKE_NONBLOCK             _PR_MD_MAKE_NONBLOCK
00316 #define _MD_INIT_FD_INHERITABLE       _PR_MD_INIT_FD_INHERITABLE
00317 #define _MD_QUERY_FD_INHERITABLE      _PR_MD_QUERY_FD_INHERITABLE
00318 #define _MD_SHUTDOWN                  _PR_MD_SHUTDOWN
00319 #define _MD_LISTEN                    _PR_MD_LISTEN
00320 #define _MD_CLOSE_SOCKET(s)           _PR_MD_CLOSE(s, PR_TRUE)
00321 #define _MD_SENDTO                    _PR_MD_SENDTO
00322 #define _MD_RECVFROM                  _PR_MD_RECVFROM
00323 #define _MD_SOCKETPAIR(s, type, proto, sv) -1
00324 #define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
00325 #define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
00326 #define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
00327 #define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
00328 #define _MD_SELECT                    select
00329 extern int _PR_NTFiberSafeSelect(int, fd_set *, fd_set *, fd_set *,
00330     const struct timeval *);
00331 #define _MD_FSYNC                     _PR_MD_FSYNC
00332 #define _MD_SOCKETAVAILABLE           _PR_MD_SOCKETAVAILABLE
00333 #define _MD_PIPEAVAILABLE             _PR_MD_PIPEAVAILABLE
00334 #define _MD_SET_FD_INHERITABLE        _PR_MD_SET_FD_INHERITABLE
00335 
00336 #define _MD_INIT_ATOMIC()
00337 #if defined(_M_IX86) || defined(_X86_)
00338 #define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
00339 #define _MD_ATOMIC_ADD               _PR_MD_ATOMIC_ADD
00340 #define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
00341 #else /* non-x86 processors */
00342 #define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
00343 #define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
00344 #define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
00345 #endif /* x86 */
00346 #define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
00347 
00348 #define _MD_INIT_IO                   _PR_MD_INIT_IO
00349 #define _MD_SOCKET                    _PR_MD_SOCKET
00350 #define _MD_CONNECT                   _PR_MD_CONNECT
00351 
00352 #define _MD_ACCEPT(s, a, l, to)       \
00353         _MD_FAST_ACCEPT(s, a, l, to, PR_FALSE, NULL, NULL)
00354 #define _MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba) \
00355         _PR_MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba)
00356 #define _MD_ACCEPT_READ(s, ns, ra, buf, l, t) \
00357         _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, PR_FALSE, NULL, NULL)
00358 #define _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba) \
00359         _PR_MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba)
00360 #define _MD_UPDATE_ACCEPT_CONTEXT     _PR_MD_UPDATE_ACCEPT_CONTEXT
00361 
00362 #define _MD_BIND                      _PR_MD_BIND
00363 #define _MD_RECV                      _PR_MD_RECV
00364 #define _MD_SEND                      _PR_MD_SEND
00365 #define _MD_SENDFILE                 _PR_MD_SENDFILE
00366 #define _MD_PR_POLL                   _PR_MD_PR_POLL
00367 
00368 /* --- Scheduler stuff --- */
00369 #define _MD_PAUSE_CPU                   _PR_MD_PAUSE_CPU
00370 
00371 /* --- DIR stuff --- */
00372 #define PR_DIRECTORY_SEPARATOR        '\\'
00373 #define PR_DIRECTORY_SEPARATOR_STR    "\\"
00374 #define PR_PATH_SEPARATOR          ';'
00375 #define PR_PATH_SEPARATOR_STR             ";"
00376 #define _MD_ERRNO()                   GetLastError()
00377 #define _MD_OPEN_DIR                  _PR_MD_OPEN_DIR
00378 #define _MD_CLOSE_DIR                 _PR_MD_CLOSE_DIR
00379 #define _MD_READ_DIR                  _PR_MD_READ_DIR
00380 
00381 /* --- Segment stuff --- */
00382 #define _MD_INIT_SEGS()
00383 #define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
00384 #define _MD_FREE_SEGMENT(seg)
00385 
00386 /* --- Environment Stuff --- */
00387 #define _MD_GET_ENV                 _PR_MD_GET_ENV
00388 #define _MD_PUT_ENV                 _PR_MD_PUT_ENV
00389 
00390 /* --- Threading Stuff --- */
00391 #define _MD_DEFAULT_STACK_SIZE            0
00392 #define _MD_INIT_THREAD             _PR_MD_INIT_THREAD
00393 #define _MD_INIT_ATTACHED_THREAD    _PR_MD_INIT_THREAD
00394 #define _MD_CREATE_THREAD           _PR_MD_CREATE_THREAD
00395 #define _MD_JOIN_THREAD             _PR_MD_JOIN_THREAD
00396 #define _MD_END_THREAD              _PR_MD_END_THREAD
00397 #define _MD_YIELD                   _PR_MD_YIELD
00398 #define _MD_SET_PRIORITY            _PR_MD_SET_PRIORITY
00399 #define _MD_CLEAN_THREAD            _PR_MD_CLEAN_THREAD
00400 #define _MD_SETTHREADAFFINITYMASK   _PR_MD_SETTHREADAFFINITYMASK
00401 #define _MD_GETTHREADAFFINITYMASK   _PR_MD_GETTHREADAFFINITYMASK
00402 #define _MD_EXIT_THREAD             _PR_MD_EXIT_THREAD
00403 #define _MD_SUSPEND_THREAD          _PR_MD_SUSPEND_THREAD
00404 #define _MD_RESUME_THREAD           _PR_MD_RESUME_THREAD
00405 #define _MD_SUSPEND_CPU             _PR_MD_SUSPEND_CPU
00406 #define _MD_RESUME_CPU              _PR_MD_RESUME_CPU
00407 #define _MD_BEGIN_SUSPEND_ALL()
00408 #define _MD_BEGIN_RESUME_ALL()
00409 #define _MD_END_SUSPEND_ALL()
00410 #define _MD_END_RESUME_ALL()
00411 
00412 extern void _PR_Unblock_IO_Wait(PRThread *thr);
00413 
00414 /* --- Lock stuff --- */
00415 #define _MD_NEW_LOCK(lock)            (InitializeCriticalSection(&((lock)->mutex)),PR_SUCCESS)
00416 #define _MD_FREE_LOCK(lock)           DeleteCriticalSection(&((lock)->mutex))
00417 #ifndef PROFILE_LOCKS
00418 #define _MD_LOCK(lock)                EnterCriticalSection(&((lock)->mutex))
00419 #define _MD_TEST_AND_LOCK(lock)       (TryEnterCriticalSection(&((lock)->mutex))== FALSE)
00420 #define _MD_UNLOCK(lock)              LeaveCriticalSection(&((lock)->mutex))
00421 #else
00422 #define _MD_LOCK(lock)                 \
00423     PR_BEGIN_MACRO \
00424     BOOL rv = TryEnterCriticalSection(&((lock)->mutex)); \
00425     if (rv == TRUE) { \
00426         InterlockedIncrement(&((lock)->hitcount)); \
00427     } else { \
00428         InterlockedIncrement(&((lock)->misscount)); \
00429         EnterCriticalSection(&((lock)->mutex)); \
00430     } \
00431     PR_END_MACRO
00432 #define _MD_TEST_AND_LOCK(lock)       0  /* XXXMB */
00433 #define _MD_UNLOCK(lock)              LeaveCriticalSection(&((lock)->mutex))
00434 #endif
00435 #define _PR_LOCK                      _MD_LOCK
00436 #define _PR_UNLOCK                                 _MD_UNLOCK
00437 
00438 /* --- lock and cv waiting --- */
00439 #define _MD_WAIT                      _PR_MD_WAIT
00440 #define _MD_WAKEUP_WAITER             _PR_MD_WAKEUP_WAITER
00441 
00442    /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
00443 extern  struct _MDLock              _pr_ioq_lock;
00444 #define _MD_IOQ_LOCK()                _MD_LOCK(&_pr_ioq_lock)
00445 #define _MD_IOQ_UNLOCK()              _MD_UNLOCK(&_pr_ioq_lock)
00446 
00447 
00448 /* --- Initialization stuff --- */
00449 #define _MD_START_INTERRUPTS()
00450 #define _MD_STOP_INTERRUPTS()
00451 #define _MD_DISABLE_CLOCK_INTERRUPTS()
00452 #define _MD_ENABLE_CLOCK_INTERRUPTS()
00453 #define _MD_BLOCK_CLOCK_INTERRUPTS()
00454 #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
00455 #define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
00456 #define _MD_FINAL_INIT()
00457 #define _MD_INIT_CPUS()
00458 #define _MD_INIT_RUNNING_CPU(cpu)
00459 
00460 struct PRProcess;
00461 struct PRProcessAttr;
00462 
00463 /* --- Create a new process --- */
00464 #define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
00465 extern struct PRProcess * _PR_CreateWindowsProcess(
00466     const char *path,
00467     char *const *argv,
00468     char *const *envp,
00469     const struct PRProcessAttr *attr
00470 );
00471 
00472 #define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
00473 extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
00474 
00475 /* --- Wait for a child process to terminate --- */
00476 #define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
00477 extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process, 
00478     PRInt32 *exitCode);
00479 
00480 #define _MD_KILL_PROCESS _PR_KillWindowsProcess
00481 extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
00482 
00483 /* --- User Threading stuff --- */
00484 #define HAVE_FIBERS
00485 #define _MD_CREATE_USER_THREAD            _PR_MD_CREATE_USER_THREAD
00486 #define _MD_CREATE_PRIMORDIAL_USER_THREAD _PR_MD_CREATE_PRIMORDIAL_USER_THREAD
00487 #define _MD_CLEANUP_BEFORE_EXIT           _PR_MD_CLEANUP_BEFORE_EXIT
00488 #define _MD_EXIT                          _PR_MD_EXIT
00489 #define _MD_INIT_CONTEXT                  _PR_MD_INIT_CONTEXT
00490 #define _MD_SWITCH_CONTEXT                _PR_MD_SWITCH_CONTEXT
00491 #define _MD_RESTORE_CONTEXT               _PR_MD_RESTORE_CONTEXT
00492 
00493 /* --- Intervals --- */
00494 #define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
00495 #define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
00496 #define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
00497 #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
00498 #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
00499 
00500 /* --- Time --- */
00501 extern void _PR_FileTimeToPRTime(const FILETIME *filetime, PRTime *prtm);
00502 
00503 /* --- Native-Thread Specific Definitions ------------------------------- */
00504 
00505 extern BOOL _pr_use_static_tls;
00506 
00507 extern __declspec(thread) struct PRThread *_pr_current_fiber;
00508 extern DWORD _pr_currentFiberIndex;
00509 
00510 #define _MD_GET_ATTACHED_THREAD() \
00511     (_pr_use_static_tls ? _pr_current_fiber \
00512     : (PRThread *) TlsGetValue(_pr_currentFiberIndex))
00513 
00514 extern struct PRThread * _MD_CURRENT_THREAD(void);
00515 
00516 #define _MD_SET_CURRENT_THREAD(_thread) \
00517     PR_BEGIN_MACRO \
00518         if (_pr_use_static_tls) { \
00519             _pr_current_fiber = (_thread); \
00520         } else { \
00521             TlsSetValue(_pr_currentFiberIndex, (_thread)); \
00522         } \
00523     PR_END_MACRO
00524 
00525 extern __declspec(thread) struct PRThread *_pr_fiber_last_run;
00526 extern DWORD _pr_lastFiberIndex;
00527 
00528 #define _MD_LAST_THREAD() \
00529     (_pr_use_static_tls ? _pr_fiber_last_run \
00530     : (PRThread *) TlsGetValue(_pr_lastFiberIndex))
00531 
00532 #define _MD_SET_LAST_THREAD(_thread) \
00533     PR_BEGIN_MACRO \
00534         if (_pr_use_static_tls) { \
00535             _pr_fiber_last_run = (_thread); \
00536         } else { \
00537             TlsSetValue(_pr_lastFiberIndex, (_thread)); \
00538         } \
00539     PR_END_MACRO
00540 
00541 extern __declspec(thread) struct _PRCPU *_pr_current_cpu;
00542 extern DWORD _pr_currentCPUIndex;
00543 
00544 #define _MD_CURRENT_CPU() \
00545     (_pr_use_static_tls ? _pr_current_cpu \
00546     : (struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
00547 
00548 #define _MD_SET_CURRENT_CPU(_cpu) \
00549     PR_BEGIN_MACRO \
00550         if (_pr_use_static_tls) { \
00551             _pr_current_cpu = (_cpu); \
00552         } else { \
00553             TlsSetValue(_pr_currentCPUIndex, (_cpu)); \
00554         } \
00555     PR_END_MACRO
00556 
00557 extern __declspec(thread) PRUintn _pr_ints_off;
00558 extern DWORD _pr_intsOffIndex;
00559 
00560 #define _MD_GET_INTSOFF() \
00561     (_pr_use_static_tls ? _pr_ints_off \
00562     : (PRUintn) TlsGetValue(_pr_intsOffIndex))
00563 
00564 #define _MD_SET_INTSOFF(_val) \
00565     PR_BEGIN_MACRO \
00566         if (_pr_use_static_tls) { \
00567             _pr_ints_off = (_val); \
00568         } else { \
00569             TlsSetValue(_pr_intsOffIndex, (LPVOID) (_val)); \
00570         } \
00571     PR_END_MACRO
00572 
00573 /* --- Initialization stuff --- */
00574 #define _MD_INIT_LOCKS()
00575 
00576 /* --- Stack stuff --- */
00577 #define _MD_INIT_STACK(stack, redzone)
00578 #define _MD_CLEAR_STACK(stack)
00579 
00580 /* --- Memory-mapped files stuff --- */
00581 
00582 struct _MDFileMap {
00583     HANDLE hFileMap;
00584     DWORD dwAccess;
00585 };
00586 
00587 extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
00588 #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
00589 
00590 extern PRInt32 _MD_GetMemMapAlignment(void);
00591 #define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
00592 
00593 extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
00594         PRUint32 len);
00595 #define _MD_MEM_MAP _MD_MemMap
00596 
00597 extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
00598 #define _MD_MEM_UNMAP _MD_MemUnmap
00599 
00600 extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
00601 #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
00602 
00603 /* --- Named semaphores stuff --- */
00604 #define _PR_HAVE_NAMED_SEMAPHORES
00605 #define _MD_OPEN_SEMAPHORE            _PR_MD_OPEN_SEMAPHORE
00606 #define _MD_WAIT_SEMAPHORE            _PR_MD_WAIT_SEMAPHORE
00607 #define _MD_POST_SEMAPHORE            _PR_MD_POST_SEMAPHORE
00608 #define _MD_CLOSE_SEMAPHORE           _PR_MD_CLOSE_SEMAPHORE
00609 #define _MD_DELETE_SEMAPHORE(name)    PR_SUCCESS  /* no op */
00610 
00611 #endif /* nspr_win32_defs_h___ */