Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef SANDBOX_SRC_HANDLE_CLOSER_H_ |
michael@0 | 6 | #define SANDBOX_SRC_HANDLE_CLOSER_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <map> |
michael@0 | 9 | #include <set> |
michael@0 | 10 | |
michael@0 | 11 | #include "base/basictypes.h" |
michael@0 | 12 | #include "base/strings/string16.h" |
michael@0 | 13 | #include "sandbox/win/src/interception.h" |
michael@0 | 14 | #include "sandbox/win/src/sandbox_types.h" |
michael@0 | 15 | #include "sandbox/win/src/target_process.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace sandbox { |
michael@0 | 18 | |
michael@0 | 19 | // This is a map of handle-types to names that we need to close in the |
michael@0 | 20 | // target process. A null set means we need to close all handles of the |
michael@0 | 21 | // given type. |
michael@0 | 22 | typedef std::map<const string16, std::set<const string16> > HandleMap; |
michael@0 | 23 | |
michael@0 | 24 | // Type and set of corresponding handle names to close. |
michael@0 | 25 | struct HandleListEntry { |
michael@0 | 26 | size_t record_bytes; // Rounded to sizeof(size_t) bytes. |
michael@0 | 27 | size_t offset_to_names; // Nul terminated strings of name_count names. |
michael@0 | 28 | size_t name_count; |
michael@0 | 29 | char16 handle_type[1]; |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | // Global parameters and a pointer to the list of entries. |
michael@0 | 33 | struct HandleCloserInfo { |
michael@0 | 34 | size_t record_bytes; // Rounded to sizeof(size_t) bytes. |
michael@0 | 35 | size_t num_handle_types; |
michael@0 | 36 | struct HandleListEntry handle_entries[1]; |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | SANDBOX_INTERCEPT HandleCloserInfo* g_handle_closer_info; |
michael@0 | 40 | |
michael@0 | 41 | // Adds handles to close after lockdown. |
michael@0 | 42 | class HandleCloser { |
michael@0 | 43 | public: |
michael@0 | 44 | HandleCloser(); |
michael@0 | 45 | |
michael@0 | 46 | // Adds a handle that will be closed in the target process after lockdown. |
michael@0 | 47 | // A NULL value for handle_name indicates all handles of the specified type. |
michael@0 | 48 | // An empty string for handle_name indicates the handle is unnamed. |
michael@0 | 49 | ResultCode AddHandle(const char16* handle_type, const char16* handle_name); |
michael@0 | 50 | |
michael@0 | 51 | // Serializes and copies the closer table into the target process. |
michael@0 | 52 | bool InitializeTargetHandles(TargetProcess* target); |
michael@0 | 53 | |
michael@0 | 54 | // Adds any interceptions that may be required due to closed system handles. |
michael@0 | 55 | bool SetupHandleInterceptions(InterceptionManager* manager); |
michael@0 | 56 | |
michael@0 | 57 | private: |
michael@0 | 58 | // Calculates the memory needed to copy the serialized handles list (rounded |
michael@0 | 59 | // to the nearest machine-word size). |
michael@0 | 60 | size_t GetBufferSize(); |
michael@0 | 61 | |
michael@0 | 62 | // Serializes the handle list into the target process. |
michael@0 | 63 | bool SetupHandleList(void* buffer, size_t buffer_bytes); |
michael@0 | 64 | |
michael@0 | 65 | HandleMap handles_to_close_; |
michael@0 | 66 | |
michael@0 | 67 | DISALLOW_COPY_AND_ASSIGN(HandleCloser); |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | // Returns the object manager's name associated with a handle |
michael@0 | 71 | bool GetHandleName(HANDLE handle, string16* handle_name); |
michael@0 | 72 | |
michael@0 | 73 | } // namespace sandbox |
michael@0 | 74 | |
michael@0 | 75 | #endif // SANDBOX_SRC_HANDLE_CLOSER_H_ |