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 BOOL16 WINAPI
NotifyRegister16( HTASK16 htask
, FARPROC16 lpfnCallback
,
45 TRACE("(%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( GetProcessHeap(), 0,
54 sizeof(struct notify
) );
56 notifys
=(struct notify
*)HeapReAlloc( GetProcessHeap(), 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("(%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( GetProcessHeap(), 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 BOOL16 WINAPI
InterruptRegister16( HTASK16 task
, FARPROC callback
)
105 BOOL16 WINAPI
InterruptUnRegister16( HTASK16 task
)
110 /***********************************************************************
111 * ToolHelpHook (KERNEL.341)
112 * see "Undocumented Windows"
114 FARPROC16 WINAPI
ToolHelpHook16(FARPROC16 lpfnNotifyHandler
)
118 HookNotify
= lpfnNotifyHandler
;
119 /* just return previously installed notification function */
124 /***********************************************************************
125 * CreateToolHelp32Snapshot (KERNEL32.179)
127 HANDLE WINAPI
CreateToolhelp32Snapshot( DWORD flags
, DWORD process
)
129 struct create_snapshot_request
*req
= get_req_buffer();
131 TRACE("%lx,%lx\n", flags
, process
);
132 if (flags
& (TH32CS_SNAPHEAPLIST
|TH32CS_SNAPMODULE
|TH32CS_SNAPTHREAD
))
133 FIXME("flags %lx not implemented\n", flags
);
134 if (!(flags
& TH32CS_SNAPPROCESS
))
136 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
137 return INVALID_HANDLE_VALUE
;
140 /* Now do the snapshot */
141 req
->flags
= flags
& ~TH32CS_INHERIT
;
142 req
->inherit
= (flags
& TH32CS_INHERIT
) != 0;
143 server_call( REQ_CREATE_SNAPSHOT
);
148 /***********************************************************************
149 * Thread32First (KERNEL32.686)
151 * Return info about the first thread in a toolhelp32 snapshot
153 BOOL WINAPI
Thread32First(HANDLE hSnapshot
, LPTHREADENTRY lpte
)
158 FIXME("(%d,%p),stub!\n",hSnapshot
,lpte
);
162 /***********************************************************************
163 * Thread32Next (KERNEL32.687)
165 * Return info about the "next" thread in a toolhelp32 snapshot
167 BOOL WINAPI
Thread32Next(HANDLE hSnapshot
, LPTHREADENTRY lpte
)
172 FIXME("(%d,%p),stub!\n",hSnapshot
,lpte
);
176 /***********************************************************************
177 * TOOLHELP_Process32Next
179 * Implementation of Process32First/Next
181 static BOOL
TOOLHELP_Process32Next( HANDLE handle
, LPPROCESSENTRY lppe
, BOOL first
)
183 struct next_process_request
*req
= get_req_buffer();
185 if (lppe
->dwSize
< sizeof (PROCESSENTRY
))
187 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
188 ERR("Result buffer too small\n");
191 req
->handle
= handle
;
193 if (server_call( REQ_NEXT_PROCESS
)) return FALSE
;
195 lppe
->th32ProcessID
= (DWORD
)req
->pid
;
196 lppe
->th32DefaultHeapID
= 0; /* FIXME */
197 lppe
->th32ModuleID
= 0; /* FIXME */
198 lppe
->cntThreads
= req
->threads
;
199 lppe
->th32ParentProcessID
= 0; /* FIXME */
200 lppe
->pcPriClassBase
= req
->priority
;
201 lppe
->dwFlags
= -1; /* FIXME */
202 lppe
->szExeFile
[0] = 0; /* FIXME */
207 /***********************************************************************
208 * Process32First (KERNEL32.555)
210 * Return info about the first process in a toolhelp32 snapshot
212 BOOL WINAPI
Process32First(HANDLE hSnapshot
, LPPROCESSENTRY lppe
)
214 return TOOLHELP_Process32Next( hSnapshot
, lppe
, TRUE
);
217 /***********************************************************************
218 * Process32Next (KERNEL32.556)
220 * Return info about the "next" process in a toolhelp32 snapshot
222 BOOL WINAPI
Process32Next(HANDLE hSnapshot
, LPPROCESSENTRY lppe
)
224 return TOOLHELP_Process32Next( hSnapshot
, lppe
, FALSE
);
227 /***********************************************************************
228 * Module32First (KERNEL32.527)
230 * Return info about the "first" module in a toolhelp32 snapshot
232 BOOL WINAPI
Module32First(HANDLE hSnapshot
, LPMODULEENTRY lpme
)
234 FIXME("(%d,%p),stub!\n",hSnapshot
,lpme
);
238 /***********************************************************************
239 * Module32Next (KERNEL32.528)
241 * Return info about the "next" module in a toolhelp32 snapshot
243 BOOL WINAPI
Module32Next(HANDLE hSnapshot
, LPMODULEENTRY lpme
)
245 FIXME("(%d,%p),stub!\n",hSnapshot
,lpme
);
249 /************************************************************************
250 * GlobalMasterHandle16 (KERNEL.28)
253 * Should return selector and handle of the information structure for
254 * the global heap. selector and handle are stored in the THHOOK as
255 * pGlobalHeap and hGlobalHeap.
256 * As Wine doesn't have this structure, we return both values as zero
257 * Applications should interpret this as "No Global Heap"
259 DWORD WINAPI
GlobalMasterHandle16(void)