- Timestamp:
- 2/11/2010 2:15:09 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Util.Native/OpenHandle.NameResolver.cpp
r1802 r1812 23 23 #include "OpenHandle.h" 24 24 25 #pragma managed(push)26 25 #pragma unmanaged 27 26 28 27 namespace { 28 HANDLE NameResolutionThread; 29 NameResolutionThreadParams NameResolutionThreadParam; 30 29 31 DWORD __stdcall nameResolutionThread(void* data) 30 32 { … … 86 88 return 0; 87 89 } 90 91 void CreateNameThread(HANDLE& handle, NameResolutionThreadParams& params) 92 { 93 //If the handle is valid terminate the thread 94 if (handle) 95 { 96 TerminateThread(handle, 1); 97 CloseHandle(handle); 98 } 99 100 //Create the thread 101 handle = CreateThread(NULL, 0, nameResolutionThread, ¶ms, 0, NULL); 102 } 103 88 104 } 89 105 90 void CreateNameThread(HANDLE& handle, NameResolutionThreadParams& params)106 std::wstring ResolveHandleName(HANDLE handle, int pid) 91 107 { 92 //If the handle is valid terminate the thread 93 if (handle) 108 //Start a name resolution thread (in case one entry hangs) 109 if (NameResolutionThread == NULL) 110 CreateNameThread(NameResolutionThread, NameResolutionThreadParam); 111 112 //Create a duplicate handle 113 HANDLE localHandle; 114 HANDLE processHandle = OpenProcess(PROCESS_DUP_HANDLE, false, pid); 115 DuplicateHandle(processHandle, static_cast<void*>(handle), GetCurrentProcess(), 116 &localHandle, 0, false, DUPLICATE_SAME_ACCESS); 117 CloseHandle(processHandle); 118 119 //We need a handle 120 if (!localHandle) 121 return std::wstring(); 122 123 //Send the handle to the secondary thread for name resolution 124 NameResult result(localHandle); 125 NameResolutionThreadParam.Input.push_back(&result); 126 ReleaseSemaphore(NameResolutionThreadParam.Semaphore, 1, NULL); 127 128 //Wait for the result 129 if (WaitForSingleObject(result.Event, 50) != WAIT_OBJECT_0) 94 130 { 95 TerminateThread(handle, 1);96 C loseHandle(handle);131 //The wait failed. Terminate the thread and recreate another. 132 CreateNameThread(NameResolutionThread, NameResolutionThreadParam); 97 133 } 98 134 99 //Create the thread 100 handle = CreateThread(NULL, 0, nameResolutionThread, ¶ms, 0, NULL); 135 //Close the handle which we duplicated 136 CloseHandle(localHandle); 137 138 //Return the result 139 return result.Name; 101 140 }
Note: See TracChangeset
for help on using the changeset viewer.
