]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/config/platform/vxworks.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / config / platform / vxworks.hpp
1 // (C) Copyright Dustin Spicuzza 2009.
2 // Adapted to vxWorks 6.9 by Peter Brockamp 2012.
3 // Updated for VxWorks 7 by Brian Kuhl 2016
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8 // See http://www.boost.org for most recent version.
9
10 // Old versions of vxWorks (namely everything below 6.x) are
11 // absolutely unable to use boost. Old STLs and compilers
12 // like (GCC 2.96) . Do not even think of getting this to work,
13 // a miserable failure will be guaranteed!
14 //
15 // Equally, this file has been tested for RTPs (Real Time Processes)
16 // only, not for DKMs (Downloadable Kernel Modules). These two types
17 // of executables differ largely in the available functionality of
18 // the C-library, STL, and so on. A DKM uses a C89 library with no
19 // wide character support and no guarantee of ANSI C. The same Dinkum
20 // STL library is used in both contexts.
21 //
22 // Similarly the Dinkum abridged STL that supports the loosely specified
23 // embedded C++ standard has not been tested and is unlikely to work
24 // on anything but the simplest library.
25 // ====================================================================
26 //
27 // Additional Configuration
28 // -------------------------------------------------------------------
29 //
30 // Because of the ordering of include files and other issues the following
31 // additional definitions worked better outside this file.
32 //
33 // When building the log library add the following to the b2 invocation
34 // define=BOOST_LOG_WITHOUT_IPC
35 // and
36 // -DBOOST_LOG_WITHOUT_DEFAULT_FACTORIES
37 // to your compile options.
38 //
39 // When building the test library add
40 // -DBOOST_TEST_LIMITED_SIGNAL_DETAILS
41 // to your compile options
42 //
43 // When building containers library add
44 // -DHAVE_MORECORE=0
45 // to your c compile options so dlmalloc heap library is compiled
46 // without brk() calls
47 //
48 // ====================================================================
49 //
50 // Some important information regarding the usage of POSIX semaphores:
51 // -------------------------------------------------------------------
52 //
53 // VxWorks as a real time operating system handles threads somewhat
54 // different from what "normal" OSes do, regarding their scheduling!
55 // This could lead to a scenario called "priority inversion" when using
56 // semaphores, see http://en.wikipedia.org/wiki/Priority_inversion.
57 //
58 // Now, VxWorks POSIX-semaphores for DKM's default to the usage of
59 // priority inverting semaphores, which is fine. On the other hand,
60 // for RTP's it defaults to using non priority inverting semaphores,
61 // which could easily pose a serious problem for a real time process.
62 //
63 // To change the default properties for POSIX-semaphores in VxWorks 7
64 // enable core > CORE_USER Menu > DEFAULT_PTHREAD_PRIO_INHERIT
65 //
66 // In VxWorks 6.x so as to integrate with boost.
67 // - Edit the file
68 // installDir/vxworks-6.x/target/usr/src/posix/pthreadLib.c
69 // - Around line 917 there should be the definition of the default
70 // mutex attributes:
71 //
72 // LOCAL pthread_mutexattr_t defaultMutexAttr =
73 // {
74 // PTHREAD_INITIALIZED_OBJ, PTHREAD_PRIO_NONE, 0,
75 // PTHREAD_MUTEX_DEFAULT
76 // };
77 //
78 // Here, replace PTHREAD_PRIO_NONE by PTHREAD_PRIO_INHERIT.
79 // - Around line 1236 there should be a definition for the function
80 // pthread_mutexattr_init(). A couple of lines below you should
81 // find a block of code like this:
82 //
83 // pAttr->mutexAttrStatus = PTHREAD_INITIALIZED_OBJ;
84 // pAttr->mutexAttrProtocol = PTHREAD_PRIO_NONE;
85 // pAttr->mutexAttrPrioceiling = 0;
86 // pAttr->mutexAttrType = PTHREAD_MUTEX_DEFAULT;
87 //
88 // Here again, replace PTHREAD_PRIO_NONE by PTHREAD_PRIO_INHERIT.
89 // - Finally, rebuild your VSB. This will rebuild the libraries
90 // with the changed properties. That's it! Now, using boost should
91 // no longer cause any problems with task deadlocks!
92 //
93 // ====================================================================
94
95 // Block out all versions before vxWorks 6.x, as these don't work:
96 // Include header with the vxWorks version information and query them
97 #include <version.h>
98 #if !defined(_WRS_VXWORKS_MAJOR) || (_WRS_VXWORKS_MAJOR < 6)
99 # error "The vxWorks version you're using is so badly outdated,\
100 it doesn't work at all with boost, sorry, no chance!"
101 #endif
102
103 // Handle versions above 5.X but below 6.9
104 #if (_WRS_VXWORKS_MAJOR == 6) && (_WRS_VXWORKS_MINOR < 9)
105 // TODO: Starting from what version does vxWorks work with boost?
106 // We can't reasonably insert a #warning "" as a user hint here,
107 // as this will show up with every file including some boost header,
108 // badly bugging the user... So for the time being we just leave it.
109 #endif
110
111 // vxWorks specific config options:
112 // --------------------------------
113 #define BOOST_PLATFORM "vxWorks"
114
115 // Special behaviour for DKMs:
116 #ifdef _WRS_KERNEL
117 // DKMs do not have the <cwchar>-header,
118 // but apparently they do have an intrinsic wchar_t meanwhile!
119 # define BOOST_NO_CWCHAR
120
121 // Lots of wide-functions and -headers are unavailable for DKMs as well:
122 # define BOOST_NO_CWCTYPE
123 # define BOOST_NO_SWPRINTF
124 # define BOOST_NO_STD_WSTRING
125 # define BOOST_NO_STD_WSTREAMBUF
126 #endif
127
128 // Generally available headers:
129 #define BOOST_HAS_UNISTD_H
130 #define BOOST_HAS_STDINT_H
131 #define BOOST_HAS_DIRENT_H
132 #define BOOST_HAS_SLIST
133
134 // vxWorks does not have installed an iconv-library by default,
135 // so unfortunately no Unicode support from scratch is available!
136 // Thus, instead it is suggested to switch to ICU, as this seems
137 // to be the most complete and portable option...
138 #define BOOST_LOCALE_WITH_ICU
139
140 // Generally available functionality:
141 #define BOOST_HAS_THREADS
142 #define BOOST_HAS_NANOSLEEP
143 #define BOOST_HAS_GETTIMEOFDAY
144 #define BOOST_HAS_CLOCK_GETTIME
145 #define BOOST_HAS_MACRO_USE_FACET
146
147 // Generally available threading API's:
148 #define BOOST_HAS_PTHREADS
149 #define BOOST_HAS_SCHED_YIELD
150 #define BOOST_HAS_SIGACTION
151
152 // Functionality available for RTPs only:
153 #ifdef __RTP__
154 # define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE
155 # define BOOST_HAS_LOG1P
156 # define BOOST_HAS_EXPM1
157 #endif
158
159 // Functionality available for DKMs only:
160 #ifdef _WRS_KERNEL
161 // Luckily, at the moment there seems to be none!
162 #endif
163
164 // These #defines allow detail/posix_features to work, since vxWorks doesn't
165 // #define them itself for DKMs (for RTPs on the contrary it does):
166 #ifdef _WRS_KERNEL
167 # ifndef _POSIX_TIMERS
168 # define _POSIX_TIMERS 1
169 # endif
170 # ifndef _POSIX_THREADS
171 # define _POSIX_THREADS 1
172 # endif
173 #endif
174
175 #if (_WRS_VXWORKS_MAJOR < 7)
176 // vxWorks-around: <time.h> #defines CLOCKS_PER_SEC as sysClkRateGet() but
177 // miserably fails to #include the required <sysLib.h> to make
178 // sysClkRateGet() available! So we manually include it here.
179 #ifdef __RTP__
180 # include <time.h>
181 # include <sysLib.h>
182 #endif
183
184 // vxWorks-around: In <stdint.h> the macros INT32_C(), UINT32_C(), INT64_C() and
185 // UINT64_C() are defined erroneously, yielding not a signed/
186 // unsigned long/long long type, but a signed/unsigned int/long
187 // type. Eventually this leads to compile errors in ratio_fwd.hpp,
188 // when trying to define several constants which do not fit into a
189 // long type! We correct them here by redefining.
190
191 #include <cstdint>
192
193 // Some macro-magic to do the job
194 #define VX_JOIN(X, Y) VX_DO_JOIN(X, Y)
195 #define VX_DO_JOIN(X, Y) VX_DO_JOIN2(X, Y)
196 #define VX_DO_JOIN2(X, Y) X##Y
197
198 // Correctly setup the macros
199 #undef INT32_C
200 #undef UINT32_C
201 #undef INT64_C
202 #undef UINT64_C
203 #define INT32_C(x) VX_JOIN(x, L)
204 #define UINT32_C(x) VX_JOIN(x, UL)
205 #define INT64_C(x) VX_JOIN(x, LL)
206 #define UINT64_C(x) VX_JOIN(x, ULL)
207
208 // #include Libraries required for the following function adaption
209 #include <sys/time.h>
210 #endif // _WRS_VXWORKS_MAJOR < 7
211
212 #include <ioLib.h>
213 #include <tickLib.h>
214
215 // Use C-linkage for the following helper functions
216 #ifdef __cplusplus
217 extern "C" {
218 #endif
219
220 // vxWorks-around: The required functions getrlimit() and getrlimit() are missing.
221 // But we have the similar functions getprlimit() and setprlimit(),
222 // which may serve the purpose.
223 // Problem: The vxWorks-documentation regarding these functions
224 // doesn't deserve its name! It isn't documented what the first two
225 // parameters idtype and id mean, so we must fall back to an educated
226 // guess - null, argh... :-/
227
228 // TODO: getprlimit() and setprlimit() do exist for RTPs only, for whatever reason.
229 // Thus for DKMs there would have to be another implementation.
230 #if defined ( __RTP__) && (_WRS_VXWORKS_MAJOR < 7)
231 inline int getrlimit(int resource, struct rlimit *rlp){
232 return getprlimit(0, 0, resource, rlp);
233 }
234
235 inline int setrlimit(int resource, const struct rlimit *rlp){
236 return setprlimit(0, 0, resource, const_cast<struct rlimit*>(rlp));
237 }
238 #endif
239
240 // vxWorks has ftruncate() only, so we do simulate truncate():
241 inline int truncate(const char *p, off_t l){
242 int fd = open(p, O_WRONLY);
243 if (fd == -1){
244 errno = EACCES;
245 return -1;
246 }
247 if (ftruncate(fd, l) == -1){
248 close(fd);
249 errno = EACCES;
250 return -1;
251 }
252 return close(fd);
253 }
254
255 #ifdef __GNUC__
256 #define ___unused __attribute__((unused))
257 #else
258 #define ___unused
259 #endif
260
261 // Fake symlink handling by dummy functions:
262 inline int symlink(const char* path1 ___unused, const char* path2 ___unused){
263 // vxWorks has no symlinks -> always return an error!
264 errno = EACCES;
265 return -1;
266 }
267
268 inline ssize_t readlink(const char* path1 ___unused, char* path2 ___unused, size_t size ___unused){
269 // vxWorks has no symlinks -> always return an error!
270 errno = EACCES;
271 return -1;
272 }
273
274 #if (_WRS_VXWORKS_MAJOR < 7)
275
276 inline int gettimeofday(struct timeval *tv, void * /*tzv*/) {
277 struct timespec ts;
278 clock_gettime(CLOCK_MONOTONIC, &ts);
279 tv->tv_sec = ts.tv_sec;
280 tv->tv_usec = ts.tv_nsec / 1000;
281 return 0;
282 }
283 #endif
284
285 #ifdef __cplusplus
286 } // extern "C"
287 #endif
288
289 /*
290 * moved to os/utils/unix/freind_h/times.h in VxWorks 7
291 * to avoid conflict with MPL operator times
292 */
293 #if (_WRS_VXWORKS_MAJOR < 7)
294 #ifdef __cplusplus
295
296 // vxWorks provides neither struct tms nor function times()!
297 // We implement an empty dummy-function, simply setting the user
298 // and system time to the half of thew actual system ticks-value
299 // and the child user and system time to 0.
300 // Rather ugly but at least it suppresses compiler errors...
301 // Unfortunately, this of course *does* have an severe impact on
302 // dependant libraries, actually this is chrono only! Here it will
303 // not be possible to correctly use user and system times! But
304 // as vxWorks is lacking the ability to calculate user and system
305 // process times there seems to be no other possible solution.
306 struct tms{
307 clock_t tms_utime; // User CPU time
308 clock_t tms_stime; // System CPU time
309 clock_t tms_cutime; // User CPU time of terminated child processes
310 clock_t tms_cstime; // System CPU time of terminated child processes
311 };
312
313
314 inline clock_t times(struct tms *t){
315 struct timespec ts;
316 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
317 clock_t ticks(static_cast<clock_t>(static_cast<double>(ts.tv_sec) * CLOCKS_PER_SEC +
318 static_cast<double>(ts.tv_nsec) * CLOCKS_PER_SEC / 1000000.0));
319 t->tms_utime = ticks/2U;
320 t->tms_stime = ticks/2U;
321 t->tms_cutime = 0; // vxWorks is lacking the concept of a child process!
322 t->tms_cstime = 0; // -> Set the wait times for childs to 0
323 return ticks;
324 }
325
326
327 namespace std {
328 using ::times;
329 }
330 #endif // __cplusplus
331 #endif // _WRS_VXWORKS_MAJOR < 7
332
333
334 #ifdef __cplusplus
335 extern "C" void bzero (void *, size_t); // FD_ZERO uses bzero() but doesn't include strings.h
336
337 // Put the selfmade functions into the std-namespace, just in case
338 namespace std {
339 # ifdef __RTP__
340 using ::getrlimit;
341 using ::setrlimit;
342 # endif
343 using ::truncate;
344 using ::symlink;
345 using ::readlink;
346 #if (_WRS_VXWORKS_MAJOR < 7)
347 using ::gettimeofday;
348 #endif
349 }
350 #endif // __cplusplus
351
352 // Some more macro-magic:
353 // vxWorks-around: Some functions are not present or broken in vxWorks
354 // but may be patched to life via helper macros...
355
356 // Include signal.h which might contain a typo to be corrected here
357 #include <signal.h>
358 #if (_WRS_VXWORKS_MAJOR < 7)
359 #define getpagesize() sysconf(_SC_PAGESIZE) // getpagesize is deprecated anyway!
360 inline int lstat(p, b) { return stat(p, b); } // lstat() == stat(), as vxWorks has no symlinks!
361 #endif
362 #ifndef S_ISSOCK
363 # define S_ISSOCK(mode) ((mode & S_IFMT) == S_IFSOCK) // Is file a socket?
364 #endif
365 #ifndef FPE_FLTINV
366 # define FPE_FLTINV (FPE_FLTSUB+1) // vxWorks has no FPE_FLTINV, so define one as a dummy
367 #endif
368 #if !defined(BUS_ADRALN) && defined(BUS_ADRALNR)
369 # define BUS_ADRALN BUS_ADRALNR // Correct a supposed typo in vxWorks' <signal.h>
370 #endif
371 typedef int locale_t; // locale_t is a POSIX-extension, currently not present in vxWorks!
372
373 // #include boilerplate code:
374 #include <boost/config/detail/posix_features.hpp>
375
376 // vxWorks lies about XSI conformance, there is no nl_types.h:
377 #undef BOOST_HAS_NL_TYPES_H
378
379 // vxWorks 7 adds C++11 support
380 // however it is optional, and does not match exactly the support determined
381 // by examining the Dinkum STL version and GCC version (or ICC and DCC)
382 #ifndef _WRS_CONFIG_LANG_LIB_CPLUS_CPLUS_USER_2011
383 # define BOOST_NO_CXX11_ADDRESSOF // C11 addressof operator on memory location
384 # define BOOST_NO_CXX11_ALLOCATOR
385 # define BOOST_NO_CXX11_ATOMIC_SMART_PTR
386 # define BOOST_NO_CXX11_NUMERIC_LIMITS // max_digits10 in test/../print_helper.hpp
387 # define BOOST_NO_CXX11_SMART_PTR
388 # define BOOST_NO_CXX11_STD_ALIGN
389
390
391 # define BOOST_NO_CXX11_HDR_ARRAY
392 # define BOOST_NO_CXX11_HDR_ATOMIC
393 # define BOOST_NO_CXX11_HDR_CHRONO
394 # define BOOST_NO_CXX11_HDR_CONDITION_VARIABLE
395 # define BOOST_NO_CXX11_HDR_FORWARD_LIST //serialization/test/test_list.cpp
396 # define BOOST_NO_CXX11_HDR_FUNCTIONAL
397 # define BOOST_NO_CXX11_HDR_FUTURE
398 # define BOOST_NO_CXX11_HDR_MUTEX
399 # define BOOST_NO_CXX11_HDR_RANDOM //math/../test_data.hpp
400 # define BOOST_NO_CXX11_HDR_RATIO
401 # define BOOST_NO_CXX11_HDR_REGEX
402 # define BOOST_NO_CXX14_HDR_SHARED_MUTEX
403 # define BOOST_NO_CXX11_HDR_SYSTEM_ERROR
404 # define BOOST_NO_CXX11_HDR_THREAD
405 # define BOOST_NO_CXX11_HDR_TYPEINDEX
406 # define BOOST_NO_CXX11_HDR_TYPE_TRAITS
407 # define BOOST_NO_CXX11_HDR_TUPLE
408 # define BOOST_NO_CXX11_HDR_UNORDERED_MAP
409 # define BOOST_NO_CXX11_HDR_UNORDERED_SET
410 #else
411 #ifndef BOOST_SYSTEM_NO_DEPRECATED
412 # define BOOST_SYSTEM_NO_DEPRECATED // workaround link error in spirit
413 #endif
414 #endif
415
416
417 // NONE is used in enums in lamda and other libraries
418 #undef NONE
419 // restrict is an iostreams class
420 #undef restrict
421
422 // use fake poll() from Unix layer in ASIO to get full functionality
423 // most libraries will use select() but this define allows 'iostream' functionality
424 // which is based on poll() only
425 #if (_WRS_VXWORKS_MAJOR > 6)
426 # ifndef BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR
427 # define BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR
428 # endif
429 #else
430 # define BOOST_ASIO_DISABLE_SERIAL_PORT
431 #endif
432
433