• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_WIN_WINDOWS_VERSION_H_
6 #define BASE_WIN_WINDOWS_VERSION_H_
7 #pragma once
8 
9 #include "base/base_api.h"
10 #include "base/memory/singleton.h"
11 
12 typedef void* HANDLE;
13 
14 namespace base {
15 namespace win {
16 
17 // The running version of Windows.  This is declared outside OSInfo for
18 // syntactic sugar reasons; see the declaration of GetVersion() below.
19 // NOTE: Keep these in order so callers can do things like
20 // "if (base::win::GetVersion() >= base::win::VERSION_VISTA) ...".
21 enum Version {
22   VERSION_PRE_XP = 0,   // Not supported.
23   VERSION_XP,
24   VERSION_SERVER_2003,  // Also includes Windows XP Professional x64.
25   VERSION_VISTA,
26   VERSION_SERVER_2008,
27   VERSION_WIN7,
28 };
29 
30 // A Singleton that can be used to query various pieces of information about the
31 // OS and process state.
32 class BASE_API OSInfo {
33  public:
34   struct VersionNumber {
35     int major;
36     int minor;
37     int build;
38   };
39 
40   struct ServicePack {
41     int major;
42     int minor;
43   };
44 
45   // The processor architecture this copy of Windows natively uses.  For
46   // example, given an x64-capable processor, we have three possibilities:
47   //   32-bit Chrome running on 32-bit Windows:           X86_ARCHITECTURE
48   //   32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE
49   //   64-bit Chrome running on 64-bit Windows:           X64_ARCHITECTURE
50   enum WindowsArchitecture {
51     X86_ARCHITECTURE,
52     X64_ARCHITECTURE,
53     IA64_ARCHITECTURE,
54     OTHER_ARCHITECTURE,
55   };
56 
57   // Whether a process is running under WOW64 (the wrapper that allows 32-bit
58   // processes to run on 64-bit versions of Windows).  This will return
59   // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit
60   // Chrome on 64-bit Windows".  WOW64_UNKNOWN means "an error occurred", e.g.
61   // the process does not have sufficient access rights to determine this.
62   enum WOW64Status {
63     WOW64_DISABLED,
64     WOW64_ENABLED,
65     WOW64_UNKNOWN,
66   };
67 
68   static OSInfo* GetInstance();
69 
version()70   Version version() const { return version_; }
71   // The next two functions return arrays of values, [major, minor(, build)].
version_number()72   VersionNumber version_number() const { return version_number_; }
service_pack()73   ServicePack service_pack() const { return service_pack_; }
architecture()74   WindowsArchitecture architecture() const { return architecture_; }
processors()75   int processors() const { return processors_; }
allocation_granularity()76   size_t allocation_granularity() const { return allocation_granularity_; }
wow64_status()77   WOW64Status wow64_status() const { return wow64_status_; }
78 
79   // Like wow64_status(), but for the supplied handle instead of the current
80   // process.  This doesn't touch member state, so you can bypass the singleton.
81   static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle);
82 
83  private:
84   OSInfo();
85   ~OSInfo();
86 
87   Version version_;
88   VersionNumber version_number_;
89   ServicePack service_pack_;
90   WindowsArchitecture architecture_;
91   int processors_;
92   size_t allocation_granularity_;
93   WOW64Status wow64_status_;
94 
95   friend struct DefaultSingletonTraits<OSInfo>;
96   DISALLOW_COPY_AND_ASSIGN(OSInfo);
97 };
98 
99 // Because this is by far the most commonly-requested value from the above
100 // singleton, we add a global-scope accessor here as syntactic sugar.
101 BASE_API Version GetVersion();
102 
103 }  // namespace win
104 }  // namespace base
105 
106 #endif  // BASE_WIN_WINDOWS_VERSION_H_
107