Ticket #7726: vxworks.hpp

File vxworks.hpp, 8.4 KB (added by p.brockamp@…, 10 years ago)

Config

Line 
1// (C) Copyright Dustin Spicuzza 2009.
2// Use, modification and distribution are subject to the
3// Boost Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org for most recent version.
7
8// Since WRS does not yet properly support Boost under VxWorks
9// and this file was badly outdated, but I was keen on using it,
10// I patched boost myself to make it work. This has been tested and
11// adapted for vxWorks 6.9 only, there's no proper version checking!
12// This would need some knowledge about older versions (which I am
13// lacking). The only thing I know for sure is that very old versions
14// of vxWorks (namely everything below 6.x) is absolutely unable to
15// use Boost. This is mainly due to the absolutely outdated libraries
16// and ancient compiler (GCC 2.96 or worse). Do not even think of
17// getting this working, a miserable failure is guaranteed!
18
19// TODO: Versions below vxWorks 6.x need to be blocked out,
20// raising a compiler error.
21
22// vxWorks specific config options:
23
24#define BOOST_PLATFORM "vxWorks"
25
26// Special behaviour for the DKM (Kernel-Mode):
27#ifdef _WRS_KERNEL
28 // The DKM does not have the <cwchar>-header,
29 // but apparently it does have an intrinsic wchar_t meanwhile!
30# define BOOST_NO_CWCHAR
31
32 // Lots of wide-functions and -headers are unavailable for DKM as well:
33# define BOOST_NO_CWCTYPE
34# define BOOST_NO_SWPRINTF
35# define BOOST_NO_STD_WSTRING
36# define BOOST_NO_STD_WSTREAMBUF
37#endif
38
39// Generally available headers:
40#define BOOST_HAS_UNISTD_H
41#define BOOST_HAS_STDINT_H
42#define BOOST_HAS_DIRENT_H
43#define BOOST_HAS_SLIST
44
45// vxWorks does not have installed an iconv-library by default!
46// So, instead it is suggested to switch to ICU, as this seems to be
47// the most complete and portable option...
48#define BOOST_LOCALE_WITH_ICU
49
50// Generally available functionality:
51#define BOOST_HAS_THREADS
52#define BOOST_HAS_NANOSLEEP
53#define BOOST_HAS_CLOCK_GETTIME
54#define BOOST_HAS_MACRO_USE_FACET
55
56// Generally unavailable functioality:
57//#define BOOST_NO_DEDUCED_TYPENAME // Commented out, the test gives an errorneous result!
58#define BOOST_NO_CXX11_EXTERN_TEMPLATE
59#define BOOST_NO_CXX11_VARIADIC_MACROS
60
61// Generally available threading API's:
62#define BOOST_HAS_PTHREADS
63#define BOOST_HAS_SCHED_YIELD
64#define BOOST_HAS_SIGACTION
65
66// Functionality available for RTP only:
67#ifdef __RTP__
68# define BOOST_HAS_GETTIMEOFDAY
69# define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE
70# define BOOST_HAS_LOG1P
71# define BOOST_HAS_EXPM1
72#endif
73
74// Functionality available for DKM only:
75#ifdef _WRS_KERNEL
76 // Luckily, at the moment there seems to be none!
77#endif
78
79// These #defines allow posix_features to work, since vxWorks doesn't
80// define them itself if for DKM (In RTP on the contrary it does):
81#ifdef _WRS_KERNEL
82# define _POSIX_TIMERS 1
83# define _POSIX_THREADS 1
84#endif
85
86// vxWorks doesn't work with asio serial ports:
87#define BOOST_ASIO_DISABLE_SERIAL_PORT
88// TODO: The problem here seems to bee that vxWorks uses its own, very specific
89// ways to handle serial ports, incompatible with POSIX or anything...
90// Maybe a specific implementation would be possible, but until the
91// straight need arises... This implementation would presumably consist
92// of some vxWOrks specific ioctl-calls, etc.
93
94// vxWorks-around: <time.h> defines CLOCKS_PER_SEC as sysClkRateGet() but
95// miserably fails to #include the required <sysLib.h> to make
96// sysClkRateGet() available! So we manually include it here.
97#ifdef __RTP__
98# include <sysLib.h>
99#endif
100
101// vxWorks-around: In <stdint.h> the macros INT32_C(), UINT32_C(), INT64_C() and
102// UINT64_C() are defined errorneously, yielding not an signed/
103// unsigned long/long long type, but a signed/unsigned int/long
104// type. Eventually this leads to compile errors in ratio_fwd.hpp,
105// when trying to define several constants which do not fit into a
106// long type! We correct them here by redefining.
107#ifdef __cplusplus
108# include <cstdint>
109#else
110# include <stdint.h>
111#endif
112
113// Some macro-magic
114#define VX_JOIN(X, Y) VX_DO_JOIN(X, Y)
115#define VX_DO_JOIN(X, Y) VX_DO_JOIN2(X, Y)
116#define VX_DO_JOIN2(X, Y) X##Y
117
118// Correctly setup the macros
119#undef INT32_C
120#undef UINT32_C
121#undef INT64_C
122#undef UINT64_C
123#define INT32_C(x) VX_JOIN(x, L)
124#define UINT32_C(x) VX_JOIN(x, UL)
125#define INT64_C(x) VX_JOIN(x, LL)
126#define UINT64_C(x) VX_JOIN(x, ULL)
127
128// include Libraries required for the following function adaption
129#include <ioLib.h>
130#include <tickLib.h>
131#ifdef __cplusplus
132 extern "C" {
133#endif
134
135// vxWorks-around: The required functions getrlimit() and getrlimit() are missing.
136// But we have the similar functions getprlimit() and setprlimit(),
137// which may serve the purpose.
138// Problem: The vxWorks-documentation regarding these functions
139// doesn't deserve its name! It isn't documented what the first two
140// parameters idtype and id mean, so we fall back to an educated
141// guess - null... :-/
142
143// TODO: getprlimit() and setprlimit() do exist in RTP only, for whatever reason.
144// Thus for DKM there would have to be another implementation.
145#ifdef __RTP__
146 inline int getrlimit(int resource, struct rlimit *rlp){
147 return getprlimit(0, 0, resource, rlp);
148 }
149
150 inline int setrlimit(int resource, const struct rlimit *rlp){
151# ifdef __cplusplus
152 return setprlimit(0, 0, resource, const_cast<struct rlimit*>(rlp));
153# else
154 return setprlimit(0, 0, resource, (struct rlimit*)rlp);
155# endif
156 }
157#endif
158
159// vxWorks only has ftruncate(), so we simulate truncate():
160inline int truncate(const char *p, off_t l){
161 int fd = open(p, O_WRONLY);
162 if (fd == -1){
163 errno = EACCES;
164 return -1;
165 }
166 if (ftruncate(fd, l) == -1){
167 close(fd);
168 errno = EACCES;
169 return -1;
170 }
171 return close(fd);
172}
173
174// vxWorks has no symlinks -> always return an error!
175#ifdef __cplusplus
176 inline int symlink(const char*, const char*){
177#else
178 inline int symlink(const char *t, const char *f){
179#endif
180 errno = EACCES;
181 return -1;
182}
183
184// vxWorks has no symlinks -> always return an error!
185#ifdef __cplusplus
186 inline ssize_t readlink(const char*, char*, size_t){
187#else
188 inline ssize_t readlink(const char *p, char *b, size_t s){
189#endif
190 errno = EACCES;
191 return -1;
192}
193
194// vxWorks does provide neither struct tms nor function times!
195// We implement an empty dummy-function, simply setting everything
196// to the actual system ticks-value (better than setting to 0).
197struct tms{
198 clock_t tms_utime; // User CPU time
199 clock_t tms_stime; // System CPU time
200 clock_t tms_cutime; // User CPU time of terminated child processes
201 clock_t tms_cstime; // System CPU time of terminated child processes
202};
203
204inline clock_t times(struct tms *t){
205 clock_t ticks = (clock_t)tickGet();
206 t->tms_utime =
207 t->tms_stime =
208 t->tms_cutime =
209 t->tms_cstime = ticks;
210 return ticks;
211}
212
213// Put the selfmade functions into the std-namespace
214#ifdef __cplusplus
215 } // extern "C"
216 namespace std {
217# ifdef __RTP__
218 using ::getrlimit;
219 using ::setrlimit;
220# endif
221 using ::truncate;
222 using ::symlink;
223 using ::readlink;
224 using ::times;
225 }
226#endif
227
228// Some more macro-magic
229// vxWorks-around: Some functions are not present in vxWorks but may be patched
230// via a helper macro...
231#define getpagesize() sysconf(_SC_PAGESIZE) // getpagesize is deprecated anyway!
232#ifndef S_ISSOCK
233# define S_ISSOCK(mode) ((mode & S_IFMT) == S_IFSOCK) // Is file a socket?
234#endif
235#define lstat(p, b) stat(p, b) // lstat == stat, as vxWorks has no symlinks!
236#ifndef FPE_FLTINV
237# define FPE_FLTINV (FPE_FLTSUB+1) // vxWorks has no FPE_FLTINV, so define one as a dummy
238#endif
239#ifndef BUS_ADRALN
240# define BUS_ADRALN BUS_ADRALNR // Correct a supposed typo in vxWorks' <signals.h>?
241#endif
242//typedef int locale_t; // locale_t is a POSIX-extension, currently unpresent in vxWorks!
243
244// boilerplate code:
245#include <boost/config/posix_features.hpp>
246
247// vxWorks lies about XSI conformance, there is no nl_types.h:
248#undef BOOST_HAS_NL_TYPES_H