Upload Tizen:Base source
[toolchains/nspr.git] / mozilla / nsprpub / pr / include / md / _osf1.h
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is the Netscape Portable Runtime (NSPR).
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998-2000
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 #ifndef nspr_osf1_defs_h___
39 #define nspr_osf1_defs_h___
40
41 /*
42  * Internal configuration macros
43  */
44
45 #define PR_LINKER_ARCH  "osf"
46 #define _PR_SI_SYSNAME  "OSF"
47 #define _PR_SI_ARCHITECTURE "alpha"
48 #define PR_DLL_SUFFIX           ".so"
49
50 #define _PR_VMBASE              0x30000000
51 #define _PR_STACK_VMBASE        0x50000000
52 #define _MD_DEFAULT_STACK_SIZE  131072L
53 #define _MD_MMAP_FLAGS          MAP_PRIVATE
54
55 #undef  HAVE_STACK_GROWING_UP
56 #undef  HAVE_WEAK_IO_SYMBOLS
57 #undef  HAVE_WEAK_MALLOC_SYMBOLS
58 #define HAVE_DLL
59 #define HAVE_BSD_FLOCK
60
61 #define NEED_TIME_R
62 #define USE_DLFCN
63
64 #define _PR_POLL_AVAILABLE
65 #define _PR_USE_POLL
66 #define _PR_STAT_HAS_ONLY_ST_ATIME
67 #define _PR_HAVE_LARGE_OFF_T
68 #define _PR_HAVE_GETIPNODEBYNAME
69 #define _PR_HAVE_GETIPNODEBYADDR
70 #define _PR_HAVE_GETADDRINFO
71 #define _PR_INET6_PROBE
72 #ifdef _PR_INET6
73 #define _PR_HAVE_INET_NTOP
74 #else
75 #define AF_INET6 26
76 #ifndef AI_CANONNAME
77 #define AI_CANONNAME 0x00000002
78 struct addrinfo {
79     int              ai_flags;
80     int              ai_family;
81     int              ai_socktype;
82     int              ai_protocol;
83     size_t           ai_addrlen;
84     char            *ai_canonname;
85     struct sockaddr *ai_addr;
86     struct addrinfo *ai_next;
87 };
88 #endif
89 #define AI_V4MAPPED 0x00000010
90 #define AI_ALL      0x00000008
91 #define AI_ADDRCONFIG 0x00000020
92 #endif
93 #define _PR_HAVE_POSIX_SEMAPHORES
94 #define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
95
96 #define USE_SETJMP
97
98 #include <setjmp.h>
99
100 /*
101  * A jmp_buf is actually a struct sigcontext.  The sc_sp field of
102  * struct sigcontext is the stack pointer.
103  */
104 #define _MD_GET_SP(_t) (((struct sigcontext *) (_t)->md.context)->sc_sp)
105 #define PR_NUM_GCREGS _JBLEN
106 #define CONTEXT(_th) ((_th)->md.context)
107
108 /*
109 ** Initialize a thread context to run "_main()" when started
110 */
111 #define _MD_INIT_CONTEXT(_thread, _sp, _main, status)         \
112 {                                                                         \
113         *status = PR_TRUE;              \
114     if (setjmp(CONTEXT(_thread))) {                             \
115         (*_main)();                                             \
116     }                                                           \
117     _MD_GET_SP(_thread) = (long) ((_sp) - 64);                  \
118     _MD_GET_SP(_thread) &= ~15;                                 \
119 }
120
121 #define _MD_SWITCH_CONTEXT(_thread)  \
122     if (!setjmp(CONTEXT(_thread))) { \
123         (_thread)->md.errcode = errno;  \
124         _PR_Schedule();              \
125     }
126
127 /*
128 ** Restore a thread context, saved by _MD_SWITCH_CONTEXT
129 */
130 #define _MD_RESTORE_CONTEXT(_thread) \
131 {                                    \
132     errno = (_thread)->md.errcode;     \
133     _MD_SET_CURRENT_THREAD(_thread);    \
134     longjmp(CONTEXT(_thread), 1);    \
135 }
136
137 /* Machine-dependent (MD) data structures */
138
139 struct _MDThread {
140     jmp_buf context;
141     int id;
142     int errcode;
143 };
144
145 struct _MDThreadStack {
146     PRInt8 notused;
147 };
148
149 struct _MDLock {
150     PRInt8 notused;
151 };
152
153 struct _MDSemaphore {
154     PRInt8 notused;
155 };
156
157 struct _MDCVar {
158     PRInt8 notused;
159 };
160
161 struct _MDSegment {
162     PRInt8 notused;
163 };
164
165 /*
166  * md-specific cpu structure field
167  */
168 #define _PR_MD_MAX_OSFD FD_SETSIZE
169
170 struct _MDCPU_Unix {
171     PRCList ioQ;
172     PRUint32 ioq_timeout;
173     PRInt32 ioq_max_osfd;
174     PRInt32 ioq_osfd_cnt;
175 #ifndef _PR_USE_POLL
176     fd_set fd_read_set, fd_write_set, fd_exception_set;
177     PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
178                                 fd_exception_cnt[_PR_MD_MAX_OSFD];
179 #else
180         struct pollfd *ioq_pollfds;
181         int ioq_pollfds_size;
182 #endif  /* _PR_USE_POLL */
183 };
184
185 #define _PR_IOQ(_cpu)                   ((_cpu)->md.md_unix.ioQ)
186 #define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
187 #define _PR_FD_READ_SET(_cpu)           ((_cpu)->md.md_unix.fd_read_set)
188 #define _PR_FD_READ_CNT(_cpu)           ((_cpu)->md.md_unix.fd_read_cnt)
189 #define _PR_FD_WRITE_SET(_cpu)          ((_cpu)->md.md_unix.fd_write_set)
190 #define _PR_FD_WRITE_CNT(_cpu)          ((_cpu)->md.md_unix.fd_write_cnt)
191 #define _PR_FD_EXCEPTION_SET(_cpu)      ((_cpu)->md.md_unix.fd_exception_set)
192 #define _PR_FD_EXCEPTION_CNT(_cpu)      ((_cpu)->md.md_unix.fd_exception_cnt)
193 #define _PR_IOQ_TIMEOUT(_cpu)           ((_cpu)->md.md_unix.ioq_timeout)
194 #define _PR_IOQ_MAX_OSFD(_cpu)          ((_cpu)->md.md_unix.ioq_max_osfd)
195 #define _PR_IOQ_OSFD_CNT(_cpu)          ((_cpu)->md.md_unix.ioq_osfd_cnt)
196 #define _PR_IOQ_POLLFDS(_cpu)           ((_cpu)->md.md_unix.ioq_pollfds)
197 #define _PR_IOQ_POLLFDS_SIZE(_cpu)      ((_cpu)->md.md_unix.ioq_pollfds_size)
198
199 #define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)  32
200
201 struct _MDCPU {
202         struct _MDCPU_Unix md_unix;
203 };
204
205 #ifndef _PR_PTHREADS
206 #define _MD_INIT_LOCKS()
207 #endif
208 #define _MD_NEW_LOCK(lock) PR_SUCCESS
209 #define _MD_FREE_LOCK(lock)
210 #define _MD_LOCK(lock)
211 #define _MD_UNLOCK(lock)
212 #define _MD_INIT_IO()
213 #define _MD_IOQ_LOCK()
214 #define _MD_IOQ_UNLOCK()
215
216 /*
217  * The following are copied from _sunos.h, _aix.h.  This means
218  * some of them should probably be moved into _unixos.h.  But
219  * _irix.h seems to be quite different in regard to these macros.
220  */
221 #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
222 #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
223
224 #define _MD_EARLY_INIT          _MD_EarlyInit
225 #define _MD_FINAL_INIT          _PR_UnixInit
226 #define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
227 #define _MD_INIT_THREAD         _MD_InitializeThread
228 #define _MD_EXIT_THREAD(thread)
229 #define _MD_SUSPEND_THREAD(thread)
230 #define _MD_RESUME_THREAD(thread)
231 #define _MD_CLEAN_THREAD(_thread)
232
233 /* The following defines unwrapped versions of select() and poll(). */
234 #include <sys/time.h>
235 extern int __select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
236 #define _MD_SELECT              __select
237
238 #include <sys/poll.h>
239 #define _MD_POLL __poll
240 extern int __poll(struct pollfd filedes[], unsigned int nfds, int timeout);
241
242 /*
243  * Atomic operations
244  */
245 #ifdef OSF1_HAVE_MACHINE_BUILTINS_H
246 #include <machine/builtins.h>
247 #define _PR_HAVE_ATOMIC_OPS
248 #define _MD_INIT_ATOMIC()
249 #define _MD_ATOMIC_INCREMENT(val) (__ATOMIC_INCREMENT_LONG(val) + 1)
250 #define _MD_ATOMIC_ADD(ptr, val)  (__ATOMIC_ADD_LONG(ptr, val) + val)
251 #define _MD_ATOMIC_DECREMENT(val) (__ATOMIC_DECREMENT_LONG(val) - 1)
252 #define _MD_ATOMIC_SET(val, newval) __ATOMIC_EXCH_LONG(val, newval)
253 #endif /* OSF1_HAVE_MACHINE_BUILTINS_H */
254
255 #endif /* nspr_osf1_defs_h___ */