diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-06-21 13:20:18 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-06-21 20:21:03 +0000 |
commit | 00f23a4f5c21377c2a1421bbe884518e14898a88 (patch) | |
tree | 8e6e4993bd1abb7129d694eb5107dde5bb166126 /wsutil | |
parent | 9e8fb87a3eec510f0b6117af029dbc3651ef9c30 (diff) | |
download | wireshark-00f23a4f5c21377c2a1421bbe884518e14898a88.tar.gz |
Move the routine to get a CPU information string to wsutil.
Change-Id: Ibf6e57d7382cbbd831a0367fd48d684118712408
Reviewed-on: https://code.wireshark.org/review/2523
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil')
-rw-r--r-- | wsutil/CMakeLists.txt | 1 | ||||
-rw-r--r-- | wsutil/Makefile.common | 2 | ||||
-rw-r--r-- | wsutil/cpu_info.c | 68 | ||||
-rw-r--r-- | wsutil/cpu_info.h | 39 |
4 files changed, 110 insertions, 0 deletions
diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index a08787a1c7..697481bdd5 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -47,6 +47,7 @@ set(WSUTIL_FILES cfutils.c compiler_info.c copyright_info.c + cpu_info.c crash_info.c crc10.c crc16.c diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index f040ea57d3..65bb6364f9 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -35,6 +35,7 @@ LIBWSUTIL_SRC = \ cfutils.c \ compiler_info.c \ copyright_info.c \ + cpu_info.c \ crash_info.c \ crc6.c \ crc7.c \ @@ -80,6 +81,7 @@ LIBWSUTIL_INCLUDES = \ cfutils.h \ compiler_info.h \ copyright_info.h \ + cpu_info.h \ crash_info.h \ crc6.h \ crc7.h \ diff --git a/wsutil/cpu_info.c b/wsutil/cpu_info.c new file mode 100644 index 0000000000..3f3fdeffc4 --- /dev/null +++ b/wsutil/cpu_info.c @@ -0,0 +1,68 @@ +/* cpu_info.c + * Routines to report information about the CPU on which we're running + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <string.h> + +#include <glib.h> + +#include <wsutil/ws_cpuid.h> + +#include <wsutil/cpu_info.h> + +/* + * Get the CPU info, and append it to the GString + */ +void +get_cpu_info(GString *str _U_) +{ + guint32 CPUInfo[4]; + char CPUBrandString[0x40]; + unsigned nExIds; + + /* http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.100).aspx */ + + /* Calling __cpuid with 0x80000000 as the InfoType argument*/ + /* gets the number of valid extended IDs.*/ + if (!ws_cpuid(CPUInfo, 0x80000000)) + return; + nExIds = CPUInfo[0]; + + if( nExIds<0x80000005) + return; + memset(CPUBrandString, 0, sizeof(CPUBrandString)); + + /* Interpret CPU brand string.*/ + ws_cpuid(CPUInfo, 0x80000002); + memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo)); + ws_cpuid(CPUInfo, 0x80000003); + memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo)); + ws_cpuid(CPUInfo, 0x80000004); + memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo)); + + g_string_append_printf(str, "\n%s", CPUBrandString); + + if (ws_cpuid_sse42()) + g_string_append(str, " (with SSE4.2)"); +} + diff --git a/wsutil/cpu_info.h b/wsutil/cpu_info.h new file mode 100644 index 0000000000..6692ffcbb9 --- /dev/null +++ b/wsutil/cpu_info.h @@ -0,0 +1,39 @@ +/* cpu_info.h + * Declarations of outines to report information about the CPU on which + * we're running + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __WSUTIL_CPU_INFO_H__ +#define __WSUTIL_CPU_INFO_H__ + +#include "ws_symbol_export.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +WS_DLL_PUBLIC void get_cpu_info(GString *str); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __WSUTIL_CPU_INFO_H__ */ |