Remove remnants of the old code.
[wine/multimedia.git] / dlls / kernel / toolhelp.c
blob74cea4e9d9a30ba73c9ea362a1cdab6d4d3bc50b
1 /*
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
21 #include "config.h"
23 #include <stdlib.h>
24 #include <string.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include <ctype.h>
29 #include <assert.h>
30 #include "winbase.h"
31 #include "wine/winbase16.h"
32 #include "winerror.h"
33 #include "local.h"
34 #include "tlhelp32.h"
35 #include "toolhelp.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
46 static struct notify
48 HTASK16 htask;
49 FARPROC16 lpfnCallback;
50 WORD wFlags;
51 } *notifys = NULL;
53 static int nrofnotifys = 0;
55 static FARPROC16 HookNotify = NULL;
57 /***********************************************************************
58 * NotifyRegister (TOOLHELP.73)
60 BOOL16 WINAPI NotifyRegister16( HTASK16 htask, FARPROC16 lpfnCallback,
61 WORD wFlags )
63 int i;
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)
70 break;
71 if (i==nrofnotifys) {
72 if (notifys==NULL)
73 notifys=(struct notify*)HeapAlloc( GetProcessHeap(), 0,
74 sizeof(struct notify) );
75 else
76 notifys=(struct notify*)HeapReAlloc( GetProcessHeap(), 0, notifys,
77 sizeof(struct notify)*(nrofnotifys+1));
78 if (!notifys) return FALSE;
79 nrofnotifys++;
81 notifys[i].htask=htask;
82 notifys[i].lpfnCallback=lpfnCallback;
83 notifys[i].wFlags=wFlags;
84 return TRUE;
87 /***********************************************************************
88 * NotifyUnregister (TOOLHELP.74)
90 BOOL16 WINAPI NotifyUnregister16( HTASK16 htask )
92 int i;
94 FIXME("(%x), semi-stub.\n", htask );
95 if (!htask) htask = GetCurrentTask();
96 for (i=nrofnotifys;i--;)
97 if (notifys[i].htask==htask)
98 break;
99 if (i==-1)
100 return FALSE;
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));
104 nrofnotifys--;
105 return TRUE;
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);
114 return TRUE;
117 /***********************************************************************
118 * StackTraceFirst (TOOLHELP.66)
120 BOOL16 WINAPI StackTraceFirst16(STACKTRACEENTRY *ste, HTASK16 Task)
122 FIXME("(%p, %04x), stub.\n", ste, Task);
123 return TRUE;
126 /***********************************************************************
127 * StackTraceNext (TOOLHELP.68)
129 BOOL16 WINAPI StackTraceNext16(STACKTRACEENTRY *ste)
131 FIXME("(%p), stub.\n", ste);
132 return TRUE;
135 /***********************************************************************
136 * InterruptRegister (TOOLHELP.75)
138 BOOL16 WINAPI InterruptRegister16( HTASK16 task, FARPROC callback )
140 FIXME("(%04x, %p), stub.\n", task, callback);
141 return TRUE;
144 /***********************************************************************
145 * InterruptUnRegister (TOOLHELP.76)
147 BOOL16 WINAPI InterruptUnRegister16( HTASK16 task )
149 FIXME("(%04x), stub.\n", task);
150 return TRUE;
153 /***********************************************************************
154 * TimerCount (TOOLHELP.80)
156 BOOL16 WINAPI TimerCount16( TIMERINFO *pTimerInfo )
158 /* FIXME
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();
170 return TRUE;
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 );
186 return TRUE;
190 /***********************************************************************
191 * ToolHelpHook (KERNEL.341)
192 * see "Undocumented Windows"
194 FARPROC16 WINAPI ToolHelpHook16(FARPROC16 lpfnNotifyHandler)
196 FARPROC16 tmp;
198 FIXME("(%p), stub.\n", lpfnNotifyHandler);
199 tmp = HookNotify;
200 HookNotify = lpfnNotifyHandler;
201 /* just return previously installed notification function */
202 return tmp;
206 /***********************************************************************
207 * CreateToolhelp32Snapshot (KERNEL32.@)
209 HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process )
211 HANDLE ret;
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 = 0;
225 if (flags & TH32CS_SNAPMODULE) req->flags |= SNAP_MODULE;
226 if (flags & TH32CS_SNAPPROCESS) req->flags |= SNAP_PROCESS;
227 if (flags & TH32CS_SNAPTHREAD) req->flags |= SNAP_THREAD;
229 req->inherit = (flags & TH32CS_INHERIT) != 0;
230 req->pid = process;
231 wine_server_call_err( req );
232 ret = reply->handle;
234 SERVER_END_REQ;
235 if (!ret) ret = INVALID_HANDLE_VALUE;
236 return ret;
240 /***********************************************************************
241 * TOOLHELP_Thread32Next
243 * Implementation of Thread32First/Next
245 static BOOL TOOLHELP_Thread32Next( HANDLE handle, LPTHREADENTRY32 lpte, BOOL first )
247 BOOL ret;
249 if (lpte->dwSize < sizeof(THREADENTRY32))
251 SetLastError( ERROR_INSUFFICIENT_BUFFER );
252 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(THREADENTRY32), lpte->dwSize);
253 return FALSE;
255 SERVER_START_REQ( next_thread )
257 req->handle = handle;
258 req->reset = first;
259 if ((ret = !wine_server_call_err( req )))
261 lpte->cntUsage = reply->count;
262 lpte->th32ThreadID = (DWORD)reply->tid;
263 lpte->th32OwnerProcessID = (DWORD)reply->pid;
264 lpte->tpBasePri = reply->base_pri;
265 lpte->tpDeltaPri = reply->delta_pri;
266 lpte->dwFlags = 0; /* SDK: "reserved; do not use" */
269 SERVER_END_REQ;
270 return ret;
273 /***********************************************************************
274 * Thread32First (KERNEL32.@)
276 * Return info about the first thread in a toolhelp32 snapshot
278 BOOL WINAPI Thread32First(HANDLE hSnapshot, LPTHREADENTRY32 lpte)
280 return TOOLHELP_Thread32Next(hSnapshot, lpte, TRUE);
283 /***********************************************************************
284 * Thread32Next (KERNEL32.@)
286 * Return info about the "next" thread in a toolhelp32 snapshot
288 BOOL WINAPI Thread32Next(HANDLE hSnapshot, LPTHREADENTRY32 lpte)
290 return TOOLHELP_Thread32Next(hSnapshot, lpte, FALSE);
293 /***********************************************************************
294 * TOOLHELP_Process32Next
296 * Implementation of Process32First/Next
298 static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY32 lppe, BOOL first )
300 BOOL ret;
302 if (lppe->dwSize < sizeof(PROCESSENTRY32))
304 SetLastError( ERROR_INSUFFICIENT_BUFFER );
305 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(PROCESSENTRY32), lppe->dwSize);
306 return FALSE;
308 SERVER_START_REQ( next_process )
310 req->handle = handle;
311 req->reset = first;
312 wine_server_set_reply( req, lppe->szExeFile, sizeof(lppe->szExeFile)-1 );
313 if ((ret = !wine_server_call_err( req )))
315 lppe->cntUsage = reply->count;
316 lppe->th32ProcessID = (DWORD)reply->pid;
317 lppe->th32DefaultHeapID = (DWORD)reply->heap;
318 lppe->th32ModuleID = (DWORD)reply->module;
319 lppe->cntThreads = reply->threads;
320 lppe->th32ParentProcessID = (DWORD)reply->ppid;
321 lppe->pcPriClassBase = reply->priority;
322 lppe->dwFlags = -1; /* FIXME */
323 lppe->szExeFile[wine_server_reply_size(reply)] = 0;
326 SERVER_END_REQ;
327 return ret;
331 /***********************************************************************
332 * Process32First (KERNEL32.@)
334 * Return info about the first process in a toolhelp32 snapshot
336 BOOL WINAPI Process32First(HANDLE hSnapshot, LPPROCESSENTRY32 lppe)
338 return TOOLHELP_Process32Next( hSnapshot, lppe, TRUE );
341 /***********************************************************************
342 * Process32Next (KERNEL32.@)
344 * Return info about the "next" process in a toolhelp32 snapshot
346 BOOL WINAPI Process32Next(HANDLE hSnapshot, LPPROCESSENTRY32 lppe)
348 return TOOLHELP_Process32Next( hSnapshot, lppe, FALSE );
352 /***********************************************************************
353 * TOOLHELP_Module32Next
355 * Implementation of Module32First/Next
357 static BOOL TOOLHELP_Module32Next( HANDLE handle, LPMODULEENTRY32 lpme, BOOL first )
359 BOOL ret;
361 if (lpme->dwSize < sizeof (MODULEENTRY32))
363 SetLastError( ERROR_INSUFFICIENT_BUFFER );
364 ERR("Result buffer too small (req: %d, was: %ld)\n", sizeof(MODULEENTRY32), lpme->dwSize);
365 return FALSE;
367 SERVER_START_REQ( next_module )
369 req->handle = handle;
370 req->reset = first;
371 wine_server_set_reply( req, lpme->szExePath, sizeof(lpme->szExePath)-1 );
372 if ((ret = !wine_server_call_err( req )))
374 lpme->th32ModuleID = 0; /* toolhelp internal id, never used */
375 lpme->th32ProcessID = (DWORD)reply->pid;
376 lpme->GlblcntUsage = 0; /* FIXME */
377 lpme->ProccntUsage = 0; /* FIXME */
378 lpme->modBaseAddr = reply->base;
379 lpme->modBaseSize = reply->size;
380 lpme->hModule = (HMODULE)reply->base;
381 lpme->szModule[0] = 0; /* FIXME */
382 lpme->szExePath[wine_server_reply_size(reply)] = 0;
385 SERVER_END_REQ;
386 return ret;
389 /***********************************************************************
390 * Module32First (KERNEL32.@)
392 * Return info about the "first" module in a toolhelp32 snapshot
394 BOOL WINAPI Module32First(HANDLE hSnapshot, LPMODULEENTRY32 lpme)
396 return TOOLHELP_Module32Next( hSnapshot, lpme, TRUE );
399 /***********************************************************************
400 * Module32Next (KERNEL32.@)
402 * Return info about the "next" module in a toolhelp32 snapshot
404 BOOL WINAPI Module32Next(HANDLE hSnapshot, LPMODULEENTRY32 lpme)
406 return TOOLHELP_Module32Next( hSnapshot, lpme, FALSE );
409 /************************************************************************
410 * GlobalMasterHandle (KERNEL.28)
413 * Should return selector and handle of the information structure for
414 * the global heap. selector and handle are stored in the THHOOK as
415 * pGlobalHeap and hGlobalHeap.
416 * As Wine doesn't have this structure, we return both values as zero
417 * Applications should interpret this as "No Global Heap"
419 DWORD WINAPI GlobalMasterHandle16(void)
421 FIXME(": stub\n");
422 return 0;