| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_HANDLE_CLOSER_H_ | |
| 6 #define SANDBOX_SRC_HANDLE_CLOSER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <set> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/strings/string16.h" | |
| 15 #include "sandbox/win/src/interception.h" | |
| 16 #include "sandbox/win/src/sandbox_types.h" | |
| 17 #include "sandbox/win/src/target_process.h" | |
| 18 | |
| 19 namespace sandbox { | |
| 20 | |
| 21 // This is a map of handle-types to names that we need to close in the | |
| 22 // target process. A null set means we need to close all handles of the | |
| 23 // given type. | |
| 24 typedef std::map<const base::string16, std::set<base::string16> > HandleMap; | |
| 25 | |
| 26 // Type and set of corresponding handle names to close. | |
| 27 struct HandleListEntry { | |
| 28 size_t record_bytes; // Rounded to sizeof(size_t) bytes. | |
| 29 size_t offset_to_names; // Nul terminated strings of name_count names. | |
| 30 size_t name_count; | |
| 31 base::char16 handle_type[1]; | |
| 32 }; | |
| 33 | |
| 34 // Global parameters and a pointer to the list of entries. | |
| 35 struct HandleCloserInfo { | |
| 36 size_t record_bytes; // Rounded to sizeof(size_t) bytes. | |
| 37 size_t num_handle_types; | |
| 38 struct HandleListEntry handle_entries[1]; | |
| 39 }; | |
| 40 | |
| 41 SANDBOX_INTERCEPT HandleCloserInfo* g_handle_closer_info; | |
| 42 | |
| 43 // Adds handles to close after lockdown. | |
| 44 class HandleCloser { | |
| 45 public: | |
| 46 HandleCloser(); | |
| 47 ~HandleCloser(); | |
| 48 | |
| 49 // Adds a handle that will be closed in the target process after lockdown. | |
| 50 // A NULL value for handle_name indicates all handles of the specified type. | |
| 51 // An empty string for handle_name indicates the handle is unnamed. | |
| 52 ResultCode AddHandle(const base::char16* handle_type, | |
| 53 const base::char16* handle_name); | |
| 54 | |
| 55 // Serializes and copies the closer table into the target process. | |
| 56 bool InitializeTargetHandles(TargetProcess* target); | |
| 57 | |
| 58 private: | |
| 59 // Calculates the memory needed to copy the serialized handles list (rounded | |
| 60 // to the nearest machine-word size). | |
| 61 size_t GetBufferSize(); | |
| 62 | |
| 63 // Serializes the handle list into the target process. | |
| 64 bool SetupHandleList(void* buffer, size_t buffer_bytes); | |
| 65 | |
| 66 HandleMap handles_to_close_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(HandleCloser); | |
| 69 }; | |
| 70 | |
| 71 // Returns the object manager's name associated with a handle | |
| 72 bool GetHandleName(HANDLE handle, base::string16* handle_name); | |
| 73 | |
| 74 } // namespace sandbox | |
| 75 | |
| 76 #endif // SANDBOX_SRC_HANDLE_CLOSER_H_ | |
| OLD | NEW |