Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2006-05-02 16:11:25 -0400
committerDoug Schaefer2006-05-02 16:11:25 -0400
commit2ba5d92ebbb666a51196dd1facab207a60ab86ee (patch)
treeeb2ec2fd8074fa65e30c8d487668025bd82a230d
parent07fa3d405eb341e5206e0d59a2d870017aa6bfc1 (diff)
downloadorg.eclipse.cdt-2ba5d92ebbb666a51196dd1facab207a60ab86ee.tar.gz
org.eclipse.cdt-2ba5d92ebbb666a51196dd1facab207a60ab86ee.tar.xz
org.eclipse.cdt-2ba5d92ebbb666a51196dd1facab207a60ab86ee.zip
Removed killer.cpp.
-rw-r--r--core/org.eclipse.cdt.core.win32/library/starter/killer.cpp269
-rw-r--r--core/org.eclipse.cdt.core.win32/library/starter/killer.h122
-rw-r--r--core/org.eclipse.cdt.core.win32/library/starter/starter.cpp10
-rw-r--r--core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exebin16384 -> 8192 bytes
4 files changed, 2 insertions, 399 deletions
diff --git a/core/org.eclipse.cdt.core.win32/library/starter/killer.cpp b/core/org.eclipse.cdt.core.win32/library/starter/killer.cpp
deleted file mode 100644
index 69e345ffe9..0000000000
--- a/core/org.eclipse.cdt.core.win32/library/starter/killer.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002 - 2005 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * QNX Software Systems - initial API and implementation
- *
- * starter.cpp
- *
- * This is a helper function for the process killing
- * Implementation based on the article "Terminating Windows Processes"
- * see http://www.alexfedotov.com/articles/killproc.asp
-***********************************************************************/
-
-
-
-#define STRICT
-#include <Windows.h>
-#include <Tlhelp32.h>
-#include <process.h>
-#include <tchar.h>
-#include <stdio.h>
-
-#include "killer.h"
-
-#define SystemProcessesAndThreadsInformation 5
-
-#define MAX_CMD_LINE_LENGTH 512
-
-//#define DEBUG_MONITOR
-
-void DisplayErrorMessage();
-
-BOOL KillProcessEx(
- IN DWORD dwProcessId // Handle of the process
- )
-{
-
- OSVERSIONINFO osvi;
- DWORD dwError;
-#ifdef DEBUG_MONITOR
- _TCHAR buffer[MAX_CMD_LINE_LENGTH];
-#endif
-
- // determine operating system version
- osvi.dwOSVersionInfoSize = sizeof(osvi);
- GetVersionEx(&osvi);
-
- if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
- {
- HINSTANCE hNtDll;
- NTSTATUS (WINAPI * pZwQuerySystemInformation)(UINT, PVOID,
- ULONG, PULONG);
-
- // get NTDLL.DLL handle
- hNtDll = GetModuleHandleW(_T("ntdll.dll"));
- if(hNtDll == NULL) {
-#ifdef DEBUG_MONITOR
- _stprintf(buffer, _T("Failed to get ntdll.dll handle"));
- OutputDebugStringW(buffer);
-#endif
- return FALSE;
- }
-
- // find address of ZwQuerySystemInformation
- *(FARPROC *)&pZwQuerySystemInformation =
- GetProcAddress(hNtDll, "ZwQuerySystemInformation");
- if (pZwQuerySystemInformation == NULL)
- return SetLastError(ERROR_PROC_NOT_FOUND), NULL;
-
- // get default process heap handle
- HANDLE hHeap = GetProcessHeap();
-
- NTSTATUS Status;
- ULONG cbBuffer = 0x8000;
- PVOID pBuffer = NULL;
-
- // it is difficult to predict what buffer size will be
- // enough, so we start with 32K buffer and increase its
- // size as needed
- do
- {
- pBuffer = HeapAlloc(hHeap, 0, cbBuffer);
- if (pBuffer == NULL)
- return SetLastError(ERROR_NOT_ENOUGH_MEMORY), FALSE;
-
- Status = pZwQuerySystemInformation(
- SystemProcessesAndThreadsInformation,
- pBuffer, cbBuffer, NULL);
-
- if (Status == STATUS_INFO_LENGTH_MISMATCH)
- {
- HeapFree(hHeap, 0, pBuffer);
- cbBuffer *= 2;
- }
- else if (!NT_SUCCESS(Status))
- {
- HeapFree(hHeap, 0, pBuffer);
- return SetLastError(Status), NULL;
- }
- }
- while (Status == STATUS_INFO_LENGTH_MISMATCH);
-
- // call the helper
- dwError = KillProcessTreeNtHelper(
- (PSYSTEM_PROCESS_INFORMATION)pBuffer,
- dwProcessId);
-
- HeapFree(hHeap, 0, pBuffer);
- }
- else
- {
- // call the helper
- dwError = KillProcessTreeWinHelper(dwProcessId);
- }
-
- SetLastError(dwError);
- return dwError == ERROR_SUCCESS;
-}
-
-// Heloer function for process killing
-
-static BOOL KillProcess(
- IN DWORD dwProcessId
- )
-{
- // get process handle
- HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
- if (hProcess == NULL)
- return FALSE;
-
- DWORD dwError = ERROR_SUCCESS;
-
- // try to terminate the process
- if (!TerminateProcess(hProcess, (DWORD)-1))
- dwError = GetLastError();
-
- // close process handle
- CloseHandle(hProcess);
-
- SetLastError(dwError);
-#ifdef DEBUG_MONITOR
- if(dwError != ERROR_SUCCESS) {
- _stprintf(buffer, _T("Process %i killed"), dwProcessId);
- OutputDebugStringW(buffer);
- } else {
- _stprintf(buffer, _T("Failed to kill process %i"), dwProcessId);
- OutputDebugStringW(buffer);
- DisplayMessage();
- }
-#endif
- return dwError == ERROR_SUCCESS;
-}
-
-// a helper function that walks a process tree recursively
-// on Windows NT and terminates all processes in the tree
-static BOOL KillProcessTreeNtHelper(
- IN PSYSTEM_PROCESS_INFORMATION pInfo,
- IN DWORD dwProcessId
- )
-{
-#ifdef DEBUG_MONITOR
- _TCHAR buffer[MAX_CMD_LINE_LENGTH];
-#endif
- if(pInfo == NULL) {
-#ifdef DEBUG_MONITOR
- _stprintf(buffer, _T("KillProcessTreeNtHelper: wrong parameter"));
- OutputDebugStringW(buffer);
-#endif
- return FALSE;
- }
-
-
- // terminate all children first
- for (;;)
- {
- if (pInfo->InheritedFromProcessId == dwProcessId)
- KillProcessTreeNtHelper(pInfo, pInfo->ProcessId);
-
- if (pInfo->NextEntryDelta == 0)
- break;
-
- // find address of the next structure
- pInfo = (PSYSTEM_PROCESS_INFORMATION)(((PUCHAR)pInfo)
- + pInfo->NextEntryDelta);
- }
-
- // terminate the specified process
- if (!KillProcess(dwProcessId))
- return GetLastError();
-
- return ERROR_SUCCESS;
-}
-
-// a helper function that walks a process tree recursively
-// on Windows 9x and terminates all processes in the tree
-static BOOL KillProcessTreeWinHelper(
- IN DWORD dwProcessId
- )
-{
-#ifdef DEBUG_MONITOR
- _TCHAR buffer[MAX_CMD_LINE_LENGTH];
-#endif
- HINSTANCE hKernel;
- HANDLE (WINAPI * pCreateToolhelp32Snapshot)(DWORD, DWORD);
- BOOL (WINAPI * pProcess32First)(HANDLE, PROCESSENTRY32 *);
- BOOL (WINAPI * pProcess32Next)(HANDLE, PROCESSENTRY32 *);
-
- // get KERNEL32.DLL handle
- hKernel = GetModuleHandleW(_T("kernel32.dll"));
- if(hKernel == NULL) {
-#ifdef DEBUG_MONITOR
- _stprintf(buffer, _T("KillProcessTreeNtHelper: wrong parameter"));
- OutputDebugStringW(buffer);
-#endif
- return FALSE;
- }
-
- // find necessary entrypoints in KERNEL32.DLL
- *(FARPROC *)&pCreateToolhelp32Snapshot =
- GetProcAddress(hKernel, "CreateToolhelp32Snapshot");
- *(FARPROC *)&pProcess32First =
- GetProcAddress(hKernel, "Process32First");
- *(FARPROC *)&pProcess32Next =
- GetProcAddress(hKernel, "Process32Next");
-
- if (pCreateToolhelp32Snapshot == NULL ||
- pProcess32First == NULL ||
- pProcess32Next == NULL)
- return ERROR_PROC_NOT_FOUND;
-
- HANDLE hSnapshot;
- PROCESSENTRY32 Entry;
-
- // create a snapshot of all processes
- hSnapshot = pCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hSnapshot == INVALID_HANDLE_VALUE)
- return GetLastError();
-
- Entry.dwSize = sizeof(Entry);
- if (!pProcess32First(hSnapshot, &Entry))
- {
- DWORD dwError = GetLastError();
- CloseHandle(hSnapshot);
- return dwError;
- }
-
- // terminate children first
- do
- {
- if (Entry.th32ParentProcessID == dwProcessId)
- KillProcessTreeWinHelper(Entry.th32ProcessID);
-
- Entry.dwSize = sizeof(Entry);
- }
- while (pProcess32Next(hSnapshot, &Entry));
-
- CloseHandle(hSnapshot);
-
- // terminate the specified process
- if (!KillProcess(dwProcessId))
- return GetLastError();
-
- return ERROR_SUCCESS;
-}
-
diff --git a/core/org.eclipse.cdt.core.win32/library/starter/killer.h b/core/org.eclipse.cdt.core.win32/library/starter/killer.h
deleted file mode 100644
index 9b8b136813..0000000000
--- a/core/org.eclipse.cdt.core.win32/library/starter/killer.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002 - 2005 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * QNX Software Systems - initial API and implementation
- *
- * StdAfx.h
- *
- * This is a header file for helper function for the process killing
- * Implementation based on the article "Terminating Windows Processes"
- * see http://www.alexfedotov.com/articles/killproc.asp and
- * http://www.alexfedotov.com/samples/threads.asp
-***********************************************************************/
-
-#if !defined(_KILLER_H_INCLUDED_)
-#define _KILLER_H_INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-#include <Ntsecapi.h>
-
-
-typedef LONG KPRIORITY; // From ntddk.h
-
-//
-// Process Virtual Memory Counters
-// NtQueryInformationProcess using ProcessVmCounters
-// From ntddk.h
-
-typedef struct _VM_COUNTERS {
- SIZE_T PeakVirtualSize;
- SIZE_T VirtualSize;
- ULONG PageFaultCount;
- SIZE_T PeakWorkingSetSize;
- SIZE_T WorkingSetSize;
- SIZE_T QuotaPeakPagedPoolUsage;
- SIZE_T QuotaPagedPoolUsage;
- SIZE_T QuotaPeakNonPagedPoolUsage;
- SIZE_T QuotaNonPagedPoolUsage;
- SIZE_T PagefileUsage;
- SIZE_T PeakPagefileUsage;
-} VM_COUNTERS;
-typedef VM_COUNTERS *PVM_COUNTERS;
-
-//
-// ClientId
-//
-
-typedef struct _CLIENT_ID {
- HANDLE UniqueProcess;
- HANDLE UniqueThread;
-} CLIENT_ID;
-typedef CLIENT_ID *PCLIENT_ID;
-
-typedef struct _SYSTEM_THREAD_INFORMATION {
- LARGE_INTEGER KernelTime; // time spent in kernel mode
- LARGE_INTEGER UserTime; // time spent in user mode
- LARGE_INTEGER CreateTime; // thread creation time
- ULONG WaitTime; // wait time
- PVOID StartAddress; // start address
- CLIENT_ID ClientId; // thread and process IDs
- KPRIORITY Priority; // dynamic priority
- KPRIORITY BasePriority; // base priority
- ULONG ContextSwitchCount; // number of context switches
- LONG State; // current state
- LONG WaitReason; // wait reason
-} SYSTEM_THREAD_INFORMATION, * PSYSTEM_THREAD_INFORMATION;
-
-typedef struct _SYSTEM_PROCESS_INFORMATION {
- ULONG NextEntryDelta; // offset to the next entry
- ULONG ThreadCount; // number of threads
- ULONG Reserved1[6]; // reserved
- LARGE_INTEGER CreateTime; // process creation time
- LARGE_INTEGER UserTime; // time spent in user mode
- LARGE_INTEGER KernelTime; // time spent in kernel mode
- UNICODE_STRING ProcessName; // process name
- KPRIORITY BasePriority; // base process priority
- ULONG ProcessId; // process identifier
- ULONG InheritedFromProcessId; // parent process identifier
- ULONG HandleCount; // number of handles
- ULONG Reserved2[2]; // reserved
- VM_COUNTERS VmCounters; // virtual memory counters
-#if _WIN32_WINNT >= 0x500
- IO_COUNTERS IoCounters; // i/o counters
-#endif
- SYSTEM_THREAD_INFORMATION Threads[1]; // threads
-} SYSTEM_PROCESS_INFORMATION, * PSYSTEM_PROCESS_INFORMATION;
-
-
-static BOOL KillProcessTreeNtHelper(
- IN PSYSTEM_PROCESS_INFORMATION pInfo,
- IN DWORD dwProcessId);
-
-static BOOL KillProcessTreeWinHelper(
- IN DWORD dwProcessId);
-
-// From ntstatus.h
-// MessageId: STATUS_INFO_LENGTH_MISMATCH
-//
-// MessageText:
-//
-// The specified information record length does not match the length required for the specified information class.
-//
-#define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
-
-// From ntstatus.h
-// Generic test for success on any status value (non-negative numbers
-// indicate success).
-//
-
-#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
-
-
-
-
-#endif // _KILLER_H_INCLUDED_ \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
index 9ea10f5256..b353aebfa1 100644
--- a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
+++ b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp
@@ -29,7 +29,7 @@
int copyTo(_TCHAR * target, const _TCHAR * source, int cpyLength, int availSpace);
void DisplayErrorMessage();
-BOOL KillProcessEx(DWORD dwProcessId); // Handle of the process
+//BOOL KillProcessEx(DWORD dwProcessId); // Handle of the process
///////////////////////////////////////////////////////////////////////////////
BOOL WINAPI HandlerRoutine( DWORD dwCtrlType) // control signal type
@@ -214,7 +214,7 @@ extern "C" int _tmain(int argc, _TCHAR * argv[]) {
OutputDebugStringW(buffer);
#endif
// Create job object if it is possible
- HMODULE hKernel = GetModuleHandle("kernel32.dll");
+ HMODULE hKernel = GetModuleHandle(L"kernel32.dll");
HANDLE hJob = NULL;
HANDLE (WINAPI * pCreateJobObject)(LPSECURITY_ATTRIBUTES lpJobAttributes,
char * lpName);
@@ -297,12 +297,6 @@ extern "C" int _tmain(int argc, _TCHAR * argv[]) {
}
}
} else
- if(!KillProcessEx(pi.dwProcessId)) {
-#ifdef DEBUG_MONITOR
- _stprintf(buffer, _T("Cannot kill process (PID %i) tree\n"), pi.dwProcessId);
- OutputDebugStringW(buffer);
-#endif
- }
exitProc = TRUE;
break;
default:
diff --git a/core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe b/core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe
index 3bc462c0f0..d436988369 100644
--- a/core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe
+++ b/core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe
Binary files differ

Back to the top