2 * Misc Toolhelp functions
4 * Copyright 1996 Marcus Meissner
13 #include "wine/winbase16.h"
22 DEFAULT_DEBUG_CHANNEL(toolhelp)
25 /* FIXME: to make this working, we have to callback all these registered
26 * functions from all over the WINE code. Someone with more knowledge than
27 * me please do that. -Marcus
32 FARPROC16 lpfnCallback;
36 static int nrofnotifys = 0;
38 static FARPROC16 HookNotify = NULL;
40 BOOL16 WINAPI NotifyRegister16( HTASK16 htask, FARPROC16 lpfnCallback,
45 TRACE(toolhelp, "(%x,%lx,%x) called.\n",
46 htask, (DWORD)lpfnCallback, wFlags );
47 if (!htask) htask = GetCurrentTask();
48 for (i=0;i<nrofnotifys;i++)
49 if (notifys[i].htask==htask)
53 notifys=(struct notify*)HeapAlloc( SystemHeap, 0,
54 sizeof(struct notify) );
56 notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
57 sizeof(struct notify)*(nrofnotifys+1));
58 if (!notifys) return FALSE;
61 notifys[i].htask=htask;
62 notifys[i].lpfnCallback=lpfnCallback;
63 notifys[i].wFlags=wFlags;
67 BOOL16 WINAPI NotifyUnregister16( HTASK16 htask )
71 TRACE(toolhelp, "(%x) called.\n", htask );
72 if (!htask) htask = GetCurrentTask();
73 for (i=nrofnotifys;i--;)
74 if (notifys[i].htask==htask)
78 memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
79 notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
80 (nrofnotifys-1)*sizeof(struct notify));
85 BOOL16 WINAPI StackTraceCSIPFirst16(STACKTRACEENTRY *ste, WORD wSS, WORD wCS, WORD wIP, WORD wBP)
90 BOOL16 WINAPI StackTraceFirst16(STACKTRACEENTRY *ste, HTASK16 Task)
95 BOOL16 WINAPI StackTraceNext16(STACKTRACEENTRY *ste)
100 /***********************************************************************
101 * ToolHelpHook (KERNEL.341)
102 * see "Undocumented Windows"
104 FARPROC16 WINAPI ToolHelpHook16(FARPROC16 lpfnNotifyHandler)
108 HookNotify = lpfnNotifyHandler;
109 /* just return previously installed notification function */
114 /***********************************************************************
115 * CreateToolHelp32Snapshot (KERNEL32.179)
117 HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process )
119 struct create_snapshot_request *req = get_req_buffer();
121 TRACE( toolhelp, "%lx,%lx\n", flags, process );
122 if (flags & (TH32CS_SNAPHEAPLIST|TH32CS_SNAPMODULE|TH32CS_SNAPTHREAD))
123 FIXME( toolhelp, "flags %lx not implemented\n", flags );
124 if (!(flags & TH32CS_SNAPPROCESS))
126 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
127 return INVALID_HANDLE_VALUE;
130 /* Now do the snapshot */
131 req->flags = flags & ~TH32CS_INHERIT;
132 req->inherit = (flags & TH32CS_INHERIT) != 0;
133 server_call( REQ_CREATE_SNAPSHOT );
138 /***********************************************************************
139 * TOOLHELP_Process32Next
141 * Implementation of Process32First/Next
143 static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY lppe, BOOL first )
145 struct next_process_request *req = get_req_buffer();
147 if (lppe->dwSize < sizeof (PROCESSENTRY))
149 SetLastError( ERROR_INSUFFICIENT_BUFFER );
150 ERR (toolhelp, "Result buffer too small\n");
153 req->handle = handle;
155 if (server_call( REQ_NEXT_PROCESS )) return FALSE;
157 lppe->th32ProcessID = (DWORD)req->pid;
158 lppe->th32DefaultHeapID = 0; /* FIXME */
159 lppe->th32ModuleID = 0; /* FIXME */
160 lppe->cntThreads = req->threads;
161 lppe->th32ParentProcessID = 0; /* FIXME */
162 lppe->pcPriClassBase = req->priority;
163 lppe->dwFlags = -1; /* FIXME */
164 lppe->szExeFile[0] = 0; /* FIXME */
169 /***********************************************************************
170 * Process32First (KERNEL32.555)
172 * Return info about the first process in a toolhelp32 snapshot
174 BOOL WINAPI Process32First(HANDLE hSnapshot, LPPROCESSENTRY lppe)
176 return TOOLHELP_Process32Next( hSnapshot, lppe, TRUE );
179 /***********************************************************************
180 * Process32Next (KERNEL32.556)
182 * Return info about the "next" process in a toolhelp32 snapshot
184 BOOL WINAPI Process32Next(HANDLE hSnapshot, LPPROCESSENTRY lppe)
186 return TOOLHELP_Process32Next( hSnapshot, lppe, FALSE );
189 /***********************************************************************
190 * Module32First (KERNEL32.527)
192 * Return info about the "first" module in a toolhelp32 snapshot
194 BOOL WINAPI Module32First(HANDLE hSnapshot, LPMODULEENTRY lpme)
196 FIXME(toolhelp,"(%d,%p),stub!\n",hSnapshot,lpme);
200 /***********************************************************************
201 * Module32Next (KERNEL32.528)
203 * Return info about the "next" module in a toolhelp32 snapshot
205 BOOL WINAPI Module32Next(HANDLE hSnapshot, LPMODULEENTRY lpme)
207 FIXME(toolhelp,"(%d,%p),stub!\n",hSnapshot,lpme);
211 /************************************************************************
212 * GlobalMasterHandle16 (KERNEL.28)
215 * Should return selector and handle of the information structure for
216 * the global heap. selector and handle are stored in the THHOOK as
217 * pGlobalHeap and hGlobalHeap.
218 * As Wine doesn't have this structure, we return both values as zero
219 * Applications should interpret this as "No Global Heap"
221 DWORD WINAPI GlobalMasterHandle16(void)
223 FIXME(toolhelp,": stub\n");