OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if defined(WIN32) | 5 #if defined(WIN32) |
6 #define _CRT_RAND_S | 6 #define _CRT_RAND_S |
7 #endif | 7 #endif |
8 | 8 |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 *out_bytes = 0; | 221 *out_bytes = 0; |
222 | 222 |
223 #if defined(__native_client__) | 223 #if defined(__native_client__) |
224 if (!interface_ok_) | 224 if (!interface_ok_) |
225 return EBADF; | 225 return EBADF; |
226 | 226 |
227 size_t nread; | 227 size_t nread; |
228 int error = (*random_interface_.get_random_bytes)(buf, count, &nread); | 228 int error = (*random_interface_.get_random_bytes)(buf, count, &nread); |
229 if (error) | 229 if (error) |
230 return error; | 230 return error; |
231 | |
232 *out_bytes = count; | |
233 return 0; | |
234 #elif defined(WIN32) | 231 #elif defined(WIN32) |
235 char* out = static_cast<char*>(buf); | 232 char* out = static_cast<char*>(buf); |
236 size_t bytes_left = count; | 233 size_t bytes_left = count; |
237 while (bytes_left) { | 234 while (bytes_left) { |
238 unsigned int random_int; | 235 unsigned int random_int; |
239 errno_t err = rand_s(&random_int); | 236 errno_t err = rand_s(&random_int); |
240 if (err) { | 237 if (err) { |
241 *out_bytes = count - bytes_left; | 238 *out_bytes = count - bytes_left; |
242 return err; | 239 return err; |
243 } | 240 } |
244 | 241 |
245 int bytes_to_copy = std::min(bytes_left, sizeof(random_int)); | 242 int bytes_to_copy = std::min(bytes_left, sizeof(random_int)); |
246 memcpy(out, &random_int, bytes_to_copy); | 243 memcpy(out, &random_int, bytes_to_copy); |
247 out += bytes_to_copy; | 244 out += bytes_to_copy; |
248 bytes_left -= bytes_to_copy; | 245 bytes_left -= bytes_to_copy; |
249 } | 246 } |
| 247 #endif |
250 | 248 |
251 *out_bytes = count; | 249 *out_bytes = count; |
252 return 0; | 250 return 0; |
253 #endif | |
254 } | 251 } |
255 | 252 |
256 Error UrandomNode::Write(const HandleAttr& attr, | 253 Error UrandomNode::Write(const HandleAttr& attr, |
257 const void* buf, | 254 const void* buf, |
258 size_t count, | 255 size_t count, |
259 int* out_bytes) { | 256 int* out_bytes) { |
260 *out_bytes = count; | 257 *out_bytes = count; |
261 return 0; | 258 return 0; |
262 } | 259 } |
263 | 260 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 INITIALIZE_DEV_NODE("/tty", MountNodeTty); | 324 INITIALIZE_DEV_NODE("/tty", MountNodeTty); |
328 INITIALIZE_DEV_NODE_1("/stdin", RealNode, 0); | 325 INITIALIZE_DEV_NODE_1("/stdin", RealNode, 0); |
329 INITIALIZE_DEV_NODE_1("/stdout", RealNode, 1); | 326 INITIALIZE_DEV_NODE_1("/stdout", RealNode, 1); |
330 INITIALIZE_DEV_NODE_1("/stderr", RealNode, 2); | 327 INITIALIZE_DEV_NODE_1("/stderr", RealNode, 2); |
331 | 328 |
332 return 0; | 329 return 0; |
333 } | 330 } |
334 | 331 |
335 } // namespace nacl_io | 332 } // namespace nacl_io |
336 | 333 |
OLD | NEW |