michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef SANDBOX_SRC_HANDLE_CLOSER_H_ michael@0: #define SANDBOX_SRC_HANDLE_CLOSER_H_ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "base/strings/string16.h" michael@0: #include "sandbox/win/src/interception.h" michael@0: #include "sandbox/win/src/sandbox_types.h" michael@0: #include "sandbox/win/src/target_process.h" michael@0: michael@0: namespace sandbox { michael@0: michael@0: // This is a map of handle-types to names that we need to close in the michael@0: // target process. A null set means we need to close all handles of the michael@0: // given type. michael@0: typedef std::map > HandleMap; michael@0: michael@0: // Type and set of corresponding handle names to close. michael@0: struct HandleListEntry { michael@0: size_t record_bytes; // Rounded to sizeof(size_t) bytes. michael@0: size_t offset_to_names; // Nul terminated strings of name_count names. michael@0: size_t name_count; michael@0: char16 handle_type[1]; michael@0: }; michael@0: michael@0: // Global parameters and a pointer to the list of entries. michael@0: struct HandleCloserInfo { michael@0: size_t record_bytes; // Rounded to sizeof(size_t) bytes. michael@0: size_t num_handle_types; michael@0: struct HandleListEntry handle_entries[1]; michael@0: }; michael@0: michael@0: SANDBOX_INTERCEPT HandleCloserInfo* g_handle_closer_info; michael@0: michael@0: // Adds handles to close after lockdown. michael@0: class HandleCloser { michael@0: public: michael@0: HandleCloser(); michael@0: michael@0: // Adds a handle that will be closed in the target process after lockdown. michael@0: // A NULL value for handle_name indicates all handles of the specified type. michael@0: // An empty string for handle_name indicates the handle is unnamed. michael@0: ResultCode AddHandle(const char16* handle_type, const char16* handle_name); michael@0: michael@0: // Serializes and copies the closer table into the target process. michael@0: bool InitializeTargetHandles(TargetProcess* target); michael@0: michael@0: // Adds any interceptions that may be required due to closed system handles. michael@0: bool SetupHandleInterceptions(InterceptionManager* manager); michael@0: michael@0: private: michael@0: // Calculates the memory needed to copy the serialized handles list (rounded michael@0: // to the nearest machine-word size). michael@0: size_t GetBufferSize(); michael@0: michael@0: // Serializes the handle list into the target process. michael@0: bool SetupHandleList(void* buffer, size_t buffer_bytes); michael@0: michael@0: HandleMap handles_to_close_; michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(HandleCloser); michael@0: }; michael@0: michael@0: // Returns the object manager's name associated with a handle michael@0: bool GetHandleName(HANDLE handle, string16* handle_name); michael@0: michael@0: } // namespace sandbox michael@0: michael@0: #endif // SANDBOX_SRC_HANDLE_CLOSER_H_