root/opal/win32/win_compat.h

/* [<][>][^][v][top][bottom][index][help] */
   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2006 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2009 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2014 Cisco Systems, Inc.  All rights reserved.
  13  * $COPYRIGHT$
  14  *
  15  * Additional copyrights may follow
  16  *
  17  * $HEADER$
  18  */
  19 
  20 #ifndef OPAL_WIN_COMPAT_H
  21 #define OPAL_WIN_COMPAT_H
  22 
  23 /**
  24  * don't complain about all the deprecated functions.
  25  */
  26 #define _CRT_SECURE_NO_DEPRECATE
  27 
  28 /**
  29  * Allow usage of some recent functions (such as SwitchToThread)
  30  *  0x0400 - for SwitchToThread
  31  *  0x0500 - for using Event Objects
  32  */
  33 #define _WIN32_WINNT 0x0502
  34 
  35 /**
  36  * Windows does not define the exact same names in stat.h
  37  * Redefine them to our names.
  38  * Supposedly, links are not available
  39  */
  40 #define S_IFLNK        0xFFFF          /* identifies the file as a symbolic link */
  41 #define S_IXUSR        _S_IEXEC        /* execute/search permission, owner */
  42 #define S_IRUSR        _S_IREAD        /* read permission, owner */
  43 #define S_IWUSR        _S_IWRITE       /* write permission, owner */
  44 
  45 /**
  46  * Define it in order to get access to the "secure" version of rand.
  47  */
  48 #define _CRT_RAND_S
  49 
  50 /* It is always better to include windows.h with the lean and mean option.
  51    So, include it with that option and then include some which are required.
  52    Note: this file is included only on windows */
  53 
  54 #ifndef WIN32_LEAN_AND_MEAN
  55 #define WIN32_LEAN_AND_MEAN
  56 #endif  /* WIN32_LEAN_AND_MEAN */
  57 #ifndef VC_EXTRALEAN
  58 #define VC_EXTRALEAN
  59 #endif  /* VC_EXTRALEAN */
  60 #include <windows.h>
  61 
  62 /* FD_SETSIZE determines how many sockets windows can select() on. If not defined
  63    before including winsock2.h, it is defined to be 64. We are going to go ahead and
  64    make it 1024 for now. PLEASE CHECK IF THIS IS RIGHT */
  65 #define FD_SETSIZE 1024
  66 
  67 /* other utility header files */
  68 #include <shellapi.h>
  69 #include <winsock2.h>
  70 #include <ws2tcpip.h>
  71 #include <process.h>
  72 #include <signal.h>
  73 #include <conio.h>
  74 #include <fcntl.h>
  75 #include <stdint.h>
  76 
  77 /**
  78  * For all file io operations
  79  */
  80 #include <direct.h>
  81 #include <io.h>
  82 
  83 #include <stdlib.h>
  84 /* for alloca */
  85 #include <malloc.h>
  86 
  87 
  88 #define STDIN_FILENO  0
  89 #define STDOUT_FILENO 1
  90 #define STDERR_FILENO 2
  91 typedef unsigned short mode_t;
  92 typedef long ssize_t;
  93 typedef DWORD in_port_t;
  94 typedef char* caddr_t;
  95 typedef unsigned int uint;
  96 
  97 #ifndef WIN32_LEAN_AND_MEAN
  98 #define WIN32_LEAN_AND_MEAN
  99 #endif
 100 
 101 #ifdef _MSC_VER
 102 #if defined(OMPI_BUILDING) && OMPI_BUILDING
 103 #include "opal/win32/opal_uio.h"
 104 #include "opal/win32/opal_time.h"
 105 #include "opal/win32/opal_utsname.h"
 106 #include "opal/win32/opal_util.h"
 107 #include "opal/win32/opal_misc.h"
 108 #include "opal/win32/opal_inet.h"
 109 #include "opal/win32/opal_socket.h"
 110 #endif
 111 
 112 /* Defines for the access functions */
 113 #define F_OK  0x00
 114 #define R_OK  0x04
 115 #define W_OK  0x02
 116 #define X_OK  R_OK  /* no execution right on Windows */
 117 #define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
 118 
 119 
 120 /**
 121  * Microsoft compiler complain about non conformance of the default UNIX function.
 122  * Non conformance to the POSIX standard, and they suggest to use the version
 123  * starting with an _ instead. So, in order to keep cl.exe happy (and quiet) we can
 124  * use the followings defines.
 125  */
 126 #define getpid                    _getpid
 127 #define strdup                    _strdup
 128 #define putenv                    _putenv
 129 #define getcwd                    _getcwd
 130 #define rmdir                     _rmdir
 131 #define chdir                     _chdir
 132 #define chmod                     _chmod
 133 #define access                    _access
 134 #define open                      _open
 135 #define close                     _close
 136 #define unlink                    _unlink
 137 #define dup2                      _dup2
 138 #define dup                       _dup
 139 #define write                     _write
 140 #define read                      _read
 141 #define fileno                    _fileno
 142 #define isatty                    _isatty
 143 #define execvp                    _execvp
 144 #define S_ISDIR(STAT_MODE)        ((STAT_MODE) & _S_IFDIR)
 145 #define S_ISREG(STAT_MODE)        ((STAT_MODE) & _S_IFREG)
 146 #define strncasecmp               _strnicmp
 147 #define strcasecmp                _stricmp
 148 #define umask                     _umask
 149 #define getch                     _getch
 150 #define random                    rand
 151 #define strtok_r                  strtok_s
 152 #define srand48                   srand
 153 #define lrand48                   rand
 154 #define usleep(t)                 Sleep(t/1000)
 155 #define posix_memalign(p, a, s)   *p=_aligned_malloc(s,a)
 156 
 157 #else
 158 
 159 #undef WSABASEERR
 160 /* in MinGW, PACKED is defined to __attribute__((packed)), will have problem for our basic types */
 161 #undef PACKED
 162 #define pthread_atfork
 163 #include <winsock.h>
 164 #if defined(OMPI_BUILDING) && OMPI_BUILDING
 165 #include "opal/win32/opal_uio.h"
 166 #include "opal/win32/opal_utsname.h"
 167 #include "opal/win32/opal_util.h"
 168 #include "opal/win32/opal_inet.h"
 169 #include "opal/win32/opal_misc.h"
 170 #include "opal/win32/opal_socket.h"
 171 #endif
 172 
 173 #define strtok_r(s,d,p)           *p = strtok(s,d)
 174 
 175 #endif
 176 
 177 #define MAXPATHLEN _MAX_PATH
 178 #define MAXHOSTNAMELEN _MAX_PATH
 179 #define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1)
 180 #define PATH_MAX _MAX_PATH
 181 #define WTERMSIG(EXIT_CODE)    (1)
 182 #define WIFEXITED(EXIT_CODE)   (1)
 183 #define WEXITSTATUS(EXIT_CODE) (EXIT_CODE)
 184 #define WIFSIGNALED(EXIT_CODE) (0)
 185 #define WIFSTOPPED(EXIT_CODE)  (0)
 186 #define WSTOPSIG(EXIT_CODE)    (11)
 187 
 188 #define mkdir(PATH, MODE)         _mkdir((PATH))
 189 #define nanosleep(tp, rem)        Sleep(*tp.tv_sec*1000+*tp.tv_nsec/1000000)
 190 #define pipe(array_fd)            _pipe(array_fd, 1024, O_BINARY )
 191 #define inet_ntop                 opal_inet_ntop
 192 #define inet_pton                 opal_inet_pton
 193 #define lstat                     stat
 194 
 195 #ifndef UINT64_MAX
 196 #define UINT64_MAX            0xffffffffffffffffULL  /* 18446744073709551615ULL */
 197 #endif
 198 #ifndef UINT64_MIN
 199 #define UINT64_MIN            0
 200 #endif
 201 #ifndef INT64_MAX
 202 #define INT64_MAX             0x7fffffffffffffffLL  /*9223372036854775807LL*/
 203 #endif
 204 #ifndef INT64_MIN
 205 #define INT64_MIN             (-0x7fffffffffffffffLL - 1)  /* (-9223372036854775807 - 1) */
 206 #endif
 207 #ifndef UINT32_MAX
 208 #define UINT32_MAX            0xffffffff  /* 4294967295U */
 209 #endif
 210 #ifndef UINT32_MIN
 211 #define UINT32_MIN            0
 212 #endif
 213 #ifndef INT32_MAX
 214 #define INT32_MAX             0x7fffffff  /* 2147483647 */
 215 #endif
 216 #ifndef INT32_MIN
 217 #define INT32_MIN             (-0x7fffffff - 1)  /* (-2147483647 - 1) */
 218 #endif
 219 #ifndef UINT16_MAX
 220 #define UINT16_MAX            0xffff  /* 65535U */
 221 #endif
 222 #ifndef UINT16_MIN
 223 #define UINT16_MIN            0
 224 #endif
 225 #ifndef INT16_MAX
 226 #define INT16_MAX             0x7fff  /* 32767 */
 227 #endif
 228 #ifndef INT16_MIN
 229 #define INT16_MIN             (-0x7fff - 1)  /* (-32768) */
 230 #endif
 231 #ifndef UINT8_MAX
 232 #define UINT8_MAX             0xff  /* 255U */
 233 #endif
 234 #ifndef UINT8_MIN
 235 #define UINT8_MIN             0
 236 #endif
 237 #ifndef INT8_MAX
 238 #define INT8_MAX             0x7f  /* 127 */
 239 #endif
 240 #ifndef INT8_MIN
 241 #define INT8_MIN             (-0x7f - 1)  /* (-128) */
 242 #endif
 243 
 244 /* Make sure we let the compiler know that we support __func__ */
 245 #if !defined(HAVE_DECL___FUNC__)
 246 #define HAVE_DECL___FUNC__ 1
 247 #endif
 248 
 249 /*#define sprintf sprintf_s*/
 250 
 251 /* Ugly signal mapping since windows doesn't support the full spectrum
 252  * just a very small subset... :/
 253  * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_raise.asp
 254  * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnucmg/html/UCMGch09.asp
 255  */
 256 #define SIGHUP    1
 257 /* 2 is used for SIGINT on windows */
 258 #define SIGQUIT   3
 259 /* 4 is used for SIGILL on windows */
 260 #define SIGTRAP   5
 261 #define SIGIOT    6
 262 #define SIGBUS    7
 263 /* 8 is used for SIGFPE on windows */
 264 #define SIGKILL   9
 265 #define SIGUSR1   10
 266 /* 11 is used for SIGSEGV on windows */
 267 #define SIGUSR2   12
 268 #define SIGPIPE   13
 269 #define SIGALRM   14
 270 /* 15 is used for SIGTERM on windows */
 271 #define SIGSTKFLT 16
 272 #define SIGCHLD   17
 273 #define SIGCONT   18
 274 #define SIGSTOP   19
 275 #define SIGTSTP   20
 276 /* 21 is used for SIGBREAK on windows */
 277 /* 22 is used for SIGABRT on windows */
 278 #define SIGTTIN   23
 279 #define SIGTTOU   24
 280 #define SIGURG    25
 281 #define SIGXCPU   26
 282 #define SIGXFSZ   27
 283 #define SIGVTALRM 28
 284 #define SIGPROF   29
 285 #define SIGWINCH  30
 286 #define SIGIO     31
 287 
 288 /* Note:
 289  *   The two defines below are likely to break the orte_wait
 290  *   functionality. The proper method of replacing these bits
 291  *   of functionality is left for further investigated.
 292  */
 293 #define WUNTRACED 0
 294 #define WNOHANG   0
 295 
 296 #define sigset_t int
 297 #define in_addr_t uint32_t
 298 
 299 /* Need to define _Bool here for different version of VS.
 300    The definition in opal_config_bottom.h won't help,
 301    as long as we have a mixed C and C++ projects in one solution. */
 302 #if defined(_MSC_VER) && _MSC_VER < 1600
 303 #define _Bool BOOL
 304 #else
 305 #define _Bool bool
 306 #endif
 307 
 308 /*
 309  * No syslog.h on Windows, but these have to be defined somehow.
 310  * There could also be a notifier component later for Windows.
 311  */
 312 #define LOG_EMERG   0
 313 #define LOG_ALERT   1
 314 #define LOG_CRIT    2
 315 #define LOG_ERR     3
 316 #define LOG_WARNING 4
 317 #define LOG_NOTICE  5
 318 #define LOG_INFO    6
 319 #define LOG_DEBUG   7
 320 
 321 
 322 /*
 323  * Mask these to Windows equivalents
 324  */
 325 #define bzero(p, l) memset(p, 0, l)
 326 #define bcopy(s, t, l) memmove(t, s, l)
 327 #define isblank(c) (c == ' ' || c == '\t')?1:0
 328 
 329 /*
 330  * OMPI functions that need to be redefined.
 331  */
 332 #define ompi_debugger_notify_abort(x)
 333 #define ompi_wait_for_debugger(x)
 334 
 335 
 336 #endif /* compat */

/* [<][>][^][v][top][bottom][index][help] */