2 * Misc Toolhelp functions
4 * Copyright 1996 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/winbase16.h"
32 #include "wine/server.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(toolhelp
);
38 /* FIXME: to make this work, we have to call back all these registered
39 * functions from all over the WINE code. Someone with more knowledge than
40 * me please do that. -Marcus
45 FARPROC16 lpfnCallback
;
49 static int nrofnotifys
= 0;
51 static FARPROC16 HookNotify
= NULL
;
53 /***********************************************************************
54 * NotifyRegister (TOOLHELP.73)
56 BOOL16 WINAPI
NotifyRegister16( HTASK16 htask
, FARPROC16 lpfnCallback
,
61 FIXME("(%x,%lx,%x), semi-stub.\n",
62 htask
, (DWORD
)lpfnCallback
, wFlags
);
63 if (!htask
) htask
= GetCurrentTask();
64 for (i
=0;i
<nrofnotifys
;i
++)
65 if (notifys
[i
].htask
==htask
)
69 notifys
=(struct notify
*)HeapAlloc( GetProcessHeap(), 0,
70 sizeof(struct notify
) );
72 notifys
=(struct notify
*)HeapReAlloc( GetProcessHeap(), 0, notifys
,
73 sizeof(struct notify
)*(nrofnotifys
+1));
74 if (!notifys
) return FALSE
;
77 notifys
[i
].htask
=htask
;
78 notifys
[i
].lpfnCallback
=lpfnCallback
;
79 notifys
[i
].wFlags
=wFlags
;
83 /***********************************************************************
84 * NotifyUnregister (TOOLHELP.74)
86 BOOL16 WINAPI
NotifyUnregister16( HTASK16 htask
)
90 FIXME("(%x), semi-stub.\n", htask
);
91 if (!htask
) htask
= GetCurrentTask();
92 for (i
=nrofnotifys
;i
--;)
93 if (notifys
[i
].htask
==htask
)
97 memcpy(notifys
+i
,notifys
+(i
+1),sizeof(struct notify
)*(nrofnotifys
-i
-1));
98 notifys
=(struct notify
*)HeapReAlloc( GetProcessHeap(), 0, notifys
,
99 (nrofnotifys
-1)*sizeof(struct notify
));
104 /***********************************************************************
105 * StackTraceCSIPFirst (TOOLHELP.67)
107 BOOL16 WINAPI
StackTraceCSIPFirst16(STACKTRACEENTRY
*ste
, WORD wSS
, WORD wCS
, WORD wIP
, WORD wBP
)
109 FIXME("(%p, ss %04x, cs %04x, ip %04x, bp %04x): stub.\n", ste
, wSS
, wCS
, wIP
, wBP
);
113 /***********************************************************************
114 * StackTraceFirst (TOOLHELP.66)
116 BOOL16 WINAPI
StackTraceFirst16(STACKTRACEENTRY
*ste
, HTASK16 Task
)
118 FIXME("(%p, %04x), stub.\n", ste
, Task
);
122 /***********************************************************************
123 * StackTraceNext (TOOLHELP.68)
125 BOOL16 WINAPI
StackTraceNext16(STACKTRACEENTRY
*ste
)
127 FIXME("(%p), stub.\n", ste
);
131 /***********************************************************************
132 * InterruptRegister (TOOLHELP.75)
134 BOOL16 WINAPI
InterruptRegister16( HTASK16 task
, FARPROC callback
)
136 FIXME("(%04x, %p), stub.\n", task
, callback
);
140 /***********************************************************************
141 * InterruptUnRegister (TOOLHELP.76)
143 BOOL16 WINAPI
InterruptUnRegister16( HTASK16 task
)
145 FIXME("(%04x), stub.\n", task
);
149 /***********************************************************************
150 * TimerCount (TOOLHELP.80)
152 BOOL16 WINAPI
TimerCount16( TIMERINFO
*pTimerInfo
)
155 * In standard mode, dwmsSinceStart = dwmsThisVM
157 * I tested this, under Windows in enhanced mode, and
158 * if you never switch VM (ie start/stop DOS) these
159 * values should be the same as well.
161 * Also, Wine should adjust for the hardware timer
162 * to reduce the amount of error to ~1ms.
163 * I can't be bothered, can you?
165 pTimerInfo
->dwmsSinceStart
= pTimerInfo
->dwmsThisVM
= GetTickCount();
169 /***********************************************************************
170 * SystemHeapInfo (TOOLHELP.71)
172 BOOL16 WINAPI
SystemHeapInfo16( SYSHEAPINFO
*pHeapInfo
)
174 WORD user
= LoadLibrary16( "USER.EXE" );
175 WORD gdi
= LoadLibrary16( "GDI.EXE" );
176 pHeapInfo
->wUserFreePercent
= (int)LOCAL_CountFree(user
) * 100 / LOCAL_HeapSize(user
);
177 pHeapInfo
->wGDIFreePercent
= (int)LOCAL_CountFree(gdi
) * 100 / LOCAL_HeapSize(gdi
);
178 pHeapInfo
->hUserSegment
= user
;
179 pHeapInfo
->hGDISegment
= gdi
;
180 FreeLibrary16( user
);
181 FreeLibrary16( gdi
);
186 /***********************************************************************
187 * ToolHelpHook (KERNEL.341)
188 * see "Undocumented Windows"
190 FARPROC16 WINAPI
ToolHelpHook16(FARPROC16 lpfnNotifyHandler
)
194 FIXME("(%p), stub.\n", lpfnNotifyHandler
);
196 HookNotify
= lpfnNotifyHandler
;
197 /* just return previously installed notification function */
202 /***********************************************************************
203 * CreateToolhelp32Snapshot (KERNEL32.@)
205 HANDLE WINAPI
CreateToolhelp32Snapshot( DWORD flags
, DWORD process
)
209 TRACE("%lx,%lx\n", flags
, process
);
210 if (!(flags
& (TH32CS_SNAPPROCESS
|TH32CS_SNAPTHREAD
|TH32CS_SNAPMODULE
)))
212 FIXME("flags %lx not implemented\n", flags
);
213 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
214 return INVALID_HANDLE_VALUE
;
217 /* Now do the snapshot */
218 SERVER_START_REQ( create_snapshot
)
220 req
->flags
= flags
& ~TH32CS_INHERIT
;
221 req
->inherit
= (flags
& TH32CS_INHERIT
) != 0;
222 req
->pid
= (void *)process
;
223 wine_server_call_err( req
);
227 if (!ret
) ret
= INVALID_HANDLE_VALUE
;
232 /***********************************************************************
233 * TOOLHELP_Thread32Next
235 * Implementation of Thread32First/Next
237 static BOOL
TOOLHELP_Thread32Next( HANDLE handle
, LPTHREADENTRY32 lpte
, BOOL first
)
241 if (lpte
->dwSize
< sizeof(THREADENTRY32
))
243 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
244 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(THREADENTRY32
), lpte
->dwSize
);
247 SERVER_START_REQ( next_thread
)
249 req
->handle
= handle
;
251 if ((ret
= !wine_server_call_err( req
)))
253 lpte
->cntUsage
= reply
->count
;
254 lpte
->th32ThreadID
= (DWORD
)reply
->tid
;
255 lpte
->th32OwnerProcessID
= (DWORD
)reply
->pid
;
256 lpte
->tpBasePri
= reply
->base_pri
;
257 lpte
->tpDeltaPri
= reply
->delta_pri
;
258 lpte
->dwFlags
= 0; /* SDK: "reserved; do not use" */
265 /***********************************************************************
266 * Thread32First (KERNEL32.@)
268 * Return info about the first thread in a toolhelp32 snapshot
270 BOOL WINAPI
Thread32First(HANDLE hSnapshot
, LPTHREADENTRY32 lpte
)
272 return TOOLHELP_Thread32Next(hSnapshot
, lpte
, TRUE
);
275 /***********************************************************************
276 * Thread32Next (KERNEL32.@)
278 * Return info about the "next" thread in a toolhelp32 snapshot
280 BOOL WINAPI
Thread32Next(HANDLE hSnapshot
, LPTHREADENTRY32 lpte
)
282 return TOOLHELP_Thread32Next(hSnapshot
, lpte
, FALSE
);
285 /***********************************************************************
286 * TOOLHELP_Process32Next
288 * Implementation of Process32First/Next
290 static BOOL
TOOLHELP_Process32Next( HANDLE handle
, LPPROCESSENTRY32 lppe
, BOOL first
)
294 if (lppe
->dwSize
< sizeof(PROCESSENTRY32
))
296 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
297 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(PROCESSENTRY32
), lppe
->dwSize
);
300 SERVER_START_REQ( next_process
)
302 req
->handle
= handle
;
304 if ((ret
= !wine_server_call_err( req
)))
306 lppe
->cntUsage
= reply
->count
;
307 lppe
->th32ProcessID
= (DWORD
)reply
->pid
;
308 lppe
->th32DefaultHeapID
= 0; /* FIXME */
309 lppe
->th32ModuleID
= 0; /* FIXME */
310 lppe
->cntThreads
= reply
->threads
;
311 lppe
->th32ParentProcessID
= 0; /* FIXME */
312 lppe
->pcPriClassBase
= reply
->priority
;
313 lppe
->dwFlags
= -1; /* FIXME */
314 lppe
->szExeFile
[0] = 0; /* FIXME */
322 /***********************************************************************
323 * Process32First (KERNEL32.@)
325 * Return info about the first process in a toolhelp32 snapshot
327 BOOL WINAPI
Process32First(HANDLE hSnapshot
, LPPROCESSENTRY32 lppe
)
329 return TOOLHELP_Process32Next( hSnapshot
, lppe
, TRUE
);
332 /***********************************************************************
333 * Process32Next (KERNEL32.@)
335 * Return info about the "next" process in a toolhelp32 snapshot
337 BOOL WINAPI
Process32Next(HANDLE hSnapshot
, LPPROCESSENTRY32 lppe
)
339 return TOOLHELP_Process32Next( hSnapshot
, lppe
, FALSE
);
343 /***********************************************************************
344 * TOOLHELP_Module32Next
346 * Implementation of Module32First/Next
348 static BOOL
TOOLHELP_Module32Next( HANDLE handle
, LPMODULEENTRY32 lpme
, BOOL first
)
352 if (lpme
->dwSize
< sizeof (MODULEENTRY32
))
354 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
355 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(MODULEENTRY32
), lpme
->dwSize
);
358 SERVER_START_REQ( next_module
)
360 req
->handle
= handle
;
362 if ((ret
= !wine_server_call_err( req
)))
364 lpme
->th32ModuleID
= 0; /* toolhelp internal id, never used */
365 lpme
->th32ProcessID
= (DWORD
)reply
->pid
;
366 lpme
->GlblcntUsage
= 0; /* FIXME */
367 lpme
->ProccntUsage
= 0; /* FIXME */
368 lpme
->modBaseAddr
= reply
->base
;
369 lpme
->modBaseSize
= 0; /* FIXME */
370 lpme
->hModule
= (DWORD
)reply
->base
;
371 lpme
->szModule
[0] = 0; /* FIXME */
372 lpme
->szExePath
[0] = 0; /* FIXME */
379 /***********************************************************************
380 * Module32First (KERNEL32.@)
382 * Return info about the "first" module in a toolhelp32 snapshot
384 BOOL WINAPI
Module32First(HANDLE hSnapshot
, LPMODULEENTRY32 lpme
)
386 return TOOLHELP_Module32Next( hSnapshot
, lpme
, TRUE
);
389 /***********************************************************************
390 * Module32Next (KERNEL32.@)
392 * Return info about the "next" module in a toolhelp32 snapshot
394 BOOL WINAPI
Module32Next(HANDLE hSnapshot
, LPMODULEENTRY32 lpme
)
396 return TOOLHELP_Module32Next( hSnapshot
, lpme
, FALSE
);
399 /************************************************************************
400 * GlobalMasterHandle (KERNEL.28)
403 * Should return selector and handle of the information structure for
404 * the global heap. selector and handle are stored in the THHOOK as
405 * pGlobalHeap and hGlobalHeap.
406 * As Wine doesn't have this structure, we return both values as zero
407 * Applications should interpret this as "No Global Heap"
409 DWORD WINAPI
GlobalMasterHandle16(void)