OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

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