]> gcc.gnu.org Git - gcc.git/blame - libjava/win32.cc
unwind-c.c: Define NO_SIZE_OF_ENCODED_VALUE.
[gcc.git] / libjava / win32.cc
CommitLineData
b8fe3c1e
AM
1// win32.cc - Helper functions for Microsoft-flavored OSs.
2
a191802c 3/* Copyright (C) 2002, 2003 Free Software Foundation
b8fe3c1e
AM
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11#include <config.h>
a191802c 12#include <platform.h>
1febeb40 13#include <jvm.h>
8eeda6e0 14#include <sys/timeb.h>
455cd615 15#include <stdlib.h>
b8fe3c1e 16
1febeb40 17#include <java/lang/ArithmeticException.h>
455cd615 18#include <java/util/Properties.h>
73272ce6
TT
19
20static LONG CALLBACK
b8fe3c1e
AM
21win32_exception_handler (LPEXCEPTION_POINTERS e)
22{
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;
27 else
28 return EXCEPTION_CONTINUE_SEARCH;
29}
73272ce6 30
c068c638
AH
31// Platform-specific executable name
32static char exec_name[MAX_PATH];
33 // initialized in _Jv_platform_initialize()
34
35const char *_Jv_ThisExecutable (void)
36{
37 return exec_name;
38}
39
73272ce6
TT
40// Platform-specific VM initialization.
41void
42_Jv_platform_initialize (void)
43{
44 // Initialise winsock for networking
45 WSADATA data;
46 if (WSAStartup (MAKEWORD (1, 1), &data))
47 MessageBox (NULL, "Error initialising winsock library.", "Error",
48 MB_OK | MB_ICONEXCLAMATION);
c068c638 49
73272ce6
TT
50 // Install exception handler
51 SetUnhandledExceptionFilter (win32_exception_handler);
c068c638
AH
52
53 // Initialize our executable name
54 GetModuleFileName(NULL, exec_name, sizeof(exec_name));
73272ce6 55}
b32d2321
AM
56
57// gettimeofday implementation.
8eeda6e0
AM
58jlong
59_Jv_platform_gettimeofday ()
b32d2321 60{
8eeda6e0
AM
61 struct timeb t;
62 ftime (&t);
bb0774f3 63 return t.time * 1000LL + t.millitm;
b32d2321
AM
64}
65
9268f1c0
AM
66// The following definitions "fake out" mingw to think that -mthreads
67// was enabled and that mingwthr.dll was linked. GCJ-compiled
68// applications don't need this helper library because we can safely
69// detect thread death (return from Thread.run()).
70
71int _CRT_MT = 1;
72
73extern "C" int
74__mingwthr_key_dtor (DWORD, void (*) (void *))
75{
76 // FIXME: for now we do nothing; this causes a memory leak of
77 // approximately 24 bytes per thread created.
78 return 0;
79}
455cd615
AK
80
81// Set platform-specific System properties.
82void
83_Jv_platform_initProperties (java::util::Properties* newprops)
84{
85 // A convenience define.
86#define SET(Prop,Val) \
87 newprops->put(JvNewStringLatin1 (Prop), JvNewStringLatin1 (Val))
88
89 SET ("file.separator", "\\");
90 SET ("path.separator", ";");
91 SET ("line.separator", "\r\n");
455cd615
AK
92
93 // Use GetCurrentDirectory to set 'user.dir'.
94 DWORD buflen = MAX_PATH;
94ed0002 95 char *buffer = (char *) _Jv_MallocUnchecked (buflen);
455cd615
AK
96 if (buffer != NULL)
97 {
98 if (GetCurrentDirectory (buflen, buffer))
94ed0002
AK
99 SET ("user.dir", buffer);
100
101 if (GetTempPath (buflen, buffer))
102 SET ("java.io.tmpdir", buffer);
103
c646bade 104 _Jv_Free (buffer);
455cd615
AK
105 }
106
107 // Use GetUserName to set 'user.name'.
108 buflen = 257; // UNLEN + 1
94ed0002 109 buffer = (char *) _Jv_MallocUnchecked (buflen);
455cd615
AK
110 if (buffer != NULL)
111 {
112 if (GetUserName (buffer, &buflen))
113 SET ("user.name", buffer);
c646bade 114 _Jv_Free (buffer);
455cd615
AK
115 }
116
117 // According to the api documentation for 'GetWindowsDirectory()', the
118 // environmental variable HOMEPATH always specifies the user's home
119 // directory or a default directory. On the 3 windows machines I checked
120 // only 1 had it set. If it's not set, JDK1.3.1 seems to set it to
121 // the windows directory, so we'll do the same.
94ed0002
AK
122 char *userHome = NULL;
123 if ((userHome = ::getenv ("HOMEPATH")) == NULL )
455cd615
AK
124 {
125 // Check HOME since it's what I use.
94ed0002 126 if ((userHome = ::getenv ("HOME")) == NULL )
455cd615
AK
127 {
128 // Not found - use the windows directory like JDK1.3.1 does.
94ed0002
AK
129 char *winHome = (char *) _Jv_MallocUnchecked (MAX_PATH);
130 if (winHome != NULL)
455cd615
AK
131 {
132 if (GetWindowsDirectory (winHome, MAX_PATH))
94ed0002 133 SET ("user.home", winHome);
c646bade 134 _Jv_Free (winHome);
455cd615
AK
135 }
136 }
137 }
94ed0002 138 if (userHome != NULL)
455cd615
AK
139 SET ("user.home", userHome);
140
141 // Get and set some OS info.
142 OSVERSIONINFO osvi;
143 ZeroMemory (&osvi, sizeof(OSVERSIONINFO));
144 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
145 if (GetVersionEx (&osvi))
146 {
94ed0002 147 char *buffer = (char *) _Jv_MallocUnchecked (30);
455cd615
AK
148 if (buffer != NULL)
149 {
94ed0002
AK
150 sprintf (buffer, "%d.%d", (int) osvi.dwMajorVersion,
151 (int) osvi.dwMinorVersion);
455cd615 152 SET ("os.version", buffer);
c646bade 153 _Jv_Free (buffer);
455cd615
AK
154 }
155
156 switch (osvi.dwPlatformId)
157 {
158 case VER_PLATFORM_WIN32_WINDOWS:
159 if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
160 SET ("os.name", "Windows 95");
161 else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
162 SET ("os.name", "Windows 98");
163 else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
164 SET ("os.name", "Windows Me");
165 else
166 SET ("os.name", "Windows ??");
167 break;
168
169 case VER_PLATFORM_WIN32_NT:
170 if (osvi.dwMajorVersion <= 4 )
171 SET ("os.name", "Windows NT");
172 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
173 SET ("os.name", "Windows 2000");
174 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
175 SET ("os.name", "Windows XP");
176 else
177 SET ("os.name", "Windows NT ??");
178 break;
179
180 default:
181 SET ("os.name", "Windows UNKNOWN");
182 break;
183 }
184 }
185
186 // Set the OS architecture.
187 SYSTEM_INFO si;
188 GetSystemInfo (&si);
94ed0002 189 switch (si.dwProcessorType)
455cd615
AK
190 {
191 case PROCESSOR_INTEL_386:
192 SET ("os.arch", "i386");
193 break;
194 case PROCESSOR_INTEL_486:
195 SET ("os.arch", "i486");
196 break;
197 case PROCESSOR_INTEL_PENTIUM:
198 SET ("os.arch", "i586");
199 break;
200 case PROCESSOR_MIPS_R4000:
201 SET ("os.arch", "MIPS4000");
202 break;
203 case PROCESSOR_ALPHA_21064:
204 SET ("os.arch", "ALPHA");
205 break;
206 default:
207 SET ("os.arch", "unknown");
208 break;
209 }
210}
c2a6704f
AM
211
212/* Store up to SIZE return address of the current program state in
213 ARRAY and return the exact number of values stored. */
214int
215backtrace (void **__array, int __size)
216{
217 register void *_ebp __asm__ ("ebp");
218 register void *_esp __asm__ ("esp");
219 unsigned int *rfp;
220
221 int i=0;
222 for (rfp = *(unsigned int**)_ebp;
223 rfp && i < __size;
224 rfp = *(unsigned int **)rfp)
225 {
226 int diff = *rfp - (unsigned int)rfp;
227 if ((void*)rfp < _esp || diff > 4 * 1024 || diff < 0) break;
228
229 __array[i++] = (void*)(rfp[1]-4);
230 }
231 return i;
232}
This page took 0.163178 seconds and 5 git commands to generate.