X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fwin32-os.c;h=80a6ed2b1a53a03c722e121abb79bb35fb374d19;hb=7be8d1462a207bda809cd7553c5d76c6ebc4dda2;hp=92917e939d6f3367bac1accf321ac4bc3d5e58ec;hpb=db26c127bc13e8a4e3f56bef25fc18d2ba16aa1d;p=sbcl.git diff --git a/src/runtime/win32-os.c b/src/runtime/win32-os.c index 92917e9..80a6ed2 100644 --- a/src/runtime/win32-os.c +++ b/src/runtime/win32-os.c @@ -43,6 +43,7 @@ #include "runtime.h" #include "alloc.h" #include "genesis/primitive-objects.h" +#include "dynbind.h" #include #include @@ -50,16 +51,6 @@ #include #include -/* 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 -#undef boolean - #include #include @@ -170,7 +161,22 @@ os_validate(os_vm_address_t addr, os_vm_size_t len) return 0; } - if ((mem_info.State == MEM_RESERVE) && (mem_info.RegionSize >=len)) return addr; + if ((mem_info.State == MEM_RESERVE) && (mem_info.RegionSize >=len)) { + /* It would be correct to return here. However, support for Wine + * is beneficial, and Wine has a strange behavior in this + * department. It reports all memory below KERNEL32.DLL as + * reserved, but disallows MEM_COMMIT. + * + * Let's work around it: reserve the region we need for a second + * time. The second reservation is documented to fail on normal NT + * family, but it will succeed on Wine if this region is + * actually free. + */ + VirtualAlloc(addr, len, MEM_RESERVE, PAGE_EXECUTE_READWRITE); + /* If it is wine, the second call has succeded, and now the region + * is really reserved. */ + return addr; + } if (mem_info.State == MEM_RESERVE) { fprintf(stderr, "validation of reserved space too short.\n"); @@ -304,13 +310,20 @@ is_valid_lisp_addr(os_vm_address_t addr) return 0; } -/* - * any OS-dependent special low-level handling for signals - */ - /* A tiny bit of interrupt.c state we want our paws on. */ extern boolean internal_errors_enabled; +#ifdef LISP_FEATURE_UD2_BREAKPOINTS +#define IS_TRAP_EXCEPTION(exception_record, context) \ + (((exception_record)->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) && \ + (((unsigned short *)((context)->Eip))[0] == 0x0b0f)) +#define TRAP_CODE_WIDTH 2 +#else +#define IS_TRAP_EXCEPTION(exception_record, context) \ + ((exception_record)->ExceptionCode == EXCEPTION_BREAKPOINT) +#define TRAP_CODE_WIDTH 1 +#endif + /* * A good explanation of the exception handling semantics is * http://win32assembly.online.fr/Exceptionhandling.html . @@ -320,8 +333,18 @@ EXCEPTION_DISPOSITION handle_exception(EXCEPTION_RECORD *exception_record, struct lisp_exception_frame *exception_frame, CONTEXT *context, - void *dc) /* FIXME: What's dc again? */ + void *dispatcher_context) { + if (exception_record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)) { + /* If we're being unwound, be graceful about it. */ + + /* Undo any dynamic bindings. */ + unbind_to_here(exception_frame->bindstack_pointer, + arch_os_get_current_thread()); + + return ExceptionContinueSearch; + } + /* For EXCEPTION_ACCESS_VIOLATION only. */ void *fault_address = (void *)exception_record->ExceptionInformation[1]; @@ -333,18 +356,20 @@ handle_exception(EXCEPTION_RECORD *exception_record, return ExceptionContinueExecution; } - if (exception_record->ExceptionCode == EXCEPTION_BREAKPOINT) { - /* Pick off sigtrap case first. */ - - extern void sigtrap_handler(int signal, siginfo_t *info, void *context); - /* - * Unlike some other operating systems, Win32 leaves EIP - * pointing to the breakpoint instruction. - */ - context->Eip++; - - sigtrap_handler(0, NULL, context); - + if (IS_TRAP_EXCEPTION(exception_record, context)) { + unsigned char trap; + /* This is just for info in case the monitor wants to print an + * approximation. */ + current_control_stack_pointer = + (lispobj *)*os_context_sp_addr(context); + /* Unlike some other operating systems, Win32 leaves EIP + * pointing to the breakpoint instruction. */ + context->Eip += TRAP_CODE_WIDTH; + /* Now EIP points just after the INT3 byte and aims at the + * 'kind' value (eg trap_Cerror). */ + trap = *(unsigned char *)(*os_context_pc_addr(context)); + handle_trap(context, trap); + /* Done, we're good to go! */ return ExceptionContinueExecution; } else if (exception_record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && @@ -374,7 +399,7 @@ handle_exception(EXCEPTION_RECORD *exception_record, * exception handler if the gc doesn't take the wp violation? */ if (exception_record->ExceptionInformation[0]) { - int index = find_page_index(fault_address); + page_index_t index = find_page_index(fault_address); if ((index != -1) && (page_table[index].write_protected)) { gencgc_handle_wp_violation(fault_address); } @@ -419,7 +444,7 @@ handle_exception(EXCEPTION_RECORD *exception_record, _clearfp(); /* Call into lisp to handle things. */ - funcall2(SymbolFunction(HANDLE_WIN32_EXCEPTION), context_sap, + funcall2(StaticSymbolFunction(HANDLE_WIN32_EXCEPTION), context_sap, exception_record_sap); /* If Lisp doesn't nlx, we need to put things back. */ @@ -446,7 +471,7 @@ handle_exception(EXCEPTION_RECORD *exception_record, fflush(stderr); fake_foreign_function_call(context); - lose("fake_foreign_function_call fell through"); + lose("Exception too early in cold init, cannot continue."); /* FIXME: WTF? How are we supposed to end up here? */ return ExceptionContinueSearch; @@ -539,24 +564,26 @@ void scratch(void) Sleep(0); WriteFile(0, 0, 0, 0, 0); _get_osfhandle(0); + _rmdir(0); _pipe(0,0,0); access(0,0); - acos(0); - asin(0); close(0); - cosh(0); dup(0); - hypot(0, 0); isatty(0); - sinh(0); strerror(42); write(0, 0, 0); RtlUnwind(0, 0, 0, 0); + MapViewOfFile(0,0,0,0,0); + UnmapViewOfFile(0); + FlushViewOfFile(0,0); #ifndef LISP_FEATURE_SB_UNICODE CreateDirectoryA(0,0); + CreateFileMappingA(0,0,0,0,0,0); + CreateFileA(0,0,0,0,0,0,0); GetComputerNameA(0, 0); GetCurrentDirectoryA(0,0); GetEnvironmentVariableA(0, 0, 0); + GetFileAttributesA(0); GetVersionExA(0); MoveFileA(0,0); SHGetFolderPathA(0, 0, 0, 0, 0); @@ -564,10 +591,13 @@ void scratch(void) SetEnvironmentVariableA(0, 0); #else CreateDirectoryW(0,0); + CreateFileMappingW(0,0,0,0,0,0); + CreateFileW(0,0,0,0,0,0,0); FormatMessageW(0, 0, 0, 0, 0, 0, 0); GetComputerNameW(0, 0); GetCurrentDirectoryW(0,0); GetEnvironmentVariableW(0, 0, 0); + GetFileAttributesW(0); GetVersionExW(0); MoveFileW(0,0); SHGetFolderPathW(0, 0, 0, 0, 0); @@ -577,7 +607,7 @@ void scratch(void) } char * -os_get_runtime_executable_path() +os_get_runtime_executable_path(int external) { char path[MAX_PATH + 1]; DWORD bufsize = sizeof(path);