Release 980201
[wine] / misc / toolhelp.c
1 /*
2  * Misc Toolhelp functions
3  *
4  * Copyright 1996 Marcus Meissner
5  */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <ctype.h>
12 #include "windows.h"
13 #include "win.h"
14 #include "toolhelp.h"
15 #include "stddebug.h"
16 #include "debug.h"
17
18 /* FIXME: to make this working, we have to callback all these registered 
19  * functions from all over the WINE code. Someone with more knowledge than
20  * me please do that. -Marcus
21  */
22 static struct notify
23 {
24     HTASK16   htask;
25     FARPROC16 lpfnCallback;
26     WORD     wFlags;
27 } *notifys = NULL;
28
29 static int nrofnotifys = 0;
30
31 static FARPROC16 HookNotify = NULL;
32
33 BOOL16 WINAPI NotifyRegister( HTASK16 htask, FARPROC16 lpfnCallback,
34                               WORD wFlags )
35 {
36     int i;
37
38     dprintf_toolhelp( stddeb, "NotifyRegister(%x,%lx,%x) called.\n",
39                       htask, (DWORD)lpfnCallback, wFlags );
40     for (i=0;i<nrofnotifys;i++)
41         if (notifys[i].htask==htask)
42             break;
43     if (i==nrofnotifys) {
44         if (notifys==NULL)
45             notifys=(struct notify*)HeapAlloc( GetProcessHeap(), 0,
46                                                sizeof(struct notify) );
47         else
48             notifys=(struct notify*)HeapReAlloc( GetProcessHeap(), 0, notifys,
49                                         sizeof(struct notify)*(nrofnotifys+1));
50         if (!notifys) return FALSE;
51         nrofnotifys++;
52     }
53     notifys[i].htask=htask;
54     notifys[i].lpfnCallback=lpfnCallback;
55     notifys[i].wFlags=wFlags;
56     return TRUE;
57 }
58
59 BOOL16 WINAPI NotifyUnregister( HTASK16 htask )
60 {
61     int i;
62     
63     dprintf_toolhelp( stddeb, "NotifyUnregister(%x) called.\n", htask );
64     for (i=nrofnotifys;i--;)
65         if (notifys[i].htask==htask)
66             break;
67     if (i==-1)
68         return FALSE;
69     memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
70     notifys=(struct notify*)HeapReAlloc( GetProcessHeap(), 0, notifys,
71                                         (nrofnotifys-1)*sizeof(struct notify));
72     nrofnotifys--;
73     return TRUE;
74 }
75
76 BOOL16 WINAPI StackTraceCSIPFirst(STACKTRACEENTRY *ste, WORD wSS, WORD wCS, WORD wIP, WORD wBP)
77 {
78     return TRUE;
79 }
80
81 BOOL16 WINAPI StackTraceFirst(STACKTRACEENTRY *ste, HTASK16 Task)
82 {
83     return TRUE;
84 }
85
86 BOOL16 WINAPI StackTraceNext(STACKTRACEENTRY *ste)
87 {
88     return TRUE;
89 }
90
91 /***********************************************************************
92  *           ToolHelpHook                             (KERNEL.341)
93  *      see "Undocumented Windows"
94  */
95 FARPROC16 WINAPI ToolHelpHook(FARPROC16 lpfnNotifyHandler)
96 {
97 FARPROC16 tmp;
98         tmp = HookNotify;
99         HookNotify = lpfnNotifyHandler;
100         /* just return previously installed notification function */
101         return tmp;
102 }