Release 980503
[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 "debug.h"
16 #include "heap.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     TRACE(toolhelp, "(%x,%lx,%x) called.\n",
39                       htask, (DWORD)lpfnCallback, wFlags );
40     if (!htask) htask = GetCurrentTask();
41     for (i=0;i<nrofnotifys;i++)
42         if (notifys[i].htask==htask)
43             break;
44     if (i==nrofnotifys) {
45         if (notifys==NULL)
46             notifys=(struct notify*)HeapAlloc( SystemHeap, 0,
47                                                sizeof(struct notify) );
48         else
49             notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
50                                         sizeof(struct notify)*(nrofnotifys+1));
51         if (!notifys) return FALSE;
52         nrofnotifys++;
53     }
54     notifys[i].htask=htask;
55     notifys[i].lpfnCallback=lpfnCallback;
56     notifys[i].wFlags=wFlags;
57     return TRUE;
58 }
59
60 BOOL16 WINAPI NotifyUnregister( HTASK16 htask )
61 {
62     int i;
63     
64     TRACE(toolhelp, "(%x) called.\n", htask );
65     if (!htask) htask = GetCurrentTask();
66     for (i=nrofnotifys;i--;)
67         if (notifys[i].htask==htask)
68             break;
69     if (i==-1)
70         return FALSE;
71     memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
72     notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
73                                         (nrofnotifys-1)*sizeof(struct notify));
74     nrofnotifys--;
75     return TRUE;
76 }
77
78 BOOL16 WINAPI StackTraceCSIPFirst(STACKTRACEENTRY *ste, WORD wSS, WORD wCS, WORD wIP, WORD wBP)
79 {
80     return TRUE;
81 }
82
83 BOOL16 WINAPI StackTraceFirst(STACKTRACEENTRY *ste, HTASK16 Task)
84 {
85     return TRUE;
86 }
87
88 BOOL16 WINAPI StackTraceNext(STACKTRACEENTRY *ste)
89 {
90     return TRUE;
91 }
92
93 /***********************************************************************
94  *           ToolHelpHook                             (KERNEL.341)
95  *      see "Undocumented Windows"
96  */
97 FARPROC16 WINAPI ToolHelpHook(FARPROC16 lpfnNotifyHandler)
98 {
99 FARPROC16 tmp;
100         tmp = HookNotify;
101         HookNotify = lpfnNotifyHandler;
102         /* just return previously installed notification function */
103         return tmp;
104 }