0.9.18.6: Win32 get-internal-real-time improved
[sbcl.git] / src / runtime / win32-os.c
index 3689a21..9f945e8 100644 (file)
@@ -26,6 +26,7 @@
  * yet.
  */
 
+#include <malloc.h>
 #include <stdio.h>
 #include <sys/param.h>
 #include <sys/file.h>
@@ -334,9 +335,9 @@ EXCEPTION_DISPOSITION sigtrap_emulator(CONTEXT *context,
         memcpy(context, &exception_frame->context, sizeof(CONTEXT));
         return ExceptionContinueExecution;
 
-    } else { 
-       /* Not a trap_ContextRestore, must be a sigtrap.
-        * sigtrap_trampoline is defined in x86-assem.S. */
+    } else {
+        /* Not a trap_ContextRestore, must be a sigtrap.
+         * sigtrap_trampoline is defined in x86-assem.S. */
         extern void sigtrap_trampoline;
 
         /*
@@ -366,13 +367,13 @@ EXCEPTION_DISPOSITION sigtrap_emulator(CONTEXT *context,
          * that we don't switch stacks for exception processing...) */
         memcpy(&exception_frame->context, context, sizeof(CONTEXT));
 
-       /* FIXME: Why do we save the old EIP in EAX? The sigtrap_trampoline
-        * pushes it into stack, but the sigtrap_wrapper where the trampoline
-        * goes ignores it, and after the wrapper we hit the trap_ContextRestore,
-        * which nukes the whole context with the original one? 
-        *
-        * Am I misreading this, or is the EAX here and in the
-        * trampoline superfluous? --NS 20061024 */
+        /* FIXME: Why do we save the old EIP in EAX? The sigtrap_trampoline
+         * pushes it into stack, but the sigtrap_wrapper where the trampoline
+         * goes ignores it, and after the wrapper we hit the trap_ContextRestore,
+         * which nukes the whole context with the original one?
+         *
+         * Am I misreading this, or is the EAX here and in the
+         * trampoline superfluous? --NS 20061024 */
         context->Eax = context->Eip;
         context->Eip = (unsigned long)&sigtrap_trampoline;
 
@@ -421,30 +422,30 @@ EXCEPTION_DISPOSITION handle_exception(EXCEPTION_RECORD *exception_record,
 
     /* For EXCEPTION_ACCESS_VIOLATION only. */
     void *fault_address = (void *)exception_record->ExceptionInformation[1];
-    
+
     if (exception_record->ExceptionCode == EXCEPTION_BREAKPOINT) {
         /* Pick off sigtrap case first. */
         return sigtrap_emulator(context, exception_frame);
 
-    } 
+    }
     else if (exception_record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION &&
-            (is_valid_lisp_addr(fault_address) || 
-             is_linkage_table_addr(fault_address))) {
-       /* Pick off GC-related memory fault next. */
-       MEMORY_BASIC_INFORMATION mem_info;
-       
-       if (!VirtualQuery(fault_address, &mem_info, sizeof mem_info)) {
-           fprintf(stderr, "VirtualQuery: 0x%lx.\n", GetLastError());
-           lose("handle_exception: VirtualQuery failure");
-       }
-       
-       if (mem_info.State == MEM_RESERVE) {
-           /* First use new page, lets get some memory for it. */
-           if (!VirtualAlloc(mem_info.BaseAddress, os_vm_page_size,
-                             MEM_COMMIT, PAGE_EXECUTE_READWRITE)) {
-               fprintf(stderr, "VirtualAlloc: 0x%lx.\n", GetLastError());
+             (is_valid_lisp_addr(fault_address) ||
+              is_linkage_table_addr(fault_address))) {
+        /* Pick off GC-related memory fault next. */
+        MEMORY_BASIC_INFORMATION mem_info;
+
+        if (!VirtualQuery(fault_address, &mem_info, sizeof mem_info)) {
+            fprintf(stderr, "VirtualQuery: 0x%lx.\n", GetLastError());
+            lose("handle_exception: VirtualQuery failure");
+        }
+
+        if (mem_info.State == MEM_RESERVE) {
+            /* First use new page, lets get some memory for it. */
+            if (!VirtualAlloc(mem_info.BaseAddress, os_vm_page_size,
+                              MEM_COMMIT, PAGE_EXECUTE_READWRITE)) {
+                fprintf(stderr, "VirtualAlloc: 0x%lx.\n", GetLastError());
                 lose("handle_exception: VirtualAlloc failure");
-               
+
             } else {
                 /*
                  * Now, if the page is supposedly write-protected and this
@@ -469,13 +470,13 @@ EXCEPTION_DISPOSITION handle_exception(EXCEPTION_RECORD *exception_record,
 
         /* All else failed, drop through to the lisp-side exception handler. */
     }
-    
+
     /*
      * If we fall through to here then we need to either forward
      * the exception to the lisp-side exception handler if it's
      * set up, or drop to LDB.
      */
-    
+
     if (internal_errors_enabled) {
         /* exception_trampoline is defined in x86-assem.S. */
         extern void exception_trampoline;
@@ -485,26 +486,26 @@ EXCEPTION_DISPOSITION handle_exception(EXCEPTION_RECORD *exception_record,
          * marbles to be able to handle exceptions, but xceptions
          * aren't supposed to happen during cold init or reinit
          * anyway.
-        *
+         *
          * We use the same mechanism as the sigtrap emulator above
          * with just a couple changes. We obviously use a different
          * trampoline and wrapper function, we kill out any live
          * floating point exceptions, and we save off the exception
          * record as well as the context. */
 
-       /* Save off context and exception information */
+        /* Save off context and exception information */
         memcpy(&exception_frame->context, context, sizeof(CONTEXT));
         memcpy(&exception_frame->exception, exception_record, sizeof(EXCEPTION_RECORD));
 
         /* Set up to activate trampoline when we return
-        *
-        * FIXME: Why do we save the old EIP in EAX? The
-        * exception_trampoline pushes it into stack, but the wrapper
-        * where the trampoline goes ignores it, and then the wrapper
-        * unwinds from Lisp... WTF?
-        *
-        * Am I misreading this, or is the EAX here and in the
-        * trampoline superfluous? --NS 20061024 */
+         *
+         * FIXME: Why do we save the old EIP in EAX? The
+         * exception_trampoline pushes it into stack, but the wrapper
+         * where the trampoline goes ignores it, and then the wrapper
+         * unwinds from Lisp... WTF?
+         *
+         * Am I misreading this, or is the EAX here and in the
+         * trampoline superfluous? --NS 20061024 */
         context->Eax = context->Eip;
         context->Eip = (unsigned long)&exception_trampoline;
 
@@ -629,87 +630,62 @@ char *dirname(char *path)
 
 void scratch(void)
 {
-    strerror(42);
-    asin(0);
+    CloseHandle(0);
+    FlushConsoleInputBuffer(0);
+    FormatMessageA(0, 0, 0, 0, 0, 0, 0);
+    FreeLibrary(0);
+    GetACP();
+    GetConsoleCP();
+    GetConsoleOutputCP();
+    GetCurrentProcess();
+    GetExitCodeProcess(0, 0);
+    GetLastError();
+    GetOEMCP();
+    GetProcAddress(0, 0);
+    GetProcessTimes(0, 0, 0, 0, 0);
+    GetSystemTimeAsFileTime(0);
+    LoadLibrary(0);
+    LocalFree(0);
+    PeekConsoleInput(0, 0, 0, 0);
+    PeekNamedPipe(0, 0, 0, 0, 0, 0);
+    ReadFile(0, 0, 0, 0, 0);
+    Sleep(0);
+    WriteFile(0, 0, 0, 0, 0);
+    _get_osfhandle(0);
+    _pipe(0,0,0);
+    access(0,0);
     acos(0);
-    sinh(0);
+    asin(0);
+    close(0);
     cosh(0);
+    dup(0);
     hypot(0, 0);
+    isatty(0);
+    sinh(0);
+    strerror(42);
     write(0, 0, 0);
-    close(0);
-    #ifndef LISP_FEATURE_SB_UNICODE
-      MoveFileA(0,0);
-    #else
-      MoveFileW(0,0);
-    #endif
-    #ifndef LISP_FEATURE_SB_UNICODE
-      GetCurrentDirectoryA(0,0);
-    #else
-      GetCurrentDirectoryW(0,0);
-    #endif
-    dup(0);
-    LoadLibrary(0);
-    GetProcAddress(0, 0);
-    FreeLibrary(0);
     #ifndef LISP_FEATURE_SB_UNICODE
       CreateDirectoryA(0,0);
+      GetComputerNameA(0, 0);
+      GetCurrentDirectoryA(0,0);
+      GetEnvironmentVariableA(0, 0, 0);
+      GetVersionExA(0);
+      MoveFileA(0,0);
+      SHGetFolderPathA(0, 0, 0, 0, 0);
+      SetCurrentDirectoryA(0);
+      SetEnvironmentVariableA(0, 0);
     #else
       CreateDirectoryW(0,0);
-    #endif
-    _pipe(0,0,0);
-    isatty(0);
-    access(0,0);
-    GetLastError();
-    FormatMessageA(0, 0, 0, 0, 0, 0, 0);
-    #ifdef LISP_FEATURE_SB_UNICODE
       FormatMessageW(0, 0, 0, 0, 0, 0, 0);
-    #endif
-    _get_osfhandle(0);
-    ReadFile(0, 0, 0, 0, 0);
-    WriteFile(0, 0, 0, 0, 0);
-    PeekNamedPipe(0, 0, 0, 0, 0, 0);
-    FlushConsoleInputBuffer(0);
-    PeekConsoleInput(0, 0, 0, 0);
-    Sleep(0);
-    #ifndef LISP_FEATURE_SB_UNICODE
-      SHGetFolderPathA(0, 0, 0, 0, 0);
-    #else
-      SHGetFolderPathW(0, 0, 0, 0, 0);
-    #endif
-    GetACP();
-    GetOEMCP();
-    LocalFree(0);
-    #ifndef LISP_FEATURE_SB_UNICODE
-      GetEnvironmentVariableA(0, 0, 0);
-    #else
+      GetComputerNameW(0, 0);
+      GetCurrentDirectoryW(0,0);
       GetEnvironmentVariableW(0, 0, 0);
-    #endif
-    GetConsoleCP();
-    GetConsoleOutputCP();
-    GetExitCodeProcess(0, 0);
-    GetCurrentProcess();
-    GetProcessTimes(0, 0, 0, 0, 0);
-    #ifndef LISP_FEATURE_SB_UNICODE
-      SetEnvironmentVariableA(0, 0);
-    #else
-      SetEnvironmentVariableW(0, 0);
-    #endif
-    #ifndef LISP_FEATURE_SB_UNICODE
-      GetVersionExA(0);
-    #else
       GetVersionExW(0);
-    #endif
-    #ifndef LISP_FEATURE_SB_UNICODE
-      GetComputerNameA(0, 0);
-    #else
-      GetComputerNameW(0, 0);
-    #endif
-    #ifndef LISP_FEATURE_SB_UNICODE
-      SetCurrentDirectoryA(0);
-    #else
+      MoveFileW(0,0);
+      SHGetFolderPathW(0, 0, 0, 0, 0);
       SetCurrentDirectoryW(0);
+      SetEnvironmentVariableW(0, 0);
     #endif
-    CloseHandle(0);
 }
 
 char *