Ticket #7938: vxworks.hpp.patch

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

Support vxWorks 6.9

  • C:/Daten/Libraries/Boost/boost/config/platform/vxworks.hpp

     
    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
     1//  (C) Copyright Dustin Spicuzza 2009.
     2//      Adapted to vxWorks 6.9 by Peter Brockamp 2012.
     3//  Use, modification and distribution are subject to the
     4//  Boost Software License, Version 1.0. (See accompanying file
    45//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
    56
    67//  See http://www.boost.org for most recent version.
    78
    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!
    927
     28// Block out all versions before vxWorks 6.x, as these don't work:
     29// Include header with the vxWorks version information and query them
     30#include <version.h>
     31#if !defined(_WRS_VXWORKS_MAJOR) || (_WRS_VXWORKS_MAJOR < 6)
     32#  error "The vxWorks version you're using is so badly outdated,\
     33          it doesn't work at all with boost, sorry, no chance!"
     34#endif
     35
     36// Handle versions above 5.X but below 6.9
     37#if (_WRS_VXWORKS_MAJOR == 6) && (_WRS_VXWORKS_MINOR < 9)
     38// TODO: Starting from what version does vxWorks work with boost?
     39// We can't reasonably insert a #warning "" as a user hint here,
     40// as this will show up with every file including some boost header,
     41// badly bugging the user... So for the time being we just leave it.
     42#endif
     43
     44// vxWorks specific config options:
     45// --------------------------------
    1046#define BOOST_PLATFORM "vxWorks"
    1147
    12 #define BOOST_NO_CWCHAR
    13 #define BOOST_NO_INTRINSIC_WCHAR_T
     48// Special behaviour for DKMs:
     49#ifdef _WRS_KERNEL
     50  // DKMs do not have the <cwchar>-header,
     51  // but apparently they do have an intrinsic wchar_t meanwhile!
     52#  define BOOST_NO_CWCHAR
    1453
    15 #if defined(__GNUC__) && defined(__STRICT_ANSI__)
    16 #define BOOST_NO_INT64_T
     54  // Lots of wide-functions and -headers are unavailable for DKMs as well:
     55#  define BOOST_NO_CWCTYPE
     56#  define BOOST_NO_SWPRINTF
     57#  define BOOST_NO_STD_WSTRING
     58#  define BOOST_NO_STD_WSTREAMBUF
    1759#endif
    1860
     61// Generally available headers:
    1962#define BOOST_HAS_UNISTD_H
     63#define BOOST_HAS_STDINT_H
     64#define BOOST_HAS_DIRENT_H
     65#define BOOST_HAS_SLIST
    2066
    21 // these allow posix_features to work, since vxWorks doesn't
    22 // define them itself
    23 #define _POSIX_TIMERS 1
    24 #define _POSIX_THREADS 1
     67// vxWorks does not have installed an iconv-library by default,
     68// so unfortunately no Unicode support from scratch is available!
     69// Thus, instead it is suggested to switch to ICU, as this seems
     70// to be the most complete and portable option...
     71#define BOOST_LOCALE_WITH_ICU
    2572
    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:
    27114#define BOOST_ASIO_DISABLE_SERIAL_PORT
     115// TODO: The problem here seems to bee that vxWorks uses its own, very specific
     116//       ways to handle serial ports, incompatible with POSIX or anything...
     117//       Maybe a specific implementation would be possible, but until the
     118//       straight need arises... This implementation would presumably consist
     119//       of some vxWorks specific ioctl-calls, etc. Any voluteers?
    28120
    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
     156extern "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():
     179inline 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:
     194inline int symlink(const char*, const char*){
     195  // vxWorks has no symlinks -> always return an error!
     196  errno = EACCES;
     197  return -1;
     198}
     199
     200inline 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.
     216struct 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
     223inline 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
     235namespace 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:
    30267#include <boost/config/posix_features.hpp>
    31  
     268
     269// vxWorks lies about XSI conformance, there is no nl_types.h:
     270#undef BOOST_HAS_NL_TYPES_H
     271
     272// vxWorks blatantly lies about implementing gettimeofday:
     273// Though it even declares a prototype in sys/time.h, linking it fails!
     274#undef BOOST_HAS_GETTIMEOFDAY
     275 Kein Zeilenumbruch am Ende der Datei