wmem: allow wmem_destroy_list to ignore a NULL list.
[metze/wireshark/wip.git] / wsutil / cpu_info.c
1 /* cpu_info.c
2  * Routines to report CPU information
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include "config.h"
12
13 #include <string.h>
14 #include <glib.h>
15
16 #include <wsutil/ws_cpuid.h>
17 #include <wsutil/cpu_info.h>
18
19 /*
20  * Get the CPU info, and append it to the GString
21  */
22 void
23 get_cpu_info(GString *str)
24 {
25     guint32 CPUInfo[4];
26     char CPUBrandString[0x40];
27     unsigned nExIds;
28
29     /* http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.100).aspx */
30
31     /* Calling __cpuid with 0x80000000 as the InfoType argument */
32     /* gets the number of valid extended IDs. */
33     if (!ws_cpuid(CPUInfo, 0x80000000))
34         return;
35
36     nExIds = CPUInfo[0];
37
38     if (nExIds<0x80000005)
39         return;
40
41     memset(CPUBrandString, 0, sizeof(CPUBrandString));
42
43     /* Interpret CPU brand string */
44     ws_cpuid(CPUInfo, 0x80000002);
45     memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
46     ws_cpuid(CPUInfo, 0x80000003);
47     memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
48     ws_cpuid(CPUInfo, 0x80000004);
49     memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
50
51     if (str->len > 0)
52         g_string_append(str, ", with ");
53
54     g_string_append_printf(str, "%s", CPUBrandString);
55
56     if (ws_cpuid_sse42())
57         g_string_append(str, " (with SSE4.2)");
58 }
59
60 /*
61  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
62  *
63  * Local variables:
64  * c-basic-offset: 4
65  * tab-width: 8
66  * indent-tabs-mode: nil
67  * End:
68  *
69  * vi: set shiftwidth=4 tabstop=8 expandtab:
70  * :indentSize=4:tabSize=8:noTabs=true:
71  */