resources: Change Dutch sublanguage code to SUBLANG_NEUTRAL.
[wine] / dlls / kernel32 / toolhelp16.c
1 /*
2  * Misc Toolhelp functions
3  *
4  * Copyright 1996 Marcus Meissner
5  *
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.
10  *
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.
15  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #include <ctype.h>
30 #include <assert.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winternl.h"
34 #include "winerror.h"
35
36 #include "wine/winbase16.h"
37 #include "toolhelp.h"
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(toolhelp);
41
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
45  */
46  
47 static struct notify
48 {
49     HTASK16   htask;
50     FARPROC16 lpfnCallback;
51     WORD     wFlags;
52 } *notifys = NULL;
53
54 static int nrofnotifys = 0;
55
56 static FARPROC16 HookNotify = NULL;
57
58
59 /***********************************************************************
60  *           TaskFindHandle   (TOOLHELP.65)
61  */
62 BOOL16 WINAPI TaskFindHandle16( TASKENTRY *lpte, HTASK16 hTask )
63 {
64     lpte->hNext = hTask;
65     return TaskNext16( lpte );
66 }
67
68
69 /***********************************************************************
70  *              NotifyRegister (TOOLHELP.73)
71  */
72 BOOL16 WINAPI NotifyRegister16( HTASK16 htask, FARPROC16 lpfnCallback,
73                               WORD wFlags )
74 {
75     int i;
76
77     FIXME("(%x,%x,%x), semi-stub.\n",
78                       htask, (DWORD)lpfnCallback, wFlags );
79     if (!htask) htask = GetCurrentTask();
80     for (i=0;i<nrofnotifys;i++)
81         if (notifys[i].htask==htask)
82             break;
83     if (i==nrofnotifys) {
84         if (notifys==NULL)
85             notifys=HeapAlloc( GetProcessHeap(), 0,
86                                                sizeof(struct notify) );
87         else
88             notifys=HeapReAlloc( GetProcessHeap(), 0, notifys,
89                                         sizeof(struct notify)*(nrofnotifys+1));
90         if (!notifys) return FALSE;
91         nrofnotifys++;
92     }
93     notifys[i].htask=htask;
94     notifys[i].lpfnCallback=lpfnCallback;
95     notifys[i].wFlags=wFlags;
96     return TRUE;
97 }
98
99 /***********************************************************************
100  *              NotifyUnregister (TOOLHELP.74)
101  */
102 BOOL16 WINAPI NotifyUnregister16( HTASK16 htask )
103 {
104     int i;
105
106     FIXME("(%x), semi-stub.\n", htask );
107     if (!htask) htask = GetCurrentTask();
108     for (i=nrofnotifys;i--;)
109         if (notifys[i].htask==htask)
110             break;
111     if (i==-1)
112         return FALSE;
113     memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
114     notifys=HeapReAlloc( GetProcessHeap(), 0, notifys,
115                                         (nrofnotifys-1)*sizeof(struct notify));
116     nrofnotifys--;
117     return TRUE;
118 }
119
120 /***********************************************************************
121  *              StackTraceCSIPFirst (TOOLHELP.67)
122  */
123 BOOL16 WINAPI StackTraceCSIPFirst16(STACKTRACEENTRY *ste, WORD wSS, WORD wCS, WORD wIP, WORD wBP)
124 {
125     FIXME("(%p, ss %04x, cs %04x, ip %04x, bp %04x): stub.\n", ste, wSS, wCS, wIP, wBP);
126     return TRUE;
127 }
128
129 /***********************************************************************
130  *              StackTraceFirst (TOOLHELP.66)
131  */
132 BOOL16 WINAPI StackTraceFirst16(STACKTRACEENTRY *ste, HTASK16 Task)
133 {
134     FIXME("(%p, %04x), stub.\n", ste, Task);
135     return TRUE;
136 }
137
138 /***********************************************************************
139  *              StackTraceNext (TOOLHELP.68)
140  */
141 BOOL16 WINAPI StackTraceNext16(STACKTRACEENTRY *ste)
142 {
143     FIXME("(%p), stub.\n", ste);
144     return TRUE;
145 }
146
147 /***********************************************************************
148  *              InterruptRegister (TOOLHELP.75)
149  */
150 BOOL16 WINAPI InterruptRegister16( HTASK16 task, FARPROC callback )
151 {
152     FIXME("(%04x, %p), stub.\n", task, callback);
153     return TRUE;
154 }
155
156 /***********************************************************************
157  *              InterruptUnRegister (TOOLHELP.76)
158  */
159 BOOL16 WINAPI InterruptUnRegister16( HTASK16 task )
160 {
161     FIXME("(%04x), stub.\n", task);
162     return TRUE;
163 }
164
165 /***********************************************************************
166  *           TimerCount   (TOOLHELP.80)
167  */
168 BOOL16 WINAPI TimerCount16( TIMERINFO *pTimerInfo )
169 {
170     /* FIXME
171      * In standard mode, dwmsSinceStart = dwmsThisVM
172      *
173      * I tested this, under Windows in enhanced mode, and
174      * if you never switch VM (ie start/stop DOS) these
175      * values should be the same as well.
176      *
177      * Also, Wine should adjust for the hardware timer
178      * to reduce the amount of error to ~1ms.
179      * I can't be bothered, can you?
180      */
181     pTimerInfo->dwmsSinceStart = pTimerInfo->dwmsThisVM = GetTickCount();
182     return TRUE;
183 }
184
185 /***********************************************************************
186  *           SystemHeapInfo   (TOOLHELP.71)
187  */
188 BOOL16 WINAPI SystemHeapInfo16( SYSHEAPINFO *pHeapInfo )
189 {
190     STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
191     HANDLE16 oldDS = stack16->ds;
192     WORD user = LoadLibrary16( "USER.EXE" );
193     WORD gdi = LoadLibrary16( "GDI.EXE" );
194     stack16->ds = user;
195     pHeapInfo->wUserFreePercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
196     stack16->ds = gdi;
197     pHeapInfo->wGDIFreePercent  = (int)LocalCountFree16() * 100 / LocalHeapSize16();
198     stack16->ds = oldDS;
199     pHeapInfo->hUserSegment = user;
200     pHeapInfo->hGDISegment  = gdi;
201     FreeLibrary16( user );
202     FreeLibrary16( gdi );
203     return TRUE;
204 }
205
206
207 /***********************************************************************
208  *           ToolHelpHook                             (KERNEL.341)
209  *      see "Undocumented Windows"
210  */
211 FARPROC16 WINAPI ToolHelpHook16(FARPROC16 lpfnNotifyHandler)
212 {
213         FARPROC16 tmp;
214
215         FIXME("(%p), stub.\n", lpfnNotifyHandler);
216         tmp = HookNotify;
217         HookNotify = lpfnNotifyHandler;
218         /* just return previously installed notification function */
219         return tmp;
220 }