Correctly fill parent pid, module size and module name in process and

module snapshots. Based on patches by Eric Pouech and Andreas Mohr.
This commit is contained in:
Alexandre Julliard 2002-03-22 00:21:23 +00:00
parent cc9e3ccd2a
commit aeb566052f
9 changed files with 102 additions and 16 deletions

View File

@ -301,17 +301,18 @@ static BOOL TOOLHELP_Process32Next( HANDLE handle, LPPROCESSENTRY32 lppe, BOOL f
{
req->handle = handle;
req->reset = first;
wine_server_set_reply( req, lppe->szExeFile, sizeof(lppe->szExeFile)-1 );
if ((ret = !wine_server_call_err( req )))
{
lppe->cntUsage = reply->count;
lppe->th32ProcessID = (DWORD)reply->pid;
lppe->th32DefaultHeapID = 0; /* FIXME */
lppe->th32ModuleID = 0; /* FIXME */
lppe->th32DefaultHeapID = (DWORD)reply->heap;
lppe->th32ModuleID = (DWORD)reply->module;
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;
@ -359,6 +360,7 @@ static BOOL TOOLHELP_Module32Next( HANDLE handle, LPMODULEENTRY32 lpme, BOOL fir
{
req->handle = handle;
req->reset = first;
wine_server_set_reply( req, lpme->szExePath, sizeof(lpme->szExePath)-1 );
if ((ret = !wine_server_call_err( req )))
{
lpme->th32ModuleID = 0; /* toolhelp internal id, never used */
@ -366,10 +368,10 @@ static BOOL TOOLHELP_Module32Next( HANDLE handle, LPMODULEENTRY32 lpme, BOOL fir
lpme->GlblcntUsage = 0; /* FIXME */
lpme->ProccntUsage = 0; /* FIXME */
lpme->modBaseAddr = reply->base;
lpme->modBaseSize = 0; /* FIXME */
lpme->modBaseSize = reply->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;

View File

@ -251,10 +251,12 @@ struct init_process_done_request
{
struct request_header __header;
void* module;
size_t module_size;
void* entry;
void* name;
handle_t exe_file;
int gui;
/* VARARG(filename,string); */
};
struct init_process_done_reply
{
@ -413,9 +415,11 @@ struct load_dll_request
struct request_header __header;
handle_t handle;
void* base;
size_t size;
int dbg_offset;
int dbg_size;
void* name;
/* VARARG(filename,string); */
};
struct load_dll_reply
{
@ -1440,8 +1444,12 @@ struct next_process_reply
struct reply_header __header;
int count;
void* pid;
void* ppid;
void* heap;
void* module;
int threads;
int priority;
/* VARARG(filename,string); */
};
@ -1475,6 +1483,8 @@ struct next_module_reply
struct reply_header __header;
void* pid;
void* base;
size_t size;
/* VARARG(filename,string); */
};
@ -3117,6 +3127,6 @@ union generic_reply
struct get_window_properties_reply get_window_properties_reply;
};
#define SERVER_PROTOCOL_VERSION 73
#define SERVER_PROTOCOL_VERSION 74
#endif /* __WINE_WINE_SERVER_PROTOCOL_H */

View File

@ -688,9 +688,11 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename, DWORD flags,
{
req->handle = hFile;
req->base = (void *)hModule;
req->size = nt->OptionalHeader.SizeOfImage;
req->dbg_offset = nt->FileHeader.PointerToSymbolTable;
req->dbg_size = nt->FileHeader.NumberOfSymbols;
req->name = &wm->filename;
wine_server_add_data( req, wm->filename, strlen(wm->filename) );
wine_server_call( req );
}
SERVER_END_REQ;

View File

@ -359,11 +359,13 @@ static void start_process(void)
SERVER_START_REQ( init_process_done )
{
req->module = (void *)current_process.module;
req->module_size = PE_HEADER(current_process.module)->OptionalHeader.SizeOfImage;
req->entry = entry;
/* API requires a double indirection */
req->name = &main_exe_name_ptr;
req->exe_file = main_file;
req->gui = !console_app;
wine_server_add_data( req, main_exe_name, strlen(main_exe_name) );
wine_server_call( req );
debugged = reply->debugged;
}

View File

@ -203,6 +203,8 @@ struct thread *create_process( int fd )
process->exe.file = NULL;
process->exe.dbg_offset = 0;
process->exe.dbg_size = 0;
process->exe.namelen = 0;
process->exe.filename = NULL;
gettimeofday( &process->start_time, NULL );
if ((process->next = first_process) != NULL) process->next->prev = process;
@ -328,6 +330,7 @@ static void process_destroy( struct object *obj )
if (process->queue) release_object( process->queue );
if (process->atom_table) release_object( process->atom_table );
if (process->exe.file) release_object( process->exe.file );
if (process->exe.filename) free( process->exe.filename );
}
/* dump a process on stdout for debugging purposes */
@ -406,7 +409,7 @@ struct process *get_process_from_handle( handle_t handle, unsigned int access )
/* add a dll to a process list */
static struct process_dll *process_load_dll( struct process *process, struct file *file,
void *base )
void *base, const char *filename, size_t name_len )
{
struct process_dll *dll;
@ -422,6 +425,13 @@ static struct process_dll *process_load_dll( struct process *process, struct fil
dll->prev = &process->exe;
dll->file = NULL;
dll->base = base;
dll->filename = NULL;
dll->namelen = name_len;
if (name_len && !(dll->filename = memdup( filename, name_len )))
{
free( dll );
return NULL;
}
if (file) dll->file = (struct file *)grab_object( file );
if ((dll->next = process->exe.next)) dll->next->prev = dll;
process->exe.next = dll;
@ -441,6 +451,7 @@ static void process_unload_dll( struct process *process, void *base )
if (dll->file) release_object( dll->file );
if (dll->next) dll->next->prev = dll->prev;
if (dll->prev) dll->prev->next = dll->next;
if (dll->filename) free( dll->filename );
free( dll );
generate_debug_event( current, UNLOAD_DLL_DEBUG_EVENT, base );
return;
@ -484,6 +495,7 @@ static void process_killed( struct process *process )
struct process_dll *dll = process->exe.next;
process->exe.next = dll->next;
if (dll->file) release_object( dll->file );
if (dll->filename) free( dll->filename );
free( dll );
}
if (process->exe.file) release_object( process->exe.file );
@ -746,6 +758,9 @@ struct module_snapshot *module_snap( struct process *process, int *count )
for (ptr = snapshot, dll = &process->exe; dll; dll = dll->next, ptr++)
{
ptr->base = dll->base;
ptr->size = dll->size;
ptr->namelen = dll->namelen;
ptr->filename = memdup( dll->filename, dll->namelen );
}
*count = total;
return snapshot;
@ -848,12 +863,16 @@ DECL_HANDLER(init_process_done)
return;
}
process->exe.base = req->module;
process->exe.size = req->module_size;
process->exe.name = req->name;
if (req->exe_file) file = get_file_obj( current->process, req->exe_file, GENERIC_READ );
if (process->exe.file) release_object( process->exe.file );
process->exe.file = file;
if ((process->exe.namelen = get_req_data_size()))
process->exe.filename = memdup( get_req_data(), process->exe.namelen );
generate_startup_debug_events( current->process, req->entry );
set_event( process->init_event );
release_object( process->init_event );
@ -968,8 +987,10 @@ DECL_HANDLER(load_dll)
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, file, req->base,
get_req_data(), get_req_data_size() )))
{
dll->size = req->size;
dll->dbg_offset = req->dbg_offset;
dll->dbg_size = req->dbg_size;
dll->name = req->name;

View File

@ -34,9 +34,12 @@ struct process_dll
struct process_dll *prev;
struct file *file; /* dll file */
void *base; /* dll base address (in process addr space) */
size_t size; /* dll size */
void *name; /* ptr to ptr to name (in process addr space) */
int dbg_offset; /* debug info offset */
int dbg_size; /* debug info size */
size_t namelen; /* length of dll file name */
char *filename; /* dll file name */
};
struct process
@ -77,6 +80,9 @@ struct process_snapshot
struct module_snapshot
{
void *base; /* module base addr */
size_t size; /* module size */
size_t namelen; /* length of file name */
char *filename; /* module file name */
};
/* process functions */

