* pinfo.cc: Use autoloaded ToolHelp functions throughout for Win9x.

* autoload.cc: Autoload ToolHelp functions.
This commit is contained in:
Christopher Faylor 2001-06-11 17:57:10 +00:00
parent a179327987
commit 3ecfcf5715
4 changed files with 31 additions and 36 deletions

View File

@ -1,3 +1,8 @@
Mon Jun 11 13:55:04 2001 Christopher Faylor <cgf@cygnus.com>
* pinfo.cc: Use autoloaded ToolHelp functions throughout for Win9x.
* autoload.cc: Autoload ToolHelp functions.
Mon Jun 11 11:18:56 2001 Christopher Faylor <cgf@cygnus.com>
* path.cc (chdir): Fix call to path_conv constructor so that it REALLY

View File

@ -475,6 +475,9 @@ LoadDLLfunc (CoCreateInstance, 20, ole32)
LoadDLLfuncEx (SignalObjectAndWait, 16, kernel32, 1)
LoadDLLfuncEx (CancelIo, 4, kernel32, 1)
LoadDLLfuncEx (Process32First, 8, kernel32, 1)
LoadDLLfuncEx (Process32Next, 8, kernel32, 1)
LoadDLLfuncEx (CreateToolhelp32Snapshot, 8, kernel32, 1)
LoadDLLfuncEx (waveOutGetNumDevs, 0, winmm, 1)
LoadDLLfuncEx (waveOutOpen, 24, winmm, 1)

View File

@ -282,14 +282,6 @@ cygwin_winpid_to_pid (int winpid)
#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;
#define slop_pidlist 200
#define size_pidlist(i) (sizeof (pidlist[0]) * ((i) + 1))
#define size_pinfolist(i) (sizeof (pinfolist[0]) * ((i) + 1))
@ -369,7 +361,7 @@ winpids::enum9x (bool winpid)
{
DWORD nelem = 0;
HANDLE h = myCreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
if (!h)
{
system_printf ("Couldn't create process snapshot, %E");
@ -379,13 +371,13 @@ winpids::enum9x (bool winpid)
PROCESSENTRY32 proc;
proc.dwSize = sizeof (proc);
if (myProcess32First (h, &proc))
if (Process32First (h, &proc))
do
{
if (proc.th32ProcessID)
add (nelem, winpid, proc.th32ProcessID);
}
while (myProcess32Next (h, &proc));
while (Process32Next (h, &proc));
CloseHandle (h);
return nelem;
@ -401,26 +393,10 @@ winpids::init (bool winpid)
DWORD
winpids::enum_init (bool winpid)
{
HINSTANCE h;
if (os_being_run == winNT)
enum_processes = &winpids::enumNT;
else
{
h = GetModuleHandle ("kernel32.dll");
myCreateToolhelp32Snapshot = (CREATESNAPSHOT)
GetProcAddress(h, "CreateToolhelp32Snapshot");
myProcess32First = (PROCESSWALK)
GetProcAddress (h, "Process32First");
myProcess32Next = (PROCESSWALK)
GetProcAddress (h, "Process32Next");
if (!myCreateToolhelp32Snapshot || !myProcess32First || !myProcess32Next)
{
system_printf ("Couldn't find toolhelp processes, %E");
return 0;
}
enum_processes = &winpids::enum9x;
}
enum_processes = &winpids::enum9x;
return (this->*enum_processes) (winpid);
}

View File

@ -46,7 +46,7 @@ details. */
#define no_signals_available() (!hwait_sig || !sig_loop_wait)
#define ZOMBIEMAX ((int) (sizeof (zombies) / sizeof (zombies[0])))
#define ZOMBIEMAX ((int) (sizeof (zombies) / sizeof (zombies[0])) - 1)
/*
* Global variables
@ -300,13 +300,12 @@ proc_subproc (DWORD what, DWORD val)
sigproc_printf ("pid %d[%d] terminated, handle %p, nchildren %d, nzombies %d",
pchildren[val]->pid, val, hchildren[val], nchildren, nzombies);
if (nzombies >= ZOMBIEMAX)
sigproc_printf ("Hit zombie maximum %d", nzombies);
else
{
zombies[nzombies] = pchildren[val]; // Add to zombie array
zombies[nzombies++]->process_state = PID_ZOMBIE;// Walking dead
}
int thiszombie;
thiszombie = nzombies;
zombies[nzombies] = pchildren[val]; // Add to zombie array
zombies[nzombies++]->process_state = PID_ZOMBIE;// Walking dead
sigproc_printf ("removing [%d], pid %d, handle %p, nchildren %d",
val, pchildren[val]->pid, hchildren[val], nchildren);
if ((int) val < --nchildren)
@ -314,6 +313,18 @@ proc_subproc (DWORD what, DWORD val)
hchildren[val] = hchildren[nchildren];
pchildren[val] = pchildren[nchildren];
}
/* See if we should care about the this terminated process. If we've
filled up our table or if we're ignoring SIGCHLD, then we immediately
remove the process and move on. Otherwise, this process becomes a zombie
which must be reaped by a wait() call. */
if (nzombies >= ZOMBIEMAX
|| myself->getsig (SIGCHLD).sa_handler == (void *) SIG_IGN)
{
sigproc_printf ("automatically removing zombie %d", thiszombie);
remove_zombie (thiszombie);
}
/* Don't scan the wait queue yet. Caller will send SIGCHLD to this process.
This will cause an eventual scan of waiters. */
break;