2 * Misc Toolhelp functions
4 * Copyright 1996 Marcus Meissner
13 #include "wine/winbase16.h"
23 /* FIXME: to make this working, we have to callback all these registered
24 * functions from all over the WINE code. Someone with more knowledge than
25 * me please do that. -Marcus
30 FARPROC16 lpfnCallback
;
34 static int nrofnotifys
= 0;
36 static FARPROC16 HookNotify
= NULL
;
38 BOOL16 WINAPI
NotifyRegister16( HTASK16 htask
, FARPROC16 lpfnCallback
,
43 TRACE(toolhelp
, "(%x,%lx,%x) called.\n",
44 htask
, (DWORD
)lpfnCallback
, wFlags
);
45 if (!htask
) htask
= GetCurrentTask();
46 for (i
=0;i
<nrofnotifys
;i
++)
47 if (notifys
[i
].htask
==htask
)
51 notifys
=(struct notify
*)HeapAlloc( SystemHeap
, 0,
52 sizeof(struct notify
) );
54 notifys
=(struct notify
*)HeapReAlloc( SystemHeap
, 0, notifys
,
55 sizeof(struct notify
)*(nrofnotifys
+1));
56 if (!notifys
) return FALSE
;
59 notifys
[i
].htask
=htask
;
60 notifys
[i
].lpfnCallback
=lpfnCallback
;
61 notifys
[i
].wFlags
=wFlags
;
65 BOOL16 WINAPI
NotifyUnregister16( HTASK16 htask
)
69 TRACE(toolhelp
, "(%x) called.\n", htask
);
70 if (!htask
) htask
= GetCurrentTask();
71 for (i
=nrofnotifys
;i
--;)
72 if (notifys
[i
].htask
==htask
)
76 memcpy(notifys
+i
,notifys
+(i
+1),sizeof(struct notify
)*(nrofnotifys
-i
-1));
77 notifys
=(struct notify
*)HeapReAlloc( SystemHeap
, 0, notifys
,
78 (nrofnotifys
-1)*sizeof(struct notify
));
83 BOOL16 WINAPI
StackTraceCSIPFirst16(STACKTRACEENTRY
*ste
, WORD wSS
, WORD wCS
, WORD wIP
, WORD wBP
)
88 BOOL16 WINAPI
StackTraceFirst16(STACKTRACEENTRY
*ste
, HTASK16 Task
)
93 BOOL16 WINAPI
StackTraceNext16(STACKTRACEENTRY
*ste
)
98 /***********************************************************************
99 * ToolHelpHook (KERNEL.341)
100 * see "Undocumented Windows"
102 FARPROC16 WINAPI
ToolHelpHook16(FARPROC16 lpfnNotifyHandler
)
106 HookNotify
= lpfnNotifyHandler
;
107 /* just return previously installed notification function */
112 /***********************************************************************
113 * CreateToolHelp32Snapshot (KERNEL32.179)
115 HANDLE WINAPI
CreateToolhelp32Snapshot( DWORD flags
, DWORD process
)
117 struct create_snapshot_request req
;
118 struct create_snapshot_reply reply
;
120 TRACE( toolhelp
, "%lx,%lx\n", flags
, process
);
121 if (flags
& (TH32CS_SNAPHEAPLIST
|TH32CS_SNAPMODULE
|TH32CS_SNAPTHREAD
))
122 FIXME( toolhelp
, "flags %lx not implemented\n", flags
);
123 if (!(flags
& TH32CS_SNAPPROCESS
))
125 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
126 return INVALID_HANDLE_VALUE
;
129 /* Now do the snapshot */
130 req
.flags
= flags
& ~TH32CS_INHERIT
;
131 req
.inherit
= (flags
& TH32CS_INHERIT
) != 0;
132 CLIENT_SendRequest( REQ_CREATE_SNAPSHOT
, -1, 1, &req
, sizeof(req
) );
133 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
138 /***********************************************************************
139 * TOOLHELP_Process32Next
141 * Implementation of Process32First/Next
143 static BOOL
TOOLHELP_Process32Next( HANDLE handle
, LPPROCESSENTRY lppe
, BOOL first
)
145 struct next_process_request req
;
146 struct next_process_reply reply
;
148 if (lppe
->dwSize
< sizeof (PROCESSENTRY
))
150 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
151 ERR (toolhelp
, "Result buffer too small\n");
156 CLIENT_SendRequest( REQ_NEXT_PROCESS
, -1, 1, &req
, sizeof(req
) );
157 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
)) return FALSE
;
159 lppe
->th32ProcessID
= (DWORD
)reply
.pid
;
160 lppe
->th32DefaultHeapID
= 0; /* FIXME */
161 lppe
->th32ModuleID
= 0; /* FIXME */
162 lppe
->cntThreads
= reply
.threads
;
163 lppe
->th32ParentProcessID
= 0; /* FIXME */
164 lppe
->pcPriClassBase
= reply
.priority
;
165 lppe
->dwFlags
= -1; /* FIXME */
166 lppe
->szExeFile
[0] = 0; /* FIXME */
171 /***********************************************************************
172 * Process32First (KERNEL32.555)
174 * Return info about the first process in a toolhelp32 snapshot
176 BOOL WINAPI
Process32First(HANDLE hSnapshot
, LPPROCESSENTRY lppe
)
178 return TOOLHELP_Process32Next( hSnapshot
, lppe
, TRUE
);
181 /***********************************************************************
182 * Process32Next (KERNEL32.556)
184 * Return info about the "next" process in a toolhelp32 snapshot
186 BOOL WINAPI
Process32Next(HANDLE hSnapshot
, LPPROCESSENTRY lppe
)
188 return TOOLHELP_Process32Next( hSnapshot
, lppe
, FALSE
);