瀏覽代碼

Wrap PIT counter value - always

After restore_state, the pit.counter_start_time can be larger
than the current timestamp, leading to negative diff values, and
as a result, when get_counter_value is called, it can return
values larger than 16 bit integers. Thus, when ISA ports 0x40, 0x41, or
0x42 are read, the high-byte that counter_write returns can be larger
than 8-bit. Ultimately, this error is caught by the asserts in io.js. By
always applying a positive modulo to the counter value, it is always
ensured that the counter value is between zero and the reload value.
Ernest Wong 6 年之前
父節點
當前提交
818a6c211f
共有 1 個文件被更改,包括 3 次插入5 次删除
  1. 3 5
      src/pit.js

+ 3 - 5
src/pit.js

@@ -132,11 +132,9 @@ PIT.prototype.get_counter_value = function(i, now)
 
     dbg_log("diff=" + diff + " dticks=" + diff_in_ticks + " value=" + value + " reload=" + this.counter_reload[i], LOG_PIT);
 
-    if(value < 0)
-    {
-        var reload = this.counter_reload[i];
-        value = value % reload + reload;
-    }
+    // could be too large after restore_state
+    var reload = this.counter_reload[i];
+    value = (value % reload + reload) % reload;
 
     return value;
 };