Browse Source

Support null segment #gp in jit mode (Windows 98 / Windows ME / QNX)

Fabian 3 years ago
parent
commit
584ab0cca0

+ 2 - 3
src/rust/cpu2/cpu.rs

@@ -2169,12 +2169,11 @@ pub unsafe fn switch_seg(reg: i32, selector_raw: i32) -> bool {
 }
 
 #[no_mangle]
-pub unsafe fn assert_seg_non_null(segment: i32) {
+pub unsafe fn log_segment_null(segment: i32) {
     dbg_assert!(segment >= 0 && segment < 8);
     if *segment_is_null.offset(segment as isize) {
         dbg_assert!(segment != CS && segment != SS);
-        dbg_log!("#gp: Access null segment");
-        assert!(false);
+        dbg_log!("#gp: Access null segment in jit");
     }
 }
 

+ 1 - 0
src/rust/global_pointers.rs

@@ -13,6 +13,7 @@ pub const CPL: u32 = 612;
 
 pub const TIMESTAMP_COUNTER: u32 = 664;
 pub const SREG: u32 = 668;
+pub const SEGMENT_IS_NULL: u32 = 724;
 pub const SEGMENT_OFFSETS: u32 = 736;
 pub const REG_XMM: u32 = 832;
 pub const FPU_CONTROL_WORD: u32 = 1036;

+ 7 - 1
src/rust/modrm.rs

@@ -255,9 +255,15 @@ pub fn jit_add_seg_offset(ctx: &mut JitContext, default_segment: u32) {
 
     if cfg!(debug_assertions) && seg != CS && seg != SS {
         ctx.builder.const_i32(seg as i32);
-        ctx.builder.call_fn1("assert_seg_non_null");
+        ctx.builder.call_fn1("log_segment_null");
     }
 
+    ctx.builder
+        .load_fixed_u8(global_pointers::SEGMENT_IS_NULL + seg);
+    ctx.builder.if_void();
+    codegen::gen_trigger_gp(ctx, 0);
+    ctx.builder.block_end();
+
     ctx.builder
         .load_fixed_i32(global_pointers::get_seg_offset(seg));
     ctx.builder.add_i32();

+ 48 - 8
tests/expect/tests/indirect-call.wast

@@ -18,7 +18,8 @@
   (type $t16 (func (param i32 i32 i32 i32) (result i32)))
   (type $t17 (func (param i32 i64 i32) (result i32)))
   (type $t18 (func (param i32 i64 i64 i32) (result i32)))
-  (import "e" "assert_seg_non_null" (func $e.assert_seg_non_null (type $t1)))
+  (import "e" "log_segment_null" (func $e.log_segment_null (type $t1)))
+  (import "e" "trigger_gp" (func $e.trigger_gp (type $t1)))
   (import "e" "safe_read32s_slow_jit" (func $e.safe_read32s_slow_jit (type $t7)))
   (import "e" "safe_write32_slow_jit" (func $e.safe_write32_slow_jit (type $t15)))
   (import "e" "jit_find_cache_entry_in_page" (func $e.jit_find_cache_entry_in_page (type $t16)))
@@ -112,14 +113,53 @@
                   (i32.const 556))
                 (i32.const 2)))
             (get_local $l2)
