/* * Misc Toolhelp functions * * Copyright 1996 Marcus Meissner */ #include #include #include #include #include #include "windows.h" #include "win.h" #include "winerror.h" #include "process.h" #include "tlhelp32.h" #include "toolhelp.h" #include "heap.h" #include "k32obj.h" #include "server.h" #include "debug.h" /* The K32 snapshot object object */ typedef struct { K32OBJ header; } SNAPSHOT_OBJECT; /* FIXME: to make this working, we have to callback all these registered * functions from all over the WINE code. Someone with more knowledge than * me please do that. -Marcus */ static struct notify { HTASK16 htask; FARPROC16 lpfnCallback; WORD wFlags; } *notifys = NULL; static int nrofnotifys = 0; static FARPROC16 HookNotify = NULL; BOOL16 WINAPI NotifyRegister( HTASK16 htask, FARPROC16 lpfnCallback, WORD wFlags ) { int i; TRACE(toolhelp, "(%x,%lx,%x) called.\n", htask, (DWORD)lpfnCallback, wFlags ); if (!htask) htask = GetCurrentTask(); for (i=0;iheader.type = K32OBJ_TOOLHELP_SNAPSHOT; snapshot->header.refcount = 1; req.flags = flags & ~TH32CS_INHERIT; req.inherit = (flags & TH32CS_INHERIT) != 0; CLIENT_SendRequest( REQ_CREATE_SNAPSHOT, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) { HeapFree( SystemHeap, 0, snapshot ); return INVALID_HANDLE_VALUE32; } return HANDLE_Alloc( PROCESS_Current(), &snapshot->header, 0, req.inherit, reply.handle ); } /*********************************************************************** * TOOLHELP_Process32Next * * Implementation of Process32First/Next */ static BOOL32 TOOLHELP_Process32Next( HANDLE32 handle, LPPROCESSENTRY32 lppe, BOOL32 first ) { struct next_process_request req; struct next_process_reply reply; if (lppe->dwSize < sizeof (PROCESSENTRY32)) { SetLastError( ERROR_INSUFFICIENT_BUFFER ); ERR (toolhelp, "Result buffer too small\n"); return FALSE; } if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, K32OBJ_TOOLHELP_SNAPSHOT, 0 )) == -1) return FALSE; req.reset = first; CLIENT_SendRequest( REQ_NEXT_PROCESS, -1, 1, &req, sizeof(req) ); if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; lppe->cntUsage = 1; lppe->th32ProcessID = (DWORD)reply.pid; lppe->th32DefaultHeapID = 0; /* FIXME */ lppe->th32ModuleID = 0; /* FIXME */ lppe->cntThreads = reply.threads; lppe->th32ParentProcessID = 0; /* FIXME */ lppe->pcPriClassBase = reply.priority; lppe->dwFlags = -1; /* FIXME */ lppe->szExeFile[0] = 0; /* FIXME */ return TRUE; } /*********************************************************************** * Process32First (KERNEL32.555) * * Return info about the first process in a toolhelp32 snapshot */ BOOL32 WINAPI Process32First(HANDLE32 hSnapshot, LPPROCESSENTRY32 lppe) { return TOOLHELP_Process32Next( hSnapshot, lppe, TRUE ); } /*********************************************************************** * Process32Next (KERNEL32.556) * * Return info about the "next" process in a toolhelp32 snapshot */ BOOL32 WINAPI Process32Next(HANDLE32 hSnapshot, LPPROCESSENTRY32 lppe) { return TOOLHELP_Process32Next( hSnapshot, lppe, FALSE ); }