Home | History | Annotate | Download | only in config
      1 /*
      2  * Copyright (c) 1997-1999
      3  * Silicon Graphics Computer Systems, Inc.
      4  *
      5  * Copyright (c) 1999
      6  * Boris Fomitchev
      7  *
      8  * Copyright (c) 2003
      9  * Francois Dumont
     10  *
     11  * This material is provided "as is", with absolutely no warranty expressed
     12  * or implied. Any use is at your own risk.
     13  *
     14  * Permission to use or copy this software for any purpose is hereby granted
     15  * without fee, provided the above notices are retained on all copies.
     16  * Permission to modify the code and to distribute modified code is granted,
     17  * provided the above notices are retained, and a notice that the code was
     18  * modified is included with the above copyright notice.
     19  *
     20  */
     21 #ifndef _STLP_INTERNAL_WINDOWS_H
     22 #define _STLP_INTERNAL_WINDOWS_H
     23 
     24 #if !defined (_STLP_PLATFORM)
     25 #  define _STLP_PLATFORM "Windows"
     26 #endif
     27 
     28 #if !defined (_STLP_BIG_ENDIAN) && !defined (_STLP_LITTLE_ENDIAN)
     29 #  if defined (_MIPSEB)
     30 #    define _STLP_BIG_ENDIAN 1
     31 #  endif
     32 #  if defined (__i386) || defined (_M_IX86) || defined (_M_ARM) || \
     33       defined (__amd64__) || defined (_M_AMD64) || defined (__x86_64__) || \
     34       defined (__alpha__)
     35 #    define _STLP_LITTLE_ENDIAN 1
     36 #  endif
     37 #  if defined (__ia64__)
     38     /* itanium allows both settings (for instance via gcc -mbig-endian) - hence a seperate check is required */
     39 #    if defined (__BIG_ENDIAN__)
     40 #      define _STLP_BIG_ENDIAN 1
     41 #    else
     42 #      define _STLP_LITTLE_ENDIAN 1
     43 #    endif
     44 #  endif
     45 #endif /* _STLP_BIG_ENDIAN */
     46 
     47 #if !defined (_STLP_WINDOWS_H_INCLUDED)
     48 #  define _STLP_WINDOWS_H_INCLUDED
     49 #  if defined (__BUILDING_STLPORT)
     50 #    include <stl/config/_native_headers.h>
     51 /* Here we define _STLP_OUTERMOST_HEADER_ID to avoid indirect inclusion
     52  * of STLport stuffs from C/C++ Standard headers exposed by STLport
     53  * as configuration is not yet completed. */
     54 #    if !defined (_STLP_OUTERMOST_HEADER_ID)
     55 #      define _STLP_OUTERMOST_HEADER_ID 0x100
     56 #    endif
     57 #    if !defined (WIN32_LEAN_AND_MEAN)
     58 #      define WIN32_LEAN_AND_MEAN
     59 #    endif
     60 #    if !defined (VC_EXTRALEAN)
     61 #      define VC_EXTRALEAN
     62 #    endif
     63 /* Don't let windows.h define its min and max macros. */
     64 #    if !defined (NOMINMAX)
     65 #      define NOMINMAX
     66 #    endif
     67 #    if !defined (STRICT)
     68 #      define STRICT
     69 #    endif
     70 #    if defined (_STLP_USE_MFC)
     71 #      include <afx.h>
     72 #    else
     73 #      include <windows.h>
     74 #    endif
     75 #    if (_STLP_OUTERMOST_HEADER_ID == 0x100)
     76 #      undef _STLP_OUTERMOST_HEADER_ID
     77 #    endif
     78 #  else
     79 /* This section serves as a replacement for windows.h header. */
     80 #    if defined (__cplusplus)
     81 extern "C" {
     82 #    endif
     83 #    if (defined (_M_AMD64) || defined (_M_IA64) || (!defined (_STLP_WCE) && defined (_M_MRX000)) || defined (_M_ALPHA) || \
     84         (defined (_M_PPC) && (_STLP_MSVC_LIB >= 1000))) && !defined (RC_INVOKED)
     85 #      define InterlockedIncrement       _InterlockedIncrement
     86 #      define InterlockedDecrement       _InterlockedDecrement
     87 #      define InterlockedExchange        _InterlockedExchange
     88 #      define _STLP_STDCALL
     89 #    else
     90 #      if defined (_MAC)
     91 #        define _STLP_STDCALL _cdecl
     92 #      else
     93 #        define _STLP_STDCALL __stdcall
     94 #      endif
     95 #    endif
     96 
     97 #    if defined (_STLP_NEW_PLATFORM_SDK)
     98 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedIncrement(long volatile *);
     99 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedDecrement(long volatile *);
    100 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedExchange(long volatile *, long);
    101 #      if defined (_WIN64)
    102 _STLP_IMPORT_DECLSPEC void* _STLP_STDCALL _InterlockedExchangePointer(void* volatile *, void*);
    103 #      endif
    104 #    elif !defined (_STLP_WCE)
    105 /* boris : for the latest SDK, you may actually need the other version of the declaration (above)
    106  * even for earlier VC++ versions. There is no way to tell SDK versions apart, sorry ...
    107  */
    108 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedIncrement(long*);
    109 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedDecrement(long*);
    110 _STLP_IMPORT_DECLSPEC long _STLP_STDCALL InterlockedExchange(long*, long);
    111 #    else
    112 /* start of eMbedded Visual C++ specific section */
    113 #      include <stl/config/_native_headers.h>
    114 
    115 /* Don't let windef.h define its min and max macros. */
    116 #      if !defined (NOMINMAX)
    117 #        define NOMINMAX
    118 #      endif
    119 #      include <windef.h> /* needed for basic windows types */
    120 
    121        /** in SDKs generated with PB5, windef.h somehow includes headers which then
    122        define setjmp. */
    123 #      if (_WIN32_WCE >= 0x500)
    124 #        define _STLP_NATIVE_SETJMP_H_INCLUDED
    125 #      endif
    126 
    127 #      ifndef _WINBASE_ /* winbase.h already included? */
    128 long WINAPI InterlockedIncrement(long*);
    129 long WINAPI InterlockedDecrement(long*);
    130 long WINAPI InterlockedExchange(long*, long);
    131 #      endif
    132 
    133 #      ifndef __WINDOWS__ /* windows.h already included? */
    134 
    135 #        if defined (x86)
    136 #          include <winbase.h> /* needed for inline versions of Interlocked* functions */
    137 #        endif
    138 
    139 #        ifndef _MFC_VER
    140 
    141 #          define MessageBox MessageBoxW
    142 int WINAPI MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
    143 
    144 #          define wvsprintf wvsprintfW
    145 int WINAPI wvsprintfW(LPWSTR, LPCWSTR, va_list ArgList);
    146 
    147 void WINAPI ExitThread(DWORD dwExitCode);
    148 
    149 #          if !defined (COREDLL)
    150 #            define _STLP_WCE_WINBASEAPI DECLSPEC_IMPORT
    151 #          else
    152 #            define _STLP_WCE_WINBASEAPI
    153 #          endif
    154 
    155 _STLP_WCE_WINBASEAPI int WINAPI
    156 MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,
    157                     int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar);
    158 
    159 _STLP_WCE_WINBASEAPI UINT WINAPI GetACP();
    160 
    161 _STLP_WCE_WINBASEAPI BOOL WINAPI TerminateProcess(HANDLE hProcess, DWORD uExitCode);
    162 
    163 #          define OutputDebugString OutputDebugStringW
    164 void WINAPI OutputDebugStringW(LPCWSTR);
    165 
    166 _STLP_WCE_WINBASEAPI void WINAPI Sleep(DWORD);
    167 
    168 #          undef _STLP_WCE_WINBASEAPI
    169 
    170 #        endif /* !_MFC_VER */
    171 
    172 #      endif /* !__WINDOWS__ */
    173 
    174 /* end of eMbedded Visual C++ specific section */
    175 #    endif
    176 
    177 #    if !defined (_STLP_WCE)
    178 _STLP_IMPORT_DECLSPEC void _STLP_STDCALL Sleep(unsigned long);
    179 _STLP_IMPORT_DECLSPEC void _STLP_STDCALL OutputDebugStringA(const char* lpOutputString);
    180 #    endif
    181 
    182 #    if defined (InterlockedIncrement)
    183 #      pragma intrinsic(_InterlockedIncrement)
    184 #      pragma intrinsic(_InterlockedDecrement)
    185 #      pragma intrinsic(_InterlockedExchange)
    186 #      if defined (_WIN64)
    187 #        pragma intrinsic(_InterlockedExchangePointer)
    188 #      endif
    189 #    endif
    190 #    if defined (__cplusplus)
    191 } /* extern "C" */
    192 #    endif
    193 
    194 #  endif
    195 
    196 /* Here we use a macro different than the InterlockedExchangePointer SDK one
    197  * to avoid macro definition conflict. */
    198 #  if !defined (_WIN64)
    199 /* Under 32 bits platform we rely on a simple InterlockedExchange call. */
    200 #    if defined (__cplusplus)
    201 /* We do not define this function if we are not in a C++ translation unit just
    202  * because of the 'inline' keyword portability issue it would introduce. We will
    203  * have to fix it the day we need this function for a C translation unit.
    204  */
    205 inline
    206 void* _STLP_CALL STLPInterlockedExchangePointer(void* volatile* __a, void* __b) {
    207 #      if defined (_STLP_MSVC)
    208 /* Here MSVC produces warning if 64 bits portability issue is activated.
    209  * MSVC do not see that _STLP_ATOMIC_EXCHANGE_PTR is a macro which content
    210  * is based on the platform, Win32 or Win64
    211  */
    212 #        pragma warning (push)
    213 #        pragma warning (disable : 4311) // pointer truncation from void* to long
    214 #        pragma warning (disable : 4312) // conversion from long to void* of greater size
    215 #      endif
    216 #      if !defined (_STLP_NO_NEW_STYLE_CASTS)
    217   return reinterpret_cast<void*>(InterlockedExchange(reinterpret_cast<long*>(const_cast<void**>(__a)),
    218                                                      reinterpret_cast<long>(__b)));
    219 #      else
    220   return (void*)InterlockedExchange((long*)__a, (long)__b);
    221 #      endif
    222 #      if defined (_STLP_MSVC)
    223 #        pragma warning (pop)
    224 #      endif
    225 }
    226 #    endif
    227 #  else
    228 #    define STLPInterlockedExchangePointer _InterlockedExchangePointer
    229 #  endif
    230 
    231 #endif /* _STLP_WINDOWS_H_INCLUDED */
    232 
    233 /* _STLP_WIN95_LIKE signal the Windows 95 OS or assimilated Windows OS version that
    234  * has Interlockeded[Increment, Decrement] Win32 API functions not returning modified
    235  * value.
    236  */
    237 #if (defined (WINVER) && (WINVER < 0x0410) && (!defined (_WIN32_WINNT) || (_WIN32_WINNT < 0x400))) || \
    238     (!defined (WINVER) && (defined (_WIN32_WINDOWS) && (_WIN32_WINDOWS < 0x0410) || \
    239                           (defined (_WIN32_WINNT) && (_WIN32_WINNT < 0x400))))
    240 #  define _STLP_WIN95_LIKE
    241 #endif
    242 
    243 /* Between Windows 95 (0x400) and later Windows OSes an API enhancement forces us
    244  * to change _Refcount_Base internal struct. As _Refcount_base member methods might
    245  * be partially inlined we need to check that STLport build/use are coherent. To do
    246  * so we try to generate a link time error thanks to the following macro.
    247  * This additional check is limited to old compilers that might still be used with
    248  * Windows 95. */
    249 #if (defined (_DEBUG) || defined (_STLP_DEBUG)) && \
    250     (defined (_STLP_MSVC) && (_STLP_MSVC < 1310) || \
    251      defined (__GNUC__) && (__GNUC__ < 3))
    252 /* We invert symbol names based on macro detection, when building for Windows
    253  * 95 we expose a
    254  * building_for_windows95_or_previous_but_library_built_for_windows98_or_later
    255  * function in order to have a more obvious link error message signaling how
    256  * the lib has been built and how it is used. */
    257 #  if defined (__BUILDING_STLPORT)
    258 #    if defined (_STLP_WIN95_LIKE)
    259 #      define _STLP_SIGNAL_RUNTIME_COMPATIBILITY building_for_windows95_but_library_built_for_at_least_windows98
    260 #    else
    261 #      define _STLP_SIGNAL_RUNTIME_COMPATIBILITY building_for_at_least_windows98_but_library_built_for_windows95
    262 #    endif
    263 #  else
    264 #    if defined (_STLP_WIN95_LIKE)
    265 #      define _STLP_CHECK_RUNTIME_COMPATIBILITY building_for_windows95_but_library_built_for_at_least_windows98
    266 #    else
    267 #      define _STLP_CHECK_RUNTIME_COMPATIBILITY building_for_at_least_windows98_but_library_built_for_windows95
    268 #    endif
    269 #  endif
    270 #endif
    271 
    272 #if defined (__WIN16) || defined (WIN16) || defined (_WIN16)
    273 #  define _STLP_WIN16
    274 #else
    275 #  define _STLP_WIN32
    276 #endif
    277 
    278 #if defined(_STLP_WIN32)
    279 #  define _STLP_USE_WIN32_IO /* CreateFile/ReadFile/WriteFile */
    280 #endif
    281 
    282 #if defined(__MINGW32__) && !defined(_STLP_USE_STDIO_IO)
    283 #  define _STLP_USE_WIN32_IO /* CreateFile/ReadFile/WriteFile */
    284 #endif /* __MINGW32__ */
    285 
    286 #ifdef _STLP_WIN16
    287 #  define _STLP_USE_UNIX_EMULATION_IO /* _open/_read/_write */
    288 #  define _STLP_LDOUBLE_80
    289 #endif
    290 
    291 #endif /* _STLP_INTERNAL_WINDOWS_H */
    292