2000-02-17 20:38:33 +01:00
|
|
|
/* pinfo.cc: process table support
|
|
|
|
|
|
|
|
Copyright 1996, 1997, 1998, 2000 Cygnus Solutions.
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "fhandler.h"
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "dtable.h"
|
2000-08-22 05:58:47 +02:00
|
|
|
#include "cygerrno.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "sync.h"
|
|
|
|
#include "sigproc.h"
|
|
|
|
#include "pinfo.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "cygwin_version.h"
|
|
|
|
#include "perprocess.h"
|
|
|
|
#include "environ.h"
|
|
|
|
#include "security.h"
|
2000-10-15 03:37:07 +02:00
|
|
|
#include <assert.h>
|
2000-11-02 06:25:56 +01:00
|
|
|
#include <ntdef.h>
|
|
|
|
#include "ntdll.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
static char NO_COPY pinfo_dummy[sizeof(pinfo)] = {0};
|
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-17 01:55:58 +02:00
|
|
|
HANDLE hexec_proc = NULL;
|
2000-10-15 03:37:07 +02:00
|
|
|
|
|
|
|
void __stdcall
|
|
|
|
pinfo_fixup_after_fork ()
|
|
|
|
{
|
|
|
|
if (hexec_proc)
|
|
|
|
CloseHandle (hexec_proc);
|
|
|
|
|
|
|
|
if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &hexec_proc, 0,
|
|
|
|
TRUE, DUPLICATE_SAME_ACCESS))
|
|
|
|
{
|
|
|
|
system_printf ("couldn't save current process handle %p, %E", hMainProc);
|
|
|
|
hexec_proc = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Initialize the process table.
|
|
|
|
This is done once when the dll is first loaded. */
|
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
void __stdcall
|
2000-08-24 06:07:50 +02:00
|
|
|
set_myself (pid_t pid, HANDLE h)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-07-29 18:24:59 +02:00
|
|
|
DWORD winpid = GetCurrentProcessId ();
|
|
|
|
if (pid == 1)
|
|
|
|
pid = cygwin_pid (winpid);
|
2000-08-24 06:07:50 +02:00
|
|
|
myself.init (pid, 1, h);
|
2000-07-29 18:24:59 +02:00
|
|
|
myself->dwProcessId = winpid;
|
|
|
|
myself->process_state |= PID_IN_USE;
|
2000-02-17 20:38:33 +01:00
|
|
|
myself->start_time = time (NULL); /* Register our starting time. */
|
|
|
|
|
|
|
|
char buf[30];
|
2000-03-07 06:33:09 +01:00
|
|
|
__small_sprintf (buf, "cYg%8x %x", _STRACE_INTERFACE_ACTIVATE_ADDR,
|
|
|
|
&strace.active);
|
2000-02-17 20:38:33 +01:00
|
|
|
OutputDebugString (buf);
|
2000-02-28 06:05:33 +01:00
|
|
|
|
|
|
|
(void) GetModuleFileName (NULL, myself->progname,
|
|
|
|
sizeof(myself->progname));
|
2000-03-07 06:33:09 +01:00
|
|
|
if (strace.active)
|
2000-02-28 06:05:33 +01:00
|
|
|
{
|
|
|
|
extern char osname[];
|
2000-08-02 21:26:01 +02:00
|
|
|
strace.prntf (1, NULL, "**********************************************");
|
2000-10-13 05:13:59 +02:00
|
|
|
strace.prntf (1, NULL, "Program name: %s (%d)", myself->progname, myself->pid);
|
2000-08-02 21:26:01 +02:00
|
|
|
strace.prntf (1, NULL, "App version: %d.%d, api: %d.%d",
|
|
|
|
user_data->dll_major, user_data->dll_minor,
|
|
|
|
user_data->api_major, user_data->api_minor);
|
|
|
|
strace.prntf (1, NULL, "DLL version: %d.%d, api: %d.%d",
|
|
|
|
cygwin_version.dll_major, cygwin_version.dll_minor,
|
|
|
|
cygwin_version.api_major, cygwin_version.api_minor);
|
|
|
|
strace.prntf (1, NULL, "DLL build: %s", cygwin_version.dll_build_date);
|
|
|
|
strace.prntf (1, NULL, "OS version: Windows %s", osname);
|
|
|
|
strace.prntf (1, NULL, "**********************************************");
|
2000-02-28 06:05:33 +01:00
|
|
|
}
|
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
return;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the process table entry for the current task.
|
|
|
|
This is not called for fork'd tasks, only exec'd ones. */
|
|
|
|
void __stdcall
|
2000-10-17 01:55:58 +02:00
|
|
|
pinfo_init (char **envp, int envc)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-09-03 06:16:35 +02:00
|
|
|
if (envp)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-10-17 01:55:58 +02:00
|
|
|
environ_init (envp, envc);
|
2000-02-17 20:38:33 +01:00
|
|
|
/* spawn has already set up a pid structure for us so we'll use that */
|
|
|
|
myself->process_state |= PID_CYGPARENT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Invent our own pid. */
|
|
|
|
|
2000-08-26 03:36:20 +02:00
|
|
|
set_myself (1);
|
2000-07-29 18:24:59 +02:00
|
|
|
myself->ppid = 1;
|
|
|
|
myself->pgid = myself->sid = myself->pid;
|
2000-02-17 20:38:33 +01:00
|
|
|
myself->ctty = -1;
|
|
|
|
myself->uid = USHRT_MAX;
|
|
|
|
|
2000-10-17 01:55:58 +02:00
|
|
|
environ_init (NULL, 0); /* call after myself has been set up */
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
debug_printf ("pid %d, pgid %d", myself->pid, myself->pgid);
|
|
|
|
}
|
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
void
|
2000-10-17 01:55:58 +02:00
|
|
|
_pinfo::exit (UINT n, bool norecord)
|
2000-10-15 03:37:07 +02:00
|
|
|
{
|
2000-10-17 01:55:58 +02:00
|
|
|
if (!norecord)
|
|
|
|
process_state = PID_EXITED;
|
2000-10-15 03:37:07 +02:00
|
|
|
|
2000-10-17 01:55:58 +02:00
|
|
|
/* FIXME: There is a potential race between an execed process and its
|
|
|
|
parent here. I hated to add a mutex just for this, though. */
|
|
|
|
struct rusage r;
|
|
|
|
fill_rusage (&r, hMainProc);
|
|
|
|
add_rusage (&rusage_self, &r);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-17 01:55:58 +02:00
|
|
|
sigproc_printf ("Calling ExitProcess %d", n);
|
|
|
|
ExitProcess (n);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-10-21 06:53:49 +02:00
|
|
|
pinfo::init (pid_t n, DWORD flag, HANDLE in_h)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-07-29 18:24:59 +02:00
|
|
|
if (n == myself->pid)
|
|
|
|
{
|
2000-08-26 05:48:37 +02:00
|
|
|
procinfo = myself;
|
2000-07-29 18:24:59 +02:00
|
|
|
destroy = 0;
|
|
|
|
h = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-21 22:57:40 +02:00
|
|
|
int createit = flag & (PID_IN_USE | PID_EXECED);
|
2000-10-15 03:37:07 +02:00
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
int created;
|
|
|
|
char mapname[MAX_PATH];
|
|
|
|
__small_sprintf (mapname, "cygpid.%x", n);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
int mapsize;
|
2000-10-21 06:53:49 +02:00
|
|
|
if (flag & PID_EXECED)
|
2000-10-15 03:37:07 +02:00
|
|
|
mapsize = PINFO_REDIR_SIZE;
|
|
|
|
else
|
|
|
|
mapsize = sizeof (_pinfo);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
if (in_h)
|
|
|
|
{
|
|
|
|
h = in_h;
|
|
|
|
created = 0;
|
|
|
|
}
|
2000-10-21 06:53:49 +02:00
|
|
|
else if (!createit)
|
2000-10-15 03:37:07 +02:00
|
|
|
{
|
|
|
|
h = OpenFileMappingA (FILE_MAP_READ | FILE_MAP_WRITE, FALSE, mapname);
|
|
|
|
created = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
h = CreateFileMapping ((HANDLE) 0xffffffff, &sec_all_nih,
|
|
|
|
PAGE_READWRITE, 0, mapsize, mapname);
|
|
|
|
created = h && GetLastError () != ERROR_ALREADY_EXISTS;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
if (!h)
|
|
|
|
{
|
2000-10-21 06:53:49 +02:00
|
|
|
if (createit)
|
2000-10-15 03:37:07 +02:00
|
|
|
__seterrno ();
|
|
|
|
procinfo = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
procinfo = (_pinfo *) MapViewOfFile (h, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
|
|
|
|
ProtectHandle1 (h, pinfo_shared_handle);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-21 06:53:49 +02:00
|
|
|
if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR))
|
2000-10-20 06:20:21 +02:00
|
|
|
{
|
|
|
|
release ();
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
if (procinfo->process_state & PID_EXECED)
|
|
|
|
{
|
|
|
|
assert (!i);
|
|
|
|
pid_t realpid = procinfo->pid;
|
|
|
|
debug_printf ("execed process windows pid %d, cygwin pid %d", n, realpid);
|
|
|
|
if (realpid == n)
|
|
|
|
api_fatal ("retrieval of execed process info for pid %d failed due to recursion.", n);
|
|
|
|
n = realpid;
|
|
|
|
release ();
|
|
|
|
continue;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
/* In certain rare, pathological cases, it is possible for the shared
|
|
|
|
memory region to exist for a while after a process has exited. This
|
|
|
|
should only be a brief occurrence, so rather than introduce some kind
|
|
|
|
of locking mechanism, just loop. FIXME: I'm sure I'll regret doing it
|
|
|
|
this way at some point. */
|
2000-10-21 06:53:49 +02:00
|
|
|
if (i < 9 && !created && createit && (procinfo->process_state & PID_EXITED))
|
2000-10-15 03:37:07 +02:00
|
|
|
{
|
|
|
|
Sleep (5);
|
|
|
|
release ();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!created)
|
|
|
|
/* nothing */;
|
2000-10-21 06:53:49 +02:00
|
|
|
else if (!(flag & PID_EXECED))
|
2000-08-26 05:48:37 +02:00
|
|
|
procinfo->pid = n;
|
2000-07-29 18:24:59 +02:00
|
|
|
else
|
|
|
|
{
|
2000-08-26 05:48:37 +02:00
|
|
|
procinfo->process_state |= PID_IN_USE | PID_EXECED;
|
2000-11-03 05:27:03 +01:00
|
|
|
procinfo->pid = myself->pid;
|
2000-07-29 18:24:59 +02:00
|
|
|
}
|
2000-10-15 03:37:07 +02:00
|
|
|
break;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-07-29 18:24:59 +02:00
|
|
|
destroy = 1;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-10-09 04:53:44 +02:00
|
|
|
|
2000-08-26 05:48:37 +02:00
|
|
|
void
|
|
|
|
pinfo::release ()
|
|
|
|
{
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
#ifdef DEBUGGING
|
|
|
|
if (((DWORD) procinfo & 0x77000000) == 0x61000000) try_to_debug ();
|
|
|
|
#endif
|
|
|
|
UnmapViewOfFile (procinfo);
|
2000-10-20 06:20:21 +02:00
|
|
|
procinfo = NULL;
|
2000-08-26 05:48:37 +02:00
|
|
|
ForceCloseHandle1 (h, pinfo_shared_handle);
|
|
|
|
h = NULL;
|
|
|
|
}
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* DOCTOOL-START
|
|
|
|
|
|
|
|
<sect1 id="func-cygwin-winpid-to-pid">
|
|
|
|
<title>cygwin_winpid_to_pid</title>
|
|
|
|
|
|
|
|
<funcsynopsis>
|
|
|
|
<funcdef>extern "C" pid_t
|
|
|
|
<function>cygwin_winpid_to_pid</function>
|
|
|
|
</funcdef>
|
|
|
|
<paramdef>int <parameter>winpid</parameter></paramdef>
|
|
|
|
</funcsynopsis>
|
|
|
|
|
|
|
|
<para>Given a windows pid, converts to the corresponding Cygwin
|
|
|
|
pid, if any. Returns -1 if windows pid does not correspond to
|
|
|
|
a cygwin pid.</para>
|
|
|
|
<example>
|
|
|
|
<title>Example use of cygwin_winpid_to_pid</title>
|
|
|
|
<programlisting>
|
|
|
|
extern "C" cygwin_winpid_to_pid (int winpid);
|
|
|
|
pid_t mypid;
|
|
|
|
mypid = cygwin_winpid_to_pid (windows_pid);
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
DOCTOOL-END */
|
|
|
|
|
|
|
|
extern "C" pid_t
|
|
|
|
cygwin_winpid_to_pid (int winpid)
|
|
|
|
{
|
2000-07-29 18:24:59 +02:00
|
|
|
pinfo p (winpid);
|
|
|
|
if (p)
|
|
|
|
return p->pid;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
set_errno (ESRCH);
|
|
|
|
return (pid_t) -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <tlhelp32.h>
|
|
|
|
|
|
|
|
typedef HANDLE (WINAPI * CREATESNAPSHOT) (DWORD, DWORD);
|
|
|
|
typedef BOOL (WINAPI * PROCESSWALK) (HANDLE, LPPROCESSENTRY32);
|
|
|
|
typedef BOOL (WINAPI * CLOSESNAPSHOT) (HANDLE);
|
|
|
|
|
|
|
|
static NO_COPY CREATESNAPSHOT myCreateToolhelp32Snapshot = NULL;
|
|
|
|
static NO_COPY PROCESSWALK myProcess32First = NULL;
|
|
|
|
static NO_COPY PROCESSWALK myProcess32Next = NULL;
|
|
|
|
|
2000-11-02 06:25:56 +01:00
|
|
|
#define slop_pidlist 200
|
|
|
|
#define size_pidlist(i) (sizeof (pidlist[0]) * ((i) + 1))
|
2000-11-05 07:42:23 +01:00
|
|
|
#define size_pinfolist(i) (sizeof (pinfolist[0]) * ((i) + 1))
|
2000-11-02 06:25:56 +01:00
|
|
|
|
2000-11-05 07:42:23 +01:00
|
|
|
inline void
|
|
|
|
winpids::add (DWORD& nelem, bool winpid, DWORD pid)
|
|
|
|
{
|
|
|
|
pid_t cygpid = cygwin_pid (pid);
|
|
|
|
if (nelem >= npidlist)
|
|
|
|
{
|
|
|
|
npidlist += slop_pidlist;
|
|
|
|
pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist));
|
|
|
|
pinfolist = (pinfo *) realloc (pinfolist, size_pinfolist (npidlist));
|
|
|
|
}
|
|
|
|
|
|
|
|
pinfolist[nelem].init (cygpid, PID_NOREDIR);
|
|
|
|
if (winpid)
|
|
|
|
/* nothing to do */;
|
|
|
|
else if (!pinfolist[nelem])
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
/* Scan list of previously recorded pids to make sure that this pid hasn't
|
|
|
|
shown up before. This can happen when a process execs. */
|
|
|
|
for (unsigned i = 0; i < nelem; i++)
|
|
|
|
if (pinfolist[i]->pid == pinfolist[nelem]->pid )
|
|
|
|
{
|
|
|
|
if ((_pinfo *) pinfolist[nelem] != (_pinfo *) myself)
|
|
|
|
pinfolist[nelem].release ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pidlist[nelem++] = pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
winpids::enumNT (bool winpid)
|
2000-11-02 06:25:56 +01:00
|
|
|
{
|
|
|
|
static DWORD szprocs = 0;
|
|
|
|
static SYSTEM_PROCESSES *procs;
|
|
|
|
|
|
|
|
DWORD nelem = 0;
|
|
|
|
if (!szprocs)
|
|
|
|
procs = (SYSTEM_PROCESSES *) malloc (szprocs = 200 * sizeof (*procs));
|
|
|
|
|
|
|
|
NTSTATUS res;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
res = ZwQuerySystemInformation (SystemProcessesAndThreadsInformation,
|
|
|
|
procs, szprocs, NULL);
|
|
|
|
if (res == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (res == STATUS_INFO_LENGTH_MISMATCH)
|
|
|
|
procs = (SYSTEM_PROCESSES *)realloc (procs, szprocs += 200 * sizeof (*procs));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
system_printf ("error %p reading system process information", res);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSTEM_PROCESSES *px = procs;
|
|
|
|
for (;;)
|
|
|
|
{
|
2000-11-04 06:54:57 +01:00
|
|
|
if (px->ProcessId)
|
2000-11-05 07:42:23 +01:00
|
|
|
add (nelem, winpid, px->ProcessId);
|
|
|
|
if (!px->NextEntryDelta)
|
|
|
|
break;
|
2000-11-02 06:25:56 +01:00
|
|
|
px = (SYSTEM_PROCESSES *) ((char *) px + px->NextEntryDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nelem;
|
|
|
|
}
|
|
|
|
|
2000-11-05 07:42:23 +01:00
|
|
|
DWORD
|
|
|
|
winpids::enum9x (bool winpid)
|
2000-07-29 18:24:59 +02:00
|
|
|
{
|
2000-11-02 06:25:56 +01:00
|
|
|
DWORD nelem = 0;
|
2000-07-29 18:24:59 +02:00
|
|
|
|
2000-11-02 06:25:56 +01:00
|
|
|
HANDLE h = myCreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
|
2000-07-29 18:24:59 +02:00
|
|
|
if (!h)
|
2000-11-02 06:25:56 +01:00
|
|
|
{
|
|
|
|
system_printf ("Couldn't create process snapshot, %E");
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-29 18:24:59 +02:00
|
|
|
|
|
|
|
PROCESSENTRY32 proc;
|
|
|
|
proc.dwSize = sizeof (proc);
|
2000-11-02 06:25:56 +01:00
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
if (myProcess32First(h, &proc))
|
|
|
|
do
|
2000-11-02 06:25:56 +01:00
|
|
|
{
|
2000-11-05 07:42:23 +01:00
|
|
|
if (proc.th32ProcessID)
|
|
|
|
add (nelem, winpid, proc.th32ProcessID);
|
2000-11-02 06:25:56 +01:00
|
|
|
}
|
2000-07-29 18:24:59 +02:00
|
|
|
while (myProcess32Next (h, &proc));
|
2000-11-02 06:25:56 +01:00
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
CloseHandle (h);
|
2000-11-02 06:25:56 +01:00
|
|
|
return nelem;
|
2000-07-29 18:24:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-05 07:42:23 +01:00
|
|
|
winpids::init (bool winpid)
|
2000-07-29 18:24:59 +02:00
|
|
|
{
|
2000-11-05 07:42:23 +01:00
|
|
|
npids = (this->*enum_processes) (winpid);
|
2000-07-29 18:24:59 +02:00
|
|
|
pidlist[npids] = 0;
|
|
|
|
}
|
|
|
|
|
2000-11-05 07:42:23 +01:00
|
|
|
DWORD
|
|
|
|
winpids::enum_init (bool winpid)
|
2000-07-29 18:24:59 +02:00
|
|
|
{
|
|
|
|
HINSTANCE h;
|
|
|
|
if (os_being_run == winNT)
|
2000-11-05 07:42:23 +01:00
|
|
|
enum_processes = &winpids::enumNT;
|
2000-07-29 18:24:59 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
h = GetModuleHandle("kernel32.dll");
|
|
|
|
myCreateToolhelp32Snapshot = (CREATESNAPSHOT)
|
|
|
|
GetProcAddress(h, "CreateToolhelp32Snapshot");
|
|
|
|
myProcess32First = (PROCESSWALK)
|
|
|
|
GetProcAddress(h, "Process32First");
|
|
|
|
myProcess32Next = (PROCESSWALK)
|
|
|
|
GetProcAddress(h, "Process32Next");
|
|
|
|
if (!myCreateToolhelp32Snapshot || !myProcess32First || !myProcess32Next)
|
2000-10-31 18:01:56 +01:00
|
|
|
{
|
|
|
|
system_printf ("Couldn't find toolhelp processes, %E");
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-29 18:24:59 +02:00
|
|
|
|
2000-11-05 07:42:23 +01:00
|
|
|
enum_processes = &winpids::enum9x;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-11-05 07:42:23 +01:00
|
|
|
return (this->*enum_processes) (winpid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
winpids::release ()
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < npids; i++)
|
|
|
|
if (pinfolist[i] && (_pinfo *) pinfolist[i] != (_pinfo *) myself)
|
|
|
|
pinfolist[i].release ();
|
|
|
|
}
|
|
|
|
|
|
|
|
winpids::~winpids ()
|
|
|
|
{
|
|
|
|
if (npidlist)
|
|
|
|
{
|
|
|
|
release ();
|
|
|
|
free (pidlist);
|
|
|
|
free (pinfolist);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|