Use service thread for "true" multimedia timers.
[wine/wine-kai.git] / misc / toolhelp.c
blobd437530bc06063464f30951b967fcaff8ea1377a
1 /*
2 * Misc Toolhelp functions
4 * Copyright 1996 Marcus Meissner
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <ctype.h>
11 #include <assert.h>
12 #include "winbase.h"
13 #include "wine/winbase16.h"
14 #include "winerror.h"
15 #include "process.h"
16 #include "tlhelp32.h"
17 #include "toolhelp.h"
18 #include "heap.h"
19 #include "server.h"
20 #include "debug.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
29 static struct notify
31 HTASK16 htask;
32 FARPROC16 lpfnCallback;
33 WORD wFlags;
34 } *notifys = NULL;
36 static int nrofnotifys = 0;
38 static FARPROC16 HookNotify = NULL;
40 BOOL16 WINAPI NotifyRegister16( HTASK16 htask, FARPROC16 lpfnCallback,
41 WORD wFlags )
43 int i;
45 TRACE(toolhelp, "(%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)
50 break;
51 if (i==nrofnotifys) {
52 if (notifys==NULL)
53 notifys=(struct notify*)HeapAlloc( SystemHeap, 0,
54 sizeof(struct notify) );
55 else
56 notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
57 sizeof(struct notify)*(nrofnotifys+1));
58 if (!notifys) return FALSE;
59 nrofnotifys++;
61 notifys[i].htask=htask;
62 notifys[i].lpfnCallback=lpfnCallback;
63 notifys[i].wFlags=wFlags;
64 return TRUE;
67 BOOL16 WINAPI NotifyUnregister16( HTASK16 htask )
69 int i;
71 TRACE(toolhelp, "(%x) called.\n", htask );
72 if (!htask) htask = GetCurrentTask();
73 for (i=nrofnotifys;i--;)
74 if (notifys[i].htask==htask)
75 break;
76 if (i==-1)
77 return FALSE;
78 memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
79 notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
80 (nrofnotifys-1)*sizeof(struct notify));
81 nrofnotifys--;
82 return TRUE;
85 BOOL16 WINAPI StackTraceCSIPFirst16(STACKTRACEENTRY *ste, WORD wSS, WORD wCS, WORD wIP, WORD wBP)
87 return TRUE;
90 BOOL16 WINAPI StackTraceFirst16(STACKTRACEENTRY *ste, HTASK16 Task)
92 return TRUE;
95 BOOL16 WINAPI StackTraceNext16(STACKTRACEENTRY *ste)
97 return TRUE;
100 /***********************************************************************
101 * ToolHelpHook (KERNEL.341)
102 * see "Undocumented Windows"
104 FARPROC16 WINAPI ToolHelpHook16(FARPROC16 lpfnNotifyHandler)
106 FARPROC16 tmp;
107 tmp = HookNotify;
108 HookNotify = lpfnNotifyHandler;
109 /* just return previously installed notification function */
110 return tmp;
114 /***********************************************************************
115 * CreateToolHelp32Snapshot (KERNEL32.179)
117 HANDLE WINAPI CreateToolhelp32Snapshot( DWORD flags, DWORD process )
119 struct create_snapshot_request req;
120 struct create_snapshot_reply reply;
122 TRACE( toolhelp, "%lx,%lx\n", flags, process );
123 if (flags & (TH32CS_SNAPHEAPLIST|TH32CS_SNAPMODULE|TH32CS_SNAPTHREAD))
124 FIXME( toolhelp, "flags %lx not implemented\n", flags );
125 if (!(flags & TH32CS_SNAPPROCESS))
127 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
128 return INVALID_HANDLE_VALUE;
131 /* Now do the snapshot */
132 req.flags = flags & ~TH32CS_INHERIT;
133 req.inherit = (flags & TH32CS_INHERIT) != 0;
134 CLIENT_SendRequest( REQ_CREATE_SNAPSHOT, -1, 1, &req, sizeof(req) );
135 CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL );
136 return reply.handle;
140 /***********************************************************************
141 * TOOLHELP_Process32Next
143 * Implementation of Process32First/Next
145 static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY lppe, BOOL first )
147 struct next_process_request req;
148 struct next_process_reply reply;
150 if (lppe->dwSize < sizeof (PROCESSENTRY))
152 SetLastError( ERROR_INSUFFICIENT_BUFFER );
153 ERR (toolhelp, "Result buffer too small\n");
154 return FALSE;
156 req.handle = handle;
157 req.reset = first;
158 CLIENT_SendRequest( REQ_NEXT_PROCESS, -1, 1, &req, sizeof(req) );
159 if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE;
160 lppe->cntUsage = 1;
161 lppe->th32ProcessID = (DWORD)reply.pid;
162 lppe->th32DefaultHeapID = 0; /* FIXME */
163 lppe->th32ModuleID = 0; /* FIXME */
164 lppe->cntThreads = reply.threads;
165 lppe->th32ParentProcessID = 0; /* FIXME */
166 lppe->pcPriClassBase = reply.priority;
167 lppe->dwFlags = -1; /* FIXME */
168 lppe->szExeFile[0] = 0; /* FIXME */
169 return TRUE;
173 /***********************************************************************
174 * Process32First (KERNEL32.555)
176 * Return info about the first process in a toolhelp32 snapshot
178 BOOL WINAPI Process32First(HANDLE hSnapshot, LPPROCESSENTRY lppe)
180 return TOOLHELP_Process32Next( hSnapshot, lppe, TRUE );
183 /***********************************************************************
184 * Process32Next (KERNEL32.556)
186 * Return info about the "next" process in a toolhelp32 snapshot
188 BOOL WINAPI Process32Next(HANDLE hSnapshot, LPPROCESSENTRY lppe)
190 return TOOLHELP_Process32Next( hSnapshot, lppe, FALSE );
193 /***********************************************************************
194 * Module32First (KERNEL32.527)
196 * Return info about the "first" module in a toolhelp32 snapshot
198 BOOL WINAPI Module32First(HANDLE hSnapshot, LPMODULEENTRY lpme)
200 FIXME(toolhelp,"(%d,%p),stub!\n",hSnapshot,lpme);
201 return FALSE;
204 /***********************************************************************
205 * Module32Next (KERNEL32.528)
207 * Return info about the "next" module in a toolhelp32 snapshot
209 BOOL WINAPI Module32Next(HANDLE hSnapshot, LPMODULEENTRY lpme)
211 FIXME(toolhelp,"(%d,%p),stub!\n",hSnapshot,lpme);
212 return FALSE;
215 /************************************************************************
216 * GlobalMasterHandle16 (KERNEL.28)
219 * Should return selector and handle of the information structure for
220 * the global heap. selector and handle are stored in the THHOOK as
221 * pGlobalHeap and hGlobalHeap.
222 * As Wine doesn't have this structure, we return both values as zero
223 * Applications should interpret this as "No Global Heap"
225 DWORD WINAPI GlobalMasterHandle16(void)
227 FIXME(toolhelp,": stub\n");
228 return 0;