OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef SANDBOX_SRC_SANDBOX_NT_UTIL_H_ | 5 #ifndef SANDBOX_SRC_SANDBOX_NT_UTIL_H_ |
6 #define SANDBOX_SRC_SANDBOX_NT_UTIL_H_ | 6 #define SANDBOX_SRC_SANDBOX_NT_UTIL_H_ |
7 | 7 |
8 #include <intrin.h> | 8 #include <intrin.h> |
| 9 #include <stdint.h> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/macros.h" |
11 #include "sandbox/win/src/nt_internals.h" | 12 #include "sandbox/win/src/nt_internals.h" |
12 #include "sandbox/win/src/sandbox_nt_types.h" | 13 #include "sandbox/win/src/sandbox_nt_types.h" |
13 | 14 |
14 // Placement new and delete to be used from ntdll interception code. | 15 // Placement new and delete to be used from ntdll interception code. |
15 void* __cdecl operator new(size_t size, sandbox::AllocationType type, | 16 void* __cdecl operator new(size_t size, sandbox::AllocationType type, |
16 void* near_to = NULL); | 17 void* near_to = NULL); |
17 void __cdecl operator delete(void* memory, sandbox::AllocationType type); | 18 void __cdecl operator delete(void* memory, sandbox::AllocationType type); |
18 // Add operator delete that matches the placement form of the operator new | 19 // Add operator delete that matches the placement form of the operator new |
19 // above. This is required by compiler to generate code to call operator delete | 20 // above. This is required by compiler to generate code to call operator delete |
20 // in case the object's constructor throws an exception. | 21 // in case the object's constructor throws an exception. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // or write. | 95 // or write. |
95 // Note that write intent implies destruction of the buffer content (we actually | 96 // Note that write intent implies destruction of the buffer content (we actually |
96 // write) | 97 // write) |
97 bool ValidParameter(void* buffer, size_t size, RequiredAccess intent); | 98 bool ValidParameter(void* buffer, size_t size, RequiredAccess intent); |
98 | 99 |
99 // Copies data from a user buffer to our buffer. Returns the operation status. | 100 // Copies data from a user buffer to our buffer. Returns the operation status. |
100 NTSTATUS CopyData(void* destination, const void* source, size_t bytes); | 101 NTSTATUS CopyData(void* destination, const void* source, size_t bytes); |
101 | 102 |
102 // Copies the name from an object attributes. | 103 // Copies the name from an object attributes. |
103 NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, | 104 NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, |
104 wchar_t** out_name, uint32* attributes, HANDLE* root); | 105 wchar_t** out_name, |
| 106 uint32_t* attributes, |
| 107 HANDLE* root); |
105 | 108 |
106 // Determine full path name from object root and path. | 109 // Determine full path name from object root and path. |
107 NTSTATUS AllocAndGetFullPath(HANDLE root, | 110 NTSTATUS AllocAndGetFullPath(HANDLE root, |
108 wchar_t* path, | 111 wchar_t* path, |
109 wchar_t** full_path); | 112 wchar_t** full_path); |
110 | 113 |
111 // Initializes our ntdll level heap | 114 // Initializes our ntdll level heap |
112 bool InitHeap(); | 115 bool InitHeap(); |
113 | 116 |
114 // Returns true if the provided handle refers to the current process. | 117 // Returns true if the provided handle refers to the current process. |
(...skipping 12 matching lines...) Expand all Loading... |
127 // The returned buffer must be freed with a placement delete from the ntdll | 130 // The returned buffer must be freed with a placement delete from the ntdll |
128 // level allocator: | 131 // level allocator: |
129 // | 132 // |
130 // UNICODE_STRING* name = GetPEImageInfoFromModule(HMODULE module, &flags); | 133 // UNICODE_STRING* name = GetPEImageInfoFromModule(HMODULE module, &flags); |
131 // if (!name) { | 134 // if (!name) { |
132 // // probably not a valid dll | 135 // // probably not a valid dll |
133 // return; | 136 // return; |
134 // } | 137 // } |
135 // InsertYourLogicHere(name); | 138 // InsertYourLogicHere(name); |
136 // operator delete(name, NT_ALLOC); | 139 // operator delete(name, NT_ALLOC); |
137 UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32* flags); | 140 UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32_t* flags); |
138 | 141 |
139 // Returns the full path and filename for a given dll. | 142 // Returns the full path and filename for a given dll. |
140 // May return NULL if the provided address is not backed by a named section, or | 143 // May return NULL if the provided address is not backed by a named section, or |
141 // if the current OS version doesn't support the call. The returned buffer must | 144 // if the current OS version doesn't support the call. The returned buffer must |
142 // be freed with a placement delete (see GetImageNameFromModule example). | 145 // be freed with a placement delete (see GetImageNameFromModule example). |
143 UNICODE_STRING* GetBackingFilePath(PVOID address); | 146 UNICODE_STRING* GetBackingFilePath(PVOID address); |
144 | 147 |
145 // Returns the last component of a path that contains the module name. | 148 // Returns the last component of a path that contains the module name. |
146 // It will return NULL if the path ends with the path separator. The returned | 149 // It will return NULL if the path ends with the path separator. The returned |
147 // buffer must be freed with a placement delete (see GetImageNameFromModule | 150 // buffer must be freed with a placement delete (see GetImageNameFromModule |
(...skipping 27 matching lines...) Expand all Loading... |
175 bool changed_; | 178 bool changed_; |
176 void* address_; | 179 void* address_; |
177 size_t bytes_; | 180 size_t bytes_; |
178 ULONG old_protect_; | 181 ULONG old_protect_; |
179 | 182 |
180 DISALLOW_COPY_AND_ASSIGN(AutoProtectMemory); | 183 DISALLOW_COPY_AND_ASSIGN(AutoProtectMemory); |
181 }; | 184 }; |
182 | 185 |
183 // Returns true if the file_rename_information structure is supported by our | 186 // Returns true if the file_rename_information structure is supported by our |
184 // rename handler. | 187 // rename handler. |
185 bool IsSupportedRenameCall(FILE_RENAME_INFORMATION* file_info, DWORD length, | 188 bool IsSupportedRenameCall(FILE_RENAME_INFORMATION* file_info, |
186 uint32 file_info_class); | 189 DWORD length, |
| 190 uint32_t file_info_class); |
187 | 191 |
188 } // namespace sandbox | 192 } // namespace sandbox |
189 | 193 |
190 | 194 |
191 #endif // SANDBOX_SRC_SANDBOX_NT_UTIL_H__ | 195 #endif // SANDBOX_SRC_SANDBOX_NT_UTIL_H__ |
OLD | NEW |