home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / include / md / _win95.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  15.7 KB  |  418 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef nspr_win95_defs_h___
  20. #define nspr_win95_defs_h___
  21.  
  22. #include "prio.h"
  23.  
  24. #include <windows.h>
  25. #include <winsock.h>
  26. #include <errno.h>
  27.  
  28. /*
  29.  * Internal configuration macros
  30.  */
  31.  
  32. #define PR_LINKER_ARCH      "win32"
  33. #define _PR_SI_SYSNAME        "WIN95"
  34. #define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
  35.  
  36. #define HAVE_DLL
  37. #undef  HAVE_THREAD_AFFINITY
  38. #define HAVE_SOCKET_REUSEADDR
  39. #define HAVE_SOCKET_KEEPALIVE
  40. #define _PR_HAVE_ATOMIC_OPS
  41.  
  42. typedef char * caddr_t;
  43. typedef int    ptrdiff_t;   /* used in prnetdb.h */
  44.  
  45. /* --- Common User-Thread/Native-Thread Definitions --------------------- */
  46.  
  47. /* --- Globals --- */
  48. extern struct PRLock                      *_pr_schedLock;
  49.  
  50. /* --- Typedefs --- */
  51. typedef void (*FiberFunc)(void *);
  52.  
  53. #define PR_NUM_GCREGS           8
  54. typedef PRInt32                    PR_CONTEXT_TYPE[PR_NUM_GCREGS];
  55. #define GC_VMBASE               0x40000000
  56. #define GC_VMLIMIT              0x00FFFFFF
  57.  
  58. #define _MD_MAGIC_THREAD    0x22222222
  59. #define _MD_MAGIC_THREADSTACK    0x33333333
  60. #define _MD_MAGIC_SEGMENT    0x44444444
  61. #define _MD_MAGIC_DIR        0x55555555
  62. #define _MD_MAGIC_CV        0x66666666
  63.  
  64. struct _MDCPU {
  65.     int              unused;
  66. };
  67.  
  68. struct _MDThread {
  69.     HANDLE           blocked_sema;      /* Threads block on this when waiting
  70.                                          * for IO or CondVar.
  71.                                          */
  72.     PRBool           inCVWaitQueue;     /* PR_TRUE if the thread is in the
  73.                                          * wait queue of some cond var.
  74.                                          * PR_FALSE otherwise.  */
  75.     HANDLE           handle;            /* Win32 thread handle */
  76.     PRUint32         id;
  77.     void            *sp;                /* only valid when suspended */
  78.     PRUint32         magic;             /* for debugging */
  79.     PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
  80.     struct PRThread *prev, *next;       /* used by the cvar wait queue to
  81.                                          * chain the PRThread structures
  82.                                          * together */
  83. };
  84.  
  85. struct _MDThreadStack {
  86.     PRUint32           magic;          /* for debugging */
  87. };
  88.  
  89. struct _MDSegment {
  90.     PRUint32           magic;          /* for debugging */
  91. };
  92.  
  93. #undef PROFILE_LOCKS
  94.  
  95. struct _MDDir {
  96.     HANDLE           d_hdl;
  97.     WIN32_FIND_DATA  d_entry;
  98.     PRBool           firstEntry;     /* Is this the entry returned
  99.                                       * by FindFirstFile()? */
  100.     PRUint32         magic;          /* for debugging */
  101. };
  102.  
  103. struct _MDCVar {
  104.     PRUint32 magic;
  105.     struct PRThread *waitHead, *waitTail;  /* the wait queue: a doubly-
  106.                                             * linked list of threads
  107.                                             * waiting on this condition
  108.                                             * variable */
  109.     PRIntn nwait;                          /* number of threads in the
  110.                                             * wait queue */
  111. };
  112.  
  113. #define _MD_CV_NOTIFIED_LENGTH 6
  114. typedef struct _MDNotified _MDNotified;
  115. struct _MDNotified {
  116.     PRIntn length;                     /* # of used entries in this
  117.                                         * structure */
  118.     struct {
  119.         struct _MDCVar *cv;            /* the condition variable notified */
  120.         PRIntn times;                  /* and the number of times notified */
  121.         struct PRThread *notifyHead;   /* list of threads to wake up */
  122.     } cv[_MD_CV_NOTIFIED_LENGTH];
  123.     _MDNotified *link;                 /* link to another of these, or NULL */
  124. };
  125.  
  126. struct _MDLock {
  127.     CRITICAL_SECTION mutex;          /* this is recursive on NT */
  128.  
  129.     /*
  130.      * When notifying cvars, there is no point in actually
  131.      * waking up the threads waiting on the cvars until we've
  132.      * released the lock.  So, we temporarily record the cvars.
  133.      * When doing an unlock, we'll then wake up the waiting threads.
  134.      */
  135.     struct _MDNotified notified;     /* array of conditions notified */
  136. #ifdef PROFILE_LOCKS
  137.     PRInt32 hitcount;
  138.     PRInt32 misscount;
  139. #endif
  140. };
  141.  
  142. struct _MDSemaphore {
  143.     HANDLE           sem;
  144. };
  145.  
  146. struct _MDFileDesc {
  147.     PRInt32 osfd;    /* The osfd can come from one of three spaces:
  148.                       * - For stdin, stdout, and stderr, we are using
  149.                       *   the libc file handle (0, 1, 2), which is an int.
  150.                       * - For files and pipes, we are using Win32 HANDLE,
  151.                       *   which is a void*.
  152.                       * - For sockets, we are using Winsock SOCKET, which
  153.                       *   is a u_int.
  154.                       */
  155. };
  156.  
  157. struct _MDProcess {
  158.     HANDLE handle;
  159.     DWORD id;
  160. };
  161.  
  162. /* --- Misc stuff --- */
  163. #define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
  164.  
  165. /* --- IO stuff --- */
  166.  
  167. #define _MD_OPEN                      _PR_MD_OPEN
  168. #define _MD_READ                      _PR_MD_READ
  169. #define _MD_WRITE                     _PR_MD_WRITE
  170. #define _MD_WRITEV                    _PR_MD_WRITEV
  171. #define _MD_LSEEK                     _PR_MD_LSEEK
  172. extern PRInt32 _MD_CloseFile(PRInt32 osfd);
  173. #define _MD_CLOSE_FILE                _MD_CloseFile
  174. #define _MD_GETFILEINFO               _PR_MD_GETFILEINFO
  175. #define _MD_GETOPENFILEINFO           _PR_MD_GETOPENFILEINFO
  176. #define _MD_STAT                      _PR_MD_STAT
  177. #define _MD_RENAME                    _PR_MD_RENAME     
  178. #define _MD_ACCESS                    _PR_MD_ACCESS     
  179. #define _MD_DELETE                    _PR_MD_DELETE     
  180. #define _MD_MKDIR                     _PR_MD_MKDIR      
  181. #define _MD_RMDIR                     _PR_MD_RMDIR      
  182. #define _MD_LOCKFILE                  _PR_MD_LOCKFILE
  183. #define _MD_TLOCKFILE                 _PR_MD_TLOCKFILE
  184. #define _MD_UNLOCKFILE                _PR_MD_UNLOCKFILE
  185.  
  186. /* --- Socket IO stuff --- */
  187. #define _MD_EACCES                WSAEACCES
  188. #define _MD_EADDRINUSE            WSAEADDRINUSE
  189. #define _MD_EADDRNOTAVAIL         WSAEADDRNOTAVAIL
  190. #define _MD_EAFNOSUPPORT          WSAEAFNOSUPPORT
  191. #define _MD_EAGAIN                WSAEWOULDBLOCK
  192. #define _MD_EALREADY              WSAEALREADY
  193. #define _MD_EBADF                 WSAEBADF
  194. #define _MD_ECONNREFUSED          WSAECONNREFUSED
  195. #define _MD_ECONNRESET            WSAECONNRESET
  196. #define _MD_EFAULT                WSAEFAULT
  197. #define _MD_EINPROGRESS           WSAEINPROGRESS
  198. #define _MD_EINTR                 WSAEINTR
  199. #define _MD_EINVAL                EINVAL
  200. #define _MD_EISCONN               WSAEISCONN
  201. #define _MD_ENETUNREACH           WSAENETUNREACH
  202. #define _MD_ENOENT                ENOENT
  203. #define _MD_ENOTCONN              WSAENOTCONN
  204. #define _MD_ENOTSOCK              WSAENOTSOCK
  205. #define _MD_EOPNOTSUPP            WSAEOPNOTSUPP
  206. #define _MD_EWOULDBLOCK           WSAEWOULDBLOCK
  207. #define _MD_GET_SOCKET_ERROR()    WSAGetLastError()
  208. #define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
  209.  
  210. extern void _MD_MakeNonblock(PRFileDesc *f);
  211. #define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
  212. #define _MD_SHUTDOWN                  _PR_MD_SHUTDOWN
  213. #define _MD_LISTEN(s, backlog)        listen(s->secret->md.osfd,backlog)
  214. extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
  215. #define _MD_CLOSE_SOCKET              _MD_CloseSocket
  216. #define _MD_SENDTO                    _PR_MD_SENDTO
  217. #define _MD_RECVFROM                  _PR_MD_RECVFROM
  218. #define _MD_SOCKETPAIR(s, type, proto, sv) -1
  219. #define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
  220. #define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
  221. #define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
  222. #define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
  223. #define _MD_SELECT                    select
  224. #define _MD_FSYNC                     _PR_MD_FSYNC
  225.  
  226. #define _MD_INIT_ATOMIC()
  227. #define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
  228. #define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
  229. #define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
  230.  
  231. #define _MD_INIT_IO                   _PR_MD_INIT_IO
  232. #define _MD_TRANSMITFILE              _PR_MD_TRANSMITFILE
  233.  
  234.  
  235. /* win95 doesn't have async IO */
  236. #define _MD_SOCKET                    _PR_MD_SOCKET
  237. extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
  238. #define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
  239. #define _MD_CONNECT                   _PR_MD_CONNECT
  240. extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
  241.         PRIntervalTime timeout);
  242. #define _MD_ACCEPT                    _MD_Accept
  243. #define _MD_BIND                      _PR_MD_BIND
  244. #define _MD_RECV                      _PR_MD_RECV
  245. #define _MD_SEND                      _PR_MD_SEND
  246. #define _MD_PR_POLL                   _PR_MD_PR_POLL
  247.  
  248. /* --- Scheduler stuff --- */
  249. // #define _MD_PAUSE_CPU                 _PR_MD_PAUSE_CPU
  250. #define _MD_PAUSE_CPU
  251.  
  252. /* --- DIR stuff --- */
  253. #define PR_DIRECTORY_SEPARATOR        '\\'
  254. #define PR_DIRECTORY_SEPARATOR_STR    "\\"
  255. #define PR_PATH_SEPARATOR        ';'
  256. #define PR_PATH_SEPARATOR_STR        ";"
  257. #define _MD_ERRNO()                   GetLastError()
  258. #define _MD_OPEN_DIR                  _PR_MD_OPEN_DIR
  259. #define _MD_CLOSE_DIR                 _PR_MD_CLOSE_DIR
  260. #define _MD_READ_DIR                  _PR_MD_READ_DIR
  261.  
  262. /* --- Segment stuff --- */
  263. #define _MD_INIT_SEGS()
  264. #define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
  265. #define _MD_FREE_SEGMENT(seg)
  266.  
  267. /* --- Environment Stuff --- */
  268. #define _MD_GET_ENV                 _PR_MD_GET_ENV
  269. #define _MD_PUT_ENV                 _PR_MD_PUT_ENV
  270.  
  271. /* --- Threading Stuff --- */
  272. #define _MD_DEFAULT_STACK_SIZE            0
  273. #define _MD_INIT_THREAD             _PR_MD_INIT_THREAD
  274. #define _MD_INIT_ATTACHED_THREAD    _PR_MD_INIT_THREAD
  275. #define _MD_INIT_PRIMORDIAL_THREAD  _PR_MD_INIT_PRIMORDIAL_THREAD
  276. #define _MD_CREATE_THREAD           _PR_MD_CREATE_THREAD
  277. #define _MD_YIELD                   _PR_MD_YIELD
  278. #define _MD_SET_PRIORITY            _PR_MD_SET_PRIORITY
  279. #define _MD_CLEAN_THREAD            _PR_MD_CLEAN_THREAD
  280. #define _MD_SETTHREADAFFINITYMASK   _PR_MD_SETTHREADAFFINITYMASK
  281. #define _MD_GETTHREADAFFINITYMASK   _PR_MD_GETTHREADAFFINITYMASK
  282. #define _MD_EXIT_THREAD             _PR_MD_EXIT_THREAD
  283. #define _MD_SUSPEND_THREAD          _PR_MD_SUSPEND_THREAD
  284. #define _MD_RESUME_THREAD           _PR_MD_RESUME_THREAD
  285. #define _MD_SUSPEND_CPU             _PR_MD_SUSPEND_CPU
  286. #define _MD_RESUME_CPU              _PR_MD_RESUME_CPU
  287. #define _MD_BEGIN_SUSPEND_ALL()
  288. #define _MD_BEGIN_RESUME_ALL()
  289. #define _MD_END_SUSPEND_ALL()
  290. #define _MD_END_RESUME_ALL()
  291.  
  292. /* --- Lock stuff --- */
  293. #define _PR_LOCK                      _MD_LOCK
  294. #define _PR_UNLOCK                      _MD_UNLOCK
  295.  
  296. #define _MD_NEW_LOCK(lock)            (InitializeCriticalSection(&((lock)->mutex)),(lock)->notified.length=0,(lock)->notified.link=NULL,PR_SUCCESS)
  297. #define _MD_FREE_LOCK(lock)           DeleteCriticalSection(&((lock)->mutex))
  298. #define _MD_LOCK(lock)                EnterCriticalSection(&((lock)->mutex))
  299. #define _MD_TEST_AND_LOCK(lock)       (EnterCriticalSection(&((lock)->mutex)),PR_SUCCESS)
  300. #define _MD_UNLOCK                    _PR_MD_UNLOCK
  301.  
  302. /* --- lock and cv waiting --- */
  303. #define _MD_WAIT                      _PR_MD_WAIT
  304. #define _MD_WAKEUP_WAITER             _PR_MD_WAKEUP_WAITER
  305.  
  306. /* --- CVar ------------------- */
  307. #define _MD_WAIT_CV                      _PR_MD_WAIT_CV
  308. #define _MD_NEW_CV                      _PR_MD_NEW_CV
  309. #define _MD_FREE_CV                      _PR_MD_FREE_CV
  310. #define _MD_NOTIFY_CV                  _PR_MD_NOTIFY_CV    
  311. #define _MD_NOTIFYALL_CV              _PR_MD_NOTIFYALL_CV
  312.  
  313.    /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
  314. // extern  struct _MDLock              _pr_ioq_lock;
  315. #define _MD_IOQ_LOCK()                
  316. #define _MD_IOQ_UNLOCK()              
  317.  
  318.  
  319. /* --- Initialization stuff --- */
  320. #define _MD_START_INTERRUPTS()
  321. #define _MD_STOP_INTERRUPTS()
  322. #define _MD_DISABLE_CLOCK_INTERRUPTS()
  323. #define _MD_BLOCK_CLOCK_INTERRUPTS()
  324. #define _MD_UNBLOCK_CLOCK_INTERRUPTS()
  325. #define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
  326. #define _MD_FINAL_INIT()
  327. #define _MD_INIT_CPUS()
  328. #define _MD_INIT_RUNNING_CPU(cpu)
  329.  
  330. struct PRProcess;
  331. struct PRProcessAttr;
  332.  
  333. #define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
  334. extern struct PRProcess * _PR_CreateWindowsProcess(
  335.     const char *path,
  336.     char *const *argv,
  337.     char *const *envp,
  338.     const struct PRProcessAttr *attr
  339. );
  340.  
  341. #define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
  342. extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
  343.  
  344. /* --- Wait for a child process to terminate --- */
  345. #define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
  346. extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process, 
  347.     PRInt32 *exitCode);
  348.  
  349. #define _MD_KILL_PROCESS _PR_KillWindowsProcess
  350. extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
  351.  
  352. #define _MD_CLEANUP_BEFORE_EXIT           _PR_MD_CLEANUP_BEFORE_EXIT
  353. #define _MD_INIT_CONTEXT
  354. #define _MD_SWITCH_CONTEXT
  355. #define _MD_RESTORE_CONTEXT
  356.  
  357. /* --- Intervals --- */
  358. #define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
  359. #define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
  360. #define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
  361. #define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
  362. #define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
  363.  
  364. /* --- Native-Thread Specific Definitions ------------------------------- */
  365.  
  366. extern __declspec(thread) struct PRThread *_pr_currentThread;
  367. #define _MD_CURRENT_THREAD() _pr_currentThread
  368. #define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread))
  369.  
  370. extern __declspec(thread) struct PRThread *_pr_thread_last_run;
  371. #define _MD_LAST_THREAD() _pr_thread_last_run
  372. #define _MD_SET_LAST_THREAD(_thread) (_pr_thread_last_run = (0))
  373.  
  374. extern __declspec(thread) struct _PRCPU *_pr_currentCPU;
  375. #define _MD_CURRENT_CPU() _pr_currentCPU
  376. #define _MD_SET_CURRENT_CPU(_cpu) (_pr_currentCPU = (0))
  377.  
  378. // wtc. extern __declspec(thread) PRUintn _pr_ints_off;
  379. // lth. #define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val))
  380. // lth. #define _MD_GET_INTSOFF() _pr_ints_off
  381. // lth. #define _MD_INCREMENT_INTSOFF() (_pr_ints_off++)
  382. // lth. #define _MD_DECREMENT_INTSOFF() (_pr_ints_off--)
  383.  
  384. /* --- Scheduler stuff --- */
  385. #define LOCK_SCHEDULER()                 0
  386. #define UNLOCK_SCHEDULER()               0
  387. #define _PR_LockSched()                     0
  388. #define _PR_UnlockSched()                0
  389.  
  390. /* --- Initialization stuff --- */
  391. #define _MD_INIT_LOCKS()
  392.  
  393. /* --- Stack stuff --- */
  394. #define _MD_INIT_STACK(stack, redzone)
  395. #define _MD_CLEAR_STACK(stack)
  396.  
  397. /* --- Memory-mapped files stuff --- */
  398.  
  399. struct _MDFileMap {
  400.     HANDLE hFileMap;
  401.     DWORD dwAccess;
  402. };
  403.  
  404. extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
  405. #define _MD_CREATE_FILE_MAP _MD_CreateFileMap
  406.  
  407. extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
  408.         PRUint32 len);
  409. #define _MD_MEM_MAP _MD_MemMap
  410.  
  411. extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
  412. #define _MD_MEM_UNMAP _MD_MemUnmap
  413.  
  414. extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
  415. #define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
  416.  
  417. #endif /* nspr_win32_defs_h___ */
  418.