Revision f230a1cf deps/v8/src/utils/random-number-generator.cc

View differences:

deps/v8/src/utils/random-number-generator.cc
28 28
#include "utils/random-number-generator.h"
29 29

  
30 30
#include <cstdio>
31
#include <cstdlib>
31 32

  
32 33
#include "flags.h"
33 34
#include "platform/mutex.h"
......
67 68
    }
68 69
  }
69 70

  
71
#if V8_OS_CYGWIN || V8_OS_WIN
72
  // Use rand_s() to gather entropy on Windows. See:
73
  // https://code.google.com/p/v8/issues/detail?id=2905
74
  unsigned first_half, second_half;
75
  errno_t result = rand_s(&first_half);
76
  ASSERT_EQ(0, result);
77
  result = rand_s(&second_half);
78
  ASSERT_EQ(0, result);
79
  SetSeed((static_cast<int64_t>(first_half) << 32) + second_half);
80
#else
70 81
  // Gather entropy from /dev/urandom if available.
71 82
  FILE* fp = fopen("/dev/urandom", "rb");
72 83
  if (fp != NULL) {
......
82 93
  // We cannot assume that random() or rand() were seeded
83 94
  // properly, so instead of relying on random() or rand(),
84 95
  // we just seed our PRNG using timing data as fallback.
96
  // This is weak entropy, but it's sufficient, because
97
  // it is the responsibility of the embedder to install
98
  // an entropy source using v8::V8::SetEntropySource(),
99
  // which provides reasonable entropy, see:
100
  // https://code.google.com/p/v8/issues/detail?id=2905
85 101
  int64_t seed = Time::NowFromSystemTime().ToInternalValue() << 24;
86
  seed ^= TimeTicks::HighResNow().ToInternalValue() << 16;
102
  seed ^= TimeTicks::HighResolutionNow().ToInternalValue() << 16;
87 103
  seed ^= TimeTicks::Now().ToInternalValue() << 8;
88 104
  SetSeed(seed);
105
#endif  // V8_OS_CYGWIN || V8_OS_WIN
89 106
}
90 107

  
91 108

  

Also available in: Unified diff