2 * Misc Toolhelp functions
4 * Copyright 1996 Marcus Meissner
24 /* The K32 snapshot object object */
30 /* FIXME: to make this working, we have to callback all these registered
31 * functions from all over the WINE code. Someone with more knowledge than
32 * me please do that. -Marcus
37 FARPROC16 lpfnCallback
;
41 static int nrofnotifys
= 0;
43 static FARPROC16 HookNotify
= NULL
;
45 BOOL16 WINAPI
NotifyRegister( HTASK16 htask
, FARPROC16 lpfnCallback
,
50 TRACE(toolhelp
, "(%x,%lx,%x) called.\n",
51 htask
, (DWORD
)lpfnCallback
, wFlags
);
52 if (!htask
) htask
= GetCurrentTask();
53 for (i
=0;i
<nrofnotifys
;i
++)
54 if (notifys
[i
].htask
==htask
)
58 notifys
=(struct notify
*)HeapAlloc( SystemHeap
, 0,
59 sizeof(struct notify
) );
61 notifys
=(struct notify
*)HeapReAlloc( SystemHeap
, 0, notifys
,
62 sizeof(struct notify
)*(nrofnotifys
+1));
63 if (!notifys
) return FALSE
;
66 notifys
[i
].htask
=htask
;
67 notifys
[i
].lpfnCallback
=lpfnCallback
;
68 notifys
[i
].wFlags
=wFlags
;
72 BOOL16 WINAPI
NotifyUnregister( HTASK16 htask
)
76 TRACE(toolhelp
, "(%x) called.\n", htask
);
77 if (!htask
) htask
= GetCurrentTask();
78 for (i
=nrofnotifys
;i
--;)
79 if (notifys
[i
].htask
==htask
)
83 memcpy(notifys
+i
,notifys
+(i
+1),sizeof(struct notify
)*(nrofnotifys
-i
-1));
84 notifys
=(struct notify
*)HeapReAlloc( SystemHeap
, 0, notifys
,
85 (nrofnotifys
-1)*sizeof(struct notify
));
90 BOOL16 WINAPI
StackTraceCSIPFirst(STACKTRACEENTRY
*ste
, WORD wSS
, WORD wCS
, WORD wIP
, WORD wBP
)
95 BOOL16 WINAPI
StackTraceFirst(STACKTRACEENTRY
*ste
, HTASK16 Task
)
100 BOOL16 WINAPI
StackTraceNext(STACKTRACEENTRY
*ste
)
105 /***********************************************************************
106 * ToolHelpHook (KERNEL.341)
107 * see "Undocumented Windows"
109 FARPROC16 WINAPI
ToolHelpHook(FARPROC16 lpfnNotifyHandler
)
113 HookNotify
= lpfnNotifyHandler
;
114 /* just return previously installed notification function */
119 /***********************************************************************
120 * CreateToolHelp32Snapshot (KERNEL32.179)
122 HANDLE32 WINAPI
CreateToolhelp32Snapshot( DWORD flags
, DWORD process
)
124 SNAPSHOT_OBJECT
*snapshot
;
125 struct create_snapshot_request req
;
126 struct create_snapshot_reply reply
;
128 TRACE( toolhelp
, "%lx,%lx\n", flags
, process
);
129 if (flags
& (TH32CS_SNAPHEAPLIST
|TH32CS_SNAPMODULE
|TH32CS_SNAPTHREAD
))
130 FIXME( toolhelp
, "flags %lx not implemented\n", flags
);
131 if (!(flags
& TH32CS_SNAPPROCESS
))
133 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
134 return INVALID_HANDLE_VALUE32
;
136 /* Now do the snapshot */
137 if (!(snapshot
= HeapAlloc( SystemHeap
, 0, sizeof(*snapshot
) )))
138 return INVALID_HANDLE_VALUE32
;
139 snapshot
->header
.type
= K32OBJ_TOOLHELP_SNAPSHOT
;
140 snapshot
->header
.refcount
= 1;
142 req
.flags
= flags
& ~TH32CS_INHERIT
;
143 req
.inherit
= (flags
& TH32CS_INHERIT
) != 0;
144 CLIENT_SendRequest( REQ_CREATE_SNAPSHOT
, -1, 1, &req
, sizeof(req
) );
145 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
))
147 HeapFree( SystemHeap
, 0, snapshot
);
148 return INVALID_HANDLE_VALUE32
;
150 return HANDLE_Alloc( PROCESS_Current(), &snapshot
->header
, 0, req
.inherit
, reply
.handle
);
154 /***********************************************************************
155 * TOOLHELP_Process32Next
157 * Implementation of Process32First/Next
159 static BOOL32
TOOLHELP_Process32Next( HANDLE32 handle
, LPPROCESSENTRY32 lppe
, BOOL32 first
)
161 struct next_process_request req
;
162 struct next_process_reply reply
;
164 if (lppe
->dwSize
< sizeof (PROCESSENTRY32
))
166 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
167 ERR (toolhelp
, "Result buffer too small\n");
170 if ((req
.handle
= HANDLE_GetServerHandle( PROCESS_Current(), handle
,
171 K32OBJ_TOOLHELP_SNAPSHOT
, 0 )) == -1)
174 CLIENT_SendRequest( REQ_NEXT_PROCESS
, -1, 1, &req
, sizeof(req
) );
175 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
)) return FALSE
;
177 lppe
->th32ProcessID
= (DWORD
)reply
.pid
;
178 lppe
->th32DefaultHeapID
= 0; /* FIXME */
179 lppe
->th32ModuleID
= 0; /* FIXME */
180 lppe
->cntThreads
= reply
.threads
;
181 lppe
->th32ParentProcessID
= 0; /* FIXME */
182 lppe
->pcPriClassBase
= reply
.priority
;
183 lppe
->dwFlags
= -1; /* FIXME */
184 lppe
->szExeFile
[0] = 0; /* FIXME */
189 /***********************************************************************
190 * Process32First (KERNEL32.555)
192 * Return info about the first process in a toolhelp32 snapshot
194 BOOL32 WINAPI
Process32First(HANDLE32 hSnapshot
, LPPROCESSENTRY32 lppe
)
196 return TOOLHELP_Process32Next( hSnapshot
, lppe
, TRUE
);
199 /***********************************************************************
200 * Process32Next (KERNEL32.556)
202 * Return info about the "next" process in a toolhelp32 snapshot
204 BOOL32 WINAPI
Process32Next(HANDLE32 hSnapshot
, LPPROCESSENTRY32 lppe
)
206 return TOOLHELP_Process32Next( hSnapshot
, lppe
, FALSE
);