Update vxworks.hpp for VxWorks 7

This commit is contained in:
Brian Kuhl
2017-09-02 06:21:57 -04:00
parent 6102d18867
commit 918c5fc486
3 changed files with 120 additions and 97 deletions

View File

@ -1,30 +1,29 @@
// (C) Copyright Dustin Spicuzza 2009.
// Adapted to vxWorks 6.9 by Peter Brockamp 2012.
// Updated for VxWorks 7 by Brian Kuhl 2016
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for most recent version.
// Since WRS does not yet properly support boost under vxWorks
// and this file was badly outdated, but I was keen on using it,
// I patched boost myself to make things work. This has been tested
// and adapted by me for vxWorks 6.9 *only*, as I'm lacking access
// to earlier 6.X versions! The only thing I know for sure is that
// very old versions of vxWorks (namely everything below 6.x) are
// absolutely unable to use boost. This is mainly due to the completely
// outdated libraries and ancient compiler (GCC 2.96 or worse). Do
// not even think of getting this to work, a miserable failure will
// be guaranteed!
// Old versions of vxWorks (namely everything below 6.x) are
// absolutely unable to use boost. Old STLs and compilers
// like (GCC 2.96) . Do not even think of getting this to work,
// a miserable failure will be guaranteed!
//
// Equally, this file has been tested for RTPs (Real Time Processes)
// only, not for DKMs (Downloadable Kernel Modules). These two types
// of executables differ largely in the available functionality of
// the C-library, STL, and so on. A DKM uses a library similar to those
// of vxWorks 5.X - with all its limitations and incompatibilities
// with respect to ANSI C++ and STL. So probably there might be problems
// with the usage of boost from DKMs. WRS or any voluteers are free to
// prove the opposite!
// the C-library, STL, and so on. A DKM uses a C89 library with no
// wide character support and no guarantee of ANSI C. The same Dinkum
// STL library is used in both contexts.
//
// Similarly the Dinkum abridged STL that supports the loosely specified
// embedded C++ standard has not been tested and is unlikely to work
// on anything but the simplest library.
//
//
// ====================================================================
//
// Some important information regarding the usage of POSIX semaphores:
@ -38,29 +37,14 @@
// Now, VxWorks POSIX-semaphores for DKM's default to the usage of
// priority inverting semaphores, which is fine. On the other hand,
// for RTP's it defaults to using non priority inverting semaphores,
// which could easily pose a serious problem for a real time process,
// i.e. deadlocks! To overcome this two possibilities do exist:
// which could easily pose a serious problem for a real time process.
//
// a) Patch every piece of boost that uses semaphores to instanciate
// the proper type of semaphores. This is non-intrusive with respect
// to the OS and could relatively easy been done by giving all
// semaphores attributes deviating from the default (for in-depth
// information see the POSIX functions pthread_mutexattr_init()
// and pthread_mutexattr_setprotocol()). However this breaks all
// too easily, as with every new version some boost library could
// all in a sudden start using semaphores, resurrecting the very
// same, hard to locate problem over and over again!
// To change the default properties for POSIX-semaphores in VxWorks 7
// enable core > CORE_USER Menu > DEFAULT_PTHREAD_PRIO_INHERIT
//
// b) We could change the default properties for POSIX-semaphores
// that VxWorks uses for RTP's and this is being suggested here,
// as it will more or less seamlessly integrate with boost. I got
// the following information from WRS how to do this, compare
// Wind River TSR# 1209768:
//
// Instructions for changing the default properties of POSIX-
// semaphores for RTP's in VxWorks 6.9:
// - Edit the file /vxworks-6.9/target/usr/src/posix/pthreadLib.c
// in the root of your Workbench-installation.
// In VxWorks 6.x so as to integrate with boost.
// - Edit the file
// installDir/vxworks-6.x/target/usr/src/posix/pthreadLib.c
// - Around line 917 there should be the definition of the default
// mutex attributes:
//
@ -81,29 +65,10 @@
// pAttr->mutexAttrType = PTHREAD_MUTEX_DEFAULT;
//
// Here again, replace PTHREAD_PRIO_NONE by PTHREAD_PRIO_INHERIT.
// - Finally, rebuild your VSB. This will create a new VxWorks kernel
// - Finally, rebuild your VSB. This will rebuild the libraries
// with the changed properties. That's it! Now, using boost should
// no longer cause any problems with task deadlocks!
//
// And here's another useful piece of information concerning VxWorks'
// POSIX-functionality in general:
// VxWorks is not a genuine POSIX-OS in itself, rather it is using a
// kind of compatibility layer (sort of a wrapper) to emulate the
// POSIX-functionality by using its own resources and functions.
// At the time a task (thread) calls it's first POSIX-function during
// runtime it is being transformed by the OS into a POSIX-thread.
// This transformation does include a call to malloc() to allocate the
// memory required for the housekeeping of POSIX-threads. In a high
// priority RTP this malloc() call may be highly undesirable, as its
// timing is more or less unpredictable (depending on what your actual
// heap looks like). You can circumvent this problem by calling the
// function thread_self() at a well defined point in the code of the
// task, e.g. shortly after the task spawns up. Thereby you are able
// to define the time when the task-transformation will take place and
// you could shift it to an uncritical point where a malloc() call is
// tolerable. So, if this could pose a problem for your code, remember
// to call thread_self() from the affected task at an early stage.
//
// ====================================================================
// Block out all versions before vxWorks 6.x, as these don't work:
@ -158,11 +123,6 @@
#define BOOST_HAS_CLOCK_GETTIME
#define BOOST_HAS_MACRO_USE_FACET
// Generally unavailable functionality, delivered by boost's test function:
//#define BOOST_NO_DEDUCED_TYPENAME // Commented this out, boost's test gives an errorneous result!
#define BOOST_NO_CXX11_EXTERN_TEMPLATE
#define BOOST_NO_CXX11_VARIADIC_MACROS
// Generally available threading API's:
#define BOOST_HAS_PTHREADS
#define BOOST_HAS_SCHED_YIELD
@ -191,14 +151,7 @@
# endif
#endif
// vxWorks doesn't work with asio serial ports:
#define BOOST_ASIO_DISABLE_SERIAL_PORT
// TODO: The problem here seems to bee that vxWorks uses its own, very specific
// ways to handle serial ports, incompatible with POSIX or anything...
// Maybe a specific implementation would be possible, but until the
// straight need arises... This implementation would presumably consist
// of some vxWorks specific ioctl-calls, etc. Any voluteers?
#if (_WRS_VXWORKS_MAJOR < 7)
// vxWorks-around: <time.h> #defines CLOCKS_PER_SEC as sysClkRateGet() but
// miserably fails to #include the required <sysLib.h> to make
// sysClkRateGet() available! So we manually include it here.
@ -208,11 +161,12 @@
#endif
// vxWorks-around: In <stdint.h> the macros INT32_C(), UINT32_C(), INT64_C() and
// UINT64_C() are defined errorneously, yielding not a signed/
// UINT64_C() are defined erroneously, yielding not a signed/
// unsigned long/long long type, but a signed/unsigned int/long
// type. Eventually this leads to compile errors in ratio_fwd.hpp,
// when trying to define several constants which do not fit into a
// long type! We correct them here by redefining.
#include <cstdint>
// Some macro-magic to do the job
@ -231,12 +185,16 @@
#define UINT64_C(x) VX_JOIN(x, ULL)
// #include Libraries required for the following function adaption
#include <sys/time.h>
#endif // _WRS_VXWORKS_MAJOR < 7
#include <ioLib.h>
#include <tickLib.h>
#include <sys/time.h>
// Use C-linkage for the following helper functions
#ifdef __cplusplus
extern "C" {
#endif
// vxWorks-around: The required functions getrlimit() and getrlimit() are missing.
// But we have the similar functions getprlimit() and setprlimit(),
@ -248,7 +206,7 @@ extern "C" {
// TODO: getprlimit() and setprlimit() do exist for RTPs only, for whatever reason.
// Thus for DKMs there would have to be another implementation.
#ifdef __RTP__
#if defined ( __RTP__) && (_WRS_VXWORKS_MAJOR < 7)
inline int getrlimit(int resource, struct rlimit *rlp){
return getprlimit(0, 0, resource, rlp);
}
@ -273,14 +231,20 @@ inline int truncate(const char *p, off_t l){
return close(fd);
}
#ifdef __GNUC__
#define ___unused __attribute__((unused))
#else
#define ___unused
#endif
// Fake symlink handling by dummy functions:
inline int symlink(const char*, const char*){
inline int symlink(const char* path1 ___unused, const char* path2 ___unused){
// vxWorks has no symlinks -> always return an error!
errno = EACCES;
return -1;
}
inline ssize_t readlink(const char*, char*, size_t){
inline ssize_t readlink(const char* path1 ___unused, char* path2 ___unused, size_t size ___unused){
// vxWorks has no symlinks -> always return an error!
errno = EACCES;
return -1;
@ -297,8 +261,18 @@ inline int gettimeofday(struct timeval *tv, void * /*tzv*/) {
}
#endif
#ifdef __cplusplus
} // extern "C"
#endif
// vxWorks does provide neither struct tms nor function times()!
/*
* moved to os/utils/unix/freind_h/times.h in VxWorks 7
* to avoid conflict with MPL operator times
*/
#if (_WRS_VXWORKS_MAJOR < 7)
#ifdef __cplusplus
// vxWorks provides neither struct tms nor function times()!
// We implement an empty dummy-function, simply setting the user
// and system time to the half of thew actual system ticks-value
// and the child user and system time to 0.
@ -315,6 +289,7 @@ struct tms{
clock_t tms_cstime; // System CPU time of terminated child processes
};
inline clock_t times(struct tms *t){
struct timespec ts;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
@ -327,8 +302,16 @@ inline clock_t times(struct tms *t){
return ticks;
}
extern void bzero (void *, size_t); // FD_ZERO uses bzero() but doesn't include strings.h
} // extern "C"
namespace std {
using ::times;
}
#endif // __cplusplus
#endif // _WRS_VXWORKS_MAJOR < 7
#ifdef __cplusplus
extern "C" void bzero (void *, size_t); // FD_ZERO uses bzero() but doesn't include strings.h
// Put the selfmade functions into the std-namespace, just in case
namespace std {
@ -339,9 +322,11 @@ namespace std {
using ::truncate;
using ::symlink;
using ::readlink;
using ::times;
#if (_WRS_VXWORKS_MAJOR < 7)
using ::gettimeofday;
#endif
}
#endif // __cplusplus
// Some more macro-magic:
// vxWorks-around: Some functions are not present or broken in vxWorks
@ -349,12 +334,13 @@ namespace std {
// Include signal.h which might contain a typo to be corrected here
#include <signal.h>
inline int getpagesize() { return sysconf(_SC_PAGESIZE); } // getpagesize is deprecated anyway!
#if (_WRS_VXWORKS_MAJOR < 7)
#define getpagesize() sysconf(_SC_PAGESIZE) // getpagesize is deprecated anyway!
inline int lstat(p, b) { return stat(p, b); } // lstat() == stat(), as vxWorks has no symlinks!
#endif
#ifndef S_ISSOCK
# define S_ISSOCK(mode) ((mode & S_IFMT) == S_IFSOCK) // Is file a socket?
#endif
inline int lstat(p, b) { return stat(p, b); } // lstat() == stat(), as vxWorks has no symlinks!
#ifndef FPE_FLTINV
# define FPE_FLTINV (FPE_FLTSUB+1) // vxWorks has no FPE_FLTINV, so define one as a dummy
#endif
@ -371,22 +357,56 @@ typedef int locale_t; // locale_t is a POSIX-ex
// vxWorks 7 adds C++11 support
// however it is optional, and does not match exactly the support determined
// by examining Dinkum STL version and GCC version (or ICC and DCC)
// by examining the Dinkum STL version and GCC version (or ICC and DCC)
#ifndef _WRS_CONFIG_LANG_LIB_CPLUS_CPLUS_USER_2011
# define BOOST_NO_CXX11_ADDRESSOF // C11 addressof operator on memory location
# define BOOST_NO_CXX11_ALLOCATOR
# define BOOST_NO_CXX11_ATOMIC_SMART_PTR
# define BOOST_NO_CXX11_NUMERIC_LIMITS // max_digits10 in test/../print_helper.hpp
# define BOOST_NO_CXX11_SMART_PTR
# define BOOST_NO_CXX11_STD_ALIGN
# define BOOST_NO_CXX11_HDR_ARRAY
# define BOOST_NO_CXX11_HDR_ATOMIC
# define BOOST_NO_CXX11_HDR_CHRONO
# define BOOST_NO_CXX11_HDR_CONDITION_VARIABLE
# define BOOST_NO_CXX11_HDR_FORWARD_LIST //serialization/test/test_list.cpp
# define BOOST_NO_CXX11_HDR_FUNCTIONAL
# define BOOST_NO_CXX11_HDR_FUTURE
# define BOOST_NO_CXX11_HDR_MUTEX
# define BOOST_NO_CXX11_HDR_RANDOM //math/../test_data.hpp
# define BOOST_NO_CXX11_HDR_RATIO
# define BOOST_NO_CXX11_HDR_REGEX
# define BOOST_NO_CXX14_HDR_SHARED_MUTEX
# define BOOST_NO_CXX11_HDR_SYSTEM_ERROR
# define BOOST_NO_CXX11_HDR_THREAD
# define BOOST_NO_CXX11_HDR_TYPEINDEX
# define BOOST_NO_CXX11_HDR_TYPE_TRAITS
# define BOOST_NO_CXX11_HDR_TUPLE
# define BOOST_NO_CXX11_ALLOCATOR
# define BOOST_NO_CXX11_SMART_PTR
# define BOOST_NO_CXX11_STD_ALIGN
# define BOOST_NO_CXX11_HDR_UNORDERED_SET
# define BOOST_NO_CXX11_HDR_TYPE_TRAITS
# define BOOST_NO_CXX11_HDR_UNORDERED_MAP
# define BOOST_NO_CXX11_HDR_FUNCTIONAL
# define BOOST_NO_CXX11_HDR_ATOMIC
# define BOOST_NO_CXX11_HDR_UNORDERED_SET
#else
# define BOOST_NO_CXX11_NULLPTR
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED // workaround link error in spirit
#endif
#endif
// NONE is used in enums in lamda and other libraries
#undef NONE
// restrict is an iostreams class
#undef restrict
// use fake poll() from Unix layer in ASIO to get full functionality
// most libraries will use select() but this define allows 'iostream' functionality
// which is based on poll() only
#if (_WRS_VXWORKS_MAJOR > 6)
# ifndef BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR
# define BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR
# endif
#else
# define BOOST_ASIO_DISABLE_SERIAL_PORT
#endif

View File

@ -96,7 +96,8 @@
#include <exception>
#endif
#include <typeinfo>
#if ( (!_HAS_EXCEPTIONS && !defined(__ghs__)) || (!_HAS_NAMESPACE && defined(__ghs__)) ) && !defined(__TI_COMPILER_VERSION__) && !defined(__VISUALDSPVERSION__)
#if ( (!_HAS_EXCEPTIONS && !defined(__ghs__)) || (!_HAS_NAMESPACE && defined(__ghs__)) ) && !defined(__TI_COMPILER_VERSION__) && !defined(__VISUALDSPVERSION__) \
&& !defined(__VXWORKS__)
# define BOOST_NO_STD_TYPEINFO
#endif

View File

@ -78,6 +78,7 @@
# include <unistd.h>
#endif
#ifndef __VXWORKS__ // VxWorks uses Dinkum, not GNU STL with GCC
#if defined(__GLIBCXX__) || (defined(__GLIBCPP__) && __GLIBCPP__>=20020514) // GCC >= 3.1.0
# define BOOST_STD_EXTENSION_NAMESPACE __gnu_cxx
# define BOOST_HAS_SLIST
@ -91,6 +92,7 @@
# define BOOST_HASH_MAP_HEADER <backward/hash_map>
# endif
#endif
#endif
//
// Decide whether we have C++11 support turned on: