Release 980927
[wine] / misc / toolhelp.c
1 /*
2  * Misc Toolhelp functions
3  *
4  * Copyright 1996 Marcus Meissner
5  */
6
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <ctype.h>
11 #include "windows.h"
12 #include "win.h"
13 #include "toolhelp.h"
14 #include "debug.h"
15 #include "heap.h"
16
17 /* FIXME: to make this working, we have to callback all these registered 
18  * functions from all over the WINE code. Someone with more knowledge than
19  * me please do that. -Marcus
20  */
21 static struct notify
22 {
23     HTASK16   htask;
24     FARPROC16 lpfnCallback;
25     WORD     wFlags;
26 } *notifys = NULL;
27
28 static int nrofnotifys = 0;
29
30 static FARPROC16 HookNotify = NULL;
31
32 BOOL16 WINAPI NotifyRegister( HTASK16 htask, FARPROC16 lpfnCallback,
33                               WORD wFlags )
34 {
35     int i;
36
37     TRACE(toolhelp, "(%x,%lx,%x) called.\n",
38                       htask, (DWORD)lpfnCallback, wFlags );
39     if (!htask) htask = GetCurrentTask();
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( SystemHeap, 0,
46                                                sizeof(struct notify) );
47         else
48             notifys=(struct notify*)HeapReAlloc( SystemHeap, 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     TRACE(toolhelp, "(%x) called.\n", htask );
64     if (!htask) htask = GetCurrentTask();
65     for (i=nrofnotifys;i--;)
66         if (notifys[i].htask==htask)
67             break;
68     if (i==-1)
69         return FALSE;
70     memcpy(notifys+i,notifys+(i+1),sizeof(struct notify)*(nrofnotifys-i-1));
71     notifys=(struct notify*)HeapReAlloc( SystemHeap, 0, notifys,
72                                         (nrofnotifys-1)*sizeof(struct notify));
73     nrofnotifys--;
74     return TRUE;
75 }
76
77 BOOL16 WINAPI StackTraceCSIPFirst(STACKTRACEENTRY *ste, WORD wSS, WORD wCS, WORD wIP, WORD wBP)
78 {
79     return TRUE;
80 }
81
82 BOOL16 WINAPI StackTraceFirst(STACKTRACEENTRY *ste, HTASK16 Task)
83 {
84     return TRUE;
85 }
86
87 BOOL16 WINAPI StackTraceNext(STACKTRACEENTRY *ste)
88 {
89     return TRUE;
90 }
91
92 /***********************************************************************
93  *           ToolHelpHook                             (KERNEL.341)
94  *      see "Undocumented Windows"
95  */
96 FARPROC16 WINAPI ToolHelpHook(FARPROC16 lpfnNotifyHandler)
97 {
98 FARPROC16 tmp;
99         tmp = HookNotify;
100         HookNotify = lpfnNotifyHandler;
101         /* just return previously installed notification function */
102         return tmp;
103 }
104
105 /***********************************************************************
106  *           CreateToolHelp32Snapshot                   (KERNEL32.179)
107  *      see "Undocumented Windows"
108  */
109 HANDLE32 WINAPI CreateToolhelp32Snapshot(DWORD dwFlags, DWORD th32ProcessID) {
110         FIXME(toolhelp,"(0x%08lx,0x%08lx), stub!\n",dwFlags,th32ProcessID);
111         return INVALID_HANDLE_VALUE32;
112 }