1.0.1.1:
[sbcl.git] / src / runtime / win32-os.c
index f43af0d..b77f4ea 100644 (file)
@@ -26,6 +26,7 @@
  * yet.
  */
 
+#include <malloc.h>
 #include <stdio.h>
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <unistd.h>
+
+/* KLUDGE: Avoid double definition of boolean by rpcndr.h included via
+ * shlobj.h.
+ *
+ * FIXME: We should probably arrange to use the rpcndr.h boolean on Windows,
+ * or get rid of our own boolean type.
+ */
+#define boolean rpcndr_boolean
 #include <shlobj.h>
+#undef boolean
+
+#include <math.h>
 
 #include <excpt.h>
 
@@ -56,7 +68,6 @@
 #include "thread.h"
 size_t os_vm_page_size;
 
-
 #include "gc.h"
 #include "gencgc-internal.h"
 
@@ -281,7 +292,7 @@ is_valid_lisp_addr(os_vm_address_t addr)
     struct thread *th;
     if(in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE) ||
        in_range_p(addr, STATIC_SPACE_START   , STATIC_SPACE_SIZE) ||
-       in_range_p(addr, DYNAMIC_SPACE_START  , DYNAMIC_SPACE_SIZE))
+       in_range_p(addr, DYNAMIC_SPACE_START  , dynamic_space_size))
         return 1;
     for_each_thread(th) {
         if(((os_vm_address_t)th->control_stack_start <= addr) && (addr < (os_vm_address_t)th->control_stack_end))
@@ -323,8 +334,9 @@ extern boolean internal_errors_enabled;
  * unwinding in Lisp.
  */
 
-EXCEPTION_DISPOSITION sigtrap_emulator(CONTEXT *context,
-                                       struct lisp_exception_frame *exception_frame)
+EXCEPTION_DISPOSITION
+sigtrap_emulator(CONTEXT *context,
+                 struct lisp_exception_frame *exception_frame)
 {
     if (*((char *)context->Eip + 1) == trap_ContextRestore) {
         /* This is the cleanup for what is immediately below, and
@@ -413,19 +425,26 @@ void sigtrap_wrapper(void)
 /*     set_seh_frame(handler.handler[0]); */
 }
 
-EXCEPTION_DISPOSITION handle_exception(EXCEPTION_RECORD *exception_record,
-                                       struct lisp_exception_frame *exception_frame,
-                                       CONTEXT *context,
-                                       void *dc) /* FIXME: What's dc again? */
+EXCEPTION_DISPOSITION
+handle_exception(EXCEPTION_RECORD *exception_record,
+                 struct lisp_exception_frame *exception_frame,
+                 CONTEXT *context,
+                 void *dc) /* FIXME: What's dc again? */
 {
-
     /* For EXCEPTION_ACCESS_VIOLATION only. */
     void *fault_address = (void *)exception_record->ExceptionInformation[1];
 
+    if (single_stepping &&
+        exception_record->ExceptionCode == EXCEPTION_SINGLE_STEP) {
+        /* We are doing a displaced instruction. At least function
+         * end breakpoints uses this. */
+        restore_breakpoint_from_single_step(context);
+        return ExceptionContinueExecution;
+    }
+
     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) ||
@@ -627,89 +646,67 @@ char *dirname(char *path)
 
 /* This is a manually-maintained version of ldso_stubs.S. */
 
+void __stdcall RtlUnwind(void *, void *, void *, void *); /* I don't have winternl.h */
+
 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);
+    RtlUnwind(0, 0, 0, 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 *