1 // win32.cc - Helper functions for Microsoft-flavored OSs.
3 /* Copyright (C) 2002 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
13 #include <sys/timeb.h>
17 #include <java/lang/ArithmeticException.h>
18 #include <java/util/Properties.h>
21 win32_exception_handler (LPEXCEPTION_POINTERS e
)
23 if (e
->ExceptionRecord
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
)
24 _Jv_ThrowNullPointerException();
25 else if (e
->ExceptionRecord
->ExceptionCode
== EXCEPTION_INT_DIVIDE_BY_ZERO
)
26 throw new java::lang::ArithmeticException
;
28 return EXCEPTION_CONTINUE_SEARCH
;
31 // Platform-specific VM initialization.
33 _Jv_platform_initialize (void)
35 // Initialise winsock for networking
37 if (WSAStartup (MAKEWORD (1, 1), &data
))
38 MessageBox (NULL
, "Error initialising winsock library.", "Error",
39 MB_OK
| MB_ICONEXCLAMATION
);
40 // Install exception handler
41 SetUnhandledExceptionFilter (win32_exception_handler
);
44 // gettimeofday implementation.
46 _Jv_platform_gettimeofday ()
50 return t
.time
* 1000LL + t
.millitm
;
53 // The following definitions "fake out" mingw to think that -mthreads
54 // was enabled and that mingwthr.dll was linked. GCJ-compiled
55 // applications don't need this helper library because we can safely
56 // detect thread death (return from Thread.run()).
61 __mingwthr_key_dtor (DWORD
, void (*) (void *))
63 // FIXME: for now we do nothing; this causes a memory leak of
64 // approximately 24 bytes per thread created.
68 // Set platform-specific System properties.
70 _Jv_platform_initProperties (java::util::Properties
* newprops
)
72 // A convenience define.
73 #define SET(Prop,Val) \
74 newprops->put(JvNewStringLatin1 (Prop), JvNewStringLatin1 (Val))
76 SET ("file.separator", "\\");
77 SET ("path.separator", ";");
78 SET ("line.separator", "\r\n");
79 SET ("java.io.tmpdir", GetTempPath ());
81 // Use GetCurrentDirectory to set 'user.dir'.
82 DWORD buflen
= MAX_PATH
;
83 char* buffer
= (char *) malloc (buflen
);
86 if (GetCurrentDirectory (buflen
, buffer
))
87 SET ("user.dir", buffer
);
91 // Use GetUserName to set 'user.name'.
92 buflen
= 257; // UNLEN + 1
93 buffer
= (char *) malloc (buflen
);
96 if (GetUserName (buffer
, &buflen
))
97 SET ("user.name", buffer
);
101 // According to the api documentation for 'GetWindowsDirectory()', the
102 // environmental variable HOMEPATH always specifies the user's home
103 // directory or a default directory. On the 3 windows machines I checked
104 // only 1 had it set. If it's not set, JDK1.3.1 seems to set it to
105 // the windows directory, so we'll do the same.
106 char* userHome
= NULL
;
107 if ((userHome
= ::getenv( "HOMEPATH" )) == NULL
)
109 // Check HOME since it's what I use.
110 if ((userHome
= ::getenv( "HOME" )) == NULL
)
112 // Not found - use the windows directory like JDK1.3.1 does.
113 char* winHome
= (char *)malloc (MAX_PATH
);
114 if ( winHome
!= NULL
)
116 if (GetWindowsDirectory (winHome
, MAX_PATH
))
117 SET ("user.home", winHome
);
122 if( userHome
!= NULL
)
123 SET ("user.home", userHome
);
125 // Get and set some OS info.
127 ZeroMemory (&osvi
, sizeof(OSVERSIONINFO
));
128 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
129 if (GetVersionEx (&osvi
))
131 char *buffer
= (char *) malloc (30);
134 sprintf (buffer
, "%d.%d", (int)osvi
.dwMajorVersion
, (int)osvi
.dwMinorVersion
);
135 SET ("os.version", buffer
);
139 switch (osvi
.dwPlatformId
)
141 case VER_PLATFORM_WIN32_WINDOWS
:
142 if (osvi
.dwMajorVersion
== 4 && osvi
.dwMinorVersion
== 0)
143 SET ("os.name", "Windows 95");
144 else if (osvi
.dwMajorVersion
== 4 && osvi
.dwMinorVersion
== 10)
145 SET ("os.name", "Windows 98");
146 else if (osvi
.dwMajorVersion
== 4 && osvi
.dwMinorVersion
== 90)
147 SET ("os.name", "Windows Me");
149 SET ("os.name", "Windows ??");
152 case VER_PLATFORM_WIN32_NT
:
153 if (osvi
.dwMajorVersion
<= 4 )
154 SET ("os.name", "Windows NT");
155 else if (osvi
.dwMajorVersion
== 5 && osvi
.dwMinorVersion
== 0)
156 SET ("os.name", "Windows 2000");
157 else if (osvi
.dwMajorVersion
== 5 && osvi
.dwMinorVersion
== 1)
158 SET ("os.name", "Windows XP");
160 SET ("os.name", "Windows NT ??");
164 SET ("os.name", "Windows UNKNOWN");
169 // Set the OS architecture.
172 switch( si
.dwProcessorType
)
174 case PROCESSOR_INTEL_386
:
175 SET ("os.arch", "i386");
177 case PROCESSOR_INTEL_486
:
178 SET ("os.arch", "i486");
180 case PROCESSOR_INTEL_PENTIUM
:
181 SET ("os.arch", "i586");
183 case PROCESSOR_MIPS_R4000
:
184 SET ("os.arch", "MIPS4000");
186 case PROCESSOR_ALPHA_21064
:
187 SET ("os.arch", "ALPHA");
190 SET ("os.arch", "unknown");