win32.cc: (_Jv_pipe) Implemented.
[gcc.git] / libjava / include / win32.h
1 // win32.h -- Helper functions for Microsoft-flavored OSs.
2
3 /* Copyright (C) 2002, 2003 Free Software Foundation
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 #ifndef __JV_WIN32_H__
12 #define __JV_WIN32_H__
13
14 #define WIN32_LEAN_AND_MEAN
15 #include <windows.h>
16 #undef WIN32_LEAN_AND_MEAN
17 #undef STRICT
18
19 #include <ws2tcpip.h>
20 #include <gcj/cni.h>
21 #include <jvm.h>
22 #include <java/util/Properties.h>
23
24 #include <io.h>
25
26 // Prefix and suffix for shared libraries.
27 #define _Jv_platform_solib_prefix ""
28 #define _Jv_platform_solib_suffix ".dll"
29
30 // Separator for file name components.
31 #define _Jv_platform_file_separator ((jchar) '\\')
32 // Separator for path components.
33 #define _Jv_platform_path_separator ((jchar) ';')
34
35 // List of names for `JNI_OnLoad'. On Win32, JNI_OnLoad is an
36 // "stdcall" function taking two pointers (8 bytes) as arguments. It
37 // could also have been exported as "JNI_OnLoad@8" (MinGW) or
38 // "_JNI_OnLoad@8" (MSVC).
39 #define _Jv_platform_onload_names \
40 { "JNI_OnLoad", "JNI_OnLoad@8", "_JNI_OnLoad@8", NULL }
41
42 // Type of libffi ABI used by JNICALL methods. NOTE: This must agree
43 // with the JNICALL definition in jni.h
44 #define _Jv_platform_ffi_abi FFI_STDCALL
45
46 /* Useful helper classes and methods. */
47
48 /* A C++ wrapper around a WSAEVENT which closes the event
49 in its destructor. If dwSelFlags is non-zero, we also
50 issue an WSAEventSelect on the socket descriptor with
51 the given flags; this is undone by a corresponding call
52 to WSAEventSelect(fd, 0, 0) in our destructor. */
53 class WSAEventWrapper
54 {
55 public:
56 WSAEventWrapper(int fd, DWORD dwSelFlags);
57 ~WSAEventWrapper();
58
59 WSAEVENT getEventHandle()
60 {
61 return m_hEvent;
62 }
63
64 private:
65 WSAEVENT m_hEvent;
66 int m_fd;
67 DWORD m_dwSelFlags;
68 };
69
70 // Error string text. The int argument is compatible
71 // with both int WSAGetLastError() and DWORD GetLastError()
72 // I tried avoiding having to pass the error explicitly, but
73 // it didn't work this was invoked with say
74 // throw new SomeException(_Jv_WinStrError()).
75 extern jstring
76 _Jv_WinStrError (LPCTSTR lpszPrologue, int nErrorCode);
77
78 extern jstring
79 _Jv_WinStrError (int nErrorCode);
80
81 extern void
82 _Jv_ThrowIOException (DWORD dwErrorCode);
83
84 extern void
85 _Jv_ThrowIOException ();
86
87 extern void
88 _Jv_ThrowSocketException (DWORD dwErrorCode);
89
90 extern void
91 _Jv_ThrowSocketException ();
92
93 // Platform implementation
94 extern void _Jv_platform_initialize (void);
95 extern void _Jv_platform_initProperties (java::util::Properties*);
96 extern jlong _Jv_platform_gettimeofday ();
97 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
98 extern int _Jv_pipe (int filedes[2]);
99
100 inline void
101 _Jv_platform_close_on_exec (jint)
102 {
103 // Ignore.
104 }
105
106 #ifdef JV_HASH_SYNCHRONIZATION
107 /* Suspends the execution of the current thread for the specified
108 number of microseconds. Tries to emulate the behaviour of usleep()
109 on UNIX and provides a granularity of 1 millisecond. */
110 inline void
111 _Jv_platform_usleep (unsigned long usecs)
112 {
113 if (usecs > 0UL)
114 {
115 unsigned long millis = ((usecs + 999UL) / 1000UL);
116 Sleep (millis);
117 }
118 }
119 #endif /* JV_HASH_SYNCHRONIZATION */
120
121 /* Store up to SIZE return address of the current program state in
122 ARRAY and return the exact number of values stored. */
123 extern int backtrace (void **__array, int __size);
124
125 #endif /* __JV_WIN32_H__ */