OSDN Git Service

rebuid:
[eos/hostdependX86MAC64.git] / util / X86MAC64 / include / postgresql / server / port / win32.h
1 /* src/include/port/win32.h */
2
3 #if defined(_MSC_VER) || defined(__BORLANDC__)
4 #define WIN32_ONLY_COMPILER
5 #endif
6
7 /*
8  * Make sure _WIN32_WINNT has the minimum required value.
9  * Leave a higher value in place.
10 */
11 #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501
12 #undef _WIN32_WINNT
13 #endif
14 #ifndef _WIN32_WINNT
15 #define _WIN32_WINNT 0x0501
16 #endif
17 /*
18  * Always build with SSPI support. Keep it as a #define in case
19  * we want a switch to disable it sometime in the future.
20  */
21 #ifndef __BORLANDC__
22 #define ENABLE_SSPI 1
23 #endif
24
25 /* undefine and redefine after #include */
26 #undef mkdir
27
28 #undef ERROR
29
30 /*
31  * The Mingw64 headers choke if this is already defined - they
32  * define it themselves.
33  */
34 #if !defined(__MINGW64_VERSION_MAJOR) || defined(WIN32_ONLY_COMPILER)
35 #define _WINSOCKAPI_
36 #endif
37 #include <winsock2.h>
38 #include <ws2tcpip.h>
39 #include <windows.h>
40 #undef small
41 #include <process.h>
42 #include <signal.h>
43 #include <errno.h>
44 #include <direct.h>
45 #ifndef __BORLANDC__
46 #include <sys/utime.h>                  /* for non-unicode version */
47 #endif
48 #undef near
49
50 /* Must be here to avoid conflicting with prototype in windows.h */
51 #define mkdir(a,b)      mkdir(a)
52
53 #define ftruncate(a,b)  chsize(a,b)
54
55 /* Windows doesn't have fsync() as such, use _commit() */
56 #define fsync(fd) _commit(fd)
57
58 /*
59  * For historical reasons, we allow setting wal_sync_method to
60  * fsync_writethrough on Windows, even though it's really identical to fsync
61  * (both code paths wind up at _commit()).
62  */
63 #define HAVE_FSYNC_WRITETHROUGH
64 #define FSYNC_WRITETHROUGH_IS_FSYNC
65
66 #define USES_WINSOCK
67
68 /* defines for dynamic linking on Win32 platform
69  *
70  *      http://support.microsoft.com/kb/132044
71  *      http://msdn.microsoft.com/en-us/library/8fskxacy(v=vs.80).aspx
72  *      http://msdn.microsoft.com/en-us/library/a90k134d(v=vs.80).aspx
73  */
74
75 #if defined(WIN32) || defined(__CYGWIN__)
76
77 #ifdef BUILDING_DLL
78 #define PGDLLIMPORT __declspec (dllexport)
79 #else                                                   /* not BUILDING_DLL */
80 #define PGDLLIMPORT __declspec (dllimport)
81 #endif
82
83 #ifdef _MSC_VER
84 #define PGDLLEXPORT __declspec (dllexport)
85 #else
86 #define PGDLLEXPORT
87 #endif
88 #else                                                   /* not CYGWIN, not MSVC, not MingW */
89 #define PGDLLIMPORT
90 #define PGDLLEXPORT
91 #endif
92
93
94 /*
95  *      IPC defines
96  */
97 #undef HAVE_UNION_SEMUN
98 #define HAVE_UNION_SEMUN 1
99
100 #define IPC_RMID 256
101 #define IPC_CREAT 512
102 #define IPC_EXCL 1024
103 #define IPC_PRIVATE 234564
104 #define IPC_NOWAIT      2048
105 #define IPC_STAT 4096
106
107 #define EACCESS 2048
108 #ifndef EIDRM
109 #define EIDRM 4096
110 #endif
111
112 #define SETALL 8192
113 #define GETNCNT 16384
114 #define GETVAL 65536
115 #define SETVAL 131072
116 #define GETPID 262144
117
118
119 /*
120  *      Signal stuff
121  *
122  *      For WIN32, there is no wait() call so there are no wait() macros
123  *      to interpret the return value of system().  Instead, system()
124  *      return values < 0x100 are used for exit() termination, and higher
125  *      values are used to indicated non-exit() termination, which is
126  *      similar to a unix-style signal exit (think SIGSEGV ==
127  *      STATUS_ACCESS_VIOLATION).  Return values are broken up into groups:
128  *
129  *      http://msdn2.microsoft.com/en-gb/library/aa489609.aspx
130  *
131  *              NT_SUCCESS                      0 - 0x3FFFFFFF
132  *              NT_INFORMATION          0x40000000 - 0x7FFFFFFF
133  *              NT_WARNING                      0x80000000 - 0xBFFFFFFF
134  *              NT_ERROR                        0xC0000000 - 0xFFFFFFFF
135  *
136  *      Effectively, we don't care on the severity of the return value from
137  *      system(), we just need to know if it was because of exit() or generated
138  *      by the system, and it seems values >= 0x100 are system-generated.
139  *      See this URL for a list of WIN32 STATUS_* values:
140  *
141  *              Wine (URL used in our error messages) -
142  *                      http://source.winehq.org/source/include/ntstatus.h
143  *              Descriptions - http://www.comp.nus.edu.sg/~wuyongzh/my_doc/ntstatus.txt
144  *              MS SDK - http://www.nologs.com/ntstatus.html
145  *
146  *      It seems the exception lists are in both ntstatus.h and winnt.h, but
147  *      ntstatus.h has a more comprehensive list, and it only contains
148  *      exception values, rather than winnt, which contains lots of other
149  *      things:
150  *
151  *              http://www.microsoft.com/msj/0197/exception/exception.aspx
152  *
153  *              The ExceptionCode parameter is the number that the operating system
154  *              assigned to the exception. You can see a list of various exception codes
155  *              in WINNT.H by searching for #defines that start with "STATUS_". For
156  *              example, the code for the all-too-familiar STATUS_ACCESS_VIOLATION is
157  *              0xC0000005. A more complete set of exception codes can be found in
158  *              NTSTATUS.H from the Windows NT DDK.
159  *
160  *      Some day we might want to print descriptions for the most common
161  *      exceptions, rather than printing an include file name.  We could use
162  *      RtlNtStatusToDosError() and pass to FormatMessage(), which can print
163  *      the text of error values, but MinGW does not support
164  *      RtlNtStatusToDosError().
165  */
166 #define WIFEXITED(w)    (((w) & 0XFFFFFF00) == 0)
167 #define WIFSIGNALED(w)  (!WIFEXITED(w))
168 #define WEXITSTATUS(w)  (w)
169 #define WTERMSIG(w)             (w)
170
171 #define sigmask(sig) ( 1 << ((sig)-1) )
172
173 /* Signal function return values */
174 #undef SIG_DFL
175 #undef SIG_ERR
176 #undef SIG_IGN
177 #define SIG_DFL ((pqsigfunc)0)
178 #define SIG_ERR ((pqsigfunc)-1)
179 #define SIG_IGN ((pqsigfunc)1)
180
181 /* Some extra signals */
182 #define SIGHUP                          1
183 #define SIGQUIT                         3
184 #define SIGTRAP                         5
185 #define SIGABRT                         22      /* Set to match W32 value -- not UNIX value */
186 #define SIGKILL                         9
187 #define SIGPIPE                         13
188 #define SIGALRM                         14
189 #define SIGSTOP                         17
190 #define SIGTSTP                         18
191 #define SIGCONT                         19
192 #define SIGCHLD                         20
193 #define SIGTTIN                         21
194 #define SIGTTOU                         22      /* Same as SIGABRT -- no problem, I hope */
195 #define SIGWINCH                        28
196 #ifndef __BORLANDC__
197 #define SIGUSR1                         30
198 #define SIGUSR2                         31
199 #endif
200
201 /*
202  * New versions of mingw have gettimeofday() and also declare
203  * struct timezone to support it.
204  */
205 #ifndef HAVE_GETTIMEOFDAY
206 struct timezone
207 {
208         int                     tz_minuteswest; /* Minutes west of GMT.  */
209         int                     tz_dsttime;             /* Nonzero if DST is ever in effect.  */
210 };
211 #endif
212
213 /* for setitimer in backend/port/win32/timer.c */
214 #define ITIMER_REAL 0
215 struct itimerval
216 {
217         struct timeval it_interval;
218         struct timeval it_value;
219 };
220
221 int                     setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
222
223 /*
224  * WIN32 does not provide 64-bit off_t, but does provide the functions operating
225  * with 64-bit offsets.
226  */
227 #define pgoff_t __int64
228 #ifdef WIN32_ONLY_COMPILER
229 #define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin)
230 #define ftello(stream) _ftelli64(stream)
231 #else
232 #ifndef fseeko
233 #define fseeko(stream, offset, origin) fseeko64(stream, offset, origin)
234 #endif
235 #ifndef ftello
236 #define ftello(stream) ftello64(stream)
237 #endif
238 #endif
239
240 /*
241  * Supplement to <sys/types.h>.
242  *
243  * Perl already has typedefs for uid_t and gid_t.
244  */
245 #ifndef PLPERL_HAVE_UID_GID
246 typedef int uid_t;
247 typedef int gid_t;
248 #endif
249 typedef long key_t;
250
251 #ifdef WIN32_ONLY_COMPILER
252 typedef int pid_t;
253 #endif
254
255 /*
256  * Supplement to <sys/stat.h>.
257  */
258 #define lstat(path, sb) stat((path), (sb))
259
260 /*
261  * Supplement to <fcntl.h>.
262  * This is the same value as _O_NOINHERIT in the MS header file. This is
263  * to ensure that we don't collide with a future definition. It means
264  * we cannot use _O_NOINHERIT ourselves.
265  */
266 #define O_DSYNC 0x0080
267
268 /*
269  * Supplement to <errno.h>.
270  */
271 #undef EAGAIN
272 #undef EINTR
273 #define EINTR WSAEINTR
274 #define EAGAIN WSAEWOULDBLOCK
275 #undef EMSGSIZE
276 #define EMSGSIZE WSAEMSGSIZE
277 #undef EAFNOSUPPORT
278 #define EAFNOSUPPORT WSAEAFNOSUPPORT
279 #undef EWOULDBLOCK
280 #define EWOULDBLOCK WSAEWOULDBLOCK
281 #undef ECONNRESET
282 #define ECONNRESET WSAECONNRESET
283 #undef EINPROGRESS
284 #define EINPROGRESS WSAEINPROGRESS
285 #undef ENOBUFS
286 #define ENOBUFS WSAENOBUFS
287 #undef EPROTONOSUPPORT
288 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
289 #undef ECONNREFUSED
290 #define ECONNREFUSED WSAECONNREFUSED
291 #undef EBADFD
292 #define EBADFD WSAENOTSOCK
293 #undef EOPNOTSUPP
294 #define EOPNOTSUPP WSAEOPNOTSUPP
295
296 /*
297  * For Microsoft Visual Studio 2010 and above we intentionally redefine
298  * the regular Berkeley error constants and set them to the WSA constants.
299  * Note that this will break if those constants are used for anything else
300  * than Windows Sockets errors.
301  */
302 #if _MSC_VER >= 1600
303 #pragma warning(disable:4005)
304 #define EMSGSIZE WSAEMSGSIZE
305 #define EAFNOSUPPORT WSAEAFNOSUPPORT
306 #define EWOULDBLOCK WSAEWOULDBLOCK
307 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
308 #define ECONNRESET WSAECONNRESET
309 #define EINPROGRESS WSAEINPROGRESS
310 #define ENOBUFS WSAENOBUFS
311 #define ECONNREFUSED WSAECONNREFUSED
312 #define EOPNOTSUPP WSAEOPNOTSUPP
313 #pragma warning(default:4005)
314 #endif
315
316 /*
317  * Extended locale functions with gratuitous underscore prefixes.
318  * (These APIs are nevertheless fully documented by Microsoft.)
319  */
320 #define locale_t _locale_t
321 #define tolower_l _tolower_l
322 #define toupper_l _toupper_l
323 #define towlower_l _towlower_l
324 #define towupper_l _towupper_l
325 #define isdigit_l _isdigit_l
326 #define iswdigit_l _iswdigit_l
327 #define isalpha_l _isalpha_l
328 #define iswalpha_l _iswalpha_l
329 #define isalnum_l _isalnum_l
330 #define iswalnum_l _iswalnum_l
331 #define isupper_l _isupper_l
332 #define iswupper_l _iswupper_l
333 #define islower_l _islower_l
334 #define iswlower_l _iswlower_l
335 #define isgraph_l _isgraph_l
336 #define iswgraph_l _iswgraph_l
337 #define isprint_l _isprint_l
338 #define iswprint_l _iswprint_l
339 #define ispunct_l _ispunct_l
340 #define iswpunct_l _iswpunct_l
341 #define isspace_l _isspace_l
342 #define iswspace_l _iswspace_l
343 #define strcoll_l _strcoll_l
344 #define wcscoll_l _wcscoll_l
345 #define wcstombs_l _wcstombs_l
346 #define mbstowcs_l _mbstowcs_l
347
348
349 /* In backend/port/win32/signal.c */
350 extern PGDLLIMPORT volatile int pg_signal_queue;
351 extern PGDLLIMPORT int pg_signal_mask;
352 extern HANDLE pgwin32_signal_event;
353 extern HANDLE pgwin32_initial_signal_pipe;
354
355 #define UNBLOCKED_SIGNAL_QUEUE()        (pg_signal_queue & ~pg_signal_mask)
356
357
358 void            pgwin32_signal_initialize(void);
359 HANDLE          pgwin32_create_signal_listener(pid_t pid);
360 void            pgwin32_dispatch_queued_signals(void);
361 void            pg_queue_signal(int signum);
362
363 /* In backend/port/win32/socket.c */
364 #ifndef FRONTEND
365 #define socket(af, type, protocol) pgwin32_socket(af, type, protocol)
366 #define accept(s, addr, addrlen) pgwin32_accept(s, addr, addrlen)
367 #define connect(s, name, namelen) pgwin32_connect(s, name, namelen)
368 #define select(n, r, w, e, timeout) pgwin32_select(n, r, w, e, timeout)
369 #define recv(s, buf, len, flags) pgwin32_recv(s, buf, len, flags)
370 #define send(s, buf, len, flags) pgwin32_send(s, buf, len, flags)
371
372 SOCKET          pgwin32_socket(int af, int type, int protocol);
373 SOCKET          pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
374 int                     pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
375 int                     pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
376 int                     pgwin32_recv(SOCKET s, char *buf, int len, int flags);
377 int                     pgwin32_send(SOCKET s, const void *buf, int len, int flags);
378
379 const char *pgwin32_socket_strerror(int err);
380 int                     pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
381
382 extern int      pgwin32_noblock;
383
384 /* in backend/port/win32/security.c */
385 extern int      pgwin32_is_admin(void);
386 extern int      pgwin32_is_service(void);
387 #endif
388
389 /* in backend/port/win32_shmem.c */
390 extern int      pgwin32_ReserveSharedMemoryRegion(HANDLE);
391
392 /* in backend/port/win32/crashdump.c */
393 extern void pgwin32_install_crashdump_handler(void);
394
395 /* in port/win32error.c */
396 extern void _dosmaperr(unsigned long);
397
398 /* in port/win32env.c */
399 extern int      pgwin32_putenv(const char *);
400 extern void pgwin32_unsetenv(const char *);
401
402 #define putenv(x) pgwin32_putenv(x)
403 #define unsetenv(x) pgwin32_unsetenv(x)
404
405 /* Things that exist in MingW headers, but need to be added to MSVC & BCC */
406 #ifdef WIN32_ONLY_COMPILER
407
408 #ifndef _WIN64
409 typedef long ssize_t;
410 #else
411 typedef __int64 ssize_t;
412 #endif
413
414 #ifndef __BORLANDC__
415 typedef unsigned short mode_t;
416
417 #define S_IRUSR _S_IREAD
418 #define S_IWUSR _S_IWRITE
419 #define S_IXUSR _S_IEXEC
420 #define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
421 /* see also S_IRGRP etc below */
422 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
423 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
424 #endif   /* __BORLANDC__ */
425
426 #define F_OK 0
427 #define W_OK 2
428 #define R_OK 4
429
430 #if (_MSC_VER < 1800)
431 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
432 #define isnan(x) _isnan(x)
433 #endif
434
435 /* Pulled from Makefile.port in mingw */
436 #define DLSUFFIX ".dll"
437
438 #ifdef __BORLANDC__
439
440 /* for port/dirent.c */
441 #ifndef INVALID_FILE_ATTRIBUTES
442 #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
443 #endif
444
445 /* for port/open.c */
446 #ifndef O_RANDOM
447 #define O_RANDOM                0x0010  /* File access is primarily random */
448 #define O_SEQUENTIAL    0x0020  /* File access is primarily sequential */
449 #define O_TEMPORARY             0x0040  /* Temporary file bit */
450 #define O_SHORT_LIVED   0x1000  /* Temporary storage file, try not to flush */
451 #define _O_SHORT_LIVED  O_SHORT_LIVED
452 #endif   /* ifndef O_RANDOM */
453 #endif   /* __BORLANDC__ */
454 #endif   /* WIN32_ONLY_COMPILER */
455
456 /* These aren't provided by either MingW or MSVC */
457 #ifndef __BORLANDC__
458 #define S_IRGRP 0
459 #define S_IWGRP 0
460 #define S_IXGRP 0
461 #define S_IRWXG 0
462 #define S_IROTH 0
463 #define S_IWOTH 0
464 #define S_IXOTH 0
465 #define S_IRWXO 0
466
467 #endif   /* __BORLANDC__ */