resent: TOOLHELP: Module32Next patch
Andreas Mohr
andi at rhlx01.fht-esslingen.de
Sun Mar 10 09:13:40 CST 2002
Hello all,
Resubmission of the patch, because the previous one turned out to be
incapable of doing what it was supposed to do :)
This implements correct module name and size in the module enumeration
part of the TOOLHELP snapshots.
This is a patch done by HAX (see #WineHQ), with "some" consulting done
by me, and it's based in parts on a patch done by Eric Pouech :)
THe license is irrelevant to them (as long as it's not Microsoft,
I guess :), so apply it wherever you want.
This patch sort of requires the main module initialization to be altered
(call both create_process and load_dll request), otherwise the module
enumeration will be incomplete, because it won't have proper data
for the main exe module.
Maybe Alexandre will look into this...
--
Andreas Mohr Stauferstr. 6, D-71272 Renningen, Germany
-------------- next part --------------
Index: dlls/kernel/toolhelp.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/toolhelp.c,v
retrieving revision 1.14
diff -u -r1.14 toolhelp.c
--- dlls/kernel/toolhelp.c 30 Nov 2001 18:46:43 -0000 1.14
+++ dlls/kernel/toolhelp.c 10 Mar 2002 12:45:09 -0000
@@ -287,6 +287,7 @@
{
req->handle = handle;
req->reset = first;
+ wine_server_set_reply( req, lppe->szExeFile, sizeof(lppe->szExeFile));
if ((ret = !wine_server_call_err( req )))
{
lppe->cntUsage = reply->count;
@@ -294,10 +295,10 @@
lppe->th32DefaultHeapID = 0; /* FIXME */
lppe->th32ModuleID = 0; /* FIXME */
lppe->cntThreads = reply->threads;
- lppe->th32ParentProcessID = 0; /* FIXME */
+ lppe->th32ParentProcessID = (DWORD)reply->ppid;
lppe->pcPriClassBase = reply->priority;
lppe->dwFlags = -1; /* FIXME */
- lppe->szExeFile[0] = 0; /* FIXME */
+ lppe->szExeFile[wine_server_reply_size(reply)] = 0;
}
}
SERVER_END_REQ;
@@ -345,6 +346,7 @@
{
req->handle = handle;
req->reset = first;
+ wine_server_set_reply( req, lpme->szExePath, sizeof(lpme->szExePath));
if ((ret = !wine_server_call_err( req )))
{
lpme->th32ModuleID = 0; /* toolhelp internal id, never used */
@@ -352,10 +354,10 @@
lpme->GlblcntUsage = 0; /* FIXME */
lpme->ProccntUsage = 0; /* FIXME */
lpme->modBaseAddr = reply->base;
- lpme->modBaseSize = 0; /* FIXME */
+ lpme->modBaseSize = reply->base_size;
lpme->hModule = (DWORD)reply->base;
lpme->szModule[0] = 0; /* FIXME */
- lpme->szExePath[0] = 0; /* FIXME */
+ lpme->szExePath[wine_server_reply_size(reply)] = 0;
}
}
SERVER_END_REQ;
Index: include/wine/server_protocol.h
===================================================================
RCS file: /home/wine/wine/include/wine/server_protocol.h,v
retrieving revision 1.26
diff -u -r1.26 server_protocol.h
--- include/wine/server_protocol.h 27 Feb 2002 01:55:02 -0000 1.26
+++ include/wine/server_protocol.h 10 Mar 2002 12:45:10 -0000
@@ -413,6 +413,7 @@
struct request_header __header;
handle_t handle;
void* base;
+ unsigned int base_size;
int dbg_offset;
int dbg_size;
void* name;
@@ -1437,10 +1438,12 @@
struct next_process_reply
{
struct reply_header __header;
- int count;
- void* pid;
- int threads;
- int priority;
+ int count;
+ void* pid;
+ void* ppid;
+ int threads;
+ int priority;
+ /* VARARG(name,string); */
};
@@ -1474,6 +1477,8 @@
struct reply_header __header;
void* pid;
void* base;
+ unsigned int base_size;
+ /* VARARG(name,string); */
};
@@ -3075,6 +3080,6 @@
struct get_window_properties_reply get_window_properties_reply;
};
-#define SERVER_PROTOCOL_VERSION 72
+#define SERVER_PROTOCOL_VERSION 73
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */
Index: loader/pe_image.c
===================================================================
RCS file: /home/wine/wine/loader/pe_image.c,v
retrieving revision 1.105
diff -u -r1.105 pe_image.c
--- loader/pe_image.c 2 Feb 2002 18:42:19 -0000 1.105
+++ loader/pe_image.c 10 Mar 2002 12:45:11 -0000
@@ -677,6 +677,7 @@
{
req->handle = hFile;
req->base = (void *)hModule;
+ req->base_size = PE_HEADER(hModule)->OptionalHeader.SizeOfImage;
req->dbg_offset = nt->FileHeader.PointerToSymbolTable;
req->dbg_size = nt->FileHeader.NumberOfSymbols;
req->name = &wm->filename;
Index: server/process.c
===================================================================
RCS file: /home/wine/wine/server/process.c,v
retrieving revision 1.77
diff -u -r1.77 process.c
--- server/process.c 27 Feb 2002 01:28:31 -0000 1.77
+++ server/process.c 10 Mar 2002 12:45:11 -0000
@@ -391,8 +391,7 @@
}
/* add a dll to a process list */
-static struct process_dll *process_load_dll( struct process *process, struct file *file,
- void *base )
+static struct process_dll *process_load_dll( struct process *process, void *base )
{
struct process_dll *dll;
@@ -405,10 +404,8 @@
if ((dll = mem_alloc( sizeof(*dll) )))
{
+ /* link dll into list */
dll->prev = &process->exe;
- dll->file = NULL;
- dll->base = base;
- if (file) dll->file = (struct file *)grab_object( file );
if ((dll->next = process->exe.next)) dll->next->prev = dll;
process->exe.next = dll;
}
@@ -707,12 +704,26 @@
ptr = snapshot;
for (process = first_process; process; process = process->next)
{
+ int adr;
+
if (!process->running_threads) continue;
ptr->process = process;
ptr->threads = process->running_threads;
ptr->count = process->obj.refcount;
ptr->priority = process->priority;
+ ptr->parent = process->parent;
+ ptr->name[0] = 0;
+ if (process->exe.name){
+ read_process_memory( process, process->exe.name, 4, &adr);
+ if(adr)
+ read_process_memory( process, (void*)adr,
+ sizeof(ptr->name),
+ (int*)ptr->name);
+ }
+
+
grab_object( process );
+ if (process->parent) grab_object( process->parent );
ptr++;
}
*count = running_processes;
@@ -731,7 +742,17 @@
for (ptr = snapshot, dll = &process->exe; dll; dll = dll->next, ptr++)
{
+ int adr;
ptr->base = dll->base;
+ ptr->base_size = dll->base_size;
+ ptr->name[0] = 0;
+ if (dll->name){
+ read_process_memory( process, dll->name, 4, &adr);
+ if(adr)
+ read_process_memory( process, (void*)adr,
+ sizeof(ptr->name),
+ (int*)ptr->name);
+ }
}
*count = total;
return snapshot;
@@ -954,11 +975,16 @@
if (req->handle &&
!(file = get_file_obj( current->process, req->handle, GENERIC_READ ))) return;
- if ((dll = process_load_dll( current->process, file, req->base )))
+ if ((dll = process_load_dll( current->process, req->base )))
{
+ dll->file = NULL;
+ if (file) dll->file = (struct file *)grab_object( file );
+ dll->base = req->base;
+ dll->base_size = req->base_size;
+ dll->name = req->name;
dll->dbg_offset = req->dbg_offset;
dll->dbg_size = req->dbg_size;
- dll->name = req->name;
+
/* only generate event if initialization is done */
if (!current->process->init_event)
generate_debug_event( current, LOAD_DLL_DEBUG_EVENT, dll );
Index: server/process.h
===================================================================
RCS file: /home/wine/wine/server/process.h,v
retrieving revision 1.25
diff -u -r1.25 process.h
--- server/process.h 27 Feb 2002 01:28:31 -0000 1.25
+++ server/process.h 10 Mar 2002 12:45:11 -0000
@@ -20,6 +20,7 @@
struct process_dll *prev;
struct file *file; /* dll file */
void *base; /* dll base address (in process addr space) */
+ unsigned int base_size; /* size, in bytes, of the dll image */
void *name; /* ptr to ptr to name (in process addr space) */
int dbg_offset; /* debug info offset */
int dbg_size; /* debug info size */
@@ -55,14 +56,18 @@
struct process_snapshot
{
struct process *process; /* process ptr */
+ struct process *parent; /* parent process */
int count; /* process refcount */
int threads; /* number of threads */
int priority; /* priority class */
+ char name[MAX_PATH];/* process name */
};
struct module_snapshot
{
- void *base; /* module base addr */
+ void *base; /* module base addr */
+ unsigned int base_size; /* size, in bytes, of the dll image */
+ char name[MAX_PATH]; /* module path */
};
/* process functions */
Index: server/protocol.def
===================================================================
RCS file: /home/wine/wine/server/protocol.def,v
retrieving revision 1.26
diff -u -r1.26 protocol.def
--- server/protocol.def 27 Feb 2002 01:55:03 -0000 1.26
+++ server/protocol.def 10 Mar 2002 12:45:12 -0000
@@ -335,6 +335,7 @@
@REQ(load_dll)
handle_t handle; /* file handle */
void* base; /* base address */
+ unsigned int base_size; /* size, in bytes, of the dll image */
int dbg_offset; /* debug info offset */
int dbg_size; /* debug info size */
void* name; /* ptr to ptr to name (in process addr space) */
@@ -1042,10 +1043,12 @@
handle_t handle; /* handle to the snapshot */
int reset; /* reset snapshot position? */
@REPLY
- int count; /* process usage count */
- void* pid; /* process id */
- int threads; /* number of threads */
- int priority; /* process priority */
+ int count; /* process usage count */
+ void* pid; /* process id */
+ void* ppid; /* process parent id */
+ int threads; /* number of threads */
+ int priority; /* process priority */
+ VARARG(name,string); /* process (path)name */
@END
@@ -1067,8 +1070,10 @@
handle_t handle; /* handle to the snapshot */
int reset; /* reset snapshot position? */
@REPLY
- void* pid; /* process id */
- void* base; /* module base address */
+ void* pid; /* process id */
+ void* base; /* module base address */
+ unsigned int base_size; /* size, in bytes, of the dll image */
+ VARARG(name,string); /* module (path)name */
@END
Index: server/snapshot.c
===================================================================
RCS file: /home/wine/wine/server/snapshot.c,v
retrieving revision 1.12
diff -u -r1.12 snapshot.c
--- server/snapshot.c 20 Dec 2001 00:07:09 -0000 1.12
+++ server/snapshot.c 10 Mar 2002 12:45:13 -0000
@@ -112,8 +112,10 @@
ptr = &snapshot->processes[snapshot->process_pos++];
reply->count = ptr->count;
reply->pid = get_process_id( ptr->process );
+ reply->ppid = get_process_id( ptr->parent );
reply->threads = ptr->threads;
reply->priority = ptr->priority;
+ set_reply_data( ptr->name, strlen(ptr->name) );
return 1;
}
@@ -157,8 +159,11 @@
return 0;
}
ptr = &snapshot->modules[snapshot->module_pos++];
- reply->pid = get_process_id( snapshot->process );
- reply->base = ptr->base;
+ reply->pid = get_process_id( snapshot->process );
+ reply->base = ptr->base;
+ reply->base_size = ptr->base_size;
+ set_reply_data( ptr->name, strlen(ptr->name) );
+
return 1;
}
@@ -178,7 +183,11 @@
if (snapshot->process_count)
{
for (i = 0; i < snapshot->process_count; i++)
+ {
release_object( snapshot->processes[i].process );
+ if (snapshot->processes[i].parent)
+ release_object( snapshot->processes[i].parent );
+ }
free( snapshot->processes );
}
if (snapshot->thread_count)
Index: server/trace.c
===================================================================
RCS file: /home/wine/wine/server/trace.c,v
retrieving revision 1.123
diff -u -r1.123 trace.c
--- server/trace.c 27 Feb 2002 01:55:03 -0000 1.123
+++ server/trace.c 10 Mar 2002 12:45:14 -0000
@@ -489,6 +489,7 @@
{
fprintf( stderr, " handle=%d,", req->handle );
fprintf( stderr, " base=%p,", req->base );
+ fprintf( stderr, " base_size=%08x,", req->base_size );
fprintf( stderr, " dbg_offset=%d,", req->dbg_offset );
fprintf( stderr, " dbg_size=%d,", req->dbg_size );
fprintf( stderr, " name=%p", req->name );
@@ -1199,8 +1200,11 @@
{
fprintf( stderr, " count=%d,", req->count );
fprintf( stderr, " pid=%p,", req->pid );
+ fprintf( stderr, " ppid=%p,", req->ppid );
fprintf( stderr, " threads=%d,", req->threads );
- fprintf( stderr, " priority=%d", req->priority );
+ fprintf( stderr, " priority=%d,", req->priority );
+ fprintf( stderr, " name=" );
+ dump_varargs_string( cur_size );
}
static void dump_next_thread_request( const struct next_thread_request *req )
@@ -1227,7 +1231,10 @@
static void dump_next_module_reply( const struct next_module_reply *req )
{
fprintf( stderr, " pid=%p,", req->pid );
- fprintf( stderr, " base=%p", req->base );
+ fprintf( stderr, " base=%p,", req->base );
+ fprintf( stderr, " base_size=%08x,", req->base_size );
+ fprintf( stderr, " name=" );
+ dump_varargs_string( cur_size );
}
static void dump_wait_debug_event_request( const struct wait_debug_event_request *req )
More information about the wine-patches
mailing list