Branch data Line data Source code
1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto
2 : : // Copyright (c) 2009-2022 The Bitcoin Core developers
3 : : // Distributed under the MIT software license, see the accompanying
4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 : :
6 : : #include <config/bitcoin-config.h> // IWYU pragma: keep
7 : :
8 : : #include <randomenv.h>
9 : :
10 : : #include <clientversion.h>
11 : : #include <compat/compat.h>
12 : : #include <compat/cpuid.h>
13 : : #include <crypto/sha512.h>
14 : : #include <span.h>
15 : : #include <support/cleanse.h>
16 : : #include <util/time.h>
17 : :
18 : : #include <algorithm>
19 : : #include <atomic>
20 : : #include <cstdint>
21 : : #include <cstring>
22 : : #include <chrono>
23 : : #include <climits>
24 : : #include <thread>
25 : : #include <vector>
26 : :
27 : : #include <sys/types.h> // must go before a number of other headers
28 : :
29 : : #ifdef WIN32
30 : : #include <windows.h>
31 : : #include <winreg.h>
32 : : #else
33 : : #include <fcntl.h>
34 : : #include <netinet/in.h>
35 : : #include <sys/resource.h>
36 : : #include <sys/socket.h>
37 : : #include <sys/stat.h>
38 : : #include <sys/time.h>
39 : : #include <sys/utsname.h>
40 : : #include <unistd.h>
41 : : #endif
42 : : #if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
43 : : #include <ifaddrs.h>
44 : : #endif
45 : : #if HAVE_SYSCTL
46 : : #include <sys/sysctl.h>
47 : : #if HAVE_VM_VM_PARAM_H
48 : : #include <vm/vm_param.h>
49 : : #endif
50 : : #if HAVE_SYS_RESOURCES_H
51 : : #include <sys/resources.h>
52 : : #endif
53 : : #if HAVE_SYS_VMMETER_H
54 : : #include <sys/vmmeter.h>
55 : : #endif
56 : : #endif
57 : : #if defined(HAVE_STRONG_GETAUXVAL)
58 : : #include <sys/auxv.h>
59 : : #endif
60 : :
61 : : extern char** environ; // NOLINT(readability-redundant-declaration): Necessary on some platforms
62 : :
63 : : namespace {
64 : :
65 : 1 : void RandAddSeedPerfmon(CSHA512& hasher)
66 : : {
67 : : #ifdef WIN32
68 : : // Seed with the entire set of perfmon data
69 : :
70 : : // This can take up to 2 seconds, so only do it every 10 minutes.
71 : : // Initialize last_perfmon to 0 seconds, we don't skip the first call.
72 : : static std::atomic<std::chrono::seconds> last_perfmon{0s};
73 : : auto last_time = last_perfmon.load();
74 : : auto current_time = GetTime<std::chrono::seconds>();
75 : : if (current_time < last_time + std::chrono::minutes{10}) return;
76 : : last_perfmon = current_time;
77 : :
78 : : std::vector<unsigned char> vData(250000, 0);
79 : : long ret = 0;
80 : : unsigned long nSize = 0;
81 : : const size_t nMaxSize = 10000000; // Bail out at more than 10MB of performance data
82 : : while (true) {
83 : : nSize = vData.size();
84 : : ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", nullptr, nullptr, vData.data(), &nSize);
85 : : if (ret != ERROR_MORE_DATA || vData.size() >= nMaxSize)
86 : : break;
87 : : vData.resize(std::min((vData.size() * 3) / 2, nMaxSize)); // Grow size of buffer exponentially
88 : : }
89 : : RegCloseKey(HKEY_PERFORMANCE_DATA);
90 : : if (ret == ERROR_SUCCESS) {
91 : : hasher.Write(vData.data(), nSize);
92 : : memory_cleanse(vData.data(), nSize);
93 : : } else {
94 : : // Performance data is only a best-effort attempt at improving the
95 : : // situation when the OS randomness (and other sources) aren't
96 : : // adequate. As a result, failure to read it is isn't considered critical,
97 : : // so we don't call RandFailure().
98 : : // TODO: Add logging when the logger is made functional before global
99 : : // constructors have been invoked.
100 : : }
101 : : #endif
102 : 1 : }
103 : :
104 : : /** Helper to easily feed data into a CSHA512.
105 : : *
106 : : * Note that this does not serialize the passed object (like stream.h's << operators do).
107 : : * Its raw memory representation is used directly.
108 : : */
109 : : template<typename T>
110 : 315 : CSHA512& operator<<(CSHA512& hasher, const T& data) {
111 : : static_assert(!std::is_same<typename std::decay<T>::type, char*>::value, "Calling operator<<(CSHA512, char*) is probably not what you want");
112 : : static_assert(!std::is_same<typename std::decay<T>::type, unsigned char*>::value, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
113 : : static_assert(!std::is_same<typename std::decay<T>::type, const char*>::value, "Calling operator<<(CSHA512, const char*) is probably not what you want");
114 : : static_assert(!std::is_same<typename std::decay<T>::type, const unsigned char*>::value, "Calling operator<<(CSHA512, const unsigned char*) is probably not what you want");
115 : 315 : hasher.Write((const unsigned char*)&data, sizeof(data));
116 : 315 : return hasher;
117 : : }
118 : :
119 : : #ifndef WIN32
120 : 21 : void AddSockaddr(CSHA512& hasher, const struct sockaddr *addr)
121 : : {
122 [ + + ]: 21 : if (addr == nullptr) return;
123 [ + + + ]: 16 : switch (addr->sa_family) {
124 : : case AF_INET:
125 : 6 : hasher.Write((const unsigned char*)addr, sizeof(sockaddr_in));
126 : 6 : break;
127 : : case AF_INET6:
128 : 6 : hasher.Write((const unsigned char*)addr, sizeof(sockaddr_in6));
129 : 6 : break;
130 : : default:
131 : 4 : hasher.Write((const unsigned char*)&addr->sa_family, sizeof(addr->sa_family));
132 : 4 : }
133 : 21 : }
134 : :
135 : 18 : void AddFile(CSHA512& hasher, const char *path)
136 : : {
137 : 18 : struct stat sb = {};
138 : 18 : int f = open(path, O_RDONLY);
139 : 18 : size_t total = 0;
140 [ + + ]: 18 : if (f != -1) {
141 : 16 : unsigned char fbuf[4096];
142 : 16 : int n;
143 : 16 : hasher.Write((const unsigned char*)&f, sizeof(f));
144 [ + - ]: 16 : if (fstat(f, &sb) == 0) hasher << sb;
145 : 16 : do {
146 : 18 : n = read(f, fbuf, sizeof(fbuf));
147 [ - + ]: 18 : if (n > 0) hasher.Write(fbuf, n);
148 : 18 : total += n;
149 : : /* not bothering with EINTR handling. */
150 [ + + + + ]: 18 : } while (n == sizeof(fbuf) && total < 1048576); // Read only the first 1 Mbyte
151 : 16 : close(f);
152 : 16 : }
153 : 18 : }
154 : :
155 : 5 : void AddPath(CSHA512& hasher, const char *path)
156 : : {
157 : 5 : struct stat sb = {};
158 [ + - ]: 5 : if (stat(path, &sb) == 0) {
159 : 5 : hasher.Write((const unsigned char*)path, strlen(path) + 1);
160 : 5 : hasher << sb;
161 : 5 : }
162 : 5 : }
163 : : #endif
164 : :
165 : : #if HAVE_SYSCTL
166 : : template<int... S>
167 : : void AddSysctl(CSHA512& hasher)
168 : : {
169 : : int CTL[sizeof...(S)] = {S...};
170 : : unsigned char buffer[65536];
171 : : size_t siz = 65536;
172 : : int ret = sysctl(CTL, sizeof...(S), buffer, &siz, nullptr, 0);
173 : : if (ret == 0 || (ret == -1 && errno == ENOMEM)) {
174 : : hasher << sizeof(CTL);
175 : : hasher.Write((const unsigned char*)CTL, sizeof(CTL));
176 : : if (siz > sizeof(buffer)) siz = sizeof(buffer);
177 : : hasher << siz;
178 : : hasher.Write(buffer, siz);
179 : : }
180 : : }
181 : : #endif
182 : :
183 : : #ifdef HAVE_GETCPUID
184 : 43 : void inline AddCPUID(CSHA512& hasher, uint32_t leaf, uint32_t subleaf, uint32_t& ax, uint32_t& bx, uint32_t& cx, uint32_t& dx)
185 : : {
186 : 43 : GetCPUID(leaf, subleaf, ax, bx, cx, dx);
187 : 43 : hasher << leaf << subleaf << ax << bx << cx << dx;
188 : 43 : }
189 : :
190 : 1 : void AddAllCPUID(CSHA512& hasher)
191 : : {
192 : 1 : uint32_t ax, bx, cx, dx;
193 : : // Iterate over all standard leaves
194 : 1 : AddCPUID(hasher, 0, 0, ax, bx, cx, dx); // Returns max leaf in ax
195 : 1 : uint32_t max = ax;
196 [ + + + + ]: 23 : for (uint32_t leaf = 1; leaf <= max && leaf <= 0xFF; ++leaf) {
197 : 22 : uint32_t maxsub = 0;
198 [ + - ]: 55 : for (uint32_t subleaf = 0; subleaf <= 0xFF; ++subleaf) {
199 : 33 : AddCPUID(hasher, leaf, subleaf, ax, bx, cx, dx);
200 : : // Iterate subleafs for leaf values 4, 7, 11, 13
201 [ + + ]: 33 : if (leaf == 4) {
202 [ + + ]: 5 : if ((ax & 0x1f) == 0) break;
203 [ + + ]: 32 : } else if (leaf == 7) {
204 [ - + ]: 1 : if (subleaf == 0) maxsub = ax;
205 [ - + ]: 1 : if (subleaf == maxsub) break;
206 [ + + ]: 27 : } else if (leaf == 11) {
207 [ + + ]: 3 : if ((cx & 0xff00) == 0) break;
208 [ + + ]: 26 : } else if (leaf == 13) {
209 [ + + + - : 6 : if (ax == 0 && bx == 0 && cx == 0 && dx == 0) break;
+ - - + ]
210 : 5 : } else {
211 : : // For any other leaf, stop after subleaf 0.
212 : 18 : break;
213 : : }
214 : 11 : }
215 : 22 : }
216 : : // Iterate over all extended leaves
217 : 1 : AddCPUID(hasher, 0x80000000, 0, ax, bx, cx, dx); // Returns max extended leaf in ax
218 : 1 : uint32_t ext_max = ax;
219 [ + + + + ]: 9 : for (uint32_t leaf = 0x80000001; leaf <= ext_max && leaf <= 0x800000FF; ++leaf) {
220 : 8 : AddCPUID(hasher, leaf, 0, ax, bx, cx, dx);
221 : 8 : }
222 : 1 : }
223 : : #endif
224 : : } // namespace
225 : :
226 : 1 : void RandAddDynamicEnv(CSHA512& hasher)
227 : : {
228 : 1 : RandAddSeedPerfmon(hasher);
229 : :
230 : : // Various clocks
231 : : #ifdef WIN32
232 : : FILETIME ftime;
233 : : GetSystemTimeAsFileTime(&ftime);
234 : : hasher << ftime;
235 : : #else
236 : 1 : struct timespec ts = {};
237 : : # ifdef CLOCK_MONOTONIC
238 : 1 : clock_gettime(CLOCK_MONOTONIC, &ts);
239 : 1 : hasher << ts;
240 : : # endif
241 : : # ifdef CLOCK_REALTIME
242 : 1 : clock_gettime(CLOCK_REALTIME, &ts);
243 : 1 : hasher << ts;
244 : : # endif
245 : : # ifdef CLOCK_BOOTTIME
246 : 1 : clock_gettime(CLOCK_BOOTTIME, &ts);
247 : 1 : hasher << ts;
248 : : # endif
249 : : // gettimeofday is available on all UNIX systems, but only has microsecond precision.
250 : 1 : struct timeval tv = {};
251 : 1 : gettimeofday(&tv, nullptr);
252 : 1 : hasher << tv;
253 : : #endif
254 : : // Probably redundant, but also use all the standard library clocks:
255 : 1 : hasher << std::chrono::system_clock::now().time_since_epoch().count();
256 : 1 : hasher << std::chrono::steady_clock::now().time_since_epoch().count();
257 : 1 : hasher << std::chrono::high_resolution_clock::now().time_since_epoch().count();
258 : :
259 : : #ifndef WIN32
260 : : // Current resource usage.
261 : 1 : struct rusage usage = {};
262 [ + - ]: 1 : if (getrusage(RUSAGE_SELF, &usage) == 0) hasher << usage;
263 : : #endif
264 : :
265 : : #ifdef __linux__
266 : 1 : AddFile(hasher, "/proc/diskstats");
267 : 1 : AddFile(hasher, "/proc/vmstat");
268 : 1 : AddFile(hasher, "/proc/schedstat");
269 : 1 : AddFile(hasher, "/proc/zoneinfo");
270 : 1 : AddFile(hasher, "/proc/meminfo");
271 : 1 : AddFile(hasher, "/proc/softirqs");
272 : 1 : AddFile(hasher, "/proc/stat");
273 : 1 : AddFile(hasher, "/proc/self/schedstat");
274 : 1 : AddFile(hasher, "/proc/self/status");
275 : : #endif
276 : :
277 : : #if HAVE_SYSCTL
278 : : # ifdef CTL_KERN
279 : : # if defined(KERN_PROC) && defined(KERN_PROC_ALL)
280 : : AddSysctl<CTL_KERN, KERN_PROC, KERN_PROC_ALL>(hasher);
281 : : # endif
282 : : # endif
283 : : # ifdef CTL_HW
284 : : # ifdef HW_DISKSTATS
285 : : AddSysctl<CTL_HW, HW_DISKSTATS>(hasher);
286 : : # endif
287 : : # endif
288 : : # ifdef CTL_VM
289 : : # ifdef VM_LOADAVG
290 : : AddSysctl<CTL_VM, VM_LOADAVG>(hasher);
291 : : # endif
292 : : # ifdef VM_TOTAL
293 : : AddSysctl<CTL_VM, VM_TOTAL>(hasher);
294 : : # endif
295 : : # ifdef VM_METER
296 : : AddSysctl<CTL_VM, VM_METER>(hasher);
297 : : # endif
298 : : # endif
299 : : #endif
300 : :
301 : : // Stack and heap location
302 : 1 : void* addr = malloc(4097);
303 : 1 : hasher << &addr << addr;
304 : 1 : free(addr);
305 : 1 : }
306 : :
307 : 1 : void RandAddStaticEnv(CSHA512& hasher)
308 : : {
309 : : // Some compile-time static properties
310 : 1 : hasher << (CHAR_MIN < 0) << sizeof(void*) << sizeof(long) << sizeof(int);
311 : : #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
312 : 1 : hasher << __GNUC__ << __GNUC_MINOR__ << __GNUC_PATCHLEVEL__;
313 : : #endif
314 : : #ifdef _MSC_VER
315 : : hasher << _MSC_VER;
316 : : #endif
317 : 1 : hasher << __cplusplus;
318 : : #ifdef _XOPEN_VERSION
319 : 1 : hasher << _XOPEN_VERSION;
320 : : #endif
321 : : #ifdef __VERSION__
322 : 1 : const char* COMPILER_VERSION = __VERSION__;
323 : 1 : hasher.Write((const unsigned char*)COMPILER_VERSION, strlen(COMPILER_VERSION) + 1);
324 : : #endif
325 : :
326 : : // Bitcoin client version
327 : 1 : hasher << CLIENT_VERSION;
328 : :
329 : : #if defined(HAVE_STRONG_GETAUXVAL)
330 : : // Information available through getauxval()
331 : : # ifdef AT_HWCAP
332 : 1 : hasher << getauxval(AT_HWCAP);
333 : : # endif
334 : : # ifdef AT_HWCAP2
335 : 1 : hasher << getauxval(AT_HWCAP2);
336 : : # endif
337 : : # ifdef AT_RANDOM
338 : 1 : const unsigned char* random_aux = (const unsigned char*)getauxval(AT_RANDOM);
339 [ - + ]: 1 : if (random_aux) hasher.Write(random_aux, 16);
340 : : # endif
341 : : # ifdef AT_PLATFORM
342 : 1 : const char* platform_str = (const char*)getauxval(AT_PLATFORM);
343 [ - + ]: 1 : if (platform_str) hasher.Write((const unsigned char*)platform_str, strlen(platform_str) + 1);
344 : : # endif
345 : : # ifdef AT_EXECFN
346 : 1 : const char* exec_str = (const char*)getauxval(AT_EXECFN);
347 [ - + ]: 1 : if (exec_str) hasher.Write((const unsigned char*)exec_str, strlen(exec_str) + 1);
348 : : # endif
349 : : #endif // HAVE_STRONG_GETAUXVAL
350 : :
351 : : #ifdef HAVE_GETCPUID
352 : 1 : AddAllCPUID(hasher);
353 : : #endif
354 : :
355 : : // Memory locations
356 : 1 : hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ;
357 : :
358 : : // Hostname
359 : : #ifdef WIN32
360 : : constexpr DWORD max_size = MAX_COMPUTERNAME_LENGTH + 1;
361 : : char hname[max_size];
362 : : DWORD size = max_size;
363 : : if (GetComputerNameA(hname, &size) != 0) {
364 : : hasher.Write(UCharCast(hname), size);
365 : : }
366 : : #else
367 : 1 : char hname[256];
368 [ + - ]: 1 : if (gethostname(hname, 256) == 0) {
369 : 1 : hasher.Write((const unsigned char*)hname, strnlen(hname, 256));
370 : 1 : }
371 : : #endif
372 : :
373 : : #if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
374 : : // Network interfaces
375 : 1 : struct ifaddrs *ifad = nullptr;
376 : 1 : getifaddrs(&ifad);
377 : 1 : struct ifaddrs *ifit = ifad;
378 [ + + ]: 8 : while (ifit != nullptr) {
379 : 7 : hasher.Write((const unsigned char*)&ifit, sizeof(ifit));
380 : 7 : hasher.Write((const unsigned char*)ifit->ifa_name, strlen(ifit->ifa_name) + 1);
381 : 7 : hasher.Write((const unsigned char*)&ifit->ifa_flags, sizeof(ifit->ifa_flags));
382 : 7 : AddSockaddr(hasher, ifit->ifa_addr);
383 : 7 : AddSockaddr(hasher, ifit->ifa_netmask);
384 : 7 : AddSockaddr(hasher, ifit->ifa_dstaddr);
385 : 7 : ifit = ifit->ifa_next;
386 : : }
387 : 1 : freeifaddrs(ifad);
388 : : #endif
389 : :
390 : : #ifndef WIN32
391 : : // UNIX kernel information
392 : 1 : struct utsname name;
393 [ - + ]: 1 : if (uname(&name) != -1) {
394 : 1 : hasher.Write((const unsigned char*)&name.sysname, strlen(name.sysname) + 1);
395 : 1 : hasher.Write((const unsigned char*)&name.nodename, strlen(name.nodename) + 1);
396 : 1 : hasher.Write((const unsigned char*)&name.release, strlen(name.release) + 1);
397 : 1 : hasher.Write((const unsigned char*)&name.version, strlen(name.version) + 1);
398 : 1 : hasher.Write((const unsigned char*)&name.machine, strlen(name.machine) + 1);
399 : 1 : }
400 : :
401 : : /* Path and filesystem provided data */
402 : 1 : AddPath(hasher, "/");
403 : 1 : AddPath(hasher, ".");
404 : 1 : AddPath(hasher, "/tmp");
405 : 1 : AddPath(hasher, "/home");
406 : 1 : AddPath(hasher, "/proc");
407 : : #ifdef __linux__
408 : 1 : AddFile(hasher, "/proc/cmdline");
409 : 1 : AddFile(hasher, "/proc/cpuinfo");
410 : 1 : AddFile(hasher, "/proc/version");
411 : : #endif
412 : 1 : AddFile(hasher, "/etc/passwd");
413 : 1 : AddFile(hasher, "/etc/group");
414 : 1 : AddFile(hasher, "/etc/hosts");
415 : 1 : AddFile(hasher, "/etc/resolv.conf");
416 : 1 : AddFile(hasher, "/etc/timezone");
417 : 1 : AddFile(hasher, "/etc/localtime");
418 : : #endif
419 : :
420 : : // For MacOS/BSDs, gather data through sysctl instead of /proc. Not all of these
421 : : // will exist on every system.
422 : : #if HAVE_SYSCTL
423 : : # ifdef CTL_HW
424 : : # ifdef HW_MACHINE
425 : : AddSysctl<CTL_HW, HW_MACHINE>(hasher);
426 : : # endif
427 : : # ifdef HW_MODEL
428 : : AddSysctl<CTL_HW, HW_MODEL>(hasher);
429 : : # endif
430 : : # ifdef HW_NCPU
431 : : AddSysctl<CTL_HW, HW_NCPU>(hasher);
432 : : # endif
433 : : # ifdef HW_PHYSMEM
434 : : AddSysctl<CTL_HW, HW_PHYSMEM>(hasher);
435 : : # endif
436 : : # ifdef HW_USERMEM
437 : : AddSysctl<CTL_HW, HW_USERMEM>(hasher);
438 : : # endif
439 : : # ifdef HW_MACHINE_ARCH
440 : : AddSysctl<CTL_HW, HW_MACHINE_ARCH>(hasher);
441 : : # endif
442 : : # ifdef HW_REALMEM
443 : : AddSysctl<CTL_HW, HW_REALMEM>(hasher);
444 : : # endif
445 : : # ifdef HW_CPU_FREQ
446 : : AddSysctl<CTL_HW, HW_CPU_FREQ>(hasher);
447 : : # endif
448 : : # ifdef HW_BUS_FREQ
449 : : AddSysctl<CTL_HW, HW_BUS_FREQ>(hasher);
450 : : # endif
451 : : # ifdef HW_CACHELINE
452 : : AddSysctl<CTL_HW, HW_CACHELINE>(hasher);
453 : : # endif
454 : : # endif
455 : : # ifdef CTL_KERN
456 : : # ifdef KERN_BOOTFILE
457 : : AddSysctl<CTL_KERN, KERN_BOOTFILE>(hasher);
458 : : # endif
459 : : # ifdef KERN_BOOTTIME
460 : : AddSysctl<CTL_KERN, KERN_BOOTTIME>(hasher);
461 : : # endif
462 : : # ifdef KERN_CLOCKRATE
463 : : AddSysctl<CTL_KERN, KERN_CLOCKRATE>(hasher);
464 : : # endif
465 : : # ifdef KERN_HOSTID
466 : : AddSysctl<CTL_KERN, KERN_HOSTID>(hasher);
467 : : # endif
468 : : # ifdef KERN_HOSTUUID
469 : : AddSysctl<CTL_KERN, KERN_HOSTUUID>(hasher);
470 : : # endif
471 : : # ifdef KERN_HOSTNAME
472 : : AddSysctl<CTL_KERN, KERN_HOSTNAME>(hasher);
473 : : # endif
474 : : # ifdef KERN_OSRELDATE
475 : : AddSysctl<CTL_KERN, KERN_OSRELDATE>(hasher);
476 : : # endif
477 : : # ifdef KERN_OSRELEASE
478 : : AddSysctl<CTL_KERN, KERN_OSRELEASE>(hasher);
479 : : # endif
480 : : # ifdef KERN_OSREV
481 : : AddSysctl<CTL_KERN, KERN_OSREV>(hasher);
482 : : # endif
483 : : # ifdef KERN_OSTYPE
484 : : AddSysctl<CTL_KERN, KERN_OSTYPE>(hasher);
485 : : # endif
486 : : # ifdef KERN_POSIX1
487 : : AddSysctl<CTL_KERN, KERN_OSREV>(hasher);
488 : : # endif
489 : : # ifdef KERN_VERSION
490 : : AddSysctl<CTL_KERN, KERN_VERSION>(hasher);
491 : : # endif
492 : : # endif
493 : : #endif
494 : :
495 : : // Env variables
496 [ - + ]: 1 : if (environ) {
497 [ + + ]: 8 : for (size_t i = 0; environ[i]; ++i) {
498 : 7 : hasher.Write((const unsigned char*)environ[i], strlen(environ[i]));
499 : 7 : }
500 : 1 : }
501 : :
502 : : // Process, thread, user, session, group, ... ids.
503 : : #ifdef WIN32
504 : : hasher << GetCurrentProcessId() << GetCurrentThreadId();
505 : : #else
506 : 1 : hasher << getpid() << getppid() << getsid(0) << getpgid(0) << getuid() << geteuid() << getgid() << getegid();
507 : : #endif
508 : 1 : hasher << std::this_thread::get_id();
509 : 1 : }
|