| 2177 | namespace platform { |
| 2178 | |
| 2179 | int getRandomSeed() { |
| 2180 | INJECT_FAULT(platform_error, "getRandomSeed"); // getting a random seed failed |
| 2181 | int randomSeed; |
| 2182 | int retryCount = 0; |
| 2183 | |
| 2184 | #ifdef _WIN32 |
| 2185 | do { |
| 2186 | retryCount++; |
| 2187 | if (rand_s((unsigned int*)&randomSeed) != 0) { |
| 2188 | TraceEvent(SevError, "WindowsRandomSeedError").log(); |
| 2189 | throw platform_error(); |
| 2190 | } |
| 2191 | } while (randomSeed == 0 && |
| 2192 | retryCount < |
| 2193 | FLOW_KNOBS->RANDOMSEED_RETRY_LIMIT); // randomSeed cannot be 0 since we use mersenne twister in |
| 2194 | // DeterministicRandom. Get a new one if randomSeed is 0. |
| 2195 | #else |
| 2196 | int devRandom = open("/dev/urandom", O_RDONLY | O_CLOEXEC); |
| 2197 | do { |
| 2198 | retryCount++; |
| 2199 | if (read(devRandom, &randomSeed, sizeof(randomSeed)) != sizeof(randomSeed)) { |
| 2200 | TraceEvent(SevError, "OpenURandom").GetLastError(); |
| 2201 | throw platform_error(); |
| 2202 | } |
| 2203 | } while (randomSeed == 0 && retryCount < FLOW_KNOBS->RANDOMSEED_RETRY_LIMIT); |
| 2204 | close(devRandom); |
| 2205 | #endif |
| 2206 | |
| 2207 | if (randomSeed == 0) { |
| 2208 | TraceEvent(SevError, "RandomSeedZeroError").log(); |
| 2209 | throw platform_error(); |
| 2210 | } |
| 2211 | return randomSeed; |
| 2212 | } |
| 2213 | } // namespace platform |
| 2214 | |
| 2215 | std::string joinPath(std::string const& directory, std::string const& filename) { |
no test coverage detected