View File

@ -239,10 +239,12 @@ typedef struct
/* Signal the end of the process initialization */
@REQ(init_process_done)
void* module; /* main module base address */
size_t module_size; /* main module size */
void* entry; /* process entry point */
void* name; /* ptr to ptr to name (in process addr space) */
handle_t exe_file; /* file handle for main exe */
int gui; /* is it a GUI process? */
VARARG(filename,string); /* file name of main exe */
@REPLY
int debugged; /* being debugged? */
@END
@ -349,9 +351,11 @@ typedef struct
@REQ(load_dll)
handle_t handle; /* file handle */
void* base; /* base address */
size_t size; /* dll size */
int dbg_offset; /* debug info offset */
int dbg_size; /* debug info size */
void* name; /* ptr to ptr to name (in process addr space) */
VARARG(filename,string); /* file name of dll */
@END
@ -1059,8 +1063,12 @@ enum char_info_mode
@REPLY
int count; /* process usage count */
void* pid; /* process id */
void* ppid; /* parent process id */
void* heap; /* heap base */
void* module; /* main module */
int threads; /* number of threads */
int priority; /* process priority */
VARARG(filename,string); /* file name of main exe */
@END
@ -1084,6 +1092,8 @@ enum char_info_mode
@REPLY
void* pid; /* process id */
void* base; /* module base address */
size_t size; /* module size */
VARARG(filename,string); /* file name of module */
@END

