#include <config.h>
#include <platform.h>
#include <jvm.h>
#include <sys/timeb.h>
#include <stdlib.h>
#include <java/lang/ArithmeticException.h>
#include <java/util/Properties.h>
static LONG CALLBACK
win32_exception_handler (LPEXCEPTION_POINTERS e)
{
if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
_Jv_ThrowNullPointerException();
else if (e->ExceptionRecord->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO)
throw new java::lang::ArithmeticException;
else
return EXCEPTION_CONTINUE_SEARCH;
}
void
_Jv_platform_initialize (void)
{
WSADATA data;
if (WSAStartup (MAKEWORD (1, 1), &data))
MessageBox (NULL, "Error initialising winsock library.", "Error",
MB_OK | MB_ICONEXCLAMATION);
SetUnhandledExceptionFilter (win32_exception_handler);
}
jlong
_Jv_platform_gettimeofday ()
{
struct timeb t;
ftime (&t);
return t.time * 1000LL + t.millitm;
}
int _CRT_MT = 1;
extern "C" int
__mingwthr_key_dtor (DWORD, void (*) (void *))
{
return 0;
}
void
_Jv_platform_initProperties (java::util::Properties* newprops)
{
#define SET(Prop,Val) \
newprops->put(JvNewStringLatin1 (Prop), JvNewStringLatin1 (Val))
SET ("file.separator", "\\");
SET ("path.separator", ";");
SET ("line.separator", "\r\n");
DWORD buflen = MAX_PATH;
char *buffer = (char *) _Jv_MallocUnchecked (buflen);
if (buffer != NULL)
{
if (GetCurrentDirectory (buflen, buffer))
SET ("user.dir", buffer);
if (GetTempPath (buflen, buffer))
SET ("java.io.tmpdir", buffer);
_Jv_Free (buffer);
}
buflen = 257; buffer = (char *) _Jv_MallocUnchecked (buflen);
if (buffer != NULL)
{
if (GetUserName (buffer, &buflen))
SET ("user.name", buffer);
_Jv_Free (buffer);
}
char *userHome = NULL;
if ((userHome = ::getenv ("HOMEPATH")) == NULL )
{
if ((userHome = ::getenv ("HOME")) == NULL )
{
char *winHome = (char *) _Jv_MallocUnchecked (MAX_PATH);
if (winHome != NULL)
{
if (GetWindowsDirectory (winHome, MAX_PATH))
SET ("user.home", winHome);
_Jv_Free (winHome);
}
}
}
if (userHome != NULL)
SET ("user.home", userHome);
OSVERSIONINFO osvi;
ZeroMemory (&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx (&osvi))
{
char *buffer = (char *) _Jv_MallocUnchecked (30);
if (buffer != NULL)
{
sprintf (buffer, "%d.%d", (int) osvi.dwMajorVersion,
(int) osvi.dwMinorVersion);
SET ("os.version", buffer);
_Jv_Free (buffer);
}
switch (osvi.dwPlatformId)
{
case VER_PLATFORM_WIN32_WINDOWS:
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
SET ("os.name", "Windows 95");
else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
SET ("os.name", "Windows 98");
else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
SET ("os.name", "Windows Me");
else
SET ("os.name", "Windows ??");
break;
case VER_PLATFORM_WIN32_NT:
if (osvi.dwMajorVersion <= 4 )
SET ("os.name", "Windows NT");
else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
SET ("os.name", "Windows 2000");
else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
SET ("os.name", "Windows XP");
else
SET ("os.name", "Windows NT ??");
break;
default:
SET ("os.name", "Windows UNKNOWN");
break;
}
}
SYSTEM_INFO si;
GetSystemInfo (&si);
switch (si.dwProcessorType)
{
case PROCESSOR_INTEL_386:
SET ("os.arch", "i386");
break;
case PROCESSOR_INTEL_486:
SET ("os.arch", "i486");
break;
case PROCESSOR_INTEL_PENTIUM:
SET ("os.arch", "i586");
break;
case PROCESSOR_MIPS_R4000:
SET ("os.arch", "MIPS4000");
break;
case PROCESSOR_ALPHA_21064:
SET ("os.arch", "ALPHA");
break;
default:
SET ("os.arch", "unknown");
break;
}
}
int
backtrace (void **__array, int __size)
{
register void *_ebp __asm__ ("ebp");
register void *_esp __asm__ ("esp");
unsigned int *rfp;
int i=0;
for (rfp = *(unsigned int**)_ebp;
rfp && i < __size;
rfp = *(unsigned int **)rfp)
{
int diff = *rfp - (unsigned int)rfp;
if ((void*)rfp < _esp || diff > 4 * 1024 || diff < 0) break;
__array[i++] = (void*)(rfp[1]-4);
}
return i;
}