-            (call $e.assert_seg_non_null
+            (call $e.log_segment_null
               (i32.const 3))
+            (if $I6
+              (i32.load8_u
+                (i32.const 727))
+              (then
+                (i32.store
+                  (i32.const 64)
+                  (get_local $l2))
+                (i32.store
+                  (i32.const 68)
+                  (get_local $l3))
+                (i32.store
+                  (i32.const 72)
+                  (get_local $l4))
+                (i32.store
+                  (i32.const 76)
+                  (get_local $l5))
+                (i32.store
+                  (i32.const 80)
+                  (get_local $l6))
+                (i32.store
+                  (i32.const 84)
+                  (get_local $l7))
+                (i32.store
+                  (i32.const 88)
+                  (get_local $l8))
+                (i32.store
+                  (i32.const 92)
+                  (get_local $l9))
+                (i32.store
+                  (i32.const 560)
+                  (i32.or
+                    (i32.and
+                      (i32.load
+                        (i32.const 556))
+                      (i32.const -4096))
+                    (i32.const 0)))
+                (call $e.trigger_gp
+                  (i32.const 0))
+                (return)))
             (i32.load
               (i32.const 748))
             (i32.add)
             (set_local $l10)
-            (block $B6
-              (br_if $B6
+            (block $B7
+              (br_if $B7
                 (i32.and
                   (i32.eq
                     (i32.and
@@ -170,8 +210,8 @@
                     (i32.const 4)))
                 (i32.load
                   (i32.const 744))))
-            (block $B7
-              (br_if $B7
+            (block $B8
+              (br_if $B8
                 (i32.and
                   (i32.eq
                     (i32.and
@@ -211,7 +251,7 @@
             (i32.store
               (i32.const 556)
               (get_local $l10))
-            (if $I8
+            (if $I9
               (i32.eqz
                 (i32.and
                   (i32.xor
@@ -220,7 +260,7 @@
                       (i32.const 560)))
                   (i32.const -4096)))
               (then
-                (if $I9
+                (if $I10
                   (i32.ge_s
                     (tee_local $l10
                       (call $e.jit_find_cache_entry_in_page

+ 44 - 4
tests/expect/tests/mem32r.wast

@@ -18,7 +18,8 @@
   (type $t16 (func (param i32 i32 i32 i32) (result i32)))
   (type $t17 (func (param i32 i64 i32) (result i32)))
   (type $t18 (func (param i32 i64 i64 i32) (result i32)))
-  (import "e" "assert_seg_non_null" (func $e.assert_seg_non_null (type $t1)))
+  (import "e" "log_segment_null" (func $e.log_segment_null (type $t1)))
+  (import "e" "trigger_gp" (func $e.trigger_gp (type $t1)))
   (import "e" "safe_read32s_slow_jit" (func $e.safe_read32s_slow_jit (type $t7)))
   (import "e" "instr_F4" (func $e.instr_F4 (type $t0)))
   (import "e" "trigger_pagefault_end_jit" (func $e.trigger_pagefault_end_jit (type $t0)))
@@ -101,14 +102,53 @@
           (i32.add
             (get_local $l5)
             (i32.const 123456789))
-          (call $e.assert_seg_non_null
+          (call $e.log_segment_null
             (i32.const 3))
+          (if $I5
+            (i32.load8_u
+              (i32.const 727))
+            (then
+              (i32.store
+                (i32.const 64)
+                (get_local $l2))
+              (i32.store
+                (i32.const 68)
+                (get_local $l3))
+              (i32.store
+                (i32.const 72)
+                (get_local $l4))
+              (i32.store
+                (i32.const 76)
+                (get_local $l5))
+              (i32.store
+                (i32.const 80)
+                (get_local $l6))
+              (i32.store
+                (i32.const 84)
+                (get_local $l7))
+              (i32.store
+                (i32.const 88)
+                (get_local $l8))
+              (i32.store
+                (i32.const 92)
+                (get_local $l9))
+              (i32.store
+                (i32.const 560)
+                (i32.or
+                  (i32.and
+                    (i32.load
+                      (i32.const 556))
+                    (i32.const -4096))
+                  (i32.const 0)))
+              (call $e.trigger_gp
+                (i32.const 0))
+              (return)))
           (i32.load
             (i32.const 748))
           (i32.add)
           (set_local $l10)
-          (block $B5
-            (br_if $B5
+          (block $B6
+            (br_if $B6
               (i32.and
                 (i32.eq
                   (i32.and

+ 47 - 7
tests/expect/tests/mem32rmw.wast

@@ -18,7 +18,8 @@
   (type $t16 (func (param i32 i32 i32 i32) (result i32)))
   (type $t17 (func (param i32 i64 i32) (result i32)))
   (type $t18 (func (param i32 i64 i64 i32) (result i32)))
-  (import "e" "assert_seg_non_null" (func $e.assert_seg_non_null (type $t1)))
+  (import "e" "log_segment_null" (func $e.log_segment_null (type $t1)))
+  (import "e" "trigger_gp" (func $e.trigger_gp (type $t1)))
   (import "e" "safe_read_write32s_slow_jit" (func $e.safe_read_write32s_slow_jit (type $t7)))
   (import "e" "safe_write32_slow_jit" (func $e.safe_write32_slow_jit (type $t15)))
   (import "e" "bug_gen_safe_read_write_page_fault" (func $e.bug_gen_safe_read_write_page_fault (type $t2)))
@@ -103,14 +104,53 @@
           (i32.add
             (get_local $l2)
             (i32.const 123456789))
-          (call $e.assert_seg_non_null
+          (call $e.log_segment_null
             (i32.const 3))
+          (if $I5
+            (i32.load8_u
+              (i32.const 727))
+            (then
+              (i32.store
+                (i32.const 64)
+                (get_local $l2))
+              (i32.store
+                (i32.const 68)
+                (get_local $l3))
+              (i32.store
+                (i32.const 72)
+                (get_local $l4))
+              (i32.store
+                (i32.const 76)
+                (get_local $l5))
+              (i32.store
+                (i32.const 80)
+                (get_local $l6))
+              (i32.store
+                (i32.const 84)
+                (get_local $l7))
+              (i32.store
+                (i32.const 88)
+                (get_local $l8))
+              (i32.store
+                (i32.const 92)
+                (get_local $l9))
+              (i32.store
+                (i32.const 560)
+                (i32.or
+                  (i32.and
+                    (i32.load
+                      (i32.const 556))
+                    (i32.const -4096))
+                  (i32.const 0)))
+              (call $e.trigger_gp
+                (i32.const 0))
+              (return)))
           (i32.load
             (i32.const 748))
           (i32.add)
           (set_local $l10)
-          (block $B5
-            (br_if $B5
+          (block $B6
+            (br_if $B6
               (tee_local $l12
                 (i32.and
                   (i32.eq
@@ -153,7 +193,7 @@
                 (i32.load
                   (i32.const 120))
                 (i32.const -2))
-              (if $I6 (result i32)
+              (if $I7 (result i32)
                 (i32.and
                   (tee_local $l14
                     (i32.load
@@ -196,11 +236,11 @@
             (i32.const 2260))
           (set_local $l13
             (get_local $l13))
-          (if $I7
+          (if $I8
             (i32.eqz
               (get_local $l12))
             (then
-              (if $I8
+              (if $I9
                 (i32.and
                   (call $e.safe_write32_slow_jit
                     (get_local $l10)

+ 44 - 4
tests/expect/tests/mem32w.wast

@@ -18,7 +18,8 @@
   (type $t16 (func (param i32 i32 i32 i32) (result i32)))
   (type $t17 (func (param i32 i64 i32) (result i32)))
   (type $t18 (func (param i32 i64 i64 i32) (result i32)))
-  (import "e" "assert_seg_non_null" (func $e.assert_seg_non_null (type $t1)))
+  (import "e" "log_segment_null" (func $e.log_segment_null (type $t1)))
+  (import "e" "trigger_gp" (func $e.trigger_gp (type $t1)))
   (import "e" "safe_write32_slow_jit" (func $e.safe_write32_slow_jit (type $t15)))
   (import "e" "instr_F4" (func $e.instr_F4 (type $t0)))
   (import "e" "trigger_pagefault_end_jit" (func $e.trigger_pagefault_end_jit (type $t0)))
@@ -101,14 +102,53 @@
           (i32.add
             (get_local $l5)
             (i32.const 123456789))
-          (call $e.assert_seg_non_null
+          (call $e.log_segment_null
             (i32.const 3))
+          (if $I5
+            (i32.load8_u
+              (i32.const 727))
+            (then
+              (i32.store
+                (i32.const 64)
+                (get_local $l2))
+              (i32.store
+                (i32.const 68)
+                (get_local $l3))
+              (i32.store
+                (i32.const 72)
+                (get_local $l4))
+              (i32.store
+                (i32.const 76)
+                (get_local $l5))
+              (i32.store
+                (i32.const 80)
+                (get_local $l6))
+              (i32.store
+                (i32.const 84)
+                (get_local $l7))
+              (i32.store
+                (i32.const 88)
+                (get_local $l8))
+              (i32.store
+                (i32.const 92)
+                (get_local $l9))
+              (i32.store
+                (i32.const 560)
+                (i32.or
+                  (i32.and
+                    (i32.load
+                      (i32.const 556))
+                    (i32.const -4096))
+                  (i32.const 0)))
+              (call $e.trigger_gp
+                (i32.const 0))
+              (return)))
           (i32.load
             (i32.const 748))
           (i32.add)
           (set_local $l10)
-          (block $B5
-            (br_if $B5
+          (block $B6
+            (br_if $B6
               (i32.and
                 (i32.eq
                   (i32.and

+ 44 - 4
tests/expect/tests/mov-immoffs.wast

@@ -18,7 +18,8 @@
   (type $t16 (func (param i32 i32 i32 i32) (result i32)))
   (type $t17 (func (param i32 i64 i32) (result i32)))
   (type $t18 (func (param i32 i64 i64 i32) (result i32)))
-  (import "e" "assert_seg_non_null" (func $e.assert_seg_non_null (type $t1)))
+  (import "e" "log_segment_null" (func $e.log_segment_null (type $t1)))
+  (import "e" "trigger_gp" (func $e.trigger_gp (type $t1)))
   (import "e" "safe_read32s_slow_jit" (func $e.safe_read32s_slow_jit (type $t7)))
   (import "e" "instr_F4" (func $e.instr_F4 (type $t0)))
   (import "e" "trigger_pagefault_end_jit" (func $e.trigger_pagefault_end_jit (type $t0)))
@@ -99,14 +100,53 @@
                 (i32.const 664))
               (i32.const 2)))
           (i32.const 51966)
-          (call $e.assert_seg_non_null
+          (call $e.log_segment_null
             (i32.const 3))
+          (if $I5
+            (i32.load8_u
+              (i32.const 727))
+            (then
+              (i32.store
+                (i32.const 64)
+                (get_local $l2))
+              (i32.store
+                (i32.const 68)
+                (get_local $l3))
+              (i32.store
+                (i32.const 72)
+                (get_local $l4))
+              (i32.store
+                (i32.const 76)
+                (get_local $l5))
+              (i32.store
+                (i32.const 80)
+                (get_local $l6))
+              (i32.store
+                (i32.const 84)
+                (get_local $l7))
+              (i32.store
+                (i32.const 88)
+                (get_local $l8))
+              (i32.store
+                (i32.const 92)
+                (get_local $l9))
+              (i32.store
+                (i32.const 560)
+                (i32.or
+                  (i32.and
+                    (i32.load
+                      (i32.const 556))
+                    (i32.const -4096))
+                  (i32.const 0)))
+              (call $e.trigger_gp
+                (i32.const 0))
+              (return)))
           (i32.load
             (i32.const 748))
           (i32.add)
           (set_local $l10)
-          (block $B5
-            (br_if $B5
+          (block $B6
+            (br_if $B6
               (i32.and
                 (i32.eq
                   (i32.and