OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #if !defined(__STDC_FORMAT_MACROS) | 15 #if !defined(__STDC_FORMAT_MACROS) |
16 #define __STDC_FORMAT_MACROS | 16 #define __STDC_FORMAT_MACROS |
17 #endif | 17 #endif |
18 | 18 |
19 #include "util/misc/uuid.h" | 19 #include "util/misc/uuid.h" |
20 | 20 |
21 #include <inttypes.h> | 21 #include <inttypes.h> |
22 #include <stdio.h> | 22 #include <stdio.h> |
23 #include <string.h> | 23 #include <string.h> |
24 | 24 |
25 #include "base/logging.h" | 25 #include "base/logging.h" |
| 26 #include "base/rand_util.h" |
26 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
27 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
28 #include "base/sys_byteorder.h" | 29 #include "base/sys_byteorder.h" |
29 #include "util/stdlib/cxx.h" | 30 #include "util/stdlib/cxx.h" |
30 | 31 |
31 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
32 #include <uuid/uuid.h> | 33 #include <uuid/uuid.h> |
33 #endif // OS_MACOSX | 34 #endif // OS_MACOSX |
34 | 35 |
35 #if CXX_LIBRARY_VERSION >= 2011 | 36 #if CXX_LIBRARY_VERSION >= 2011 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 InitializeFromBytes(uuid); | 104 InitializeFromBytes(uuid); |
104 return true; | 105 return true; |
105 #elif defined(OS_WIN) | 106 #elif defined(OS_WIN) |
106 ::UUID system_uuid; | 107 ::UUID system_uuid; |
107 if (UuidCreate(&system_uuid) != RPC_S_OK) { | 108 if (UuidCreate(&system_uuid) != RPC_S_OK) { |
108 LOG(ERROR) << "UuidCreate"; | 109 LOG(ERROR) << "UuidCreate"; |
109 return false; | 110 return false; |
110 } | 111 } |
111 InitializeFromSystemUUID(&system_uuid); | 112 InitializeFromSystemUUID(&system_uuid); |
112 return true; | 113 return true; |
| 114 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
| 115 // Linux does not provide a UUID generator in a widely-available system |
| 116 // library. uuid_generate() from libuuid is not available everywhere. |
| 117 base::RandBytes(this, sizeof(*this)); |
| 118 |
| 119 // Set six bits per RFC 4122 §4.4 to identify this as a pseudo-random UUID. |
| 120 data_3 = (4 << 12) | (data_3 & 0x0fff); // §4.1.3 |
| 121 data_4[0] = 0x80 | (data_4[0] & 0x3f); // §4.1.1 |
| 122 |
| 123 return true; |
113 #else | 124 #else |
114 #error Port. | 125 #error Port. |
115 #endif // OS_MACOSX | 126 #endif // OS_MACOSX |
116 } | 127 } |
117 | 128 |
118 #if defined(OS_WIN) | 129 #if defined(OS_WIN) |
119 void UUID::InitializeFromSystemUUID(const ::UUID* system_uuid) { | 130 void UUID::InitializeFromSystemUUID(const ::UUID* system_uuid) { |
120 static_assert(sizeof(::UUID) == sizeof(UUID), | 131 static_assert(sizeof(::UUID) == sizeof(UUID), |
121 "unexpected system uuid size"); | 132 "unexpected system uuid size"); |
122 static_assert(offsetof(::UUID, Data1) == offsetof(UUID, data_1), | 133 static_assert(offsetof(::UUID, Data1) == offsetof(UUID, data_1), |
(...skipping 17 matching lines...) Expand all Loading... |
140 data_5[5]); | 151 data_5[5]); |
141 } | 152 } |
142 | 153 |
143 #if defined(OS_WIN) | 154 #if defined(OS_WIN) |
144 base::string16 UUID::ToString16() const { | 155 base::string16 UUID::ToString16() const { |
145 return base::UTF8ToUTF16(ToString()); | 156 return base::UTF8ToUTF16(ToString()); |
146 } | 157 } |
147 #endif // OS_WIN | 158 #endif // OS_WIN |
148 | 159 |
149 } // namespace crashpad | 160 } // namespace crashpad |
OLD | NEW |