Coverage Report

Created: 2025-03-18 19:34

/root/bitcoin/src/randomenv.cpp
Line
Count
Source (jump to first uncovered line)
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 <bitcoin-build-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
#else
32
#include <fcntl.h>
33
#include <netinet/in.h>
34
#include <sys/resource.h>
35
#include <sys/socket.h>
36
#include <sys/stat.h>
37
#include <sys/time.h>
38
#include <sys/utsname.h>
39
#include <unistd.h>
40
#endif
41
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
42
#include <ifaddrs.h>
43
#endif
44
#ifdef HAVE_SYSCTL
45
#include <sys/sysctl.h>
46
#ifdef HAVE_VM_VM_PARAM_H
47
#include <vm/vm_param.h>
48
#endif
49
#ifdef HAVE_SYS_RESOURCES_H
50
#include <sys/resources.h>
51
#endif
52
#ifdef HAVE_SYS_VMMETER_H
53
#include <sys/vmmeter.h>
54
#endif
55
#endif
56
#if defined(HAVE_STRONG_GETAUXVAL)
57
#include <sys/auxv.h>
58
#endif
59
60
#ifndef _MSC_VER
61
extern char** environ; // NOLINT(readability-redundant-declaration): Necessary on some platforms
62
#endif
63
64
namespace {
65
66
/** Helper to easily feed data into a CSHA512.
67
 *
68
 * Note that this does not serialize the passed object (like stream.h's << operators do).
69
 * Its raw memory representation is used directly.
70
 */
71
template<typename T>
72
0
CSHA512& operator<<(CSHA512& hasher, const T& data) {
73
0
    static_assert(!std::is_same_v<std::decay_t<T>, char*>, "Calling operator<<(CSHA512, char*) is probably not what you want");
74
0
    static_assert(!std::is_same_v<std::decay_t<T>, unsigned char*>, "Calling operator<<(CSHA512, unsigned char*) is probably not what you want");
75
0
    static_assert(!std::is_same_v<std::decay_t<T>, const char*>, "Calling operator<<(CSHA512, const char*) is probably not what you want");
76
0
    static_assert(!std::is_same_v<std::decay_t<T>, const unsigned char*>, "Calling operator<<(CSHA512, const unsigned char*) is probably not what you want");
77
0
    hasher.Write((const unsigned char*)&data, sizeof(data));
78
0
    return hasher;
79
0
}
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <stat>(CSHA512&, stat const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <unsigned int>(CSHA512&, unsigned int const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <timespec>(CSHA512&, timespec const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <timeval>(CSHA512&, timeval const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <long>(CSHA512&, long const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <rusage>(CSHA512&, rusage const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <void**>(CSHA512&, void** const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <void*>(CSHA512&, void* const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <bool>(CSHA512&, bool const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <unsigned long>(CSHA512&, unsigned long const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <int>(CSHA512&, int const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <CSHA512*>(CSHA512&, CSHA512* const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <void (*)(CSHA512&)>(CSHA512&, void (* const&)(CSHA512&))
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <void* (*)(unsigned long) noexcept>(CSHA512&, void* (* const&)(unsigned long) noexcept)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <int*>(CSHA512&, int* const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <char***>(CSHA512&, char*** const&)
Unexecuted instantiation: randomenv.cpp:CSHA512& (anonymous namespace)::operator<< <std::thread::id>(CSHA512&, std::thread::id const&)
80
81
#ifndef WIN32
82
void AddSockaddr(CSHA512& hasher, const struct sockaddr *addr)
83
0
{
84
0
    if (addr == nullptr) return;
  Branch (84:9): [True: 0, False: 0]
85
0
    switch (addr->sa_family) {
86
0
    case AF_INET:
  Branch (86:5): [True: 0, False: 0]
87
0
        hasher.Write((const unsigned char*)addr, sizeof(sockaddr_in));
88
0
        break;
89
0
    case AF_INET6:
  Branch (89:5): [True: 0, False: 0]
90
0
        hasher.Write((const unsigned char*)addr, sizeof(sockaddr_in6));
91
0
        break;
92
0
    default:
  Branch (92:5): [True: 0, False: 0]
93
0
        hasher.Write((const unsigned char*)&addr->sa_family, sizeof(addr->sa_family));
94
0
    }
95
0
}
96
97
void AddFile(CSHA512& hasher, const char *path)
98
0
{
99
0
    struct stat sb = {};
100
0
    int f = open(path, O_RDONLY);
101
0
    size_t total = 0;
102
0
    if (f != -1) {
  Branch (102:9): [True: 0, False: 0]
103
0
        unsigned char fbuf[4096];
104
0
        int n;
105
0
        hasher.Write((const unsigned char*)&f, sizeof(f));
106
0
        if (fstat(f, &sb) == 0) hasher << sb;
  Branch (106:13): [True: 0, False: 0]
107
0
        do {
108
0
            n = read(f, fbuf, sizeof(fbuf));
109
0
            if (n > 0) hasher.Write(fbuf, n);
  Branch (109:17): [True: 0, False: 0]
110
0
            total += n;
111
            /* not bothering with EINTR handling. */
112
0
        } while (n == sizeof(fbuf) && total < 1048576); // Read only the first 1 Mbyte
  Branch (112:18): [True: 0, False: 0]
  Branch (112:39): [True: 0, False: 0]
113
0
        close(f);
114
0
    }
115
0
}
116
117
void AddPath(CSHA512& hasher, const char *path)
118
0
{
119
0
    struct stat sb = {};
120
0
    if (stat(path, &sb) == 0) {
  Branch (120:9): [True: 0, False: 0]
121
0
        hasher.Write((const unsigned char*)path, strlen(path) + 1);
122
0
        hasher << sb;
123
0
    }
124
0
}
125
#endif
126
127
#ifdef HAVE_SYSCTL
128
template<int... S>
129
void AddSysctl(CSHA512& hasher)
130
{
131
    int CTL[sizeof...(S)] = {S...};
132
    unsigned char buffer[65536];
133
    size_t siz = 65536;
134
    int ret = sysctl(CTL, sizeof...(S), buffer, &siz, nullptr, 0);
135
    if (ret == 0 || (ret == -1 && errno == ENOMEM)) {
136
        hasher << sizeof(CTL);
137
        hasher.Write((const unsigned char*)CTL, sizeof(CTL));
138
        if (siz > sizeof(buffer)) siz = sizeof(buffer);
139
        hasher << siz;
140
        hasher.Write(buffer, siz);
141
    }
142
}
143
#endif
144
145
#ifdef HAVE_GETCPUID
146
void inline AddCPUID(CSHA512& hasher, uint32_t leaf, uint32_t subleaf, uint32_t& ax, uint32_t& bx, uint32_t& cx, uint32_t& dx)
147
0
{
148
0
    GetCPUID(leaf, subleaf, ax, bx, cx, dx);
149
0
    hasher << leaf << subleaf << ax << bx << cx << dx;
150
0
}
151
152
void AddAllCPUID(CSHA512& hasher)
153
0
{
154
0
    uint32_t ax, bx, cx, dx;
155
    // Iterate over all standard leaves
156
0
    AddCPUID(hasher, 0, 0, ax, bx, cx, dx); // Returns max leaf in ax
157
0
    uint32_t max = ax;
158
0
    for (uint32_t leaf = 1; leaf <= max && leaf <= 0xFF; ++leaf) {
  Branch (158:29): [True: 0, False: 0]
  Branch (158:44): [True: 0, False: 0]
159
0
        uint32_t maxsub = 0;
160
0
        for (uint32_t subleaf = 0; subleaf <= 0xFF; ++subleaf) {
  Branch (160:36): [True: 0, False: 0]
161
0
            AddCPUID(hasher, leaf, subleaf, ax, bx, cx, dx);
162
            // Iterate subleafs for leaf values 4, 7, 11, 13
163
0
            if (leaf == 4) {
  Branch (163:17): [True: 0, False: 0]
164
0
                if ((ax & 0x1f) == 0) break;
  Branch (164:21): [True: 0, False: 0]
165
0
            } else if (leaf == 7) {
  Branch (165:24): [True: 0, False: 0]
166
0
                if (subleaf == 0) maxsub = ax;
  Branch (166:21): [True: 0, False: 0]
167
0
                if (subleaf == maxsub) break;
  Branch (167:21): [True: 0, False: 0]
168
0
            } else if (leaf == 11) {
  Branch (168:24): [True: 0, False: 0]
169
0
                if ((cx & 0xff00) == 0) break;
  Branch (169:21): [True: 0, False: 0]
170
0
            } else if (leaf == 13) {
  Branch (170:24): [True: 0, False: 0]
171
0
                if (ax == 0 && bx == 0 && cx == 0 && dx == 0) break;
  Branch (171:21): [True: 0, False: 0]
  Branch (171:32): [True: 0, False: 0]
  Branch (171:43): [True: 0, False: 0]
  Branch (171:54): [True: 0, False: 0]
172
0
            } else {
173
                // For any other leaf, stop after subleaf 0.
174
0
                break;
175
0
            }
176
0
        }
177
0
    }
178
    // Iterate over all extended leaves
179
0
    AddCPUID(hasher, 0x80000000, 0, ax, bx, cx, dx); // Returns max extended leaf in ax
180
0
    uint32_t ext_max = ax;
181
0
    for (uint32_t leaf = 0x80000001; leaf <= ext_max && leaf <= 0x800000FF; ++leaf) {
  Branch (181:38): [True: 0, False: 0]
  Branch (181:57): [True: 0, False: 0]
182
0
        AddCPUID(hasher, leaf, 0, ax, bx, cx, dx);
183
0
    }
184
0
}
185
#endif
186
} // namespace
187
188
void RandAddDynamicEnv(CSHA512& hasher)
189
0
{
190
    // Various clocks
191
#ifdef WIN32
192
    FILETIME ftime;
193
    GetSystemTimeAsFileTime(&ftime);
194
    hasher << ftime;
195
#else
196
0
    struct timespec ts = {};
197
0
#    ifdef CLOCK_MONOTONIC
198
0
    clock_gettime(CLOCK_MONOTONIC, &ts);
199
0
    hasher << ts;
200
0
#    endif
201
0
#    ifdef CLOCK_REALTIME
202
0
    clock_gettime(CLOCK_REALTIME, &ts);
203
0
    hasher << ts;
204
0
#    endif
205
0
#    ifdef CLOCK_BOOTTIME
206
0
    clock_gettime(CLOCK_BOOTTIME, &ts);
207
0
    hasher << ts;
208
0
#    endif
209
    // gettimeofday is available on all UNIX systems, but only has microsecond precision.
210
0
    struct timeval tv = {};
211
0
    gettimeofday(&tv, nullptr);
212
0
    hasher << tv;
213
0
#endif
214
    // Probably redundant, but also use all the standard library clocks:
215
0
    hasher << std::chrono::system_clock::now().time_since_epoch().count();
216
0
    hasher << std::chrono::steady_clock::now().time_since_epoch().count();
217
0
    hasher << std::chrono::high_resolution_clock::now().time_since_epoch().count();
218
219
0
#ifndef WIN32
220
    // Current resource usage.
221
0
    struct rusage usage = {};
222
0
    if (getrusage(RUSAGE_SELF, &usage) == 0) hasher << usage;
  Branch (222:9): [True: 0, False: 0]
223
0
#endif
224
225
0
#ifdef __linux__
226
0
    AddFile(hasher, "/proc/diskstats");
227
0
    AddFile(hasher, "/proc/vmstat");
228
0
    AddFile(hasher, "/proc/schedstat");
229
0
    AddFile(hasher, "/proc/zoneinfo");
230
0
    AddFile(hasher, "/proc/meminfo");
231
0
    AddFile(hasher, "/proc/softirqs");
232
0
    AddFile(hasher, "/proc/stat");
233
0
    AddFile(hasher, "/proc/self/schedstat");
234
0
    AddFile(hasher, "/proc/self/status");
235
0
#endif
236
237
#ifdef HAVE_SYSCTL
238
#  ifdef CTL_KERN
239
#    if defined(KERN_PROC) && defined(KERN_PROC_ALL)
240
    AddSysctl<CTL_KERN, KERN_PROC, KERN_PROC_ALL>(hasher);
241
#    endif
242
#  endif
243
#  ifdef CTL_HW
244
#    ifdef HW_DISKSTATS
245
    AddSysctl<CTL_HW, HW_DISKSTATS>(hasher);
246
#    endif
247
#  endif
248
#  ifdef CTL_VM
249
#    ifdef VM_LOADAVG
250
    AddSysctl<CTL_VM, VM_LOADAVG>(hasher);
251
#    endif
252
#    ifdef VM_TOTAL
253
    AddSysctl<CTL_VM, VM_TOTAL>(hasher);
254
#    endif
255
#    ifdef VM_METER
256
    AddSysctl<CTL_VM, VM_METER>(hasher);
257
#    endif
258
#  endif
259
#endif
260
261
    // Stack and heap location
262
0
    void* addr = malloc(4097);
263
0
    hasher << &addr << addr;
264
0
    free(addr);
265
0
}
266
267
void RandAddStaticEnv(CSHA512& hasher)
268
0
{
269
    // Some compile-time static properties
270
0
    hasher << (CHAR_MIN < 0) << sizeof(void*) << sizeof(long) << sizeof(int);
271
0
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
272
0
    hasher << __GNUC__ << __GNUC_MINOR__ << __GNUC_PATCHLEVEL__;
273
0
#endif
274
#ifdef _MSC_VER
275
    hasher << _MSC_VER;
276
#endif
277
0
    hasher << __cplusplus;
278
0
#ifdef _XOPEN_VERSION
279
0
    hasher << _XOPEN_VERSION;
280
0
#endif
281
0
#ifdef __VERSION__
282
0
    const char* COMPILER_VERSION = __VERSION__;
283
0
    hasher.Write((const unsigned char*)COMPILER_VERSION, strlen(COMPILER_VERSION) + 1);
284
0
#endif
285
286
    // Bitcoin client version
287
0
    hasher << CLIENT_VERSION;
288
289
0
#if defined(HAVE_STRONG_GETAUXVAL)
290
    // Information available through getauxval()
291
0
#  ifdef AT_HWCAP
292
0
    hasher << getauxval(AT_HWCAP);
293
0
#  endif
294
0
#  ifdef AT_HWCAP2
295
0
    hasher << getauxval(AT_HWCAP2);
296
0
#  endif
297
0
#  ifdef AT_RANDOM
298
0
    const unsigned char* random_aux = (const unsigned char*)getauxval(AT_RANDOM);
299
0
    if (random_aux) hasher.Write(random_aux, 16);
  Branch (299:9): [True: 0, False: 0]
300
0
#  endif
301
0
#  ifdef AT_PLATFORM
302
0
    const char* platform_str = (const char*)getauxval(AT_PLATFORM);
303
0
    if (platform_str) hasher.Write((const unsigned char*)platform_str, strlen(platform_str) + 1);
  Branch (303:9): [True: 0, False: 0]
304
0
#  endif
305
0
#  ifdef AT_EXECFN
306
0
    const char* exec_str = (const char*)getauxval(AT_EXECFN);
307
0
    if (exec_str) hasher.Write((const unsigned char*)exec_str, strlen(exec_str) + 1);
  Branch (307:9): [True: 0, False: 0]
308
0
#  endif
309
0
#endif // HAVE_STRONG_GETAUXVAL
310
311
0
#ifdef HAVE_GETCPUID
312
0
    AddAllCPUID(hasher);
313
0
#endif
314
315
    // Memory locations
316
0
    hasher << &hasher << &RandAddStaticEnv << &malloc << &errno << &environ;
317
318
    // Hostname
319
#ifdef WIN32
320
    constexpr DWORD max_size = MAX_COMPUTERNAME_LENGTH + 1;
321
    char hname[max_size];
322
    DWORD size = max_size;
323
    if (GetComputerNameA(hname, &size) != 0) {
324
        hasher.Write(UCharCast(hname), size);
325
    }
326
#else
327
0
    char hname[256];
328
0
    if (gethostname(hname, 256) == 0) {
  Branch (328:9): [True: 0, False: 0]
329
0
        hasher.Write((const unsigned char*)hname, strnlen(hname, 256));
330
0
    }
331
0
#endif
332
333
0
#if HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS
334
    // Network interfaces
335
0
    struct ifaddrs *ifad = nullptr;
336
0
    getifaddrs(&ifad);
337
0
    struct ifaddrs *ifit = ifad;
338
0
    while (ifit != nullptr) {
  Branch (338:12): [True: 0, False: 0]
339
0
        hasher.Write((const unsigned char*)&ifit, sizeof(ifit));
340
0
        hasher.Write((const unsigned char*)ifit->ifa_name, strlen(ifit->ifa_name) + 1);
341
0
        hasher.Write((const unsigned char*)&ifit->ifa_flags, sizeof(ifit->ifa_flags));
342
0
        AddSockaddr(hasher, ifit->ifa_addr);
343
0
        AddSockaddr(hasher, ifit->ifa_netmask);
344
0
        AddSockaddr(hasher, ifit->ifa_dstaddr);
345
0
        ifit = ifit->ifa_next;
346
0
    }
347
0
    freeifaddrs(ifad);
348
0
#endif
349
350
0
#ifndef WIN32
351
    // UNIX kernel information
352
0
    struct utsname name;
353
0
    if (uname(&name) != -1) {
  Branch (353:9): [True: 0, False: 0]
354
0
        hasher.Write((const unsigned char*)&name.sysname, strlen(name.sysname) + 1);
355
0
        hasher.Write((const unsigned char*)&name.nodename, strlen(name.nodename) + 1);
356
0
        hasher.Write((const unsigned char*)&name.release, strlen(name.release) + 1);
357
0
        hasher.Write((const unsigned char*)&name.version, strlen(name.version) + 1);
358
0
        hasher.Write((const unsigned char*)&name.machine, strlen(name.machine) + 1);
359
0
    }
360
361
    /* Path and filesystem provided data */
362
0
    AddPath(hasher, "/");
363
0
    AddPath(hasher, ".");
364
0
    AddPath(hasher, "/tmp");
365
0
    AddPath(hasher, "/home");
366
0
    AddPath(hasher, "/proc");
367
0
#ifdef __linux__
368
0
    AddFile(hasher, "/proc/cmdline");
369
0
    AddFile(hasher, "/proc/cpuinfo");
370
0
    AddFile(hasher, "/proc/version");
371
0
#endif
372
0
    AddFile(hasher, "/etc/passwd");
373
0
    AddFile(hasher, "/etc/group");
374
0
    AddFile(hasher, "/etc/hosts");
375
0
    AddFile(hasher, "/etc/resolv.conf");
376
0
    AddFile(hasher, "/etc/timezone");
377
0
    AddFile(hasher, "/etc/localtime");
378
0
#endif
379
380
    // For MacOS/BSDs, gather data through sysctl instead of /proc. Not all of these
381
    // will exist on every system.
382
#ifdef HAVE_SYSCTL
383
#  ifdef CTL_HW
384
#    ifdef HW_MACHINE
385
    AddSysctl<CTL_HW, HW_MACHINE>(hasher);
386
#    endif
387
#    ifdef HW_MODEL
388
    AddSysctl<CTL_HW, HW_MODEL>(hasher);
389
#    endif
390
#    ifdef HW_NCPU
391
    AddSysctl<CTL_HW, HW_NCPU>(hasher);
392
#    endif
393
#    ifdef HW_PHYSMEM
394
    AddSysctl<CTL_HW, HW_PHYSMEM>(hasher);
395
#    endif
396
#    ifdef HW_USERMEM
397
    AddSysctl<CTL_HW, HW_USERMEM>(hasher);
398
#    endif
399
#    ifdef HW_MACHINE_ARCH
400
    AddSysctl<CTL_HW, HW_MACHINE_ARCH>(hasher);
401
#    endif
402
#    ifdef HW_REALMEM
403
    AddSysctl<CTL_HW, HW_REALMEM>(hasher);
404
#    endif
405
#    ifdef HW_CPU_FREQ
406
    AddSysctl<CTL_HW, HW_CPU_FREQ>(hasher);
407
#    endif
408
#    ifdef HW_BUS_FREQ
409
    AddSysctl<CTL_HW, HW_BUS_FREQ>(hasher);
410
#    endif
411
#    ifdef HW_CACHELINE
412
    AddSysctl<CTL_HW, HW_CACHELINE>(hasher);
413
#    endif
414
#  endif
415
#  ifdef CTL_KERN
416
#    ifdef KERN_BOOTFILE
417
     AddSysctl<CTL_KERN, KERN_BOOTFILE>(hasher);
418
#    endif
419
#    ifdef KERN_BOOTTIME
420
     AddSysctl<CTL_KERN, KERN_BOOTTIME>(hasher);
421
#    endif
422
#    ifdef KERN_CLOCKRATE
423
     AddSysctl<CTL_KERN, KERN_CLOCKRATE>(hasher);
424
#    endif
425
#    ifdef KERN_HOSTID
426
     AddSysctl<CTL_KERN, KERN_HOSTID>(hasher);
427
#    endif
428
#    ifdef KERN_HOSTUUID
429
     AddSysctl<CTL_KERN, KERN_HOSTUUID>(hasher);
430
#    endif
431
#    ifdef KERN_HOSTNAME
432
     AddSysctl<CTL_KERN, KERN_HOSTNAME>(hasher);
433
#    endif
434
#    ifdef KERN_OSRELDATE
435
     AddSysctl<CTL_KERN, KERN_OSRELDATE>(hasher);
436
#    endif
437
#    ifdef KERN_OSRELEASE
438
     AddSysctl<CTL_KERN, KERN_OSRELEASE>(hasher);
439
#    endif
440
#    ifdef KERN_OSREV
441
     AddSysctl<CTL_KERN, KERN_OSREV>(hasher);
442
#    endif
443
#    ifdef KERN_OSTYPE
444
     AddSysctl<CTL_KERN, KERN_OSTYPE>(hasher);
445
#    endif
446
#    ifdef KERN_POSIX1
447
     AddSysctl<CTL_KERN, KERN_OSREV>(hasher);
448
#    endif
449
#    ifdef KERN_VERSION
450
     AddSysctl<CTL_KERN, KERN_VERSION>(hasher);
451
#    endif
452
#  endif
453
#endif
454
455
    // Env variables
456
0
    if (environ) {
  Branch (456:9): [True: 0, False: 0]
457
0
        for (size_t i = 0; environ[i]; ++i) {
  Branch (457:28): [True: 0, False: 0]
458
0
            hasher.Write((const unsigned char*)environ[i], strlen(environ[i]));
459
0
        }
460
0
    }
461
462
    // Process, thread, user, session, group, ... ids.
463
#ifdef WIN32
464
    hasher << GetCurrentProcessId() << GetCurrentThreadId();
465
#else
466
0
    hasher << getpid() << getppid() << getsid(0) << getpgid(0) << getuid() << geteuid() << getgid() << getegid();
467
0
#endif
468
0
    hasher << std::this_thread::get_id();
469
0
}