1 /* src/include/port/win32.h */
3 #if defined(_MSC_VER) || defined(__BORLANDC__)
4 #define WIN32_ONLY_COMPILER
8 * Make sure _WIN32_WINNT has the minimum required value.
9 * Leave a higher value in place.
11 #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501
15 #define _WIN32_WINNT 0x0501
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.
25 /* undefine and redefine after #include */
31 * The Mingw64 headers choke if this is already defined - they
32 * define it themselves.
34 #if !defined(__MINGW64_VERSION_MAJOR) || defined(WIN32_ONLY_COMPILER)
46 #include <sys/utime.h> /* for non-unicode version */
50 /* Must be here to avoid conflicting with prototype in windows.h */
51 #define mkdir(a,b) mkdir(a)
53 #define ftruncate(a,b) chsize(a,b)
55 /* Windows doesn't have fsync() as such, use _commit() */
56 #define fsync(fd) _commit(fd)
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()).
63 #define HAVE_FSYNC_WRITETHROUGH
64 #define FSYNC_WRITETHROUGH_IS_FSYNC
68 /* defines for dynamic linking on Win32 platform
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
75 #if defined(WIN32) || defined(__CYGWIN__)
78 #define PGDLLIMPORT __declspec (dllexport)
79 #else /* not BUILDING_DLL */
80 #define PGDLLIMPORT __declspec (dllimport)
84 #define PGDLLEXPORT __declspec (dllexport)
88 #else /* not CYGWIN, not MSVC, not MingW */
97 #undef HAVE_UNION_SEMUN
98 #define HAVE_UNION_SEMUN 1
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
113 #define GETNCNT 16384
115 #define SETVAL 131072
116 #define GETPID 262144
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:
129 * http://msdn2.microsoft.com/en-gb/library/aa489609.aspx
131 * NT_SUCCESS 0 - 0x3FFFFFFF
132 * NT_INFORMATION 0x40000000 - 0x7FFFFFFF
133 * NT_WARNING 0x80000000 - 0xBFFFFFFF
134 * NT_ERROR 0xC0000000 - 0xFFFFFFFF
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:
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
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
151 * http://www.microsoft.com/msj/0197/exception/exception.aspx
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.
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().
166 #define WIFEXITED(w) (((w) & 0XFFFFFF00) == 0)
167 #define WIFSIGNALED(w) (!WIFEXITED(w))
168 #define WEXITSTATUS(w) (w)
169 #define WTERMSIG(w) (w)
171 #define sigmask(sig) ( 1 << ((sig)-1) )
173 /* Signal function return values */
177 #define SIG_DFL ((pqsigfunc)0)
178 #define SIG_ERR ((pqsigfunc)-1)
179 #define SIG_IGN ((pqsigfunc)1)
181 /* Some extra signals */
185 #define SIGABRT 22 /* Set to match W32 value -- not UNIX value */
194 #define SIGTTOU 22 /* Same as SIGABRT -- no problem, I hope */
202 * New versions of mingw have gettimeofday() and also declare
203 * struct timezone to support it.
205 #ifndef HAVE_GETTIMEOFDAY
208 int tz_minuteswest; /* Minutes west of GMT. */
209 int tz_dsttime; /* Nonzero if DST is ever in effect. */
213 /* for setitimer in backend/port/win32/timer.c */
214 #define ITIMER_REAL 0
217 struct timeval it_interval;
218 struct timeval it_value;
221 int setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
224 * WIN32 does not provide 64-bit off_t, but does provide the functions operating
225 * with 64-bit offsets.
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)
233 #define fseeko(stream, offset, origin) fseeko64(stream, offset, origin)
236 #define ftello(stream) ftello64(stream)
241 * Supplement to <sys/types.h>.
243 * Perl already has typedefs for uid_t and gid_t.
245 #ifndef PLPERL_HAVE_UID_GID
251 #ifdef WIN32_ONLY_COMPILER
256 * Supplement to <sys/stat.h>.
258 #define lstat(path, sb) stat((path), (sb))
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.
266 #define O_DSYNC 0x0080
269 * Supplement to <errno.h>.
273 #define EINTR WSAEINTR
274 #define EAGAIN WSAEWOULDBLOCK
276 #define EMSGSIZE WSAEMSGSIZE
278 #define EAFNOSUPPORT WSAEAFNOSUPPORT
280 #define EWOULDBLOCK WSAEWOULDBLOCK
282 #define ECONNRESET WSAECONNRESET
284 #define EINPROGRESS WSAEINPROGRESS
286 #define ENOBUFS WSAENOBUFS
287 #undef EPROTONOSUPPORT
288 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
290 #define ECONNREFUSED WSAECONNREFUSED
292 #define EBADFD WSAENOTSOCK
294 #define EOPNOTSUPP WSAEOPNOTSUPP
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.
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)
317 * Extended locale functions with gratuitous underscore prefixes.
318 * (These APIs are nevertheless fully documented by Microsoft.)
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
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;
355 #define UNBLOCKED_SIGNAL_QUEUE() (pg_signal_queue & ~pg_signal_mask)
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);
363 /* In backend/port/win32/socket.c */
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)
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);
379 const char *pgwin32_socket_strerror(int err);
380 int pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
382 extern int pgwin32_noblock;
384 /* in backend/port/win32/security.c */
385 extern int pgwin32_is_admin(void);
386 extern int pgwin32_is_service(void);
389 /* in backend/port/win32_shmem.c */
390 extern int pgwin32_ReserveSharedMemoryRegion(HANDLE);
392 /* in backend/port/win32/crashdump.c */
393 extern void pgwin32_install_crashdump_handler(void);
395 /* in port/win32error.c */
396 extern void _dosmaperr(unsigned long);
398 /* in port/win32env.c */
399 extern int pgwin32_putenv(const char *);
400 extern void pgwin32_unsetenv(const char *);
402 #define putenv(x) pgwin32_putenv(x)
403 #define unsetenv(x) pgwin32_unsetenv(x)
405 /* Things that exist in MingW headers, but need to be added to MSVC & BCC */
406 #ifdef WIN32_ONLY_COMPILER
409 typedef long ssize_t;
411 typedef __int64 ssize_t;
415 typedef unsigned short mode_t;
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__ */
430 #if (_MSC_VER < 1800)
431 #define isinf(x) ((_fpclass(x) == _FPCLASS_PINF) || (_fpclass(x) == _FPCLASS_NINF))
432 #define isnan(x) _isnan(x)
435 /* Pulled from Makefile.port in mingw */
436 #define DLSUFFIX ".dll"
440 /* for port/dirent.c */
441 #ifndef INVALID_FILE_ATTRIBUTES
442 #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
445 /* for port/open.c */
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 */
456 /* These aren't provided by either MingW or MSVC */
467 #endif /* __BORLANDC__ */