1999-02-14 19:03:15 +01:00
|
|
|
/*
|
|
|
|
* Server-side snapshots
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Alexandre Julliard
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2000-04-16 21:45:05 +02:00
|
|
|
* FIXME: heap snapshots not implemented
|
1999-02-14 19:03:15 +01:00
|
|
|
*/
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
1999-02-14 19:03:15 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2006-01-03 12:06:03 +01:00
|
|
|
#include <stdarg.h>
|
1999-02-14 19:03:15 +01:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2000-12-15 22:30:35 +01:00
|
|
|
#include "windef.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "winternl.h"
|
1999-05-15 12:48:19 +02:00
|
|
|
|
|
|
|
#include "handle.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "thread.h"
|
1999-06-22 19:26:53 +02:00
|
|
|
#include "request.h"
|
1999-02-14 19:03:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct snapshot
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
2000-04-16 21:45:05 +02:00
|
|
|
struct process_snapshot *processes; /* processes snapshot */
|
1999-02-14 19:03:15 +01:00
|
|
|
int process_count; /* count of processes */
|
|
|
|
int process_pos; /* current position in proc snapshot */
|
2000-04-16 21:45:05 +02:00
|
|
|
struct thread_snapshot *threads; /* threads snapshot */
|
|
|
|
int thread_count; /* count of threads */
|
|
|
|
int thread_pos; /* current position in thread snapshot */
|
1999-02-14 19:03:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void snapshot_dump( struct object *obj, int verbose );
|
|
|
|
static void snapshot_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops snapshot_ops =
|
|
|
|
{
|
2000-01-01 01:56:27 +01:00
|
|
|
sizeof(struct snapshot), /* size */
|
|
|
|
snapshot_dump, /* dump */
|
2007-12-05 18:16:42 +01:00
|
|
|
no_get_type, /* get_type */
|
2000-01-01 01:56:27 +01:00
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
2005-04-24 19:35:52 +02:00
|
|
|
no_signal, /* signal */
|
2000-12-19 03:12:45 +01:00
|
|
|
no_get_fd, /* get_fd */
|
2005-12-12 14:57:40 +01:00
|
|
|
no_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2005-11-22 15:55:42 +01:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 13:07:19 +01:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2007-03-22 11:44:29 +01:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 14:37:09 +01:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2005-06-09 17:39:52 +02:00
|
|
|
no_close_handle, /* close_handle */
|
2000-01-01 01:56:27 +01:00
|
|
|
snapshot_destroy /* destroy */
|
1999-02-14 19:03:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* create a new snapshot */
|
2008-12-09 11:49:37 +01:00
|
|
|
static struct snapshot *create_snapshot( unsigned int flags )
|
1999-02-14 19:03:15 +01:00
|
|
|
{
|
|
|
|
struct snapshot *snapshot;
|
1999-06-22 19:26:53 +02:00
|
|
|
|
2008-12-09 11:49:37 +01:00
|
|
|
if (!(snapshot = alloc_object( &snapshot_ops ))) return NULL;
|
2000-04-16 21:45:05 +02:00
|
|
|
|
|
|
|
snapshot->process_pos = 0;
|
|
|
|
snapshot->process_count = 0;
|
2003-01-09 01:01:28 +01:00
|
|
|
if (flags & SNAP_PROCESS)
|
2000-04-16 21:45:05 +02:00
|
|
|
snapshot->processes = process_snap( &snapshot->process_count );
|
|
|
|
|
|
|
|
snapshot->thread_pos = 0;
|
|
|
|
snapshot->thread_count = 0;
|
2003-01-09 01:01:28 +01:00
|
|
|
if (flags & SNAP_THREAD)
|
2000-04-16 21:45:05 +02:00
|
|
|
snapshot->threads = thread_snap( &snapshot->thread_count );
|
|
|
|
|
1999-06-22 19:26:53 +02:00
|
|
|
return snapshot;
|
1999-02-14 19:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get the next process in the snapshot */
|
2001-11-30 19:46:42 +01:00
|
|
|
static int snapshot_next_process( struct snapshot *snapshot, struct next_process_reply *reply )
|
1999-02-14 19:03:15 +01:00
|
|
|
{
|
|
|
|
struct process_snapshot *ptr;
|
2006-02-16 12:13:01 +01:00
|
|
|
struct process_dll *exe_module;
|
1999-06-26 10:43:26 +02:00
|
|
|
|
1999-02-14 19:03:15 +01:00
|
|
|
if (!snapshot->process_count)
|
|
|
|
{
|
2000-01-24 22:58:06 +01:00
|
|
|
set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
|
1999-02-14 19:03:15 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
if (snapshot->process_pos >= snapshot->process_count)
|
1999-02-14 19:03:15 +01:00
|
|
|
{
|
2000-01-24 22:58:06 +01:00
|
|
|
set_error( STATUS_NO_MORE_FILES );
|
1999-02-14 19:03:15 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2000-04-16 21:45:05 +02:00
|
|
|
ptr = &snapshot->processes[snapshot->process_pos++];
|
2001-11-30 19:46:42 +01:00
|
|
|
reply->count = ptr->count;
|
|
|
|
reply->pid = get_process_id( ptr->process );
|
2016-04-21 12:34:07 +02:00
|
|
|
reply->ppid = ptr->process->parent_id;
|
2001-11-30 19:46:42 +01:00
|
|
|
reply->threads = ptr->threads;
|
|
|
|
reply->priority = ptr->priority;
|
2003-09-16 03:07:21 +02:00
|
|
|
reply->handles = ptr->handles;
|
2012-04-16 12:35:17 +02:00
|
|
|
reply->unix_pid = ptr->process->unix_pid;
|
2006-02-16 12:13:01 +01:00
|
|
|
if ((exe_module = get_process_exe_module( ptr->process )) && exe_module->filename)
|
2002-03-22 01:21:23 +01:00
|
|
|
{
|
2006-07-26 10:43:25 +02:00
|
|
|
data_size_t len = min( exe_module->namelen, get_reply_max_size() );
|
2006-02-16 12:13:01 +01:00
|
|
|
set_reply_data( exe_module->filename, len );
|
2002-03-22 01:21:23 +01:00
|
|
|
}
|
1999-02-14 19:03:15 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-04-16 21:45:05 +02:00
|
|
|
/* get the next thread in the snapshot */
|
2001-11-30 19:46:42 +01:00
|
|
|
static int snapshot_next_thread( struct snapshot *snapshot, struct next_thread_reply *reply )
|
2000-04-16 21:45:05 +02:00
|
|
|
{
|
|
|
|
struct thread_snapshot *ptr;
|
|
|
|
|
|
|
|
if (!snapshot->thread_count)
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
if (snapshot->thread_pos >= snapshot->thread_count)
|
2000-04-16 21:45:05 +02:00
|
|
|
{
|
|
|
|
set_error( STATUS_NO_MORE_FILES );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ptr = &snapshot->threads[snapshot->thread_pos++];
|
2001-11-30 19:46:42 +01:00
|
|
|
reply->count = ptr->count;
|
|
|
|
reply->pid = get_process_id( ptr->thread->process );
|
|
|
|
reply->tid = get_thread_id( ptr->thread );
|
|
|
|
reply->base_pri = ptr->priority;
|
|
|
|
reply->delta_pri = 0; /* FIXME */
|
2020-06-29 03:43:18 +02:00
|
|
|
reply->unix_tid = ptr->thread->unix_tid;
|
2000-04-16 21:45:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-02-14 19:03:15 +01:00
|
|
|
static void snapshot_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct snapshot *snapshot = (struct snapshot *)obj;
|
|
|
|
assert( obj->ops == &snapshot_ops );
|
2008-12-09 11:49:37 +01:00
|
|
|
fprintf( stderr, "Snapshot: %d procs %d threads\n",
|
|
|
|
snapshot->process_count, snapshot->thread_count );
|
1999-02-14 19:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void snapshot_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct snapshot *snapshot = (struct snapshot *)obj;
|
|
|
|
assert( obj->ops == &snapshot_ops );
|
|
|
|
if (snapshot->process_count)
|
|
|
|
{
|
|
|
|
for (i = 0; i < snapshot->process_count; i++)
|
2000-04-16 21:45:05 +02:00
|
|
|
release_object( snapshot->processes[i].process );
|
|
|
|
free( snapshot->processes );
|
|
|
|
}
|
|
|
|
if (snapshot->thread_count)
|
|
|
|
{
|
|
|
|
for (i = 0; i < snapshot->thread_count; i++)
|
|
|
|
release_object( snapshot->threads[i].thread );
|
|
|
|
free( snapshot->threads );
|
1999-02-14 19:03:15 +01:00
|
|
|
}
|
|
|
|
}
|
1999-05-15 12:48:19 +02:00
|
|
|
|
|
|
|
/* create a snapshot */
|
|
|
|
DECL_HANDLER(create_snapshot)
|
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
struct snapshot *snapshot;
|
1999-05-15 12:48:19 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
reply->handle = 0;
|
2008-12-09 11:49:37 +01:00
|
|
|
if ((snapshot = create_snapshot( req->flags )))
|
1999-05-15 12:48:19 +02:00
|
|
|
{
|
2005-12-09 13:58:25 +01:00
|
|
|
reply->handle = alloc_handle( current->process, snapshot, 0, req->attributes );
|
1999-06-22 19:26:53 +02:00
|
|
|
release_object( snapshot );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the next process from a snapshot */
|
|
|
|
DECL_HANDLER(next_process)
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
struct snapshot *snapshot;
|
|
|
|
|
|
|
|
if ((snapshot = (struct snapshot *)get_handle_obj( current->process, req->handle,
|
|
|
|
0, &snapshot_ops )))
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
if (req->reset) snapshot->process_pos = 0;
|
|
|
|
snapshot_next_process( snapshot, reply );
|
1999-06-26 10:43:26 +02:00
|
|
|
release_object( snapshot );
|
|
|
|
}
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
2000-04-16 21:45:05 +02:00
|
|
|
|
|
|
|
/* get the next thread from a snapshot */
|
|
|
|
DECL_HANDLER(next_thread)
|
|
|
|
{
|
|
|
|
struct snapshot *snapshot;
|
|
|
|
|
|
|
|
if ((snapshot = (struct snapshot *)get_handle_obj( current->process, req->handle,
|
|
|
|
0, &snapshot_ops )))
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
if (req->reset) snapshot->thread_pos = 0;
|
|
|
|
snapshot_next_thread( snapshot, reply );
|
2000-04-16 21:45:05 +02:00
|
|
|
release_object( snapshot );
|
|
|
|
}
|
|
|
|
}
|