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

Side by Side Diff: sandbox/win/src/sandbox_utils.cc

Issue 10951038: Remove GetModuleHandleHelper(), which was only needed for Win2k (which we don't support). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « sandbox/win/src/sandbox_utils.h ('k') | sandbox/win/src/service_resolver_32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sandbox/win/src/sandbox_utils.h" 5 #include "sandbox/win/src/sandbox_utils.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
11 #include "sandbox/win/src/internal_types.h" 11 #include "sandbox/win/src/internal_types.h"
12 #include "sandbox/win/src/nt_internals.h"
13 12
14 namespace sandbox { 13 namespace sandbox {
15 14
16 bool GetModuleHandleHelper(DWORD flags, const wchar_t* module_name,
17 HMODULE* module) {
18 DCHECK(module);
19
20 HMODULE kernel32_base = ::GetModuleHandle(kKerneldllName);
21 if (!kernel32_base) {
22 NOTREACHED();
23 return false;
24 }
25
26 GetModuleHandleExFunction get_module_handle_ex = reinterpret_cast<
27 GetModuleHandleExFunction>(::GetProcAddress(kernel32_base,
28 "GetModuleHandleExW"));
29 if (get_module_handle_ex)
30 return (get_module_handle_ex(flags, module_name, module) != FALSE);
31
32 if (!flags) {
33 *module = ::LoadLibrary(module_name);
34 } else if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN) {
35 NOTREACHED();
36 return false;
37 } else if (!(flags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)) {
38 DCHECK((flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT) ==
39 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT);
40
41 *module = ::GetModuleHandle(module_name);
42 } else {
43 DCHECK((flags & (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
44 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)) ==
45 (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
46 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS));
47
48 MEMORY_BASIC_INFORMATION info = {0};
49 size_t returned = VirtualQuery(module_name, &info, sizeof(info));
50 if (sizeof(info) != returned)
51 return false;
52 *module = reinterpret_cast<HMODULE>(info.AllocationBase);
53 }
54 return true;
55 }
56
57 bool IsXPSP2OrLater() { 15 bool IsXPSP2OrLater() {
58 base::win::Version version = base::win::GetVersion(); 16 base::win::Version version = base::win::GetVersion();
59 return (version > base::win::VERSION_XP) || 17 return (version > base::win::VERSION_XP) ||
60 ((version == base::win::VERSION_XP) && 18 ((version == base::win::VERSION_XP) &&
61 (base::win::OSInfo::GetInstance()->service_pack().major >= 2)); 19 (base::win::OSInfo::GetInstance()->service_pack().major >= 2));
62 } 20 }
63 21
64 void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root, 22 void InitObjectAttribs(const std::wstring& name,
65 OBJECT_ATTRIBUTES* obj_attr, UNICODE_STRING* uni_name) { 23 ULONG attributes,
24 HANDLE root,
25 OBJECT_ATTRIBUTES* obj_attr,
26 UNICODE_STRING* uni_name) {
66 static RtlInitUnicodeStringFunction RtlInitUnicodeString; 27 static RtlInitUnicodeStringFunction RtlInitUnicodeString;
67 if (!RtlInitUnicodeString) { 28 if (!RtlInitUnicodeString) {
68 HMODULE ntdll = ::GetModuleHandle(kNtdllName); 29 HMODULE ntdll = ::GetModuleHandle(kNtdllName);
69 RtlInitUnicodeString = reinterpret_cast<RtlInitUnicodeStringFunction>( 30 RtlInitUnicodeString = reinterpret_cast<RtlInitUnicodeStringFunction>(
70 GetProcAddress(ntdll, "RtlInitUnicodeString")); 31 GetProcAddress(ntdll, "RtlInitUnicodeString"));
71 DCHECK(RtlInitUnicodeString); 32 DCHECK(RtlInitUnicodeString);
72 } 33 }
73 RtlInitUnicodeString(uni_name, name.c_str()); 34 RtlInitUnicodeString(uni_name, name.c_str());
74 InitializeObjectAttributes(obj_attr, uni_name, attributes, root, NULL); 35 InitializeObjectAttributes(obj_attr, uni_name, attributes, root, NULL);
75 } 36 }
76 37
77 }; // namespace sandbox 38 }; // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/sandbox_utils.h ('k') | sandbox/win/src/service_resolver_32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698