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

Side by Side Diff: sandbox/win/src/win_utils.h

Issue 1851213002: Remove sandbox on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nacl compile issues Created 4 years, 8 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
« no previous file with comments | « sandbox/win/src/win2k_threadpool.cc ('k') | sandbox/win/src/win_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2010 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 SANDBOX_SRC_WIN_UTILS_H_
6 #define SANDBOX_SRC_WIN_UTILS_H_
7
8 #include <windows.h>
9 #include <stddef.h>
10 #include <string>
11
12 #include "base/macros.h"
13 #include "base/strings/string16.h"
14
15 namespace sandbox {
16
17 // Prefix for path used by NT calls.
18 const wchar_t kNTPrefix[] = L"\\??\\";
19 const size_t kNTPrefixLen = arraysize(kNTPrefix) - 1;
20
21 const wchar_t kNTDevicePrefix[] = L"\\Device\\";
22 const size_t kNTDevicePrefixLen = arraysize(kNTDevicePrefix) - 1;
23
24 // Automatically acquires and releases a lock when the object is
25 // is destroyed.
26 class AutoLock {
27 public:
28 // Acquires the lock.
29 explicit AutoLock(CRITICAL_SECTION *lock) : lock_(lock) {
30 ::EnterCriticalSection(lock);
31 };
32
33 // Releases the lock;
34 ~AutoLock() {
35 ::LeaveCriticalSection(lock_);
36 };
37
38 private:
39 CRITICAL_SECTION *lock_;
40 DISALLOW_IMPLICIT_CONSTRUCTORS(AutoLock);
41 };
42
43 // Basic implementation of a singleton which calls the destructor
44 // when the exe is shutting down or the DLL is being unloaded.
45 template <typename Derived>
46 class SingletonBase {
47 public:
48 static Derived* GetInstance() {
49 static Derived* instance = NULL;
50 if (NULL == instance) {
51 instance = new Derived();
52 // Microsoft CRT extension. In an exe this this called after
53 // winmain returns, in a dll is called in DLL_PROCESS_DETACH
54 _onexit(OnExit);
55 }
56 return instance;
57 }
58
59 private:
60 // this is the function that gets called by the CRT when the
61 // process is shutting down.
62 static int __cdecl OnExit() {
63 delete GetInstance();
64 return 0;
65 }
66 };
67
68 // Convert a short path (C:\path~1 or \\??\\c:\path~1) to the long version of
69 // the path. If the path is not a valid filesystem path, the function returns
70 // false and argument is not modified.
71 bool ConvertToLongPath(base::string16* path);
72
73 // Returns ERROR_SUCCESS if the path contains a reparse point,
74 // ERROR_NOT_A_REPARSE_POINT if there's no reparse point in this path, or an
75 // error code when the function fails.
76 // This function is not smart. It looks for each element in the path and
77 // returns true if any of them is a reparse point.
78 DWORD IsReparsePoint(const base::string16& full_path);
79
80 // Returns true if the handle corresponds to the object pointed by this path.
81 bool SameObject(HANDLE handle, const wchar_t* full_path);
82
83 // Resolves a handle to an nt path. Returns true if the handle can be resolved.
84 bool GetPathFromHandle(HANDLE handle, base::string16* path);
85
86 // Resolves a win32 path to an nt path using GetPathFromHandle. The path must
87 // exist. Returs true if the translation was succesful.
88 bool GetNtPathFromWin32Path(const base::string16& path,
89 base::string16* nt_path);
90
91 // Translates a reserved key name to its handle.
92 // For example "HKEY_LOCAL_MACHINE" returns HKEY_LOCAL_MACHINE.
93 // Returns NULL if the name does not represent any reserved key name.
94 HKEY GetReservedKeyFromName(const base::string16& name);
95
96 // Resolves a user-readable registry path to a system-readable registry path.
97 // For example, HKEY_LOCAL_MACHINE\\Software\\microsoft is translated to
98 // \\registry\\machine\\software\\microsoft. Returns false if the path
99 // cannot be resolved.
100 bool ResolveRegistryName(base::string16 name, base::string16* resolved_name);
101
102 // Writes |length| bytes from the provided |buffer| into the address space of
103 // |child_process|, at the specified |address|, preserving the original write
104 // protection attributes. Returns true on success.
105 bool WriteProtectedChildMemory(HANDLE child_process, void* address,
106 const void* buffer, size_t length);
107
108 // Returns true if the provided path points to a pipe.
109 bool IsPipe(const base::string16& path);
110
111 } // namespace sandbox
112
113 // Resolves a function name in NTDLL to a function pointer. The second parameter
114 // is a pointer to the function pointer.
115 void ResolveNTFunctionPtr(const char* name, void* ptr);
116
117 #endif // SANDBOX_SRC_WIN_UTILS_H_
OLDNEW
« no previous file with comments | « sandbox/win/src/win2k_threadpool.cc ('k') | sandbox/win/src/win_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698