csutil/win32/csosdefs.h
00001 /* 00002 Copyright (C) 1998 by Jorrit Tyberghein 00003 Written by Andrew Zabolotny <[email protected]> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSOSDEFS_H__ 00021 #define __CS_CSOSDEFS_H__ 00022 00023 #define CS_EXPORT_SYM_DLL __declspec(dllexport) 00024 #define CS_IMPORT_SYM_DLL __declspec(dllimport) 00025 00026 #ifdef CS_BUILD_SHARED_LIBS 00027 #define CS_EXPORT_SYM CS_EXPORT_SYM_DLL 00028 #define CS_IMPORT_SYM CS_IMPORT_SYM_DLL 00029 #else 00030 #define CS_EXPORT_SYM 00031 #define CS_IMPORT_SYM 00032 #endif // CS_BUILD_SHARED_LIBS 00033 00034 #if defined(CS_COMPILER_MSVC) 00035 //#pragma warning(disable:4097) // use of xxx as synonym for a classname 00036 //#pragma warning(disable:4099) // type seen as both 'struct' and `class' 00037 //#pragma warning(disable:4100) // Use of void* as a formal function parameter 00038 //#pragma warning(disable:4102) // 'label' : unreferenced label 00039 //#pragma warning(disable:4146) /* unary minus operator applied to unsigned 00040 // * type, result still unsigned */ 00041 //#pragma warning(disable:4201) // VC6: structure/ union without name. 00042 #pragma warning(disable:4244) // conversion from 'double' to 'float' 00043 #pragma warning(disable:4250) // '...' inherits '..' via dominance 00044 //#pragma warning(disable:4251) /* class needs to have dll-interface to be 00045 // * used by clients */ 00046 //#pragma warning(disable:4275) /* non-DLL-interface used as base for 00047 // * DLL-interface */ 00048 #pragma warning(disable:4290) // C++ exception specification ignored 00049 //#pragma warning(disable:4291) // no matching operator delete found 00050 #pragma warning(disable:4312) /* 'variable' : conversion from 'type' to 00051 * 'type' of greater size */ 00052 #pragma warning(disable:4345) /* VC7.1: an object of POD type constructed 00053 * with an initializer of the form () will 00054 * be default-initialized */ 00055 #pragma warning(disable:4355) // 'this' used in base member initializer list 00056 //#pragma warning(disable:4390) // Empty control statement 00057 //#pragma warning(disable:4505) /* 'function' : unreferenced local function 00058 // * has been removed */ 00059 //#pragma warning(disable:4611) /* interaction between _setjmp and C++ 00060 // * destructors not portable */ 00061 //#pragma warning(disable:4702) // Unreachable Code 00062 //#pragma warning(disable:4706) // Assignment in conditional expression 00063 //#pragma warning(disable:4710) // function not inlined 00064 // #pragma warning(disable:4711) /* function 'function' selected for inline 00065 // * expansion */ 00066 // #pragma warning(disable:4786) /* VC6: identifier was truncated to '255' 00067 // * characters in the browser information */ 00068 // #pragma warning(disable:4800) // Forcing value to bool 00069 //#pragma warning(disable:4805) // unsafe mix of bool and int. 00070 00071 // #pragma warning(default:4265) /* class has virtual functions, but 00072 // * destructor is not virtual */ 00073 00074 #pragma inline_depth (255) 00075 #pragma inline_recursion (on) 00076 #pragma auto_inline (on) 00077 00078 #define CS_FORCEINLINE __forceinline 00079 00080 #pragma intrinsic (memset, memcpy, memcmp) 00081 #pragma intrinsic (strcpy, strcmp, strlen, strcat) 00082 #pragma intrinsic (abs, fabs) 00083 #pragma intrinsic (_byteswap_ushort, _byteswap_ulong, _byteswap_uint64) 00084 00085 #if _MSC_VER >= 1400 00086 /* Work around an apparent incompatibility between VC8's intrin.h and 00087 * the Windows SDK 6.0's winnt.h - _interlockedbittestandset and 00088 * _interlockedbittestandreset have slightly different prototypes. 00089 * Go Microsoft! 00090 */ 00091 #define _interlockedbittestandset workaround_header_bug_1 00092 #define _interlockedbittestandreset workaround_header_bug_2 00093 #include <intrin.h> 00094 #undef _interlockedbittestandset 00095 #undef _interlockedbittestandreset 00096 #else 00097 extern "C" long _InterlockedCompareExchange (long volatile *, long, long); 00098 extern "C" long _InterlockedDecrement (long volatile *); 00099 extern "C" long _InterlockedExchange (long volatile *, long); 00100 extern "C" long _InterlockedIncrement (long volatile *); 00101 #endif 00102 #pragma intrinsic (_InterlockedCompareExchange) 00103 #pragma intrinsic (_InterlockedDecrement) 00104 #pragma intrinsic (_InterlockedExchange) 00105 #pragma intrinsic (_InterlockedIncrement) 00106 00107 #if defined(__CRYSTAL_SPACE__) && !defined(CS_DEBUG) 00108 #pragma code_seg("CSpace") // Just for fun :) 00109 // However, doing this in debug builds prevents Edit & Continue from 00110 // functioning properly :/ 00111 #endif 00112 00113 // VC8 quirks 00114 #if (_MSC_VER >= 1400) 00115 // Also note quirk in csconfig.h 00116 00117 // Nothing else atm. 00118 #endif 00119 #endif 00120 00121 #ifndef WINVER 00122 #define WINVER 0x0400 00123 #endif 00124 00125 // So many things require this. IF you have an issue with something defined 00126 // in it then undef that def here. 00127 00128 #if defined(CS_COMPILER_GCC) 00129 00130 // From the w32api header files: 00131 00132 #if defined(__i686__) && !defined(_M_IX86) 00133 #define _M_IX86 600 00134 #elif defined(__i586__) && !defined(_M_IX86) 00135 #define _M_IX86 500 00136 #elif defined(__i486__) && !defined(_M_IX86) 00137 #define _M_IX86 400 00138 #elif defined(__i386__) && !defined(_M_IX86) 00139 #define _M_IX86 300 00140 #endif 00141 #if defined(_M_IX86) && !defined(_X86_) 00142 #define _X86_ 00143 #endif 00144 00145 #ifdef __GNUC__ 00146 #ifndef NONAMELESSUNION 00147 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) 00148 #define _ANONYMOUS_UNION __extension__ 00149 #define _ANONYMOUS_STRUCT __extension__ 00150 #else 00151 #if defined(__cplusplus) 00152 #define _ANONYMOUS_UNION __extension__ 00153 #endif /* __cplusplus */ 00154 #endif /* __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) */ 00155 #endif /* NONAMELESSUNION */ 00156 #endif /* __GNUC__ */ 00157 00158 #ifndef _ANONYMOUS_UNION 00159 #define _ANONYMOUS_UNION 00160 #define _UNION_NAME(x) x 00161 #define DUMMYUNIONNAME u 00162 #define DUMMYUNIONNAME2 u2 00163 #define DUMMYUNIONNAME3 u3 00164 #define DUMMYUNIONNAME4 u4 00165 #define DUMMYUNIONNAME5 u5 00166 #define DUMMYUNIONNAME6 u6 00167 #define DUMMYUNIONNAME7 u7 00168 #define DUMMYUNIONNAME8 u8 00169 #else 00170 #define _UNION_NAME(x) 00171 #define DUMMYUNIONNAME 00172 #define DUMMYUNIONNAME2 00173 #define DUMMYUNIONNAME3 00174 #define DUMMYUNIONNAME4 00175 #define DUMMYUNIONNAME5 00176 #define DUMMYUNIONNAME6 00177 #define DUMMYUNIONNAME7 00178 #define DUMMYUNIONNAME8 00179 #endif 00180 #ifndef _ANONYMOUS_STRUCT 00181 #define _ANONYMOUS_STRUCT 00182 #define _STRUCT_NAME(x) x 00183 #define DUMMYSTRUCTNAME s 00184 #define DUMMYSTRUCTNAME2 s2 00185 #define DUMMYSTRUCTNAME3 s3 00186 #else 00187 #define _STRUCT_NAME(x) 00188 #define DUMMYSTRUCTNAME 00189 #define DUMMYSTRUCTNAME2 00190 #define DUMMYSTRUCTNAME3 00191 #endif 00192 00193 #else 00194 00195 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && \ 00196 defined(_M_IX86) 00197 #define _X86_ 00198 #endif 00199 00200 #if !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && \ 00201 defined(_M_AMD64) 00202 #define _AMD64_ 00203 #endif 00204 00205 #if !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && \ 00206 defined(_M_IA64) && !defined(_IA64_) 00207 #define _IA64_ 00208 #endif 00209 00210 #endif 00211 00212 #ifndef __CYGWIN32__ 00213 #include <excpt.h> 00214 #endif 00215 #include <stdarg.h> 00216 #include <windef.h> 00217 #include <winbase.h> 00218 #include <malloc.h> 00219 #include <sys/types.h> 00220 #include <sys/stat.h> 00221 #ifdef CS_HAVE_SYS_PARAM_H 00222 #include <sys/param.h> 00223 #endif 00224 #ifndef __CYGWIN32__ 00225 #include <direct.h> 00226 #endif 00227 00228 00229 #ifndef WINGDIAPI 00230 #define WINGDIAPI DECLSPEC_IMPORT 00231 #endif 00232 00233 /* 00234 LONG_PTR is used in the Win32 canvases, but it's only defined in newer 00235 Platform or DirectX SDKs (in BaseTsd.h). 00236 Ergo, on older SDKs, we have to define it ourselves. One indicator for the 00237 presence of LONG_PTR seems to be if the __int3264 macro is #defined. 00238 So, if it's not, we define LONG_PTR. 00239 */ 00240 #ifndef __int3264 00241 typedef LONG LONG_PTR; 00242 typedef ULONG ULONG_PTR; 00243 typedef DWORD DWORD_PTR; 00244 #endif 00245 00246 #if defined(_DEBUG) || defined(CS_DEBUG) 00247 #include <assert.h> 00248 #ifndef CS_DEBUG 00249 #define CS_DEBUG 00250 #endif 00251 00252 #if defined(CS_COMPILER_MSVC) 00253 #include <crtdbg.h> 00254 00255 #if defined(CS_EXTENSIVE_MEMDEBUG) 00256 #define malloc(size) \ 00257 _malloc_dbg ((size), _NORMAL_BLOCK, __FILE__, __LINE__) 00258 #define free(ptr) _free_dbg ((ptr), _NORMAL_BLOCK) 00259 #define realloc(ptr, size) \ 00260 _realloc_dbg ((ptr), (size), _NORMAL_BLOCK, __FILE__, __LINE__) 00261 #define calloc(num, size) \ 00262 _calloc_dbg ((num), (size), _NORMAL_BLOCK, __FILE__, __LINE__) 00263 00264 // heap consistency check is on by default, leave it 00265 #define CS_WIN32_MSVC_DEBUG_GOOP \ 00266 _CrtSetDbgFlag ( \ 00267 _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF) 00268 #else 00269 // turn heap consistency check off 00270 #define CS_WIN32_MSVC_DEBUG_GOOP \ 00271 _CrtSetDbgFlag ( \ 00272 (_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG) & ~_CRTDBG_ALLOC_MEM_DF) | \ 00273 _CRTDBG_LEAK_CHECK_DF) 00274 #endif 00275 #endif 00276 00277 #endif 00278 00279 #ifdef CS_WIN32_MSVC_DEBUG_GOOP 00280 #define CS_INITIALIZE_PLATFORM_APPLICATION CS_WIN32_MSVC_DEBUG_GOOP 00281 #endif 00282 00283 // The 2D graphics driver used by software renderer on this platform 00284 #define CS_SOFTWARE_2D_DRIVER "crystalspace.graphics2d.directdraw" 00285 #define CS_OPENGL_2D_DRIVER "crystalspace.graphics2d.glwin32" 00286 00287 // The sound driver 00288 #define CS_SOUND_DRIVER "crystalspace.sound.driver.waveout" 00289 #define CS_SNDSYS_DRIVER "crystalspace.sndsys.software.driver.directsound" 00290 00291 // SCF symbol export facility. 00292 #ifndef CS_STATIC_LINKED 00293 // No need to export the symbols when statically linking into one big binary. 00294 # undef CS_EXPORTED_FUNCTION 00295 # define CS_EXPORTED_FUNCTION extern "C" __declspec(dllexport) 00296 #endif 00297 00298 #if defined (CS_COMPILER_BCC) 00299 # define strcasecmp stricmp 00300 # define strncasecmp strnicmp 00301 #endif 00302 00303 #if defined (CS_COMPILER_MSVC) 00304 # define strcasecmp _stricmp 00305 # define strncasecmp _strnicmp 00306 #endif 00307 00308 #if defined (CS_COMPILER_MSVC) 00309 # if defined(_MSC_VER) && (_MSC_VER < 1300) 00310 # include <assert.h> 00311 static inline longlong strtoll(char const* s, char** sN, int base) 00312 { 00313 assert(sN == 0); 00314 assert(base == 10); 00315 return _atoi64(s); 00316 } 00317 # else 00318 # define strtoll _strtoi64 00319 # endif 00320 #endif 00321 00322 // Maximal path length 00323 #ifndef CS_MAXPATHLEN 00324 # ifdef _MAX_FNAME 00325 # define CS_MAXPATHLEN _MAX_FNAME 00326 # else 00327 # define CS_MAXPATHLEN 260 /* not 256 */ 00328 # endif 00329 #endif 00330 #define CS_PATH_DELIMITER ';' 00331 #define CS_PATH_SEPARATOR '\\' 00332 00333 #if defined (__CYGWIN32__) 00334 # define CS_MKDIR(path) mkdir(path, 0755) 00335 #else 00336 # define CS_MKDIR(path) _mkdir(path) 00337 #endif 00338 00339 // Directory read functions, file access, etc. 00340 #include <io.h> 00341 #ifndef F_OK 00342 # define F_OK 0 00343 #endif 00344 #ifndef R_OK 00345 # define R_OK 2 00346 #endif 00347 #ifndef W_OK 00348 # define W_OK 4 00349 #endif 00350 00351 #define CS_PROVIDES_EXPAND_PATH 1 00352 inline void csPlatformExpandPath(const char* /*path*/, char* /*buffer*/, 00353 int /*nbuf*/) {} 00354 00355 // Although CS_COMPILER_GCC has opendir(), readdir(), etc., we prefer the CS 00356 // versions of these functions. 00357 #define CS_WIN32_USE_CUSTOM_OPENDIR 00358 00359 #ifndef CS_WIN32_USE_CUSTOM_OPENDIR 00360 # include <dirent.h> 00361 #else 00362 struct dirent 00363 { 00364 char d_name [CS_MAXPATHLEN + 1]; // File name, 0 terminated 00365 size_t d_size; // File size (bytes) 00366 long dwFileAttributes; // File attributes (Windows-specific) 00367 }; 00368 00369 struct DIR; 00370 # ifdef CS_CRYSTALSPACE_LIB 00371 extern "C" CS_EXPORT_SYM DIR *opendir (const char *name); 00372 extern "C" CS_EXPORT_SYM dirent *readdir (DIR *dirp); 00373 extern "C" CS_EXPORT_SYM int closedir (DIR *dirp); 00374 extern "C" CS_EXPORT_SYM bool isdir (const char *path, dirent *de); 00375 # else 00376 extern "C" CS_IMPORT_SYM DIR *opendir (const char *name); 00377 extern "C" CS_IMPORT_SYM dirent *readdir (DIR *dirp); 00378 extern "C" CS_IMPORT_SYM int closedir (DIR *dirp); 00379 extern "C" CS_IMPORT_SYM bool isdir (const char *path, dirent *de); 00380 # endif // CS_BUILD_SHARED_LIBS 00381 #endif 00382 00383 #if defined (CS_COMPILER_BCC) || defined (__CYGWIN32__) 00384 # define GETPID() getpid() 00385 #else 00386 # define GETPID() _getpid() 00387 #endif 00388 00389 #ifdef __CYGWIN32__ 00390 # include <unistd.h> 00391 # define CS_TEMP_FILE "cs%lu.tmp", (unsigned long)getpid() 00392 # define CS_TEMP_DIR "/tmp" 00393 #else 00394 # include <process.h> 00395 # define CS_TEMP_FILE "%x.cs", (int)GETPID() 00396 # define CS_TEMP_DIR win32_tempdir() 00397 // This is the function called by CS_TEMP_DIR macro 00398 static inline char *win32_tempdir() 00399 { 00400 char *tmp; 00401 if ((tmp = getenv ("TMP")) != 0) 00402 return tmp; 00403 if ((tmp = getenv ("TEMP")) != 0) 00404 return tmp; 00405 return ""; 00406 } 00407 #endif 00408 00409 // Microsoft Visual C++ compiler includes a very in-efficient 'memcpy'. 00410 // This also replaces the older 'better_memcpy', which was also not as 00411 // efficient as it could be ergo... heres a better solution. 00412 #if defined(CS_COMPILER_MSVC) && (_MSC_VER < 1300) 00413 #include <memory.h> 00414 #define memcpy fast_mem_copy 00415 static inline void* fast_mem_copy (void *dest, const void *src, int count) 00416 { 00417 __asm 00418 { 00419 mov eax, count 00420 mov esi, src 00421 mov edi, dest 00422 xor ecx, ecx 00423 00424 // Check for 'short' moves 00425 cmp eax, 16 00426 jl do_short 00427 00428 // Move enough bytes to align 'dest' 00429 sub ecx, edi 00430 and ecx, 3 00431 je skip 00432 sub eax, ecx 00433 rep movsb 00434 00435 skip: 00436 mov ecx, eax 00437 and eax, 3 00438 shr ecx, 2 00439 rep movsd 00440 test eax, eax 00441 je end 00442 00443 do_short: 00444 mov ecx, eax 00445 rep movsb 00446 00447 end: 00448 } 00449 00450 return dest; 00451 } 00452 #endif 00453 00454 #ifdef CS_COMPILER_BCC 00455 // Major hack due to pow failures in CS for Borland, removing this 00456 // causes millions of strings to print out -- Brandon Ehle 00457 #define pow(arga, argb) ( (!arga && !argb)?0:pow(arga, argb) ) 00458 // Dunno why this is in CS -- Brandon Ehle 00459 #define DEBUG_BREAK 00460 #endif 00461 00462 #if defined (CS_PROCESSOR_X86) 00463 # define CS_LITTLE_ENDIAN 00464 #else 00465 # error "Please define a suitable CS_XXX_ENDIAN macro in win32/csosdefs.h!" 00466 #endif 00467 00468 #if defined(CS_COMPILER_BCC) 00469 // The Borland C++ compiler does not accept a 'main' routine 00470 // in a program which already contains WinMain. This is a work-around. 00471 #undef main 00472 #define main csMain 00473 #endif 00474 00475 // cygwin has no _beginthread and _endthread functions 00476 #ifdef __CYGWIN32__ 00477 #ifndef _beginthread 00478 #define _beginthread(func, stack, ptr) CreateThread (0, 0, \ 00479 LPTHREAD_START_ROUTINE(func), ptr, CREATE_SUSPENDED, 0) 00480 #endif 00481 #ifndef _endthread 00482 #define _endthread() {} 00483 #endif 00484 #endif 00485 00486 // Fake up setenv(), if necessary 00487 #ifndef CS_HAVE_SETENV 00488 #ifdef CS_CRYSTALSPACE_LIB 00489 CS_EXPORT_SYM int setenv (const char* name, const char* value, 00490 bool overwrite); 00491 #else 00492 CS_IMPORT_SYM int setenv (const char* name, const char* value, 00493 bool overwrite); 00494 #endif 00495 #endif 00496 00497 // just to avoid windows.h inclusion 00498 #define csSW_SHOWNORMAL 1 00499 00500 #if defined(CS_COMPILER_GCC) && defined(__STRICT_ANSI__) 00501 // Need those... 00502 extern int _argc; 00503 extern char** _argv; 00504 #define CS_WIN32_ARGC _argc 00505 #define CS_WIN32_ARGV _argv 00506 #elif defined(CS_COMPILER_BCC) 00507 #define CS_WIN32_ARGC _argc 00508 #define CS_WIN32_ARGV _argv 00509 #else 00510 #define CS_WIN32_ARGC __argc 00511 #define CS_WIN32_ARGV __argv 00512 #endif 00513 00514 00515 #ifdef __CYGWIN32__ 00516 #if !defined(CS_IMPLEMENT_PLATFORM_APPLICATION) 00517 #define CS_IMPLEMENT_PLATFORM_APPLICATION 00518 #endif 00519 00520 #else // __CYGWIN32__ 00521 00522 /* 00523 if the EXE is compiled as a GUI app, 00524 a WinMain is needed. But if compiled 00525 as a console app it's not used but main() is 00526 instead. 00527 */ 00528 00529 #if !defined(CS_IMPLEMENT_PLATFORM_APPLICATION) 00530 #ifndef __STRICT_ANSI__ 00531 #define csMain main 00532 #else 00533 /* Work around "error: ISO C++ forbids taking address of function `::main'" 00534 * when compiling -ansi -pedantic */ 00535 #define csMain mainWithAnotherNameBecauseISOCPPForbidsIt 00536 #endif 00537 #define CS_IMPLEMENT_PLATFORM_APPLICATION \ 00538 int csMain (int argc, char* argv[]); \ 00539 int WINAPI WinMain (HINSTANCE hApp, HINSTANCE prev, LPSTR cmd, int show)\ 00540 { \ 00541 (void)hApp; \ 00542 (void)show; \ 00543 (void)prev; \ 00544 (void)cmd; \ 00545 int ret = csMain (CS_WIN32_ARGC, CS_WIN32_ARGV); \ 00546 return ret; \ 00547 } 00548 #ifdef __STRICT_ANSI__ 00549 #define main mainWithAnotherNameBecauseISOCPPForbidsIt 00550 #endif 00551 #endif // CS_IMPLEMENT_PLATFORM_APPLICATION 00552 00553 #endif // __CYGWIN32__ 00554 00555 #if !defined(CS_STATIC_LINKED) 00556 00557 #if !defined(CS_IMPLEMENT_PLATFORM_PLUGIN) 00558 #define CS_IMPLEMENT_PLATFORM_PLUGIN \ 00559 int _cs_main(int /*argc*/, char* /*argv*/[]) \ 00560 { \ 00561 return 0; \ 00562 } \ 00563 extern "C" BOOL WINAPI \ 00564 DllMain (HINSTANCE /*hinstDLL*/, DWORD /*fdwReason*/, LPVOID /*lpvReserved*/) \ 00565 { \ 00566 return TRUE; \ 00567 } \ 00568 CS_EXPORTED_FUNCTION const char* plugin_compiler() \ 00569 { \ 00570 return CS_COMPILER_NAME; \ 00571 } 00572 #endif // CS_IMPLEMENT_PLATFORM_PLUGIN 00573 00574 #endif // CS_STATIC_LINKED 00575 00576 #include "sanity.inc" 00577 00578 #endif // __CS_CSOSDEFS_H__
Generated for Crystal Space by doxygen 1.4.7