2002-02-07 06:26:42 +01:00
|
|
|
// win32.cc - Helper functions for Microsoft-flavored OSs.
|
|
|
|
|
|
|
|
/* Copyright (C) 2002 Free Software Foundation
|
|
|
|
|
|
|
|
This file is part of libgcj.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-02-12 05:35:32 +01:00
|
|
|
#include <jvm.h>
|
2002-03-08 02:03:56 +01:00
|
|
|
#include <sys/timeb.h>
|
2002-02-07 06:26:42 +01:00
|
|
|
|
2002-02-07 19:59:52 +01:00
|
|
|
#include "platform.h"
|
2002-02-12 05:35:32 +01:00
|
|
|
#include <java/lang/ArithmeticException.h>
|
2002-02-07 19:59:52 +01:00
|
|
|
|
|
|
|
static LONG CALLBACK
|
2002-02-07 06:26:42 +01:00
|
|
|
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;
|
|
|
|
}
|
2002-02-07 19:59:52 +01:00
|
|
|
|
|
|
|
// Platform-specific VM initialization.
|
|
|
|
void
|
|
|
|
_Jv_platform_initialize (void)
|
|
|
|
{
|
|
|
|
// Initialise winsock for networking
|
|
|
|
WSADATA data;
|
|
|
|
if (WSAStartup (MAKEWORD (1, 1), &data))
|
|
|
|
MessageBox (NULL, "Error initialising winsock library.", "Error",
|
|
|
|
MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
// Install exception handler
|
|
|
|
SetUnhandledExceptionFilter (win32_exception_handler);
|
|
|
|
}
|
2002-02-12 03:25:07 +01:00
|
|
|
|
|
|
|
// gettimeofday implementation.
|
2002-03-08 02:03:56 +01:00
|
|
|
jlong
|
|
|
|
_Jv_platform_gettimeofday ()
|
2002-02-12 03:25:07 +01:00
|
|
|
{
|
2002-03-08 02:03:56 +01:00
|
|
|
struct timeb t;
|
|
|
|
ftime (&t);
|
2002-03-09 23:08:35 +01:00
|
|
|
return t.time * 1000LL + t.millitm;
|
2002-02-12 03:25:07 +01:00
|
|
|
}
|
|
|
|
|
2002-03-09 23:33:49 +01:00
|
|
|
// The following definitions "fake out" mingw to think that -mthreads
|
|
|
|
// was enabled and that mingwthr.dll was linked. GCJ-compiled
|
|
|
|
// applications don't need this helper library because we can safely
|
|
|
|
// detect thread death (return from Thread.run()).
|
|
|
|
|
|
|
|
int _CRT_MT = 1;
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
__mingwthr_key_dtor (DWORD, void (*) (void *))
|
|
|
|
{
|
|
|
|
// FIXME: for now we do nothing; this causes a memory leak of
|
|
|
|
// approximately 24 bytes per thread created.
|
|
|
|
return 0;
|
|
|
|
}
|