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_SNAPHEAPLIST
|TH32CS_SNAPMODULE
|TH32CS_SNAPTHREAD
))
154 FIXME("flags %lx not implemented\n", flags
);
155 if (!(flags
& TH32CS_SNAPPROCESS
))
157 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
158 return INVALID_HANDLE_VALUE
;
161 /* Now do the snapshot */
162 req
->flags
= flags
& ~TH32CS_INHERIT
;
163 req
->inherit
= (flags
& TH32CS_INHERIT
) != 0;
164 server_call( REQ_CREATE_SNAPSHOT
);
169 /***********************************************************************
170 * Thread32First (KERNEL32.686)
172 * Return info about the first thread in a toolhelp32 snapshot
174 BOOL WINAPI
Thread32First(HANDLE hSnapshot
, LPTHREADENTRY lpte
)
179 FIXME("(%d,%p),stub!\n",hSnapshot
,lpte
);
183 /***********************************************************************
184 * Thread32Next (KERNEL32.687)
186 * Return info about the "next" thread in a toolhelp32 snapshot
188 BOOL WINAPI
Thread32Next(HANDLE hSnapshot
, LPTHREADENTRY lpte
)
193 FIXME("(%d,%p),stub!\n",hSnapshot
,lpte
);
197 /***********************************************************************
198 * TOOLHELP_Process32Next
200 * Implementation of Process32First/Next
202 static BOOL
TOOLHELP_Process32Next( HANDLE handle
, LPPROCESSENTRY lppe
, BOOL first
)
204 struct next_process_request
*req
= get_req_buffer();
206 if (lppe
->dwSize
< sizeof (PROCESSENTRY
))
208 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
209 ERR("Result buffer too small\n");
212 req
->handle
= handle
;
214 if (server_call( REQ_NEXT_PROCESS
)) return FALSE
;
216 lppe
->th32ProcessID
= (DWORD
)req
->pid
;
217 lppe
->th32DefaultHeapID
= 0; /* FIXME */
218 lppe
->th32ModuleID
= 0; /* FIXME */
219 lppe
->cntThreads
= req
->threads
;
220 lppe
->th32ParentProcessID
= 0; /* FIXME */
221 lppe
->pcPriClassBase
= req
->priority
;
222 lppe
->dwFlags
= -1; /* FIXME */
223 lppe
->szExeFile
[0] = 0; /* FIXME */
228 /***********************************************************************
229 * Process32First (KERNEL32.555)
231 * Return info about the first process in a toolhelp32 snapshot
233 BOOL WINAPI
Process32First(HANDLE hSnapshot
, LPPROCESSENTRY lppe
)
235 return TOOLHELP_Process32Next( hSnapshot
, lppe
, TRUE
);
238 /***********************************************************************
239 * Process32Next (KERNEL32.556)
241 * Return info about the "next" process in a toolhelp32 snapshot
243 BOOL WINAPI
Process32Next(HANDLE hSnapshot
, LPPROCESSENTRY lppe
)
245 return TOOLHELP_Process32Next( hSnapshot
, lppe
, FALSE
);
248 /***********************************************************************
249 * Module32First (KERNEL32.527)
251 * Return info about the "first" module in a toolhelp32 snapshot
253 BOOL WINAPI
Module32First(HANDLE hSnapshot
, LPMODULEENTRY lpme
)
255 FIXME("(%d,%p),stub!\n",hSnapshot
,lpme
);
259 /***********************************************************************
260 * Module32Next (KERNEL32.528)
262 * Return info about the "next" module in a toolhelp32 snapshot
264 BOOL WINAPI
Module32Next(HANDLE hSnapshot
, LPMODULEENTRY lpme
)
266 FIXME("(%d,%p),stub!\n",hSnapshot
,lpme
);
270 /************************************************************************
271 * GlobalMasterHandle16 (KERNEL.28)
274 * Should return selector and handle of the information structure for
275 * the global heap. selector and handle are stored in the THHOOK as
276 * pGlobalHeap and hGlobalHeap.
277 * As Wine doesn't have this structure, we return both values as zero
278 * Applications should interpret this as "No Global Heap"
280 DWORD WINAPI
GlobalMasterHandle16(void)