Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "base/cpu.h" |
michael@0 | 6 | #include <intrin.h> |
michael@0 | 7 | #include <string> |
michael@0 | 8 | |
michael@0 | 9 | namespace base { |
michael@0 | 10 | |
michael@0 | 11 | CPU::CPU() |
michael@0 | 12 | : type_(0), |
michael@0 | 13 | family_(0), |
michael@0 | 14 | model_(0), |
michael@0 | 15 | stepping_(0), |
michael@0 | 16 | ext_model_(0), |
michael@0 | 17 | ext_family_(0), |
michael@0 | 18 | cpu_vendor_("unknown") { |
michael@0 | 19 | Initialize(); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | void CPU::Initialize() { |
michael@0 | 23 | int cpu_info[4] = {-1}; |
michael@0 | 24 | char cpu_string[0x20]; |
michael@0 | 25 | |
michael@0 | 26 | // __cpuid with an InfoType argument of 0 returns the number of |
michael@0 | 27 | // valid Ids in CPUInfo[0] and the CPU identification string in |
michael@0 | 28 | // the other three array elements. The CPU identification string is |
michael@0 | 29 | // not in linear order. The code below arranges the information |
michael@0 | 30 | // in a human readable form. |
michael@0 | 31 | // |
michael@0 | 32 | // More info can be found here: |
michael@0 | 33 | // http://msdn.microsoft.com/en-us/library/hskdteyh.aspx |
michael@0 | 34 | __cpuid(cpu_info, 0); |
michael@0 | 35 | int num_ids = cpu_info[0]; |
michael@0 | 36 | memset(cpu_string, 0, sizeof(cpu_string)); |
michael@0 | 37 | *(reinterpret_cast<int*>(cpu_string)) = cpu_info[1]; |
michael@0 | 38 | *(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3]; |
michael@0 | 39 | *(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2]; |
michael@0 | 40 | |
michael@0 | 41 | // Interpret CPU feature information. |
michael@0 | 42 | if (num_ids > 0) { |
michael@0 | 43 | __cpuid(cpu_info, 1); |
michael@0 | 44 | stepping_ = cpu_info[0] & 0xf; |
michael@0 | 45 | model_ = (cpu_info[0] >> 4) & 0xf; |
michael@0 | 46 | family_ = (cpu_info[0] >> 8) & 0xf; |
michael@0 | 47 | type_ = (cpu_info[0] >> 12) & 0x3; |
michael@0 | 48 | ext_model_ = (cpu_info[0] >> 16) & 0xf; |
michael@0 | 49 | ext_family_ = (cpu_info[0] >> 20) & 0xff; |
michael@0 | 50 | cpu_vendor_ = cpu_string; |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | } // namespace base |