2 * Misc Toolhelp functions
4 * Copyright 1996 Marcus Meissner
13 #include "wine/winbase16.h"
20 #include "debugtools.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 /***********************************************************************
43 BOOL16 WINAPI
NotifyRegister16( HTASK16 htask
, FARPROC16 lpfnCallback
,
48 TRACE("(%x,%lx,%x) called.\n",
49 htask
, (DWORD
)lpfnCallback
, wFlags
);
50 if (!htask
) htask
= GetCurrentTask();
51 for (i
=0;i
<nrofnotifys
;i
++)
52 if (notifys
[i
].htask
==htask
)
56 notifys
=(struct notify
*)HeapAlloc( GetProcessHeap(), 0,
57 sizeof(struct notify
) );
59 notifys
=(struct notify
*)HeapReAlloc( GetProcessHeap(), 0, notifys
,
60 sizeof(struct notify
)*(nrofnotifys
+1));
61 if (!notifys
) return FALSE
;
64 notifys
[i
].htask
=htask
;
65 notifys
[i
].lpfnCallback
=lpfnCallback
;
66 notifys
[i
].wFlags
=wFlags
;
70 /***********************************************************************
73 BOOL16 WINAPI
NotifyUnregister16( HTASK16 htask
)
77 TRACE("(%x) called.\n", htask
);
78 if (!htask
) htask
= GetCurrentTask();
79 for (i
=nrofnotifys
;i
--;)
80 if (notifys
[i
].htask
==htask
)
84 memcpy(notifys
+i
,notifys
+(i
+1),sizeof(struct notify
)*(nrofnotifys
-i
-1));
85 notifys
=(struct notify
*)HeapReAlloc( GetProcessHeap(), 0, notifys
,
86 (nrofnotifys
-1)*sizeof(struct notify
));
91 /***********************************************************************
92 * StackTraceCSIPFirst16
94 BOOL16 WINAPI
StackTraceCSIPFirst16(STACKTRACEENTRY
*ste
, WORD wSS
, WORD wCS
, WORD wIP
, WORD wBP
)
99 /***********************************************************************
102 BOOL16 WINAPI
StackTraceFirst16(STACKTRACEENTRY
*ste
, HTASK16 Task
)
107 /***********************************************************************
110 BOOL16 WINAPI
StackTraceNext16(STACKTRACEENTRY
*ste
)
115 /***********************************************************************
116 * InterruptRegister16
118 BOOL16 WINAPI
InterruptRegister16( HTASK16 task
, FARPROC callback
)
123 /***********************************************************************
124 * InterruptUnRegister16
126 BOOL16 WINAPI
InterruptUnRegister16( HTASK16 task
)
131 /***********************************************************************
132 * ToolHelpHook (KERNEL.341)
133 * see "Undocumented Windows"
135 FARPROC16 WINAPI
ToolHelpHook16(FARPROC16 lpfnNotifyHandler
)
139 HookNotify
= lpfnNotifyHandler
;
140 /* just return previously installed notification function */
145 /***********************************************************************
146 * CreateToolhelp32Snapshot (KERNEL32.179)
148 HANDLE WINAPI
CreateToolhelp32Snapshot( DWORD flags
, DWORD process
)
150 struct create_snapshot_request
*req
= get_req_buffer();
152 TRACE("%lx,%lx\n", flags
, process
);
153 if (!(flags
& (TH32CS_SNAPPROCESS
|TH32CS_SNAPTHREAD
|TH32CS_SNAPMODULE
)))
155 FIXME("flags %lx not implemented\n", flags
);
156 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
157 return INVALID_HANDLE_VALUE
;
160 /* Now do the snapshot */
161 req
->flags
= flags
& ~TH32CS_INHERIT
;
162 req
->inherit
= (flags
& TH32CS_INHERIT
) != 0;
163 req
->pid
= (void *)process
;
164 server_call( REQ_CREATE_SNAPSHOT
);
169 /***********************************************************************
170 * TOOLHELP_Thread32Next
172 * Implementation of Thread32First/Next
174 static BOOL
TOOLHELP_Thread32Next( HANDLE handle
, LPTHREADENTRY32 lpte
, BOOL first
)
176 struct next_thread_request
*req
= get_req_buffer();
178 if (lpte
->dwSize
< sizeof(THREADENTRY32
))
180 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
181 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(THREADENTRY32
), lpte
->dwSize
);
184 req
->handle
= handle
;
186 if (server_call( REQ_NEXT_THREAD
)) return FALSE
;
187 lpte
->cntUsage
= req
->count
;
188 lpte
->th32ThreadID
= (DWORD
)req
->tid
;
189 lpte
->th32OwnerProcessID
= (DWORD
)req
->pid
;
190 lpte
->tbBasePri
= req
->base_pri
;
191 lpte
->tbDeltaPri
= req
->delta_pri
;
192 lpte
->dwFlags
= 0; /* SDK: "reserved; do not use" */
196 /***********************************************************************
197 * Thread32First (KERNEL32.686)
199 * Return info about the first thread in a toolhelp32 snapshot
201 BOOL WINAPI
Thread32First(HANDLE hSnapshot
, LPTHREADENTRY32 lpte
)
203 return TOOLHELP_Thread32Next(hSnapshot
, lpte
, TRUE
);
206 /***********************************************************************
207 * Thread32Next (KERNEL32.687)
209 * Return info about the "next" thread in a toolhelp32 snapshot
211 BOOL WINAPI
Thread32Next(HANDLE hSnapshot
, LPTHREADENTRY32 lpte
)
213 return TOOLHELP_Thread32Next(hSnapshot
, lpte
, FALSE
);
216 /***********************************************************************
217 * TOOLHELP_Process32Next
219 * Implementation of Process32First/Next
221 static BOOL
TOOLHELP_Process32Next( HANDLE handle
, LPPROCESSENTRY32 lppe
, BOOL first
)
223 struct next_process_request
*req
= get_req_buffer();
225 if (lppe
->dwSize
< sizeof(PROCESSENTRY32
))
227 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
228 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(PROCESSENTRY32
), lppe
->dwSize
);
231 req
->handle
= handle
;
233 if (server_call( REQ_NEXT_PROCESS
)) return FALSE
;
234 lppe
->cntUsage
= req
->count
;
235 lppe
->th32ProcessID
= (DWORD
)req
->pid
;
236 lppe
->th32DefaultHeapID
= 0; /* FIXME */
237 lppe
->th32ModuleID
= 0; /* FIXME */
238 lppe
->cntThreads
= req
->threads
;
239 lppe
->th32ParentProcessID
= 0; /* FIXME */
240 lppe
->pcPriClassBase
= req
->priority
;
241 lppe
->dwFlags
= -1; /* FIXME */
242 lppe
->szExeFile
[0] = 0; /* FIXME */
247 /***********************************************************************
248 * Process32First (KERNEL32.555)
250 * Return info about the first process in a toolhelp32 snapshot
252 BOOL WINAPI
Process32First(HANDLE hSnapshot
, LPPROCESSENTRY32 lppe
)
254 return TOOLHELP_Process32Next( hSnapshot
, lppe
, TRUE
);
257 /***********************************************************************
258 * Process32Next (KERNEL32.556)
260 * Return info about the "next" process in a toolhelp32 snapshot
262 BOOL WINAPI
Process32Next(HANDLE hSnapshot
, LPPROCESSENTRY32 lppe
)
264 return TOOLHELP_Process32Next( hSnapshot
, lppe
, FALSE
);
268 /***********************************************************************
269 * TOOLHELP_Module32Next
271 * Implementation of Module32First/Next
273 static BOOL
TOOLHELP_Module32Next( HANDLE handle
, LPMODULEENTRY32 lpme
, BOOL first
)
275 struct next_module_request
*req
= get_req_buffer();
277 if (lpme
->dwSize
< sizeof (MODULEENTRY32
))
279 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
280 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(MODULEENTRY32
), lpme
->dwSize
);
283 req
->handle
= handle
;
285 if (server_call( REQ_NEXT_MODULE
)) return FALSE
;
286 lpme
->th32ModuleID
= 0; /* toolhelp internal id, never used */
287 lpme
->th32ProcessID
= (DWORD
)req
->pid
;
288 lpme
->GlblcntUsage
= 0; /* FIXME */
289 lpme
->ProccntUsage
= 0; /* FIXME */
290 lpme
->modBaseAddr
= req
->base
;
291 lpme
->modBaseSize
= 0; /* FIXME */
292 lpme
->hModule
= (DWORD
)req
->base
;
293 lpme
->szModule
[0] = 0; /* FIXME */
294 lpme
->szExePath
[0] = 0; /* FIXME */
298 /***********************************************************************
299 * Module32First (KERNEL32.527)
301 * Return info about the "first" module in a toolhelp32 snapshot
303 BOOL WINAPI
Module32First(HANDLE hSnapshot
, LPMODULEENTRY32 lpme
)
305 return TOOLHELP_Module32Next( hSnapshot
, lpme
, TRUE
);
308 /***********************************************************************
309 * Module32Next (KERNEL32.528)
311 * Return info about the "next" module in a toolhelp32 snapshot
313 BOOL WINAPI
Module32Next(HANDLE hSnapshot
, LPMODULEENTRY32 lpme
)
315 return TOOLHELP_Module32Next( hSnapshot
, lpme
, FALSE
);
318 /************************************************************************
319 * GlobalMasterHandle16 (KERNEL.28)
322 * Should return selector and handle of the information structure for
323 * the global heap. selector and handle are stored in the THHOOK as
324 * pGlobalHeap and hGlobalHeap.
325 * As Wine doesn't have this structure, we return both values as zero
326 * Applications should interpret this as "No Global Heap"
328 DWORD WINAPI
GlobalMasterHandle16(void)