]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/os-windows-x86.64.cpp
webapps.wiki: adding search bar
[factor.git] / vm / os-windows-x86.64.cpp
index 6533287ce8c30881ea59d64e95d22e5322da501e..a2ce092b9c1ea89a1e6becbdbf6838d3678b1eba 100644 (file)
@@ -4,7 +4,9 @@ namespace factor {
 
 typedef unsigned char UBYTE;
 
+#ifndef UNW_FLAG_EHANDLER
 const UBYTE UNW_FLAG_EHANDLER = 0x1;
+#endif
 
 struct UNWIND_INFO {
   UBYTE Version : 3;
@@ -24,19 +26,19 @@ struct seh_data {
 };
 
 void factor_vm::c_to_factor_toplevel(cell quot) {
-  /* The annoying thing about Win64 SEH is that the offsets in
-   * function tables are 32-bit integers, and the exception handler
-   * itself must reside between the start and end pointers, so
-   * we stick everything at the beginning of the code heap and
-   * generate a small trampoline that jumps to the real
-   * exception handler. */
+  // The annoying thing about Win64 SEH is that the offsets in
+  // function tables are 32-bit integers, and the exception handler
+  // itself must reside between the start and end pointers, so
+  // we stick everything at the beginning of the code heap and
+  // generate a small trampoline that jumps to the real
+  // exception handler.
 
   seh_data* seh_area = (seh_data*)code->seh_area;
   cell base = code->seg->start;
 
-  /* Should look at generating this with the Factor assembler */
+  // Should look at generating this with the Factor assembler
 
-  /* mov rax,0 */
+  // mov rax,0
   seh_area->handler[0] = 0x48;
   seh_area->handler[1] = 0xb8;
   seh_area->handler[2] = 0x0;
@@ -48,13 +50,13 @@ void factor_vm::c_to_factor_toplevel(cell quot) {
   seh_area->handler[8] = 0x0;
   seh_area->handler[9] = 0x0;
 
-  /* jmp rax */
+  // jmp rax
   seh_area->handler[10] = 0x48;
   seh_area->handler[11] = 0xff;
   seh_area->handler[12] = 0xe0;
 
-  /* Store address of exception handler in the operand of the 'mov' */
-  cell handler = (cell) & factor::exception_handler;
+  // Store address of exception handler in the operand of the 'mov'
+  cell handler = (cell)&factor::exception_handler;
   memcpy(&seh_area->handler[2], &handler, sizeof(cell));
 
   UNWIND_INFO* unwind_info = &seh_area->unwind_info;
@@ -64,13 +66,13 @@ void factor_vm::c_to_factor_toplevel(cell quot) {
   unwind_info->CountOfCodes = 0;
   unwind_info->FrameRegister = 0;
   unwind_info->FrameOffset = 0;
-  unwind_info->ExceptionHandler = (DWORD)((cell) & seh_area->handler[0] - base);
+  unwind_info->ExceptionHandler = (DWORD)((cell)&seh_area->handler[0] - base);
   unwind_info->ExceptionData[0] = 0;
 
   RUNTIME_FUNCTION* func = &seh_area->func;
   func->BeginAddress = 0;
   func->EndAddress = (DWORD)(code->seg->end - base);
-  func->UnwindData = (DWORD)((cell) & seh_area->unwind_info - base);
+  func->UnwindData = (DWORD)((cell)&seh_area->unwind_info - base);
 
   if (!RtlAddFunctionTable(func, 1, base))
     fatal_error("RtlAddFunctionTable() failed", 0);