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