0.9.11.13
[sbcl.git] / src / runtime / win32-os.c
index 9e41866..10c51d7 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include <sys/param.h>
 #include <sys/file.h>
+#include <io.h>
 #include "sbcl.h"
 #include "./signal.h"
 #include "os.h"
@@ -38,6 +39,7 @@
 #include "interrupt.h"
 #include "interr.h"
 #include "lispregs.h"
+#include "runtime.h"
 #include "monitor.h"
 #include "alloc.h"
 #include "genesis/primitive-objects.h"
@@ -47,6 +49,7 @@
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <shlobj.h>
 
 #include <excpt.h>
 
@@ -413,7 +416,12 @@ EXCEPTION_DISPOSITION handle_exception(EXCEPTION_RECORD *exception_record,
         return sigtrap_emulator(context, exception_frame);
 
     } else if (exception_record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION &&
-               is_valid_lisp_addr(fault_address)) {
+               (is_valid_lisp_addr(fault_address) ||
+                /* the linkage table does not contain valid lisp
+                 * objects, but is also committed on-demand here
+                 */
+                in_range_p(fault_address, LINKAGE_TABLE_SPACE_START,
+                           LINKAGE_TABLE_SPACE_END))) {
         /* Pick off GC-related memory fault next. */
         MEMORY_BASIC_INFORMATION mem_info;
 
@@ -615,14 +623,70 @@ void scratch(void)
     hypot(0, 0);
     write(0, 0, 0);
     close(0);
-    rename(0,0);
-    getcwd(0,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);
-    mkdir(0);
+    FreeLibrary(0);
+    #ifndef LISP_FEATURE_SB_UNICODE
+      CreateDirectoryA(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
+      GetEnvironmentVariableW(0,0,0);
+    #endif
+    GetConsoleCP();
+    GetConsoleOutputCP();
+}
+
+char *
+os_get_runtime_executable_path()
+{
+    char path[MAX_PATH + 1];
+    DWORD bufsize = sizeof(path);
+    DWORD size;
+
+    if ((size = GetModuleFileNameA(NULL, path, bufsize)) == 0)
+        return NULL;
+    else if (size == bufsize && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+        return NULL;
+
+    return copied_string(path);
 }
 
 /* EOF */