View File

@ -126,8 +126,16 @@ static int snapshot_next_process( struct snapshot *snapshot, struct next_process
ptr = &snapshot->processes[snapshot->process_pos++];
reply->count = ptr->count;
reply->pid = get_process_id( ptr->process );
reply->ppid = get_process_id( ptr->process->parent );
reply->heap = 0; /* FIXME */
reply->module = 0; /* FIXME */
reply->threads = ptr->threads;
reply->priority = ptr->priority;
if (ptr->process->exe.filename)
{
size_t len = min( ptr->process->exe.namelen, get_reply_max_size() );
set_reply_data( ptr->process->exe.filename, len );
}
return 1;
}
@ -173,6 +181,12 @@ static int snapshot_next_module( struct snapshot *snapshot, struct next_module_r
ptr = &snapshot->modules[snapshot->module_pos++];
reply->pid = get_process_id( snapshot->process );
reply->base = ptr->base;
reply->size = ptr->size;
if (ptr->filename)
{
size_t len = min( ptr->namelen, get_reply_max_size() );
set_reply_data( ptr->filename, len );
}
return 1;
}
@ -201,7 +215,12 @@ static void snapshot_destroy( struct object *obj )
release_object( snapshot->threads[i].thread );
free( snapshot->threads );
}
if (snapshot->module_count) free( snapshot->modules );
if (snapshot->module_count)
{
for (i = 0; i < snapshot->module_count; i++)
free( snapshot->modules[i].filename );
free( snapshot->modules );
}
if (snapshot->process) release_object( snapshot->process );
}

View File

@ -383,10 +383,13 @@ static void dump_init_process_reply( const struct init_process_reply *req )
static void dump_init_process_done_request( const struct init_process_done_request *req )
{
fprintf( stderr, " module=%p,", req->module );
fprintf( stderr, " module_size=%d,", req->module_size );
fprintf( stderr, " entry=%p,", req->entry );
fprintf( stderr, " name=%p,", req->name );
fprintf( stderr, " exe_file=%d,", req->exe_file );
fprintf( stderr, " gui=%d", req->gui );
fprintf( stderr, " gui=%d,", req->gui );
fprintf( stderr, " filename=" );
dump_varargs_string( cur_size );
}
static void dump_init_process_done_reply( const struct init_process_done_reply *req )
@ -503,9 +506,12 @@ static void dump_load_dll_request( const struct load_dll_request *req )
{
fprintf( stderr, " handle=%d,", req->handle );
fprintf( stderr, " base=%p,", req->base );
fprintf( stderr, " size=%d,", req->size );
fprintf( stderr, " dbg_offset=%d,", req->dbg_offset );
fprintf( stderr, " dbg_size=%d,", req->dbg_size );
fprintf( stderr, " name=%p", req->name );
fprintf( stderr, " name=%p,", req->name );
fprintf( stderr, " filename=" );
dump_varargs_string( cur_size );
}
static void dump_unload_dll_request( const struct unload_dll_request *req )
@ -1213,8 +1219,13 @@ static void dump_next_process_reply( const struct next_process_reply *req )
{
fprintf( stderr, " count=%d,", req->count );
fprintf( stderr, " pid=%p,", req->pid );
fprintf( stderr, " ppid=%p,", req->ppid );
fprintf( stderr, " heap=%p,", req->heap );
fprintf( stderr, " module=%p,", req->module );
fprintf( stderr, " threads=%d,", req->threads );
fprintf( stderr, " priority=%d", req->priority );
fprintf( stderr, " priority=%d,", req->priority );
fprintf( stderr, " filename=" );
dump_varargs_string( cur_size );
}
static void dump_next_thread_request( const struct next_thread_request *req )
@ -1241,7 +1252,10 @@ static void dump_next_module_request( const struct next_module_request *req )
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, " size=%d,", req->size );
fprintf( stderr, " filename=" );
dump_varargs_string( cur_size );
}
static void dump_wait_debug_event_request( const struct wait_debug_event_request *req )