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
31 #include "wine/winbase16.h"
36 #include "wine/server.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(toolhelp
);
42 /* FIXME: to make this work, we have to call back all these registered
43 * functions from all over the WINE code. Someone with more knowledge than
44 * me please do that. -Marcus
49 FARPROC16 lpfnCallback
;
53 static int nrofnotifys
= 0;
55 static FARPROC16 HookNotify
= NULL
;
57 /***********************************************************************
58 * NotifyRegister (TOOLHELP.73)
60 BOOL16 WINAPI
NotifyRegister16( HTASK16 htask
, FARPROC16 lpfnCallback
,
65 FIXME("(%x,%lx,%x), semi-stub.\n",
66 htask
, (DWORD
)lpfnCallback
, wFlags
);
67 if (!htask
) htask
= GetCurrentTask();
68 for (i
=0;i
<nrofnotifys
;i
++)
69 if (notifys
[i
].htask
==htask
)
73 notifys
=(struct notify
*)HeapAlloc( GetProcessHeap(), 0,
74 sizeof(struct notify
) );
76 notifys
=(struct notify
*)HeapReAlloc( GetProcessHeap(), 0, notifys
,
77 sizeof(struct notify
)*(nrofnotifys
+1));
78 if (!notifys
) return FALSE
;
81 notifys
[i
].htask
=htask
;
82 notifys
[i
].lpfnCallback
=lpfnCallback
;
83 notifys
[i
].wFlags
=wFlags
;
87 /***********************************************************************
88 * NotifyUnregister (TOOLHELP.74)
90 BOOL16 WINAPI
NotifyUnregister16( HTASK16 htask
)
94 FIXME("(%x), semi-stub.\n", htask
);
95 if (!htask
) htask
= GetCurrentTask();
96 for (i
=nrofnotifys
;i
--;)
97 if (notifys
[i
].htask
==htask
)
101 memcpy(notifys
+i
,notifys
+(i
+1),sizeof(struct notify
)*(nrofnotifys
-i
-1));
102 notifys
=(struct notify
*)HeapReAlloc( GetProcessHeap(), 0, notifys
,
103 (nrofnotifys
-1)*sizeof(struct notify
));
108 /***********************************************************************
109 * StackTraceCSIPFirst (TOOLHELP.67)
111 BOOL16 WINAPI
StackTraceCSIPFirst16(STACKTRACEENTRY
*ste
, WORD wSS
, WORD wCS
, WORD wIP
, WORD wBP
)
113 FIXME("(%p, ss %04x, cs %04x, ip %04x, bp %04x): stub.\n", ste
, wSS
, wCS
, wIP
, wBP
);
117 /***********************************************************************
118 * StackTraceFirst (TOOLHELP.66)
120 BOOL16 WINAPI
StackTraceFirst16(STACKTRACEENTRY
*ste
, HTASK16 Task
)
122 FIXME("(%p, %04x), stub.\n", ste
, Task
);
126 /***********************************************************************
127 * StackTraceNext (TOOLHELP.68)
129 BOOL16 WINAPI
StackTraceNext16(STACKTRACEENTRY
*ste
)
131 FIXME("(%p), stub.\n", ste
);
135 /***********************************************************************
136 * InterruptRegister (TOOLHELP.75)
138 BOOL16 WINAPI
InterruptRegister16( HTASK16 task
, FARPROC callback
)
140 FIXME("(%04x, %p), stub.\n", task
, callback
);
144 /***********************************************************************
145 * InterruptUnRegister (TOOLHELP.76)
147 BOOL16 WINAPI
InterruptUnRegister16( HTASK16 task
)
149 FIXME("(%04x), stub.\n", task
);
153 /***********************************************************************
154 * TimerCount (TOOLHELP.80)
156 BOOL16 WINAPI
TimerCount16( TIMERINFO
*pTimerInfo
)
159 * In standard mode, dwmsSinceStart = dwmsThisVM
161 * I tested this, under Windows in enhanced mode, and
162 * if you never switch VM (ie start/stop DOS) these
163 * values should be the same as well.
165 * Also, Wine should adjust for the hardware timer
166 * to reduce the amount of error to ~1ms.
167 * I can't be bothered, can you?
169 pTimerInfo
->dwmsSinceStart
= pTimerInfo
->dwmsThisVM
= GetTickCount();
173 /***********************************************************************
174 * SystemHeapInfo (TOOLHELP.71)
176 BOOL16 WINAPI
SystemHeapInfo16( SYSHEAPINFO
*pHeapInfo
)
178 WORD user
= LoadLibrary16( "USER.EXE" );
179 WORD gdi
= LoadLibrary16( "GDI.EXE" );
180 pHeapInfo
->wUserFreePercent
= (int)LOCAL_CountFree(user
) * 100 / LOCAL_HeapSize(user
);
181 pHeapInfo
->wGDIFreePercent
= (int)LOCAL_CountFree(gdi
) * 100 / LOCAL_HeapSize(gdi
);
182 pHeapInfo
->hUserSegment
= user
;
183 pHeapInfo
->hGDISegment
= gdi
;
184 FreeLibrary16( user
);
185 FreeLibrary16( gdi
);
190 /***********************************************************************
191 * ToolHelpHook (KERNEL.341)
192 * see "Undocumented Windows"
194 FARPROC16 WINAPI
ToolHelpHook16(FARPROC16 lpfnNotifyHandler
)
198 FIXME("(%p), stub.\n", lpfnNotifyHandler
);
200 HookNotify
= lpfnNotifyHandler
;
201 /* just return previously installed notification function */
206 /***********************************************************************
207 * CreateToolhelp32Snapshot (KERNEL32.@)
209 HANDLE WINAPI
CreateToolhelp32Snapshot( DWORD flags
, DWORD process
)
213 TRACE("%lx,%lx\n", flags
, process
);
214 if (!(flags
& (TH32CS_SNAPPROCESS
|TH32CS_SNAPTHREAD
|TH32CS_SNAPMODULE
)))
216 FIXME("flags %lx not implemented\n", flags
);
217 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
218 return INVALID_HANDLE_VALUE
;
221 /* Now do the snapshot */
222 SERVER_START_REQ( create_snapshot
)
224 req
->flags
= flags
& ~TH32CS_INHERIT
;
225 req
->inherit
= (flags
& TH32CS_INHERIT
) != 0;
227 wine_server_call_err( req
);
231 if (!ret
) ret
= INVALID_HANDLE_VALUE
;
236 /***********************************************************************
237 * TOOLHELP_Thread32Next
239 * Implementation of Thread32First/Next
241 static BOOL
TOOLHELP_Thread32Next( HANDLE handle
, LPTHREADENTRY32 lpte
, BOOL first
)
245 if (lpte
->dwSize
< sizeof(THREADENTRY32
))
247 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
248 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(THREADENTRY32
), lpte
->dwSize
);
251 SERVER_START_REQ( next_thread
)
253 req
->handle
= handle
;
255 if ((ret
= !wine_server_call_err( req
)))
257 lpte
->cntUsage
= reply
->count
;
258 lpte
->th32ThreadID
= (DWORD
)reply
->tid
;
259 lpte
->th32OwnerProcessID
= (DWORD
)reply
->pid
;
260 lpte
->tpBasePri
= reply
->base_pri
;
261 lpte
->tpDeltaPri
= reply
->delta_pri
;
262 lpte
->dwFlags
= 0; /* SDK: "reserved; do not use" */
269 /***********************************************************************
270 * Thread32First (KERNEL32.@)
272 * Return info about the first thread in a toolhelp32 snapshot
274 BOOL WINAPI
Thread32First(HANDLE hSnapshot
, LPTHREADENTRY32 lpte
)
276 return TOOLHELP_Thread32Next(hSnapshot
, lpte
, TRUE
);
279 /***********************************************************************
280 * Thread32Next (KERNEL32.@)
282 * Return info about the "next" thread in a toolhelp32 snapshot
284 BOOL WINAPI
Thread32Next(HANDLE hSnapshot
, LPTHREADENTRY32 lpte
)
286 return TOOLHELP_Thread32Next(hSnapshot
, lpte
, FALSE
);
289 /***********************************************************************
290 * TOOLHELP_Process32Next
292 * Implementation of Process32First/Next
294 static BOOL
TOOLHELP_Process32Next( HANDLE handle
, LPPROCESSENTRY32 lppe
, BOOL first
)
298 if (lppe
->dwSize
< sizeof(PROCESSENTRY32
))
300 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
301 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(PROCESSENTRY32
), lppe
->dwSize
);
304 SERVER_START_REQ( next_process
)
306 req
->handle
= handle
;
308 wine_server_set_reply( req
, lppe
->szExeFile
, sizeof(lppe
->szExeFile
)-1 );
309 if ((ret
= !wine_server_call_err( req
)))
311 lppe
->cntUsage
= reply
->count
;
312 lppe
->th32ProcessID
= (DWORD
)reply
->pid
;
313 lppe
->th32DefaultHeapID
= (DWORD
)reply
->heap
;
314 lppe
->th32ModuleID
= (DWORD
)reply
->module
;
315 lppe
->cntThreads
= reply
->threads
;
316 lppe
->th32ParentProcessID
= (DWORD
)reply
->ppid
;
317 lppe
->pcPriClassBase
= reply
->priority
;
318 lppe
->dwFlags
= -1; /* FIXME */
319 lppe
->szExeFile
[wine_server_reply_size(reply
)] = 0;
327 /***********************************************************************
328 * Process32First (KERNEL32.@)
330 * Return info about the first process in a toolhelp32 snapshot
332 BOOL WINAPI
Process32First(HANDLE hSnapshot
, LPPROCESSENTRY32 lppe
)
334 return TOOLHELP_Process32Next( hSnapshot
, lppe
, TRUE
);
337 /***********************************************************************
338 * Process32Next (KERNEL32.@)
340 * Return info about the "next" process in a toolhelp32 snapshot
342 BOOL WINAPI
Process32Next(HANDLE hSnapshot
, LPPROCESSENTRY32 lppe
)
344 return TOOLHELP_Process32Next( hSnapshot
, lppe
, FALSE
);
348 /***********************************************************************
349 * TOOLHELP_Module32Next
351 * Implementation of Module32First/Next
353 static BOOL
TOOLHELP_Module32Next( HANDLE handle
, LPMODULEENTRY32 lpme
, BOOL first
)
357 if (lpme
->dwSize
< sizeof (MODULEENTRY32
))
359 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
360 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(MODULEENTRY32
), lpme
->dwSize
);
363 SERVER_START_REQ( next_module
)
365 req
->handle
= handle
;
367 wine_server_set_reply( req
, lpme
->szExePath
, sizeof(lpme
->szExePath
)-1 );
368 if ((ret
= !wine_server_call_err( req
)))
370 lpme
->th32ModuleID
= 0; /* toolhelp internal id, never used */
371 lpme
->th32ProcessID
= (DWORD
)reply
->pid
;
372 lpme
->GlblcntUsage
= 0; /* FIXME */
373 lpme
->ProccntUsage
= 0; /* FIXME */
374 lpme
->modBaseAddr
= reply
->base
;
375 lpme
->modBaseSize
= reply
->size
;
376 lpme
->hModule
= (HMODULE
)reply
->base
;
377 lpme
->szModule
[0] = 0; /* FIXME */
378 lpme
->szExePath
[wine_server_reply_size(reply
)] = 0;
385 /***********************************************************************
386 * Module32First (KERNEL32.@)
388 * Return info about the "first" module in a toolhelp32 snapshot
390 BOOL WINAPI
Module32First(HANDLE hSnapshot
, LPMODULEENTRY32 lpme
)
392 return TOOLHELP_Module32Next( hSnapshot
, lpme
, TRUE
);
395 /***********************************************************************
396 * Module32Next (KERNEL32.@)
398 * Return info about the "next" module in a toolhelp32 snapshot
400 BOOL WINAPI
Module32Next(HANDLE hSnapshot
, LPMODULEENTRY32 lpme
)
402 return TOOLHELP_Module32Next( hSnapshot
, lpme
, FALSE
);
405 /************************************************************************
406 * GlobalMasterHandle (KERNEL.28)
409 * Should return selector and handle of the information structure for
410 * the global heap. selector and handle are stored in the THHOOK as
411 * pGlobalHeap and hGlobalHeap.
412 * As Wine doesn't have this structure, we return both values as zero
413 * Applications should interpret this as "No Global Heap"
415 DWORD WINAPI
GlobalMasterHandle16(void)