1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 * The contents of this file are subject to the Mozilla Public
4 * License Version 1.1 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of
6 * the License at http://www.mozilla.org/MPL/
8 * Software distributed under the License is distributed on an "AS
9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the License for the specific language governing
11 * rights and limitations under the License.
13 * The Original Code is the Netscape Portable Runtime (NSPR).
15 * The Initial Developer of the Original Code is Netscape
16 * Communications Corporation. Portions created by Netscape are
17 * Copyright (C) 1998-2000 Netscape Communications Corporation. All
22 * Alternatively, the contents of this file may be used under the
23 * terms of the GNU General Public License Version 2 or later (the
24 * "GPL"), in which case the provisions of the GPL are applicable
25 * instead of those above. If you wish to allow use of your
26 * version of this file only under the terms of the GPL and not to
27 * allow others to use your version of this file under the MPL,
28 * indicate your decision by deleting the provisions above and
29 * replace them with the notice and other provisions required by
30 * the GPL. If you do not delete the provisions above, a recipient
31 * may use your version of this file under either the MPL or the
37 * 5/18/96 Taken from nec.h -- chrisk@netscape.com
38 * 3/14/97 Modified for nspr20 -- chrisk@netscape.com
40 #ifndef nspr_reliantunix_defs_h___
41 #define nspr_reliantunix_defs_h___
44 * Internal configuration macros
47 #define PR_LINKER_ARCH "sinix"
48 #define _PR_SI_SYSNAME "SINIX"
49 #define _PR_SI_ARCHITECTURE "mips"
50 #define PR_DLL_SUFFIX ".so"
52 #define _PR_VMBASE 0x30000000
53 #define _PR_STACK_VMBASE 0x50000000
54 #define _MD_DEFAULT_STACK_SIZE (2*65536L)
55 #define _MD_MMAP_FLAGS MAP_PRIVATE|MAP_FIXED
57 #undef HAVE_STACK_GROWING_UP
60 #define NEED_STRFTIME_LOCK
62 #define HAVE_NETCONFIG
63 #define HAVE_WEAK_IO_SYMBOLS
64 #define HAVE_WEAK_MALLOC_SYMBOLS
65 #define _PR_RECV_BROKEN /* recv doesn't work on Unix Domain Sockets */
66 #define _PR_POLL_AVAILABLE
68 #define _PR_STAT_HAS_ST_ATIM
69 #define _PR_NO_LARGE_FILES
72 * Mike Patnode indicated that it is possibly safe now to use context-switching
73 * calls that do not change the signal mask, like setjmp vs. sigsetjmp.
74 * So we'll use our homegrown, getcontext/setcontext-compatible stuff which
75 * will save us the getcontext/setcontext system calls at each context switch.
76 * It already works in FastTrack 2.01, so it should do it here :-)
79 #define USE_SETCXT /* temporarily disabled... */
84 /* use non-syscall machine language replacement */
85 #define _GETCONTEXT getcxt
86 #define _SETCONTEXT setcxt
87 /* defined in os_ReliantUNIX.s */
88 extern int getcxt(ucontext_t
*);
89 extern int setcxt(ucontext_t
*);
91 #define _GETCONTEXT getcontext
92 #define _SETCONTEXT setcontext
95 #define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gpregs[CXT_SP]
96 #define _PR_CONTEXT_TYPE ucontext_t
97 #define _PR_NUM_GCREGS NGREG
99 #define CONTEXT(_thread) (&(_thread)->md.context)
101 #define _PR_IS_NATIVE_THREAD_SUPPORTED() 0
104 ** Machine-dependent (MD) data structures.
107 _PR_CONTEXT_TYPE context
;
112 struct _MDThreadStack
{
120 struct _MDSemaphore
{
133 * md-specific cpu structure field
135 #define _PR_MD_MAX_OSFD FD_SETSIZE
139 PRUint32 ioq_timeout
;
140 PRInt32 ioq_max_osfd
;
141 PRInt32 ioq_osfd_cnt
;
143 fd_set fd_read_set
, fd_write_set
, fd_exception_set
;
144 PRInt16 fd_read_cnt
[_PR_MD_MAX_OSFD
],fd_write_cnt
[_PR_MD_MAX_OSFD
],
145 fd_exception_cnt
[_PR_MD_MAX_OSFD
];
147 struct pollfd
*ioq_pollfds
;
148 int ioq_pollfds_size
;
149 #endif /* _PR_USE_POLL */
152 #define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
153 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
154 #define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
155 #define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
156 #define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
157 #define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
158 #define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
159 #define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
160 #define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
161 #define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
162 #define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
163 #define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
164 #define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
166 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
169 struct _MDCPU_Unix md_unix
;
172 #define _MD_INIT_LOCKS()
173 #define _MD_NEW_LOCK(lock) PR_SUCCESS
174 #define _MD_FREE_LOCK(lock)
175 #define _MD_LOCK(lock)
176 #define _MD_UNLOCK(lock)
177 #define _MD_INIT_IO()
178 #define _MD_IOQ_LOCK()
179 #define _MD_IOQ_UNLOCK()
182 ** Initialize the thread context preparing it to execute "_main()"
183 ** - get a nice, fresh context
184 ** - set its SP to the stack we allcoated for it
185 ** - set it to start things at "e"
187 #define _MD_INIT_CONTEXT(thread, _sp, _main, status) \
190 _GETCONTEXT(CONTEXT(thread)); \
191 /* this is supposed to point to the stack BASE, not to SP */ \
192 CONTEXT(thread)->uc_stack.ss_sp = thread->stack->stackBottom; \
193 CONTEXT(thread)->uc_stack.ss_size = thread->stack->stackSize; \
194 CONTEXT(thread)->uc_mcontext.gpregs[CXT_SP] = ((unsigned long)_sp - 128) & 0xfffffff8; \
195 CONTEXT(thread)->uc_mcontext.gpregs[CXT_T9] = _main; \
196 CONTEXT(thread)->uc_mcontext.gpregs[CXT_EPC] = _main; \
197 CONTEXT(thread)->uc_mcontext.gpregs[CXT_RA] = 0; \
198 thread->no_sched = 0; \
202 ** Save current context as it is scheduled away
204 #define _MD_SWITCH_CONTEXT(_thread) \
206 if (!_GETCONTEXT(CONTEXT(_thread))) { \
207 _MD_SAVE_ERRNO(_thread); \
208 _MD_SET_LAST_THREAD(_thread); \
214 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT or set up
215 ** by _MD_INIT_CONTEXT
216 ** CXT_V0 is the register that holds the return value.
217 ** We must set it to 1 so that we can see if the return from
218 ** getcontext() is the result of calling getcontext() or
220 ** setting a context got with getcontext() appears to
221 ** return from getcontext(), too!
222 ** CXT_A3 is the register that holds status when returning
223 ** from a syscall. It is set to 0 to indicate success,
224 ** because we want getcontext() on the other side of the magic
227 #define _MD_RESTORE_CONTEXT(_thread) \
229 ucontext_t *uc = CONTEXT(_thread); \
230 uc->uc_mcontext.gpregs[CXT_V0] = 1;\
231 uc->uc_mcontext.gpregs[CXT_A3] = 0;\
232 _MD_RESTORE_ERRNO(_thread); \
233 _MD_SET_CURRENT_THREAD(_thread); \
237 #define _MD_SAVE_ERRNO(t) (t)->md.errcode = errno;
238 #define _MD_RESTORE_ERRNO(t) errno = (t)->md.errcode;
240 #define _MD_GET_INTERVAL _PR_UNIX_GetInterval
241 #define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
243 #define _MD_EARLY_INIT _MD_EarlyInit
244 #define _MD_FINAL_INIT _PR_UnixInit
245 #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
246 #define _MD_INIT_THREAD _MD_InitializeThread
247 #define _MD_EXIT_THREAD(thread)
248 #define _MD_SUSPEND_THREAD(thread)
249 #define _MD_RESUME_THREAD(thread)
250 #define _MD_CLEAN_THREAD(_thread)
252 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
253 #define S_ISSOCK(mode) ((mode&0xF000) == 0xC000)
255 #if !defined(S_ISLNK) && defined(S_IFLNK)
256 #define S_ISLNK(mode) ((mode&0xA000) == 0xC000)
259 #include <sys/time.h>
260 #include <sys/types.h>
261 #include <sys/select.h>
262 extern int _select(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
263 fd_set
*execptfds
, struct timeval
*timeout
);
264 #define _MD_SELECT(nfds,r,w,e,tv) _select(nfds,r,w,e,tv)
265 #define _MD_POLL _poll
267 #endif /* nspr_reliantunix_defs_h___ */