Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Side by Side Diff: base/rand_util_nacl.cc

Issue 9474034: Make base::Logging compile with the NaCl toolchain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/logging.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/rand_util.h"
6 #include "base/rand_util_c.h"
7
8 #include "base/lazy_instance.h"
9 #include "base/logging.h"
10
11 // TODO(bbudge) Replace this with a proper system header file when NaCl
12 // provides one.
13 #include "native_client/src/untrusted/irt/irt.h"
14
15 namespace {
16
17 // Create a wrapper class so we can cache the NaCl random number interface.
18 class URandomInterface {
19 public:
20 URandomInterface() {
21 size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1,
22 &interface_,
23 sizeof(interface_));
24 DCHECK_EQ(result, sizeof(interface_)) << "Can't get random interface.";
25 }
26
27 uint64 get_random_bytes() const {
28 size_t nbytes;
29 uint64 result;
30 int error = interface_.get_random_bytes(&result,
31 sizeof(result),
32 &nbytes);
33 DCHECK_EQ(error, 0);
34 DCHECK_EQ(nbytes, sizeof(result));
35 return result;
36 }
37
38 private:
39 struct nacl_irt_random interface_;
40 };
41
42 base::LazyInstance<URandomInterface> g_urandom_interface =
43 LAZY_INSTANCE_INITIALIZER;
44
45 } // namespace
46
47 namespace base {
48
49 uint64 RandUint64() {
50 return g_urandom_interface.Pointer()->get_random_bytes();
51 }
52
53 } // namespace base
54
OLDNEW
« no previous file with comments | « base/logging.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698