1 /*
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_UTILITIES_GLOBALDEFINITIONS_SOLSTUDIO_HPP
26 #define SHARE_UTILITIES_GLOBALDEFINITIONS_SOLSTUDIO_HPP
27
28 #include "jni.h"
29
30 // This file holds compiler-dependent includes,
31 // globally used constants & types, class (forward)
32 // declarations and a few frequently used utility functions.
33
34
35 # include <ctype.h>
36 # include <string.h>
37 # include <strings.h> // for bsd'isms
38 # include <stdarg.h>
39 # include <stddef.h> // for offsetof
40 # include <stdio.h>
41 # include <stdlib.h>
42 # include <wchar.h>
43 # include <stdarg.h>
44 #ifdef SOLARIS
45 # include <ieeefp.h>
46 #endif
47 # include <math.h>
48 # include <time.h>
49 # include <fcntl.h>
50 # include <dlfcn.h>
51 # include <pthread.h>
52 #ifdef SOLARIS
53 # include <thread.h>
54 #endif
55 # include <limits.h>
56 # include <errno.h>
57 #ifdef SOLARIS
58 # include <sys/trap.h>
59 # include <sys/regset.h>
60 # include <sys/procset.h>
61 # include <ucontext.h>
62 # include <setjmp.h>
63 #endif
64 # ifdef SOLARIS_MUTATOR_LIBTHREAD
65 # include <sys/procfs.h>
66 # endif
67
68 #include <inttypes.h>
69
70 // Solaris 8 doesn't provide definitions of these
71 #ifdef SOLARIS
72 #ifndef PRIdPTR
73 #if defined(_LP64)
74 #define PRIdPTR "ld"
75 #define PRIuPTR "lu"
76 #define PRIxPTR "lx"
77 #else
78 #define PRIdPTR "d"
79 #define PRIuPTR "u"
80 #define PRIxPTR "x"
81 #endif
82 #endif
83 #endif
84
85 #ifdef LINUX
86 # include <signal.h>
87 # include <ucontext.h>
88 # include <sys/time.h>
89 #endif
90
91
92 // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures
93 // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in
94 // system header files. On 32-bit architectures, there is no problem.
95 // On 64-bit architectures, defining NULL as a 32-bit constant can cause
96 // problems with varargs functions: C++ integral promotion rules say for
97 // varargs, we pass the argument 0 as an int. So, if NULL was passed to a
98 // varargs function it will remain 32-bits. Depending on the calling
99 // convention of the machine, if the argument is passed on the stack then
100 // only 32-bits of the "NULL" pointer may be initialized to zero. The
101 // other 32-bits will be garbage. If the varargs function is expecting a
102 // pointer when it extracts the argument, then we have a problem.
103 //
104 // Solution: For 64-bit architectures, redefine NULL as 64-bit constant 0.
105 //
106 // Note: this fix doesn't work well on Linux because NULL will be overwritten
107 // whenever a system header file is included. Linux handles NULL correctly
108 // through a special type '__null'.
109 #ifdef SOLARIS
110 #ifdef _LP64
111 #undef NULL
112 #define NULL 0L
113 #else
114 #ifndef NULL
115 #define NULL 0
116 #endif
117 #endif
118 #endif
119
120 // NULL vs NULL_WORD:
121 // On Linux NULL is defined as a special type '__null'. Assigning __null to
122 // integer variable will cause gcc warning. Use NULL_WORD in places where a
123 // pointer is stored as integer value. On some platforms, sizeof(intptr_t) >
124 // sizeof(void*), so here we want something which is integer type, but has the
125 // same size as a pointer.
126 #ifdef LINUX
127 #ifdef _LP64
128 #define NULL_WORD 0L
129 #else
130 // Cast 0 to intptr_t rather than int32_t since they are not the same type
131 // on some platforms.
132 #define NULL_WORD ((intptr_t)0)
133 #endif
134 #else
135 #define NULL_WORD NULL
136 #endif
137
138 #ifndef LINUX
139 // Compiler-specific primitive types
140 typedef unsigned short uint16_t;
141 #ifndef _UINT32_T
142 #define _UINT32_T
143 typedef unsigned int uint32_t;
144 #endif
145 #if !defined(_SYS_INT_TYPES_H)
146 #ifndef _UINT64_T
147 #define _UINT64_T
148 typedef unsigned long long uint64_t;
149 #endif
150 // %%%% how to access definition of intptr_t portably in 5.5 onward?
151 typedef int intptr_t;
152 typedef unsigned int uintptr_t;
153 // If this gets an error, figure out a symbol XXX that implies the
154 // prior definition of intptr_t, and add "&& !defined(XXX)" above.
155 #endif
156 #endif
157
158 // On solaris 8, UINTPTR_MAX is defined as empty.
159 // Everywhere else it's an actual value.
160 #if UINTPTR_MAX - 1 == -1
161 #undef UINTPTR_MAX
162 #ifdef _LP64
163 #define UINTPTR_MAX UINT64_MAX
164 #else
165 #define UINTPTR_MAX UINT32_MAX
166 #endif /* ifdef _LP64 */
167 #endif
168
169 // Additional Java basic types
170
171 typedef unsigned char jubyte;
172 typedef unsigned short jushort;
173 typedef unsigned int juint;
174 typedef unsigned long long julong;
175
176
177 #ifdef SOLARIS
178 // ANSI C++ fixes
179 // NOTE:In the ANSI committee's continuing attempt to make each version
180 // of C++ incompatible with the previous version, you can no longer cast
181 // pointers to functions without specifying linkage unless you want to get
182 // warnings.
183 //
184 // This also means that pointers to functions can no longer be "hidden"
185 // in opaque types like void * because at the invokation point warnings
186 // will be generated. While this makes perfect sense from a type safety
187 // point of view it causes a lot of warnings on old code using C header
188 // files. Here are some typedefs to make the job of silencing warnings
189 // a bit easier.
190 //
191 // The final kick in the teeth is that you can only have extern "C" linkage
192 // specified at file scope. So these typedefs are here rather than in the
193 // .hpp for the class (os:Solaris usually) that needs them.
194
195 extern "C" {
196 typedef int (*int_fnP_thread_t_iP_uP_stack_tP_gregset_t)(thread_t, int*, unsigned *, stack_t*, gregset_t);
197 typedef int (*int_fnP_thread_t_i_gregset_t)(thread_t, int, gregset_t);
198 typedef int (*int_fnP_thread_t_i)(thread_t, int);
199 typedef int (*int_fnP_thread_t)(thread_t);
200
201 typedef int (*int_fnP_cond_tP_mutex_tP_timestruc_tP)(cond_t *cv, mutex_t *mx, timestruc_t *abst);
202 typedef int (*int_fnP_cond_tP_mutex_tP)(cond_t *cv, mutex_t *mx);
203
204 // typedef for missing API in libc
205 typedef int (*int_fnP_mutex_tP_i_vP)(mutex_t *, int, void *);
206 typedef int (*int_fnP_mutex_tP)(mutex_t *);
207 typedef int (*int_fnP_cond_tP_i_vP)(cond_t *cv, int scope, void *arg);
208 typedef int (*int_fnP_cond_tP)(cond_t *cv);
209 };
210 #endif
211
212 // checking for nanness
213 #ifdef SOLARIS
214 #ifdef SPARC
g_isnan(float f)215 inline int g_isnan(float f) { return isnanf(f); }
216 #else
217 // isnanf() broken on Intel Solaris use isnand()
g_isnan(float f)218 inline int g_isnan(float f) { return isnand(f); }
219 #endif
220
g_isnan(double f)221 inline int g_isnan(double f) { return isnand(f); }
222 #elif LINUX
g_isnan(float f)223 inline int g_isnan(float f) { return isnanf(f); }
g_isnan(double f)224 inline int g_isnan(double f) { return isnan(f); }
225 #else
226 #error "missing platform-specific definition here"
227 #endif
228
229 // Checking for finiteness
230
g_isfinite(jfloat f)231 inline int g_isfinite(jfloat f) { return finite(f); }
g_isfinite(jdouble f)232 inline int g_isfinite(jdouble f) { return finite(f); }
233
234
235 // Wide characters
236
wcslen(const jchar * x)237 inline int wcslen(const jchar* x) { return wcslen((const wchar_t*)x); }
238
239 // Formatting.
240 #ifdef _LP64
241 #define FORMAT64_MODIFIER "l"
242 #else // !_LP64
243 #define FORMAT64_MODIFIER "ll"
244 #endif // _LP64
245
246 #define offset_of(klass,field) offsetof(klass,field)
247
248 #ifndef USE_LIBRARY_BASED_TLS_ONLY
249 #define THREAD_LOCAL_DECL __thread
250 #endif
251
252 // Inlining support
253 #define NOINLINE
254 #define ALWAYSINLINE inline __attribute__((always_inline))
255
256 // Alignment
257 #define ATTRIBUTE_ALIGNED(x) __attribute__((aligned(x)))
258
259 #endif // SHARE_UTILITIES_GLOBALDEFINITIONS_SOLSTUDIO_HPP
260