Index: content/browser/handle_enumerator_win.h |
=================================================================== |
--- content/browser/handle_enumerator_win.h (revision 0) |
+++ content/browser/handle_enumerator_win.h (revision 0) |
@@ -0,0 +1,163 @@ |
+// Copyright (c) 2011 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 BASE_HANDLE_ENUMERATION_WIN_H_ |
+#define BASE_HANDLE_ENUMERATION_WIN_H_ |
+ |
+#include <windows.h> |
+ |
+#include "base/base_api.h" |
+#include "base/basictypes.h" |
+#include "base/process.h" |
+#include "base/utf_string_conversions.h" |
+#include "build/build_config.h" |
+#include "content/browser/renderer_host/render_process_host.h" |
+#include "content/common/child_process_info.h" |
+ |
cpu_(ooo_6.6-7.5)
2011/06/07 21:18:00
we should use either src/sandbox/tools/finder/ntun
Cris Neckar
2011/06/07 22:10:10
Done.
|
+const wchar_t kNtdllDllName[] = L"ntdll.dll"; |
+const size_t kMaxHandleNameLength = 1024; |
+ |
+#define STATUS_INFO_LENGTH_MISMATCH 0xc0000004 |
+ |
+#define SystemHandleInformation 16 |
+#define ObjectNameInformation 1 |
+#define ObjectTypeInformation 2 |
+ |
+typedef LONG (WINAPI* NtQuerySystemInformationFunction)( |
+ ULONG SystemInformationClass, |
+ PVOID SystemInformation, |
+ ULONG SystemInformationLength, |
+ PULONG ReturnLength); |
+ |
+typedef LONG (WINAPI* NtDuplicateObjectFunction)( |
+ HANDLE SourceProcessHandle, |
+ HANDLE SourceHandle, |
+ HANDLE TargetProcessHandle, |
+ PHANDLE TargetHandle, |
+ ACCESS_MASK DesiredAccess, |
+ ULONG Attributes, |
+ ULONG Options); |
+ |
+typedef LONG (WINAPI* NtQueryObjectFunction)( |
+ HANDLE ObjectHandle, |
+ ULONG ObjectInformationClass, |
+ PVOID ObjectInformation, |
+ ULONG ObjectInformationLength, |
+ PULONG ReturnLength); |
+ |
+typedef struct _SYSTEM_HANDLE { |
+ ULONG ProcessId; |
+ BYTE ObjectTypeNumber; |
+ BYTE Flags; |
+ USHORT Handle; |
+ PVOID Object; |
+ ACCESS_MASK GrantedAccess; |
+} SYSTEM_HANDLE; |
+ |
+typedef struct _SYSTEM_HANDLE_INFORMATION { |
+ ULONG HandleCount; |
+ SYSTEM_HANDLE Handles[1]; |
+} SYSTEM_HANDLE_INFORMATION; |
+ |
+typedef enum _POOL_TYPE { |
+ NonPagedPool, |
+ PagedPool, |
+ NonPagedPoolMustSucceed, |
+ ReservedType, |
+ NonPagedPoolCacheAligned, |
+ PagedPoolCacheAligned, |
+ NonPagedPoolCacheAlignedMustS |
+} POOL_TYPE; |
+ |
+typedef struct _UNICODE_STRING { |
+ USHORT Length; |
+ USHORT MaximumLength; |
+ PWSTR Buffer; |
+} UNICODE_STRING; |
+ |
+typedef struct _OBJECT_TYPE_INFORMATION { |
+ UNICODE_STRING Name; |
+ ULONG TotalNumberOfObjects; |
+ ULONG TotalNumberOfHandles; |
+ ULONG TotalPagedPoolUsage; |
+ ULONG TotalNonPagedPoolUsage; |
+ ULONG TotalNamePoolUsage; |
+ ULONG TotalHandleTableUsage; |
+ ULONG HighWaterNumberOfObjects; |
+ ULONG HighWaterNumberOfHandles; |
+ ULONG HighWaterPagedPoolUsage; |
+ ULONG HighWaterNonPagedPoolUsage; |
+ ULONG HighWaterNamePoolUsage; |
+ ULONG HighWaterHandleTableUsage; |
+ ULONG InvalidAttributes; |
+ GENERIC_MAPPING GenericMapping; |
+ ULONG ValidAccess; |
+ BOOLEAN SecurityRequired; |
+ BOOLEAN MaintainHandleCount; |
+ USHORT MaintainTypeList; |
+ POOL_TYPE PoolType; |
+ ULONG PagedPoolUsage; |
+ ULONG NonPagedPoolUsage; |
+} OBJECT_TYPE_INFORMATION; |
+ |
+typedef enum _HANDLE_TYPE { |
+ ProcessHandle, |
+ ThreadHandle, |
+ FileHandle, |
+ DirectoryHandle, |
+ KeyHandle, |
+ WindowStationHandle, |
+ DesktopHandle, |
+ ServiceHandle, |
+ EventHandle, |
+ MutexHandle, |
+ SemaphoreHandle, |
+ TimerHandle, |
+ NamedPipeHandle, |
+ JobHandle, |
+ FileMapHandle, |
+ OtherHandle |
+} HandleType; |
+ |
+class HandleEnumerator : public base::RefCountedThreadSafe<HandleEnumerator> { |
+ public: |
+ enum HandleEnumStatus { |
+ Starting, |
+ InProgress, |
+ Finished |
+ }; |
+ |
+ HandleEnumerator(base::ProcessHandle handle): |
+ handle_(handle), |
+ type_(ChildProcessInfo::UNKNOWN_PROCESS), |
+ status_(Starting) { } |
+ |
+ ChildProcessInfo::ProcessType type() { return type_; } |
+ |
+ HandleEnumStatus status() { return status_; } |
+ |
+ void RunHandleEnumeration(); |
+ |
+ void EnumerateHandles(); |
+ |
+ static HandleType StringToHandleType(string16 type); |
+ |
+ static string16 ProcessTypeString(ChildProcessInfo::ProcessType process_type); |
+ |
+ static string16 GetAccessString(HandleType handle_type, |
+ ACCESS_MASK access); |
+ |
+ private: |
+ void FindProcessOnIOThread(); |
+ |
+ void FindProcessOnUIThread(); |
+ |
+ void EnumerateHandlesAndTerminateProcess(); |
+ |
+ base::ProcessHandle handle_; |
+ ChildProcessInfo::ProcessType type_; |
+ HandleEnumStatus status_; |
+}; |
+ |
+#endif // BASE_HANDLE_ENUMERATION_WIN_H_ |