Browse Source

Remove has_rand_int, always require get_rand_int to be available

Fabian 5 years ago
parent
commit
47e91de601
3 changed files with 3 additions and 28 deletions
  1. 0 1
      src/browser/starter.js
  2. 1 19
      src/lib.js
  3. 2 8
      src/rust/cpu2/instructions_0f.rs

+ 0 - 1
src/browser/starter.js

@@ -115,7 +115,6 @@ function V86Starter(options)
         "unimplemented_sse": function() { return cpu.unimplemented_sse(); },
         "microtick": v86.microtick,
         "get_rand_int": function() { return v86util.get_rand_int(); },
-        "has_rand_int": function() { return v86util.has_rand_int(); },
         "dbg_trace": function()
         {
             dbg_trace();

+ 1 - 19
src/lib.js

@@ -83,11 +83,6 @@ if(typeof window !== "undefined" && window.crypto && window.crypto.getRandomValu
 {
     let rand_data = new Int32Array(1);
 
-    v86util.has_rand_int = function()
-    {
-        return true;
-    };
-
     v86util.get_rand_int = function()
     {
         window.crypto.getRandomValues(rand_data);
@@ -98,11 +93,6 @@ else if(typeof require !== "undefined")
 {
     const crypto = require("crypto");
 
-    v86util.has_rand_int = function()
-    {
-        return true;
-    };
-
     v86util.get_rand_int = function()
     {
         return new Int32Array(crypto.randomBytes(4));
@@ -110,15 +100,7 @@ else if(typeof require !== "undefined")
 }
 else
 {
-    v86util.has_rand_int = function()
-    {
-        return false;
-    };
-
-    v86util.get_rand_int = function()
-    {
-        console.assert(false);
-    };
+    dbg_assert(false, "Unsupported platform: No cryptographic random values");
 }
 
 

+ 2 - 8
src/rust/cpu2/instructions_0f.rs

@@ -12,8 +12,6 @@ extern "C" {
     #[no_mangle]
     fn get_rand_int() -> i32;
     #[no_mangle]
-    fn has_rand_int() -> bool;
-    #[no_mangle]
     fn cpuid();
     #[no_mangle]
     fn lsl(r: i32, v: i32) -> i32;
@@ -3838,14 +3836,10 @@ pub unsafe fn instr_0FC7_1_mem(addr: i32) {
 #[no_mangle]
 pub unsafe fn instr_0FC7_6_reg(r: i32) {
     // rdrand
-    let has_rand: i32 = has_rand_int() as i32;
-    let mut rand: i32 = 0;
-    if 0 != has_rand {
-        rand = get_rand_int()
-    }
+    let rand = get_rand_int();
     write_reg_osize(r, rand);
     *flags &= !FLAGS_ALL;
-    *flags |= has_rand;
+    *flags |= 1;
     *flags_changed = 0;
 }
 #[no_mangle]