home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-v.zip / nspr30-v / include / md / _nextstep.h < prev    next >
C/C++ Source or Header  |  1998-11-18  |  8KB  |  285 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_nextstep_defs_h___
  20. #define nspr_nextstep_defs_h___
  21.  
  22. #include "prthread.h"
  23.  
  24. #include <bsd/libc.h>
  25. #include <bsd/syscall.h>
  26.  
  27. /*    syscall() is not declared in NEXTSTEP's syscall.h ...
  28. */
  29. extern int syscall(int number, ...);
  30.  
  31. /*
  32.  * Internal configuration macros
  33.  */
  34.  
  35. #define PR_LINKER_ARCH    "nextstep"
  36. #define _PR_SI_SYSNAME  "NEXTSTEP"
  37. #if defined(__sparc__)
  38. #define _PR_SI_ARCHITECTURE "sparc"
  39. #elif defined(__m68k__)
  40. #define _PR_SI_ARCHITECTURE "m68k"
  41. #elif defined(__i386__)
  42. #define _PR_SI_ARCHITECTURE "x86"
  43. #else
  44. error Unknown NEXTSTEP architecture
  45. #endif
  46. #define PR_DLL_SUFFIX        ".so"
  47.  
  48. #define _PR_VMBASE              0x30000000
  49. #define _PR_STACK_VMBASE    0x50000000
  50. #define _MD_DEFAULT_STACK_SIZE    65536L
  51. #define _MD_MMAP_FLAGS          MAP_PRIVATE
  52.  
  53. #undef  HAVE_STACK_GROWING_UP
  54.  
  55. #define HAVE_WEAK_MALLOC_SYMBOLS
  56.  
  57. /* do this until I figure out the rhapsody dll stuff. */
  58. #define HAVE_DLL
  59. #define USE_RLD
  60. #define _PR_HAVE_SOCKADDR_LEN
  61. #define _PR_STAT_HAS_ONLY_ST_ATIME
  62. #define _PR_NO_LARGE_FILES
  63.  
  64. #define USE_SETJMP
  65.  
  66. #ifndef _PR_PTHREADS
  67.  
  68. #include <setjmp.h>
  69.  
  70. #define PR_CONTEXT_TYPE    jmp_buf
  71.  
  72. #define CONTEXT(_th) ((_th)->md.context)
  73.  
  74. /* balazs.pataki@sztaki.hu:
  75. ** __sparc__ is checked
  76. ** __m68k__ is checked
  77. ** __i386__ is a guess (one of the two defines should work)
  78. */
  79. #if defined(__sparc__)
  80. #define _MD_GET_SP(_th)        (_th)->md.context[2]
  81. #elif defined(__m68k__)
  82. #define _MD_GET_SP(_th)        (_th)->md.context[2]
  83. #elif defined(__i386__)
  84. /* One of this two must be OK ... try using sc_onstack
  85. */
  86. #define _MD_GET_SP(_th)    (((struct sigcontext *) (_th)->md.context)->sc_onstack)
  87. //#define _MD_GET_SP(_th)        (_th)->md.context[0].sc_esp
  88. #else
  89. error Unknown NEXTSTEP architecture
  90. #endif
  91.  
  92. #define PR_NUM_GCREGS    _JBLEN
  93.  
  94. /*
  95. ** Initialize a thread context to run "_main()" when started
  96. */
  97. #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
  98. {  \
  99.     *status = PR_TRUE;  \
  100.     if (setjmp(CONTEXT(_thread))) {  \
  101.         _main();  \
  102.     }  \
  103.     _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
  104. }
  105.  
  106. #define _MD_SWITCH_CONTEXT(_thread)  \
  107.     if (!setjmp(CONTEXT(_thread))) {  \
  108.     (_thread)->md.errcode = errno;  \
  109.     _PR_Schedule();  \
  110.     }
  111.  
  112. /*
  113. ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
  114. */
  115. #define _MD_RESTORE_CONTEXT(_thread) \
  116. {   \
  117.     errno = (_thread)->md.errcode;  \
  118.     _MD_SET_CURRENT_THREAD(_thread);  \
  119.     longjmp(CONTEXT(_thread), 1);  \
  120. }
  121.  
  122. /* Machine-dependent (MD) data structures */
  123.  
  124. struct _MDThread {
  125.     PR_CONTEXT_TYPE context;
  126.     int id;
  127.     int errcode;
  128. };
  129.  
  130. struct _MDThreadStack {
  131.     PRInt8 notused;
  132. };
  133.  
  134. struct _MDLock {
  135.     PRInt8 notused;
  136. };
  137.  
  138. struct _MDSemaphore {
  139.     PRInt8 notused;
  140. };
  141.  
  142. struct _MDCVar {
  143.     PRInt8 notused;
  144. };
  145.  
  146. struct _MDSegment {
  147.     PRInt8 notused;
  148. };
  149.  
  150. /*
  151.  * md-specific cpu structure field
  152.  */
  153. #define _PR_MD_MAX_OSFD FD_SETSIZE
  154.  
  155. struct _MDCPU_Unix {
  156.     PRCList ioQ;
  157.     PRUint32 ioq_timeout;
  158.     PRInt32 ioq_max_osfd;
  159.     PRInt32 ioq_osfd_cnt;
  160. #ifndef _PR_USE_POLL
  161.     fd_set fd_read_set, fd_write_set, fd_exception_set;
  162.     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
  163.                 fd_exception_cnt[_PR_MD_MAX_OSFD];
  164. #else
  165.     struct pollfd *ioq_pollfds;
  166.     int ioq_pollfds_size;
  167. #endif    /* _PR_USE_POLL */
  168. };
  169.  
  170. #define _PR_IOQ(_cpu)            ((_cpu)->md.md_unix.ioQ)
  171. #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
  172. #define _PR_FD_READ_SET(_cpu)        ((_cpu)->md.md_unix.fd_read_set)
  173. #define _PR_FD_READ_CNT(_cpu)        ((_cpu)->md.md_unix.fd_read_cnt)
  174. #define _PR_FD_WRITE_SET(_cpu)        ((_cpu)->md.md_unix.fd_write_set)
  175. #define _PR_FD_WRITE_CNT(_cpu)        ((_cpu)->md.md_unix.fd_write_cnt)
  176. #define _PR_FD_EXCEPTION_SET(_cpu)    ((_cpu)->md.md_unix.fd_exception_set)
  177. #define _PR_FD_EXCEPTION_CNT(_cpu)    ((_cpu)->md.md_unix.fd_exception_cnt)
  178. #define _PR_IOQ_TIMEOUT(_cpu)        ((_cpu)->md.md_unix.ioq_timeout)
  179. #define _PR_IOQ_MAX_OSFD(_cpu)        ((_cpu)->md.md_unix.ioq_max_osfd)
  180. #define _PR_IOQ_OSFD_CNT(_cpu)        ((_cpu)->md.md_unix.ioq_osfd_cnt)
  181. #define _PR_IOQ_POLLFDS(_cpu)        ((_cpu)->md.md_unix.ioq_pollfds)
  182. #define _PR_IOQ_POLLFDS_SIZE(_cpu)    ((_cpu)->md.md_unix.ioq_pollfds_size)
  183.  
  184. #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)    32
  185.  
  186. struct _MDCPU {
  187.     struct _MDCPU_Unix md_unix;
  188. };
  189.  
  190. #define _MD_INIT_LOCKS()
  191. #define _MD_NEW_LOCK(lock) PR_SUCCESS
  192. #define _MD_FREE_LOCK(lock)
  193. #define _MD_LOCK(lock)
  194. #define _MD_UNLOCK(lock)
  195. #define _MD_INIT_IO()
  196. #define _MD_IOQ_LOCK()
  197. #define _MD_IOQ_UNLOCK()
  198.  
  199. extern PRStatus _MD_InitializeThread(PRThread *thread);
  200.  
  201. #define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
  202. #define _MD_INIT_THREAD                 _MD_InitializeThread
  203. #define _MD_EXIT_THREAD(thread)
  204. #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
  205. #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
  206. #define _MD_CLEAN_THREAD(_thread)
  207.  
  208. extern PRStatus _MD_CREATE_THREAD(
  209.     PRThread *thread,
  210.     void (*start) (void *),
  211.     PRThreadPriority priority,
  212.     PRThreadScope scope,
  213.     PRThreadState state,
  214.     PRUint32 stackSize);
  215. extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
  216. extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
  217. extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
  218. extern void _MD_YIELD(void);
  219.  
  220. #endif /* ! _PR_PTHREADS */
  221.  
  222. extern void _MD_EarlyInit(void);
  223. extern PRIntervalTime _PR_UNIX_GetInterval(void);
  224. extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
  225.  
  226. #define _MD_EARLY_INIT                  _MD_EarlyInit
  227. #define _MD_FINAL_INIT            _PR_UnixInit
  228. #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
  229. #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
  230.  
  231. /*
  232.  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  233.  * unwrapped version.
  234.  */
  235. #define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
  236.  
  237. /* For writev() */
  238. #include <sys/uio.h>
  239.  
  240. /* signal.h */
  241. /*     balazs.pataki@sztaki.hu: this is stolen from sunos4.h. The things is that
  242. **     NEXTSTEP doesn't support these flags for `struct sigaction's sa_flags, so
  243. **    I have to fake them ...
  244. */
  245. #define SA_RESTART 0
  246.  
  247. /* mmap */
  248. /*     balazs.pataki@sztaki.hu: NEXTSTEP doesn't have mmap, at least not 
  249. **    publically. We have sys/mman.h, but it doesn't declare mmap(), and
  250. **    PROT_NONE is also missing. syscall.h has entries for mmap, munmap, and 
  251. **    mprotect so I wrap these in nextstep.c as  mmap(), munmap() and mprotect()
  252. **    and pray for it to work.
  253. **    
  254. */
  255. #define PROT_NONE    0x0
  256.  
  257. caddr_t mmap(caddr_t addr, size_t len, int prot, int flags,
  258.           int fildes, off_t off);
  259. int munmap(caddr_t addr, size_t len);
  260. int mprotect(caddr_t addr, size_t len, int prot);
  261.  
  262. /*    my_mmap() is implemented in nextstep.c and is based on map_fd() of mach.
  263. */
  264. caddr_t my_mmap(caddr_t addr, size_t len, int prot, int flags,
  265.           int fildes, off_t off);
  266. int my_munmap(caddr_t addr, size_t len);
  267.  
  268.  
  269. /*    string.h
  270. */
  271. /* balazs.pataki@sztaki.hu: this is missing so implemenetd in nextstep.c ...
  272. */
  273. char *strdup(const char *s1);
  274.  
  275. /* unistd.h
  276. */
  277. /*     balazs.pataki@sztaki.hu: these functions are hidden, though correctly 
  278. **    implemented in NEXTSTEP. Here I give the declaration for them to be used
  279. **    by prmalloc.c, and I have a wrapped syscall() version of them in nextstep.c
  280. */
  281. int brk(void *endds);
  282. void *sbrk(int incr);
  283.  
  284. #endif /* nspr_nextstep_defs_h___ */
  285.