Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: chrome_elf/thunk_getter.cc

Issue 183833004: Make chrome_elf use thunks instead of function pointers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 #include <stdint.h>
6 #include <windows.h>
7
8 #include "base/basictypes.h"
9 #include "sandbox/win/src/interception_internal.h"
10 #include "sandbox/win/src/internal_types.h"
11 #include "sandbox/win/src/sandbox_utils.h"
12 #include "sandbox/win/src/service_resolver.h"
13
14 namespace {
15 enum Version {
16 VERSION_PRE_XP_SP2 = 0, // Not supported.
17 VERSION_XP_SP2,
18 VERSION_SERVER_2003, // Also includes XP Pro x64 and Server 2003 R2.
19 VERSION_VISTA, // Also includes Windows Server 2008.
20 VERSION_WIN7, // Also includes Windows Server 2008 R2.
21 VERSION_WIN8, // Also includes Windows Server 2012.
22 VERSION_WIN8_1,
23 VERSION_WIN_LAST, // Indicates error condition.
24 };
25
26 // Whether a process is running under WOW64 (the wrapper that allows 32-bit
27 // processes to run on 64-bit versions of Windows). This will return
28 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit
29 // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g.
30 // the process does not have sufficient access rights to determine this.
31 enum WOW64Status {
32 WOW64_DISABLED,
33 WOW64_ENABLED,
34 WOW64_UNKNOWN,
35 };
36
37 WOW64Status GetWOW64StatusForCurrentProcess() {
38 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL);
39 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>(
40 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process"));
41 if (!is_wow64_process)
42 return WOW64_DISABLED;
43 BOOL is_wow64 = FALSE;
44 if (!(*is_wow64_process)(GetCurrentProcess(), &is_wow64))
robertshield 2014/02/28 21:02:22 can't you remove the parens and the dereference on
Cait (Slow) 2014/03/03 20:55:11 Done.
45 return WOW64_UNKNOWN;
46 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED;
47 }
48
49 class OSInfo {
50 public:
51 struct VersionNumber {
52 int major;
53 int minor;
54 int build;
55 };
56
57 struct ServicePack {
58 int major;
59 int minor;
60 };
61
62 OSInfo() {
63 OSVERSIONINFOEX version_info = { sizeof(version_info) };
64 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info));
65 version_number_.major = version_info.dwMajorVersion;
66 version_number_.minor = version_info.dwMinorVersion;
67 version_number_.build = version_info.dwBuildNumber;
68 if ((version_number_.major == 5) && (version_number_.minor > 0)) {
69 // Treat XP Pro x64, Home Server, and Server 2003 R2 as Server 2003.
70 version_ = (version_number_.minor == 1) ? VERSION_XP_SP2 :
71 VERSION_SERVER_2003;
72 if (version_ == VERSION_XP_SP2 && version_info.wServicePackMajor < 2)
73 version_ = VERSION_PRE_XP_SP2;
74 } else if (version_number_.major == 6) {
75 switch (version_number_.minor) {
76 case 0:
77 // Treat Windows Server 2008 the same as Windows Vista.
78 version_ = VERSION_VISTA;
79 break;
80 case 1:
81 // Treat Windows Server 2008 R2 the same as Windows 7.
82 version_ = VERSION_WIN7;
83 break;
84 case 2:
85 // Treat Windows Server 2012 the same as Windows 8.
86 version_ = VERSION_WIN8;
87 break;
88 default:
89 version_ = VERSION_WIN8_1;
90 break;
91 }
92 } else if (version_number_.major > 6) {
93 version_ = VERSION_WIN_LAST;
94 } else {
95 version_ = VERSION_PRE_XP_SP2;
96 }
97
98 service_pack_.major = version_info.wServicePackMajor;
99 service_pack_.minor = version_info.wServicePackMinor;
100 }
101
102 Version version() const { return version_; }
103 VersionNumber version_number() const { return version_number_; }
104 ServicePack service_pack() const { return service_pack_; }
105
106 private:
107 Version version_;
108 VersionNumber version_number_;
109 ServicePack service_pack_;
110
111 DISALLOW_COPY_AND_ASSIGN(OSInfo);
112 };
113
114 } // namespace
115
116 sandbox::ServiceResolverThunk* GetThunk(bool relaxed) {
117 // Create a thunk via the appropriate ServiceResolver instance.
118 sandbox::ServiceResolverThunk* thunk = NULL;
119
120 // No thunks for unsupported OS versions.
121 OSInfo os_info;
122 if (os_info.version() <= VERSION_PRE_XP_SP2)
123 return thunk;
124
125 // Pseudo-handle, no need to close.
126 HANDLE current_process = ::GetCurrentProcess();
127
128 #if defined(_WIN64)
129 // Because Windows 8 and 8.1 have different stubs in 64-bit,
130 // ServiceResolverThunk can handle all the formats in 64-bit (instead only
131 // handling 1 like it does in 32-bit versions).
132 thunk = new sandbox::ServiceResolverThunk(current_process, relaxed);
133 #else
134 if (GetWOW64StatusForCurrentProcess() == WOW64_ENABLED) {
135 if (os_info.version() >= VERSION_WIN8)
136 thunk = new sandbox::Wow64W8ResolverThunk(current_process, relaxed);
137 else
138 thunk = new sandbox::Wow64ResolverThunk(current_process, relaxed);
139 } else if (os_info.version() >= VERSION_WIN8) {
140 thunk = new sandbox::Win8ResolverThunk(current_process, relaxed);
141 } else {
142 thunk = new sandbox::ServiceResolverThunk(current_process, relaxed);
143 }
144 #endif
145
146 return thunk;
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698