8 | | // vxWorks specific config options: |
| 9 | // Since WRS does not yet properly support boost under vxWorks |
| 10 | // and this file was badly outdated, but I was keen on using it, |
| 11 | // I patched boost myself to make things work. This has been tested |
| 12 | // and adapted by me for vxWorks 6.9 *only*, as I'm lacking access |
| 13 | // to earlier 6.X versions! The only thing I know for sure is that |
| 14 | // very old versions of vxWorks (namely everything below 6.x) are |
| 15 | // absolutely unable to use boost. This is mainly due to the completely |
| 16 | // outdated libraries and ancient compiler (GCC 2.96 or worse). Do |
| 17 | // not even think of getting this to work, a miserable failure will |
| 18 | // be guaranteed! |
| 19 | // Equally, this file has been tested for RTPs (Real Time Processes) |
| 20 | // only, not for DKMs (Downloadable Kernel Modules). These two types |
| 21 | // of executables differ largely in the available functionality of |
| 22 | // the C-library, STL, and so on. A DKM uses a library similar to those |
| 23 | // of vxWorks 5.X - with all its limitations and incompatibilities |
| 24 | // in respect to ANSI C++ and STL. So probably there might be problems |
| 25 | // with the usage of boost from DKMs. WRS or any voluteers are free to |
| 26 | // prove the opposite! |
26 | | // vxworks doesn't work with asio serial ports |
| 73 | // Generally available functionality: |
| 74 | #define BOOST_HAS_THREADS |
| 75 | #define BOOST_HAS_NANOSLEEP |
| 76 | #define BOOST_HAS_CLOCK_GETTIME |
| 77 | #define BOOST_HAS_MACRO_USE_FACET |
| 78 | |
| 79 | // Generally unavailable functionality, delivered by boost's test function: |
| 80 | //#define BOOST_NO_DEDUCED_TYPENAME // Commented this out, boost's test gives an errorneous result! |
| 81 | #define BOOST_NO_CXX11_EXTERN_TEMPLATE |
| 82 | #define BOOST_NO_CXX11_VARIADIC_MACROS |
| 83 | |
| 84 | // Generally available threading API's: |
| 85 | #define BOOST_HAS_PTHREADS |
| 86 | #define BOOST_HAS_SCHED_YIELD |
| 87 | #define BOOST_HAS_SIGACTION |
| 88 | |
| 89 | // Functionality available for RTPs only: |
| 90 | #ifdef __RTP__ |
| 91 | //# define BOOST_HAS_GETTIMEOFDAY |
| 92 | # define BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE |
| 93 | # define BOOST_HAS_LOG1P |
| 94 | # define BOOST_HAS_EXPM1 |
| 95 | #endif |
| 96 | |
| 97 | // Functionality available for DKMs only: |
| 98 | #ifdef _WRS_KERNEL |
| 99 | // Luckily, at the moment there seems to be none! |
| 100 | #endif |
| 101 | |
| 102 | // These #defines allow posix_features to work, since vxWorks doesn't |
| 103 | // #define them itself for DKMs (for RTPs on the contrary it does): |
| 104 | #ifdef _WRS_KERNEL |
| 105 | # ifndef _POSIX_TIMERS |
| 106 | # define _POSIX_TIMERS 1 |
| 107 | # endif |
| 108 | # ifndef _POSIX_THREADS |
| 109 | # define _POSIX_THREADS 1 |
| 110 | # endif |
| 111 | #endif |
| 112 | |
| 113 | // vxWorks doesn't work with asio serial ports: |
29 | | // boilerplate code: |
| 121 | // vxWorks-around: <time.h> #defines CLOCKS_PER_SEC as sysClkRateGet() but |
| 122 | // miserably fails to #include the required <sysLib.h> to make |
| 123 | // sysClkRateGet() available! So we manually include it here. |
| 124 | #ifdef __RTP__ |
| 125 | # include <sysLib.h> |
| 126 | #endif |
| 127 | |
| 128 | // vxWorks-around: In <stdint.h> the macros INT32_C(), UINT32_C(), INT64_C() and |
| 129 | // UINT64_C() are defined errorneously, yielding not a signed/ |
| 130 | // unsigned long/long long type, but a signed/unsigned int/long |
| 131 | // type. Eventually this leads to compile errors in ratio_fwd.hpp, |
| 132 | // when trying to define several constants which do not fit into a |
| 133 | // long type! We correct them here by redefining. |
| 134 | #include <cstdint> |
| 135 | |
| 136 | // Some macro-magic to do the job |
| 137 | #define VX_JOIN(X, Y) VX_DO_JOIN(X, Y) |
| 138 | #define VX_DO_JOIN(X, Y) VX_DO_JOIN2(X, Y) |
| 139 | #define VX_DO_JOIN2(X, Y) X##Y |
| 140 | |
| 141 | // Correctly setup the macros |
| 142 | #undef INT32_C |
| 143 | #undef UINT32_C |
| 144 | #undef INT64_C |
| 145 | #undef UINT64_C |
| 146 | #define INT32_C(x) VX_JOIN(x, L) |
| 147 | #define UINT32_C(x) VX_JOIN(x, UL) |
| 148 | #define INT64_C(x) VX_JOIN(x, LL) |
| 149 | #define UINT64_C(x) VX_JOIN(x, ULL) |
| 150 | |
| 151 | // #include Libraries required for the following function adaption |
| 152 | #include <ioLib.h> |
| 153 | #include <tickLib.h> |
| 154 | |
| 155 | // Use C-linkage for the following helper functions |
| 156 | extern "C" { |
| 157 | |
| 158 | // vxWorks-around: The required functions getrlimit() and getrlimit() are missing. |
| 159 | // But we have the similar functions getprlimit() and setprlimit(), |
| 160 | // which may serve the purpose. |
| 161 | // Problem: The vxWorks-documentation regarding these functions |
| 162 | // doesn't deserve its name! It isn't documented what the first two |
| 163 | // parameters idtype and id mean, so we must fall back to an educated |
| 164 | // guess - null, argh... :-/ |
| 165 | |
| 166 | // TODO: getprlimit() and setprlimit() do exist for RTPs only, for whatever reason. |
| 167 | // Thus for DKMs there would have to be another implementation. |
| 168 | #ifdef __RTP__ |
| 169 | inline int getrlimit(int resource, struct rlimit *rlp){ |
| 170 | return getprlimit(0, 0, resource, rlp); |
| 171 | } |
| 172 | |
| 173 | inline int setrlimit(int resource, const struct rlimit *rlp){ |
| 174 | return setprlimit(0, 0, resource, const_cast<struct rlimit*>(rlp)); |
| 175 | } |
| 176 | #endif |
| 177 | |
| 178 | // vxWorks has ftruncate() only, so we do simulate truncate(): |
| 179 | inline int truncate(const char *p, off_t l){ |
| 180 | int fd = open(p, O_WRONLY); |
| 181 | if (fd == -1){ |
| 182 | errno = EACCES; |
| 183 | return -1; |
| 184 | } |
| 185 | if (ftruncate(fd, l) == -1){ |
| 186 | close(fd); |
| 187 | errno = EACCES; |
| 188 | return -1; |
| 189 | } |
| 190 | return close(fd); |
| 191 | } |
| 192 | |
| 193 | // Fake symlink handling by dummy functions: |
| 194 | inline int symlink(const char*, const char*){ |
| 195 | // vxWorks has no symlinks -> always return an error! |
| 196 | errno = EACCES; |
| 197 | return -1; |
| 198 | } |
| 199 | |
| 200 | inline ssize_t readlink(const char*, char*, size_t){ |
| 201 | // vxWorks has no symlinks -> always return an error! |
| 202 | errno = EACCES; |
| 203 | return -1; |
| 204 | } |
| 205 | |
| 206 | // vxWorks does provide neither struct tms nor function times()! |
| 207 | // We implement an empty dummy-function, simply setting the user |
| 208 | // and system time to the half of thew actual system ticks-value |
| 209 | // and the child user and system time to 0. |
| 210 | // Rather ugly but at least it suppresses compiler errors... |
| 211 | // Unfortunately, this of course *does* have an severe impact on |
| 212 | // dependant libraries, actually this is chrono only! Here it will |
| 213 | // not be possible to correctly use user and system times! But |
| 214 | // as vxWorks is lacking the ability to calculate user and system |
| 215 | // process times there seems to be no other possible solution. |
| 216 | struct tms{ |
| 217 | clock_t tms_utime; // User CPU time |
| 218 | clock_t tms_stime; // System CPU time |
| 219 | clock_t tms_cutime; // User CPU time of terminated child processes |
| 220 | clock_t tms_cstime; // System CPU time of terminated child processes |
| 221 | }; |
| 222 | |
| 223 | inline clock_t times(struct tms *t){ |
| 224 | clock_t ticks = static_cast<clock_t>(tickGet()); |
| 225 | t->tms_utime = ticks/2U; |
| 226 | t->tms_stime = ticks/2U; |
| 227 | t->tms_cutime = 0; |
| 228 | t->tms_cstime = 0; |
| 229 | return ticks; |
| 230 | } |
| 231 | |
| 232 | } // extern "C" |
| 233 | |
| 234 | // Put the selfmade functions into the std-namespace, just in case |
| 235 | namespace std { |
| 236 | # ifdef __RTP__ |
| 237 | using ::getrlimit; |
| 238 | using ::setrlimit; |
| 239 | # endif |
| 240 | using ::truncate; |
| 241 | using ::symlink; |
| 242 | using ::readlink; |
| 243 | using ::times; |
| 244 | } |
| 245 | |
| 246 | // Some more macro-magic: |
| 247 | // vxWorks-around: Some functions are not present or broken in vxWorks |
| 248 | // but may be patched to life via helper macros... |
| 249 | |
| 250 | // Include signal.h which contains a typo to be corrected here |
| 251 | #include <signal.h> |
| 252 | |
| 253 | #define getpagesize() sysconf(_SC_PAGESIZE) // getpagesize is deprecated anyway! |
| 254 | #ifndef S_ISSOCK |
| 255 | # define S_ISSOCK(mode) ((mode & S_IFMT) == S_IFSOCK) // Is file a socket? |
| 256 | #endif |
| 257 | #define lstat(p, b) stat(p, b) // lstat() == stat(), as vxWorks has no symlinks! |
| 258 | #ifndef FPE_FLTINV |
| 259 | # define FPE_FLTINV (FPE_FLTSUB+1) // vxWorks has no FPE_FLTINV, so define one as a dummy |
| 260 | #endif |
| 261 | #if !defined(BUS_ADRALN) && defined(BUS_ADRALNR) |
| 262 | # define BUS_ADRALN BUS_ADRALNR // Correct a supposed typo in vxWorks' <signal.h>? |
| 263 | #endif |
| 264 | //typedef int locale_t; // locale_t is a POSIX-extension, currently unpresent in vxWorks! |
| 265 | |
| 266 | // #include boilerplate code: |