mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-14 21:07:17 +00:00
iphlpapi: Reimplement get_pid_map() using the list_processes request.
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
8622eb326f
commit
747573f1e4
|
@ -1887,56 +1887,69 @@ struct pid_map
|
||||||
|
|
||||||
static struct pid_map *get_pid_map( unsigned int *num_entries )
|
static struct pid_map *get_pid_map( unsigned int *num_entries )
|
||||||
{
|
{
|
||||||
HANDLE snapshot = NULL;
|
|
||||||
struct pid_map *map;
|
struct pid_map *map;
|
||||||
unsigned int i = 0, count = 16, size = count * sizeof(*map);
|
unsigned int i = 0, map_count = 16, buffer_len = 4096, process_count, pos = 0;
|
||||||
NTSTATUS ret;
|
NTSTATUS ret;
|
||||||
|
char *buffer = NULL, *new_buffer;
|
||||||
|
|
||||||
if (!(map = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
|
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_len ))) return NULL;
|
||||||
|
|
||||||
SERVER_START_REQ( create_snapshot )
|
for (;;)
|
||||||
{
|
{
|
||||||
req->flags = SNAP_PROCESS;
|
SERVER_START_REQ( list_processes )
|
||||||
req->attributes = 0;
|
{
|
||||||
if (!(ret = wine_server_call( req )))
|
wine_server_set_reply( req, buffer, buffer_len );
|
||||||
snapshot = wine_server_ptr_handle( reply->handle );
|
ret = wine_server_call( req );
|
||||||
|
buffer_len = reply->info_size;
|
||||||
|
process_count = reply->process_count;
|
||||||
}
|
}
|
||||||
SERVER_END_REQ;
|
SERVER_END_REQ;
|
||||||
|
|
||||||
*num_entries = 0;
|
if (ret != STATUS_INFO_LENGTH_MISMATCH) break;
|
||||||
while (ret == STATUS_SUCCESS)
|
|
||||||
|
if (!(new_buffer = HeapReAlloc( GetProcessHeap(), 0, buffer, buffer_len )))
|
||||||
{
|
{
|
||||||
SERVER_START_REQ( next_process )
|
HeapFree( GetProcessHeap(), 0, buffer );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(map = HeapAlloc( GetProcessHeap(), 0, map_count * sizeof(*map) )))
|
||||||
{
|
{
|
||||||
req->handle = wine_server_obj_handle( snapshot );
|
HeapFree( GetProcessHeap(), 0, buffer );
|
||||||
req->reset = (i == 0);
|
return NULL;
|
||||||
if (!(ret = wine_server_call( req )))
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < process_count; ++i)
|
||||||
{
|
{
|
||||||
if (i >= count)
|
const struct process_info *process;
|
||||||
|
|
||||||
|
pos = (pos + 7) & ~7;
|
||||||
|
process = (const struct process_info *)(buffer + pos);
|
||||||
|
|
||||||
|
if (i >= map_count)
|
||||||
{
|
{
|
||||||
struct pid_map *new_map;
|
struct pid_map *new_map;
|
||||||
count *= 2;
|
map_count *= 2;
|
||||||
size = count * sizeof(*new_map);
|
if (!(new_map = HeapReAlloc( GetProcessHeap(), 0, map, map_count * sizeof(*map))))
|
||||||
|
|
||||||
if (!(new_map = HeapReAlloc( GetProcessHeap(), 0, map, size )))
|
|
||||||
{
|
{
|
||||||
HeapFree( GetProcessHeap(), 0, map );
|
HeapFree( GetProcessHeap(), 0, map );
|
||||||
map = NULL;
|
HeapFree( GetProcessHeap(), 0, buffer );
|
||||||
goto done;
|
return NULL;
|
||||||
}
|
}
|
||||||
map = new_map;
|
map = new_map;
|
||||||
}
|
}
|
||||||
map[i].pid = reply->pid;
|
|
||||||
map[i].unix_pid = reply->unix_pid;
|
map[i].pid = process->pid;
|
||||||
(*num_entries)++;
|
map[i].unix_pid = process->unix_pid;
|
||||||
i++;
|
|
||||||
}
|
pos += sizeof(struct process_info) + process->name_len;
|
||||||
}
|
pos = (pos + 7) & ~7;
|
||||||
SERVER_END_REQ;
|
pos += process->thread_count * sizeof(struct thread_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
HeapFree( GetProcessHeap(), 0, buffer );
|
||||||
NtClose( snapshot );
|
*num_entries = process_count;
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue