diff options
Diffstat (limited to 'sandbox/win')
-rw-r--r-- | sandbox/win/BUILD.gn | 2 | ||||
-rw-r--r-- | sandbox/win/sandbox_win.gypi | 2 | ||||
-rw-r--r-- | sandbox/win/src/shared_handles.cc | 67 | ||||
-rw-r--r-- | sandbox/win/src/shared_handles.h | 108 |
4 files changed, 0 insertions, 179 deletions
diff --git a/sandbox/win/BUILD.gn b/sandbox/win/BUILD.gn index 28244db..c8bb770 100644 --- a/sandbox/win/BUILD.gn +++ b/sandbox/win/BUILD.gn @@ -107,8 +107,6 @@ source_set("sandbox") { "src/security_level.h", "src/service_resolver.cc", "src/service_resolver.h", - "src/shared_handles.cc", - "src/shared_handles.h", "src/sharedmem_ipc_client.cc", "src/sharedmem_ipc_client.h", "src/sharedmem_ipc_server.cc", diff --git a/sandbox/win/sandbox_win.gypi b/sandbox/win/sandbox_win.gypi index ebd17cb..08d512a 100644 --- a/sandbox/win/sandbox_win.gypi +++ b/sandbox/win/sandbox_win.gypi @@ -114,8 +114,6 @@ 'src/security_level.h', 'src/service_resolver.cc', 'src/service_resolver.h', - 'src/shared_handles.cc', - 'src/shared_handles.h', 'src/sharedmem_ipc_client.cc', 'src/sharedmem_ipc_client.h', 'src/sharedmem_ipc_server.cc', diff --git a/sandbox/win/src/shared_handles.cc b/sandbox/win/src/shared_handles.cc deleted file mode 100644 index 423b67b..0000000 --- a/sandbox/win/src/shared_handles.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "sandbox/win/src/shared_handles.h" - -namespace sandbox { - -// Note once again the the assumption here is that the shared memory is -// initialized with zeros in the process that calls SetHandle and that -// the process that calls GetHandle 'sees' this memory. - -SharedHandles::SharedHandles() { - shared_.items = NULL; - shared_.max_items = 0; -} - -bool SharedHandles::Init(void* raw_mem, size_t size_bytes) { - if (size_bytes < sizeof(shared_.items[0])) { - // The shared memory is too small! - return false; - } - shared_.items = static_cast<SharedItem*>(raw_mem); - shared_.max_items = size_bytes / sizeof(shared_.items[0]); - return true; -} - -// Note that an empty slot is marked with a tag == 0 that is why is -// not a valid imput tag -bool SharedHandles::SetHandle(uint32 tag, HANDLE handle) { - if (0 == tag) { - // Invalid tag - return false; - } - // Find empty slot and put the tag and the handle there - SharedItem* empty_slot = FindByTag(0); - if (NULL == empty_slot) { - return false; - } - empty_slot->tag = tag; - empty_slot->item = handle; - return true; -} - -bool SharedHandles::GetHandle(uint32 tag, HANDLE* handle) { - if (0 == tag) { - // Invalid tag - return false; - } - SharedItem* found = FindByTag(tag); - if (NULL == found) { - return false; - } - *handle = found->item; - return true; -} - -SharedHandles::SharedItem* SharedHandles::FindByTag(uint32 tag) { - for (size_t ix = 0; ix != shared_.max_items; ++ix) { - if (tag == shared_.items[ix].tag) { - return &shared_.items[ix]; - } - } - return NULL; -} - -} // namespace sandbox diff --git a/sandbox/win/src/shared_handles.h b/sandbox/win/src/shared_handles.h deleted file mode 100644 index 2c76bfb..0000000 --- a/sandbox/win/src/shared_handles.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef SANDBOX_SRC_SHARED_HANDLES_H__ -#define SANDBOX_SRC_SHARED_HANDLES_H__ - -#include "base/basictypes.h" - -#ifndef HANDLE -// We can provide our own windows compatilble handle definition, but -// in general we want to rely on the client of this api to include -// the proper windows headers. Note that we don't want to bring the -// whole <windows.h> into scope if we don't have to. -typedef void* HANDLE; -#endif - -namespace sandbox { - -// SharedHandles is a simple class to stash and find windows object handles -// given a raw block of memory which is shared between two processes. -// It addresses the need to communicate a handle value between two windows -// processes given that they are already sharing some memory. -// -// This class is not exposed directly to users of the sanbox API, instead -// we expose the wrapper methods TargetProcess::TransferHandle( ) and -// TargetServices::GetTransferHandle() -// -// Use it for a small number of items, since internaly uses linear seach -// -// The use is very simple. Given a shared memory between proces A and B: -// process A: -// HANDLE handle = SomeFunction(..); -// SharedHandles shared_handes; -// shared_handles.Init(memory) -// shared_handles.SetHandle(3, handle); -// -// process B: -// SharedHandles shared_handes; -// shared_handles.Init(memory) -// HANDLE handle = shared_handles.GetHandle(3); -// -// Note that '3' in this example is a unique id, that must be agreed before -// transfer -// -// Note2: While this class can be used in a single process, there are -// better alternatives such as STL -// -// Note3: Under windows a kernel object handle in one process does not -// make sense for another process unless there is a DuplicateHandle( ) -// call involved which this class DOES NOT do that for you. -// -// Note4: Under windows, shared memory when created is initialized to -// zeros always. If you are not using shared memory it is your responsability -// to zero it for the setter process and to copy it to the getter process. -class SharedHandles { - public: - SharedHandles(); - - // Initializes the shared memory for use. - // Pass the shared memory base and size. It will internally compute - // how many handles can it store. If initialization fails the return value - // is false. - bool Init(void* raw_mem, size_t size_bytes); - - // Sets a handle in the shared memory for transfer. - // Parameters: - // tag : an integer, different from zero that uniquely identfies the - // handle to transfer. - // handle: the handle value associated with 'tag' to tranfer - // Returns false if there is not enough space in the shared memory for - // this handle. - bool SetHandle(uint32 tag, HANDLE handle); - - // Gets a handle previously stored by SetHandle. - // Parameters: - // tag: an integer different from zero that uniquely identfies the handle - // to retrieve. - // *handle: output handle value if the call was succesful. - // If a handle with the provided tag is not found the return value is false. - // If the tag is found the return value is true. - bool GetHandle(uint32 tag, HANDLE* handle); - - private: - // A single item is the tuple handle/tag - struct SharedItem { - uint32 tag; - void* item; - }; - - // SharedMem is used to layout the memory as an array of SharedItems - struct SharedMem { - size_t max_items; - SharedItem* items; - }; - - // Finds an Item tuple provided the handle tag. - // Uses linear search because we expect the number of handles to be - // small (say less than ~100). - SharedItem* FindByTag(uint32 tag); - - SharedMem shared_; - DISALLOW_COPY_AND_ASSIGN(SharedHandles); -}; - -} // namespace sandbox - -#endif // SANDBOX_SRC_SHARED_HANDLES_H__ |