OSDN Git Service

22139c99f4a421f3bedaac00a45db60e5837210c
[pf3gnuchains/gcc-fork.git] / libjava / win32.cc
1 // win32.cc - Helper functions for Microsoft-flavored OSs.
2
3 /* Copyright (C) 2002  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 #include <config.h>
12 #include <jvm.h>
13 #include <sys/timeb.h>
14
15 #include "platform.h"
16 #include <java/lang/ArithmeticException.h>
17
18 static LONG CALLBACK
19 win32_exception_handler (LPEXCEPTION_POINTERS e)
20 {
21   if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
22     _Jv_ThrowNullPointerException();
23   else if (e->ExceptionRecord->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO)
24     throw new java::lang::ArithmeticException;
25   else
26     return EXCEPTION_CONTINUE_SEARCH;
27 }
28
29 // Platform-specific VM initialization.
30 void
31 _Jv_platform_initialize (void)
32 {
33   // Initialise winsock for networking
34   WSADATA data;
35   if (WSAStartup (MAKEWORD (1, 1), &data))
36     MessageBox (NULL, "Error initialising winsock library.", "Error",
37                 MB_OK | MB_ICONEXCLAMATION);
38   // Install exception handler
39   SetUnhandledExceptionFilter (win32_exception_handler);
40 }
41
42 // gettimeofday implementation.
43 jlong
44 _Jv_platform_gettimeofday ()
45 {
46   struct timeb t;
47   ftime (&t);
48   return t.time * 1000LL + t.millitm;
49 }
50