- OpenConsole: try to open the Unix console if we fail with wineserver
[wine/multimedia.git] / dlls / kernel / toolhelp16.c
blobc29087decd572427d9f1734749fdbed2e64521f1
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 <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 "wine/winbase16.h"
34 #include "winerror.h"
35 #include "toolhelp.h"
36 #include "wine/server.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(toolhelp);
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
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=HeapAlloc( GetProcessHeap(), 0,
74 sizeof(struct notify) );
75 else
76 notifys=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=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 STACK16FRAME* stack16 = MapSL((SEGPTR)NtCurrentTeb()->WOW32Reserved);
179 HANDLE16 oldDS = stack16->ds;
180 WORD user = LoadLibrary16( "USER.EXE" );
181 WORD gdi = LoadLibrary16( "GDI.EXE" );
182 stack16->ds = user;
183 pHeapInfo->wUserFreePercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
184 stack16->ds = gdi;
185 pHeapInfo->wGDIFreePercent = (int)LocalCountFree16() * 100 / LocalHeapSize16();
186 stack16->ds = oldDS;
187 pHeapInfo->hUserSegment = user;
188 pHeapInfo->hGDISegment = gdi;
189 FreeLibrary16( user );
190 FreeLibrary16( gdi );
191 return TRUE;
195 /***********************************************************************
196 * ToolHelpHook (KERNEL.341)
197 * see "Undocumented Windows"
199 FARPROC16 WINAPI ToolHelpHook16(FARPROC16 lpfnNotifyHandler)
201 FARPROC16 tmp;
203 FIXME("(%p), stub.\n", lpfnNotifyHandler);
204 tmp = HookNotify;
205 HookNotify = lpfnNotifyHandler;
206 /* just return previously installed notification function */
207 return tmp;