2002-05-02 06:26:05 +02:00
|
|
|
/* fhandler_process.cc: fhandler for /proc/<pid> virtual filesystem
|
|
|
|
|
2004-02-09 05:04:24 +01:00
|
|
|
Copyright 2002, 2003, 2004 Red Hat, Inc.
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/cygwin.h>
|
2002-05-12 03:37:48 +02:00
|
|
|
#include <ntdef.h>
|
2002-05-02 06:26:05 +02:00
|
|
|
#include "cygerrno.h"
|
|
|
|
#include "security.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
#include "path.h"
|
2002-05-02 06:26:05 +02:00
|
|
|
#include "fhandler.h"
|
|
|
|
#include "pinfo.h"
|
|
|
|
#include "shared_info.h"
|
2002-05-04 05:24:35 +02:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2002-05-12 03:37:48 +02:00
|
|
|
#include "ntdll.h"
|
2002-08-31 18:37:51 +02:00
|
|
|
#include <sys/param.h>
|
2002-05-02 06:26:05 +02:00
|
|
|
#include <assert.h>
|
2002-09-25 14:24:23 +02:00
|
|
|
#include <sys/sysmacros.h>
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
#define _COMPILING_NEWLIB
|
|
|
|
#include <dirent.h>
|
|
|
|
|
2002-05-04 05:24:35 +02:00
|
|
|
static const int PROCESS_PPID = 2;
|
|
|
|
static const int PROCESS_EXENAME = 3;
|
|
|
|
static const int PROCESS_WINPID = 4;
|
|
|
|
static const int PROCESS_WINEXENAME = 5;
|
|
|
|
static const int PROCESS_STATUS = 6;
|
|
|
|
static const int PROCESS_UID = 7;
|
|
|
|
static const int PROCESS_GID = 8;
|
|
|
|
static const int PROCESS_PGID = 9;
|
|
|
|
static const int PROCESS_SID = 10;
|
|
|
|
static const int PROCESS_CTTY = 11;
|
2002-05-12 03:37:48 +02:00
|
|
|
static const int PROCESS_STAT = 12;
|
|
|
|
static const int PROCESS_STATM = 13;
|
2002-10-30 22:05:18 +01:00
|
|
|
static const int PROCESS_CMDLINE = 14;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
static const char * const process_listing[] =
|
|
|
|
{
|
2002-05-04 05:24:35 +02:00
|
|
|
".",
|
|
|
|
"..",
|
2002-05-02 06:26:05 +02:00
|
|
|
"ppid",
|
|
|
|
"exename",
|
|
|
|
"winpid",
|
|
|
|
"winexename",
|
|
|
|
"status",
|
|
|
|
"uid",
|
|
|
|
"gid",
|
|
|
|
"pgid",
|
|
|
|
"sid",
|
|
|
|
"ctty",
|
2002-05-12 03:37:48 +02:00
|
|
|
"stat",
|
|
|
|
"statm",
|
2002-11-05 05:24:48 +01:00
|
|
|
"cmdline",
|
2002-05-02 06:26:05 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
static const int PROCESS_LINK_COUNT =
|
2002-09-23 02:31:31 +02:00
|
|
|
(sizeof (process_listing) / sizeof (const char *)) - 1;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t format_process_stat (_pinfo *p, char *destbuf, size_t maxsize);
|
|
|
|
static _off64_t format_process_status (_pinfo *p, char *destbuf, size_t maxsize);
|
|
|
|
static _off64_t format_process_statm (_pinfo *p, char *destbuf, size_t maxsize);
|
2002-05-12 03:37:48 +02:00
|
|
|
static int get_process_state (DWORD dwProcessId);
|
2002-09-22 05:38:57 +02:00
|
|
|
static bool get_mem_values (DWORD dwProcessId, unsigned long *vmsize,
|
|
|
|
unsigned long *vmrss, unsigned long *vmtext,
|
|
|
|
unsigned long *vmdata, unsigned long *vmlib,
|
|
|
|
unsigned long *vmshare);
|
2002-05-12 03:37:48 +02:00
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
/* Returns 0 if path doesn't exist, >0 if path is a directory,
|
|
|
|
* <0 if path is a file.
|
|
|
|
*/
|
|
|
|
int
|
2002-05-23 00:09:58 +02:00
|
|
|
fhandler_process::exists ()
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2002-05-23 00:09:58 +02:00
|
|
|
const char *path = get_name ();
|
2002-05-02 06:26:05 +02:00
|
|
|
debug_printf ("exists (%s)", path);
|
|
|
|
path += proc_len + 1;
|
2003-01-09 09:22:05 +01:00
|
|
|
while (*path != 0 && !isdirsep (*path))
|
2002-05-02 06:26:05 +02:00
|
|
|
path++;
|
|
|
|
if (*path == 0)
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
for (int i = 0; process_listing[i]; i++)
|
|
|
|
if (pathmatch (path + 1, process_listing[i]))
|
|
|
|
return -1;
|
2002-06-02 05:13:22 +02:00
|
|
|
return 0;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fhandler_process::fhandler_process ():
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_proc ()
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_process::fstat (struct __stat64 *buf)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2002-05-12 03:37:48 +02:00
|
|
|
const char *path = get_name ();
|
2002-05-23 00:09:58 +02:00
|
|
|
int file_type = exists ();
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
(void) fhandler_base::fstat (buf);
|
2002-05-12 03:37:48 +02:00
|
|
|
path += proc_len + 1;
|
2002-07-01 01:02:58 +02:00
|
|
|
pid = atoi (path);
|
2002-06-02 05:13:22 +02:00
|
|
|
pinfo p (pid);
|
|
|
|
if (!p)
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
2002-07-01 01:02:58 +02:00
|
|
|
set_errno (ENOENT);
|
2002-06-02 05:13:22 +02:00
|
|
|
return -1;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
2002-06-02 05:13:22 +02:00
|
|
|
|
2002-05-03 01:58:20 +02:00
|
|
|
buf->st_mode &= ~_IFMT & NO_W;
|
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
switch (file_type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return -1;
|
|
|
|
case 1:
|
2002-05-03 01:58:20 +02:00
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
2002-05-02 06:26:05 +02:00
|
|
|
return 0;
|
|
|
|
case 2:
|
2002-05-12 03:37:48 +02:00
|
|
|
buf->st_ctime = buf->st_mtime = p->start_time;
|
2002-06-06 17:35:09 +02:00
|
|
|
buf->st_ctim.tv_nsec = buf->st_mtim.tv_nsec = 0;
|
2002-09-22 05:38:57 +02:00
|
|
|
time_as_timestruc_t (&buf->st_atim);
|
2002-05-12 03:37:48 +02:00
|
|
|
buf->st_uid = p->uid;
|
|
|
|
buf->st_gid = p->gid;
|
2002-05-03 01:58:20 +02:00
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
2002-05-02 06:26:05 +02:00
|
|
|
buf->st_nlink = PROCESS_LINK_COUNT;
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
case -1:
|
2002-05-12 03:37:48 +02:00
|
|
|
buf->st_uid = p->uid;
|
|
|
|
buf->st_gid = p->gid;
|
|
|
|
buf->st_mode |= S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
|
2002-05-02 06:26:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dirent *
|
|
|
|
fhandler_process::readdir (DIR * dir)
|
|
|
|
{
|
|
|
|
if (dir->__d_position >= PROCESS_LINK_COUNT)
|
2003-08-05 05:04:28 +02:00
|
|
|
return NULL;
|
2002-05-02 06:26:05 +02:00
|
|
|
strcpy (dir->__d_dirent->d_name, process_listing[dir->__d_position++]);
|
|
|
|
syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir,
|
2002-05-28 03:55:40 +02:00
|
|
|
dir->__d_dirent->d_name);
|
2002-05-02 06:26:05 +02:00
|
|
|
return dir->__d_dirent;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
fhandler_process::open (int flags, mode_t mode)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2002-07-01 01:02:58 +02:00
|
|
|
int process_file_no = -1;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
int res = fhandler_virtual::open (flags, mode);
|
2002-05-02 06:26:05 +02:00
|
|
|
if (!res)
|
|
|
|
goto out;
|
|
|
|
|
2004-04-10 15:45:10 +02:00
|
|
|
nohandle (true);
|
2002-07-02 03:36:15 +02:00
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
const char *path;
|
2002-05-03 04:43:45 +02:00
|
|
|
path = get_name () + proc_len + 1;
|
2002-05-02 06:26:05 +02:00
|
|
|
pid = atoi (path);
|
2003-01-09 09:22:05 +01:00
|
|
|
while (*path != 0 && !isdirsep (*path))
|
2002-05-02 06:26:05 +02:00
|
|
|
path++;
|
|
|
|
|
|
|
|
if (*path == 0)
|
|
|
|
{
|
2002-05-04 05:24:35 +02:00
|
|
|
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EEXIST);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-04 05:24:35 +02:00
|
|
|
else if (flags & O_WRONLY)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
flags |= O_DIROPEN;
|
|
|
|
goto success;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
process_file_no = -1;
|
|
|
|
for (int i = 0; process_listing[i]; i++)
|
|
|
|
{
|
|
|
|
if (path_prefix_p
|
2002-05-28 03:55:40 +02:00
|
|
|
(process_listing[i], path + 1, strlen (process_listing[i])))
|
|
|
|
process_file_no = i;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
if (process_file_no == -1)
|
|
|
|
{
|
2002-05-04 05:24:35 +02:00
|
|
|
if (flags & O_CREAT)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2002-05-04 05:24:35 +02:00
|
|
|
if (flags & O_WRONLY)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2002-06-02 18:42:02 +02:00
|
|
|
fileid = process_file_no;
|
2002-07-02 03:36:15 +02:00
|
|
|
if (!fill_filebuf ())
|
2002-09-19 05:30:20 +02:00
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
|
|
|
position = filesize;
|
|
|
|
else
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
success:
|
|
|
|
res = 1;
|
2002-07-01 21:03:26 +02:00
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
2002-05-12 03:37:48 +02:00
|
|
|
set_open_status ();
|
|
|
|
out:
|
|
|
|
syscall_printf ("%d = fhandler_proc::open (%p, %d)", res, flags, mode);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
bool
|
2002-06-30 19:05:48 +02:00
|
|
|
fhandler_process::fill_filebuf ()
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
2003-09-27 04:30:46 +02:00
|
|
|
pinfo p (pid);
|
2002-07-01 01:02:58 +02:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
set_errno (ENOENT);
|
|
|
|
return false;
|
2002-07-01 01:02:58 +02:00
|
|
|
}
|
|
|
|
|
2002-05-12 03:37:48 +02:00
|
|
|
switch (fileid)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
case PROCESS_UID:
|
|
|
|
case PROCESS_GID:
|
|
|
|
case PROCESS_PGID:
|
|
|
|
case PROCESS_SID:
|
|
|
|
case PROCESS_CTTY:
|
|
|
|
case PROCESS_PPID:
|
|
|
|
{
|
2002-10-30 22:05:18 +01:00
|
|
|
filebuf = (char *) realloc (filebuf, bufalloc = 40);
|
2002-05-28 03:55:40 +02:00
|
|
|
int num;
|
|
|
|
switch (fileid)
|
|
|
|
{
|
|
|
|
case PROCESS_PPID:
|
2002-07-02 03:36:15 +02:00
|
|
|
num = p->ppid;
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
|
|
|
case PROCESS_UID:
|
2002-07-02 03:36:15 +02:00
|
|
|
num = p->uid;
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
|
|
|
case PROCESS_PGID:
|
2002-07-02 03:36:15 +02:00
|
|
|
num = p->pgid;
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
|
|
|
case PROCESS_SID:
|
2002-07-02 03:36:15 +02:00
|
|
|
num = p->sid;
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
|
|
|
case PROCESS_GID:
|
2002-07-02 03:36:15 +02:00
|
|
|
num = p->gid;
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
|
|
|
case PROCESS_CTTY:
|
2002-07-02 03:36:15 +02:00
|
|
|
num = p->ctty;
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
|
|
|
default: // what's this here for?
|
|
|
|
num = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__small_sprintf (filebuf, "%d\n", num);
|
|
|
|
filesize = strlen (filebuf);
|
|
|
|
break;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2002-10-30 22:05:18 +01:00
|
|
|
case PROCESS_CMDLINE:
|
|
|
|
{
|
|
|
|
if (filebuf)
|
|
|
|
free (filebuf);
|
2003-03-08 18:56:13 +01:00
|
|
|
size_t fs;
|
|
|
|
filebuf = p->cmdline (fs);
|
|
|
|
filesize = fs;
|
2002-11-05 04:21:32 +01:00
|
|
|
if (!filebuf || !*filebuf)
|
2003-12-26 05:40:52 +01:00
|
|
|
{
|
|
|
|
filebuf = strdup ("<defunct>");
|
|
|
|
filesize = strlen (filebuf) + 1;
|
|
|
|
}
|
2002-10-30 22:05:18 +01:00
|
|
|
break;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
case PROCESS_EXENAME:
|
|
|
|
{
|
2003-11-15 00:40:06 +01:00
|
|
|
filebuf = (char *) realloc (filebuf, bufalloc = CYG_MAX_PATH);
|
2002-07-02 03:36:15 +02:00
|
|
|
if (p->process_state & (PID_ZOMBIE | PID_EXITED))
|
2002-05-28 03:55:40 +02:00
|
|
|
strcpy (filebuf, "<defunct>");
|
|
|
|
else
|
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
mount_table->conv_to_posix_path (p->progname, filebuf, 1);
|
2002-05-28 03:55:40 +02:00
|
|
|
int len = strlen (filebuf);
|
|
|
|
if (len > 4)
|
|
|
|
{
|
|
|
|
char *s = filebuf + len - 4;
|
|
|
|
if (strcasecmp (s, ".exe") == 0)
|
|
|
|
*s = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filesize = strlen (filebuf);
|
|
|
|
break;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
case PROCESS_WINPID:
|
|
|
|
{
|
2002-10-30 22:05:18 +01:00
|
|
|
filebuf = (char *) realloc (filebuf, bufalloc = 40);
|
2002-07-02 03:36:15 +02:00
|
|
|
__small_sprintf (filebuf, "%d\n", p->dwProcessId);
|
2002-05-28 03:55:40 +02:00
|
|
|
filesize = strlen (filebuf);
|
|
|
|
break;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
case PROCESS_WINEXENAME:
|
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
int len = strlen (p->progname);
|
2002-10-30 22:05:18 +01:00
|
|
|
filebuf = (char *) realloc (filebuf, bufalloc = (len + 2));
|
2002-07-02 03:36:15 +02:00
|
|
|
strcpy (filebuf, p->progname);
|
2002-05-28 03:55:40 +02:00
|
|
|
filebuf[len] = '\n';
|
|
|
|
filesize = len + 1;
|
|
|
|
break;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
case PROCESS_STATUS:
|
|
|
|
{
|
2002-10-30 22:05:18 +01:00
|
|
|
filebuf = (char *) realloc (filebuf, bufalloc = 2048);
|
2002-07-02 03:36:15 +02:00
|
|
|
filesize = format_process_status (*p, filebuf, bufalloc);
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
case PROCESS_STAT:
|
|
|
|
{
|
2002-10-30 22:05:18 +01:00
|
|
|
filebuf = (char *) realloc (filebuf, bufalloc = 2048);
|
2002-07-02 03:36:15 +02:00
|
|
|
filesize = format_process_stat (*p, filebuf, bufalloc);
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
case PROCESS_STATM:
|
|
|
|
{
|
2002-10-30 22:05:18 +01:00
|
|
|
filebuf = (char *) realloc (filebuf, bufalloc = 2048);
|
2002-07-02 03:36:15 +02:00
|
|
|
filesize = format_process_statm (*p, filebuf, bufalloc);
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
2002-06-02 08:07:01 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2002-07-01 01:02:58 +02:00
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
return true;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t
|
2002-05-12 03:37:48 +02:00
|
|
|
format_process_stat (_pinfo *p, char *destbuf, size_t maxsize)
|
|
|
|
{
|
2003-11-15 00:40:06 +01:00
|
|
|
char cmd[CYG_MAX_PATH];
|
2002-05-12 03:37:48 +02:00
|
|
|
int state = 'R';
|
|
|
|
unsigned long fault_count = 0UL,
|
2002-05-28 03:55:40 +02:00
|
|
|
utime = 0UL, stime = 0UL,
|
|
|
|
start_time = 0UL,
|
|
|
|
vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL;
|
2002-05-12 03:37:48 +02:00
|
|
|
int priority = 0;
|
|
|
|
if (p->process_state & (PID_ZOMBIE | PID_EXITED))
|
2002-07-02 03:36:15 +02:00
|
|
|
strcpy (cmd, "<defunct>");
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
strcpy (cmd, p->progname);
|
2002-05-12 03:37:48 +02:00
|
|
|
char *last_slash = strrchr (cmd, '\\');
|
|
|
|
if (last_slash != NULL)
|
2002-05-28 03:55:40 +02:00
|
|
|
strcpy (cmd, last_slash + 1);
|
2002-05-12 03:37:48 +02:00
|
|
|
int len = strlen (cmd);
|
|
|
|
if (len > 4)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
char *s = cmd + len - 4;
|
|
|
|
if (strcasecmp (s, ".exe") == 0)
|
|
|
|
*s = 0;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Note: under Windows, a _process_ is always running - it's only _threads_
|
|
|
|
* that get suspended. Therefore the default state is R (runnable).
|
|
|
|
*/
|
|
|
|
if (p->process_state & PID_ZOMBIE)
|
|
|
|
state = 'Z';
|
|
|
|
else if (p->process_state & PID_STOPPED)
|
|
|
|
state = 'T';
|
|
|
|
else if (wincap.is_winnt ())
|
|
|
|
state = get_process_state (p->dwProcessId);
|
2003-07-09 03:33:06 +02:00
|
|
|
if (!wincap.is_winnt ())
|
|
|
|
start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ;
|
|
|
|
else
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
HANDLE hProcess;
|
|
|
|
VM_COUNTERS vmc;
|
|
|
|
KERNEL_USER_TIMES put;
|
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
|
|
|
QUOTA_LIMITS ql;
|
|
|
|
SYSTEM_TIME_OF_DAY_INFORMATION stodi;
|
|
|
|
SYSTEM_PROCESSOR_TIMES spt;
|
|
|
|
hProcess = OpenProcess (PROCESS_VM_READ | PROCESS_QUERY_INFORMATION,
|
2002-05-28 03:55:40 +02:00
|
|
|
FALSE, p->dwProcessId);
|
2002-05-12 03:37:48 +02:00
|
|
|
if (hProcess != NULL)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
2002-05-30 09:45:30 +02:00
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
2002-05-28 03:55:40 +02:00
|
|
|
ProcessVmCounters,
|
|
|
|
(PVOID) &vmc,
|
|
|
|
sizeof vmc, NULL);
|
|
|
|
if (ret == STATUS_SUCCESS)
|
2002-05-30 09:45:30 +02:00
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
2002-05-28 03:55:40 +02:00
|
|
|
ProcessTimes,
|
|
|
|
(PVOID) &put,
|
|
|
|
sizeof put, NULL);
|
|
|
|
if (ret == STATUS_SUCCESS)
|
2002-05-30 09:45:30 +02:00
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
2002-05-28 03:55:40 +02:00
|
|
|
ProcessBasicInformation,
|
|
|
|
(PVOID) &pbi,
|
|
|
|
sizeof pbi, NULL);
|
|
|
|
if (ret == STATUS_SUCCESS)
|
2002-05-30 09:45:30 +02:00
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
2002-05-28 03:55:40 +02:00
|
|
|
ProcessQuotaLimits,
|
|
|
|
(PVOID) &ql,
|
|
|
|
sizeof ql, NULL);
|
|
|
|
CloseHandle (hProcess);
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
DWORD error = GetLastError ();
|
|
|
|
__seterrno_from_win_error (error);
|
2004-09-03 03:53:12 +02:00
|
|
|
debug_printf ("OpenProcess: ret %d", error);
|
2002-05-28 03:55:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
if (ret == STATUS_SUCCESS)
|
2002-05-30 09:45:30 +02:00
|
|
|
ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
|
2002-05-28 03:55:40 +02:00
|
|
|
(PVOID) &stodi,
|
|
|
|
sizeof stodi, NULL);
|
2002-05-12 03:37:48 +02:00
|
|
|
if (ret == STATUS_SUCCESS)
|
2002-05-30 09:45:30 +02:00
|
|
|
ret = NtQuerySystemInformation (SystemProcessorTimes,
|
2002-05-28 03:55:40 +02:00
|
|
|
(PVOID) &spt,
|
|
|
|
sizeof spt, NULL);
|
2002-05-12 03:37:48 +02:00
|
|
|
if (ret != STATUS_SUCCESS)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
2004-09-03 03:53:12 +02:00
|
|
|
debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %d",
|
2002-05-28 03:55:40 +02:00
|
|
|
ret, RtlNtStatusToDosError (ret));
|
|
|
|
return 0;
|
|
|
|
}
|
2003-07-09 03:33:06 +02:00
|
|
|
fault_count = vmc.PageFaultCount;
|
|
|
|
utime = put.UserTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
start_time = (put.CreateTime.QuadPart - stodi.BootTime.QuadPart) * HZ / 10000000ULL;
|
|
|
|
#if 0
|
2002-05-12 03:37:48 +02:00
|
|
|
if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart)
|
2002-09-19 05:30:20 +02:00
|
|
|
start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart -
|
|
|
|
stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / 10000000ULL;
|
2002-05-12 03:37:48 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
/*
|
|
|
|
* sometimes stodi.CurrentTime is a bit behind
|
|
|
|
* Note: some older versions of procps are broken and can't cope
|
|
|
|
* with process start times > time(NULL).
|
|
|
|
*/
|
2003-07-09 03:33:06 +02:00
|
|
|
start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
|
|
|
|
#endif
|
|
|
|
priority = pbi.BasePriority;
|
|
|
|
unsigned page_size = getpagesize ();
|
|
|
|
vmsize = vmc.PagefileUsage;
|
|
|
|
vmrss = vmc.WorkingSetSize / page_size;
|
|
|
|
vmmaxrss = ql.MaximumWorkingSetSize / page_size;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
2003-07-09 03:33:06 +02:00
|
|
|
|
2002-05-12 03:37:48 +02:00
|
|
|
return __small_sprintf (destbuf, "%d (%s) %c "
|
2002-05-28 03:55:40 +02:00
|
|
|
"%d %d %d %d %d "
|
|
|
|
"%lu %lu %lu %lu %lu %lu %lu "
|
|
|
|
"%ld %ld %ld %ld %ld %ld "
|
|
|
|
"%lu %lu "
|
|
|
|
"%ld "
|
|
|
|
"%lu",
|
|
|
|
p->pid, cmd,
|
|
|
|
state,
|
2002-09-25 14:24:23 +02:00
|
|
|
p->ppid, p->pgid, p->sid, makedev (FH_TTYS, p->ctty),
|
|
|
|
-1, 0, fault_count, fault_count, 0, 0, utime, stime,
|
2002-05-28 03:55:40 +02:00
|
|
|
utime, stime, priority, 0, 0, 0,
|
|
|
|
start_time, vmsize,
|
|
|
|
vmrss, vmmaxrss
|
|
|
|
);
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t
|
2002-05-12 03:37:48 +02:00
|
|
|
format_process_status (_pinfo *p, char *destbuf, size_t maxsize)
|
|
|
|
{
|
2003-11-15 00:40:06 +01:00
|
|
|
char cmd[CYG_MAX_PATH];
|
2002-05-12 03:37:48 +02:00
|
|
|
int state = 'R';
|
|
|
|
const char *state_str = "unknown";
|
|
|
|
unsigned long vmsize = 0UL, vmrss = 0UL, vmdata = 0UL, vmlib = 0UL, vmtext = 0UL,
|
2002-05-28 03:55:40 +02:00
|
|
|
vmshare = 0UL;
|
2002-05-12 03:37:48 +02:00
|
|
|
if (p->process_state & (PID_ZOMBIE | PID_EXITED))
|
|
|
|
strcpy (cmd, "<defunct>");
|
|
|
|
else
|
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
strcpy (cmd, p->progname);
|
2002-05-12 03:37:48 +02:00
|
|
|
char *last_slash = strrchr (cmd, '\\');
|
|
|
|
if (last_slash != NULL)
|
2002-05-28 03:55:40 +02:00
|
|
|
strcpy (cmd, last_slash + 1);
|
2002-05-12 03:37:48 +02:00
|
|
|
int len = strlen (cmd);
|
|
|
|
if (len > 4)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
char *s = cmd + len - 4;
|
|
|
|
if (strcasecmp (s, ".exe") == 0)
|
|
|
|
*s = 0;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Note: under Windows, a _process_ is always running - it's only _threads_
|
|
|
|
* that get suspended. Therefore the default state is R (runnable).
|
|
|
|
*/
|
|
|
|
if (p->process_state & PID_ZOMBIE)
|
|
|
|
state = 'Z';
|
|
|
|
else if (p->process_state & PID_STOPPED)
|
|
|
|
state = 'T';
|
|
|
|
else if (wincap.is_winnt ())
|
|
|
|
state = get_process_state (p->dwProcessId);
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case 'O':
|
|
|
|
state_str = "running";
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
case 'S':
|
|
|
|
state_str = "sleeping";
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
state_str = "runnable";
|
|
|
|
break;
|
|
|
|
case 'Z':
|
|
|
|
state_str = "zombie";
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
state_str = "stopped";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (wincap.is_winnt ())
|
|
|
|
{
|
|
|
|
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata, &vmlib, &vmshare))
|
2002-05-28 03:55:40 +02:00
|
|
|
return 0;
|
2002-09-22 05:38:57 +02:00
|
|
|
unsigned page_size = getpagesize ();
|
2002-05-12 03:37:48 +02:00
|
|
|
vmsize *= page_size; vmrss *= page_size; vmdata *= page_size;
|
|
|
|
vmtext *= page_size; vmlib *= page_size;
|
|
|
|
}
|
2002-09-25 14:24:23 +02:00
|
|
|
// The real uid value for *this* process is stored at cygheap->user.real_uid
|
|
|
|
// but we can't get at the real uid value for any other process, so
|
|
|
|
// just fake it as p->uid. Similar for p->gid.
|
2002-05-12 03:37:48 +02:00
|
|
|
return __small_sprintf (destbuf, "Name: %s\n"
|
2002-05-28 03:55:40 +02:00
|
|
|
"State: %c (%s)\n"
|
|
|
|
"Tgid: %d\n"
|
|
|
|
"Pid: %d\n"
|
|
|
|
"PPid: %d\n"
|
|
|
|
"Uid: %d %d %d %d\n"
|
|
|
|
"Gid: %d %d %d %d\n"
|
|
|
|
"VmSize: %8d kB\n"
|
|
|
|
"VmLck: %8d kB\n"
|
|
|
|
"VmRSS: %8d kB\n"
|
|
|
|
"VmData: %8d kB\n"
|
|
|
|
"VmStk: %8d kB\n"
|
|
|
|
"VmExe: %8d kB\n"
|
|
|
|
"VmLib: %8d kB\n"
|
|
|
|
"SigPnd: %016x\n"
|
|
|
|
"SigBlk: %016x\n"
|
|
|
|
"SigIgn: %016x\n",
|
|
|
|
cmd,
|
|
|
|
state, state_str,
|
|
|
|
p->pgid,
|
|
|
|
p->pid,
|
|
|
|
p->ppid,
|
2002-09-25 14:24:23 +02:00
|
|
|
p->uid, p->uid, p->uid, p->uid,
|
|
|
|
p->gid, p->gid, p->gid, p->gid,
|
2002-05-28 03:55:40 +02:00
|
|
|
vmsize >> 10, 0, vmrss >> 10, vmdata >> 10, 0, vmtext >> 10, vmlib >> 10,
|
|
|
|
0, 0, p->getsigmask ()
|
|
|
|
);
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
static _off64_t
|
2002-05-12 03:37:48 +02:00
|
|
|
format_process_statm (_pinfo *p, char *destbuf, size_t maxsize)
|
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL,
|
2002-09-19 05:30:20 +02:00
|
|
|
vmlib = 0UL, vmshare = 0UL;
|
2002-05-12 03:37:48 +02:00
|
|
|
if (wincap.is_winnt ())
|
|
|
|
{
|
2002-07-02 03:36:15 +02:00
|
|
|
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
|
|
|
|
&vmlib, &vmshare))
|
2002-05-28 03:55:40 +02:00
|
|
|
return 0;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
return __small_sprintf (destbuf, "%ld %ld %ld %ld %ld %ld %ld",
|
2002-05-28 03:55:40 +02:00
|
|
|
vmsize, vmrss, vmshare, vmtext, vmlib, vmdata, 0
|
|
|
|
);
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
|
2003-03-08 18:56:13 +01:00
|
|
|
static int
|
2002-05-12 03:37:48 +02:00
|
|
|
get_process_state (DWORD dwProcessId)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This isn't really heavy magic - just go through the processes'
|
|
|
|
* threads one by one and return a value accordingly
|
|
|
|
* Errors are silently ignored.
|
|
|
|
*/
|
|
|
|
NTSTATUS ret;
|
|
|
|
SYSTEM_PROCESSES *sp;
|
|
|
|
ULONG n = 0x1000;
|
|
|
|
PULONG p = new ULONG[n];
|
|
|
|
int state =' ';
|
|
|
|
while (STATUS_INFO_LENGTH_MISMATCH ==
|
2002-05-30 09:45:30 +02:00
|
|
|
(ret = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
|
2002-05-28 03:55:40 +02:00
|
|
|
(PVOID) p,
|
|
|
|
n * sizeof *p, NULL)))
|
2002-05-12 03:37:48 +02:00
|
|
|
delete [] p, p = new ULONG[n *= 2];
|
|
|
|
if (ret != STATUS_SUCCESS)
|
|
|
|
{
|
2004-09-03 03:53:12 +02:00
|
|
|
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d",
|
|
|
|
ret, RtlNtStatusToDosError (ret));
|
2002-05-12 03:37:48 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
state = 'Z';
|
|
|
|
sp = (SYSTEM_PROCESSES *) p;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (sp->ProcessId == dwProcessId)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
SYSTEM_THREADS *st;
|
|
|
|
if (wincap.has_process_io_counters ())
|
|
|
|
/*
|
|
|
|
* Windows 2000 and XP have an extra member in SYSTEM_PROCESSES
|
|
|
|
* which means the offset of the first SYSTEM_THREADS entry is
|
|
|
|
* different on these operating systems compared to NT 4.
|
|
|
|
*/
|
|
|
|
st = &sp->Threads[0];
|
|
|
|
else
|
|
|
|
/*
|
|
|
|
* 136 is the offset of the first SYSTEM_THREADS entry on
|
|
|
|
* Windows NT 4.
|
|
|
|
*/
|
|
|
|
st = (SYSTEM_THREADS *) ((char *) sp + 136);
|
|
|
|
state = 'S';
|
|
|
|
for (unsigned i = 0; i < sp->ThreadCount; i++)
|
|
|
|
{
|
|
|
|
if (st->State == StateRunning ||
|
|
|
|
st->State == StateReady)
|
|
|
|
{
|
|
|
|
state = 'R';
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
st++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
if (!sp->NextEntryDelta)
|
2002-05-28 03:55:40 +02:00
|
|
|
break;
|
2002-05-12 03:37:48 +02:00
|
|
|
sp = (SYSTEM_PROCESSES *) ((char *) sp + sp->NextEntryDelta);
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
out:
|
2002-05-12 03:37:48 +02:00
|
|
|
delete [] p;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2003-03-08 18:56:13 +01:00
|
|
|
static bool
|
2002-09-22 05:38:57 +02:00
|
|
|
get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss,
|
|
|
|
unsigned long *vmtext, unsigned long *vmdata,
|
|
|
|
unsigned long *vmlib, unsigned long *vmshare)
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
|
|
|
bool res = true;
|
|
|
|
NTSTATUS ret;
|
|
|
|
HANDLE hProcess;
|
|
|
|
VM_COUNTERS vmc;
|
|
|
|
MEMORY_WORKING_SET_LIST *mwsl;
|
|
|
|
ULONG n = 0x1000, length;
|
|
|
|
PULONG p = new ULONG[n];
|
2002-09-22 05:38:57 +02:00
|
|
|
unsigned page_size = getpagesize ();
|
2002-05-12 03:37:48 +02:00
|
|
|
hProcess = OpenProcess (PROCESS_QUERY_INFORMATION,
|
2002-05-28 03:55:40 +02:00
|
|
|
FALSE, dwProcessId);
|
2002-05-12 03:37:48 +02:00
|
|
|
if (hProcess == NULL)
|
|
|
|
{
|
2002-09-22 05:38:57 +02:00
|
|
|
DWORD error = GetLastError ();
|
2002-05-12 03:37:48 +02:00
|
|
|
__seterrno_from_win_error (error);
|
2004-09-03 03:53:12 +02:00
|
|
|
debug_printf ("OpenProcess: ret %d", error);
|
2002-05-12 03:37:48 +02:00
|
|
|
return false;
|
|
|
|
}
|
2002-05-30 09:45:30 +02:00
|
|
|
while ((ret = NtQueryVirtualMemory (hProcess, 0,
|
2002-05-28 03:55:40 +02:00
|
|
|
MemoryWorkingSetList,
|
|
|
|
(PVOID) p,
|
|
|
|
n * sizeof *p, &length)),
|
|
|
|
(ret == STATUS_SUCCESS || ret == STATUS_INFO_LENGTH_MISMATCH) &&
|
|
|
|
length >= n * sizeof *p)
|
2002-05-12 03:37:48 +02:00
|
|
|
delete [] p, p = new ULONG[n *= 2];
|
|
|
|
if (ret != STATUS_SUCCESS)
|
|
|
|
{
|
2004-09-03 03:53:12 +02:00
|
|
|
debug_printf ("NtQueryVirtualMemory: ret %d, Dos(ret) %d",
|
2002-05-28 03:55:40 +02:00
|
|
|
ret, RtlNtStatusToDosError (ret));
|
2002-05-12 03:37:48 +02:00
|
|
|
res = false;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
mwsl = (MEMORY_WORKING_SET_LIST *) p;
|
|
|
|
for (unsigned long i = 0; i < mwsl->NumberOfPages; i++)
|
|
|
|
{
|
|
|
|
++*vmrss;
|
|
|
|
unsigned flags = mwsl->WorkingSetList[i] & 0x0FFF;
|
|
|
|
if (flags & (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE) == (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE))
|
2002-05-28 03:55:40 +02:00
|
|
|
++*vmlib;
|
2002-05-12 03:37:48 +02:00
|
|
|
else if (flags & WSLE_PAGE_SHAREABLE)
|
2002-05-28 03:55:40 +02:00
|
|
|
++*vmshare;
|
2002-05-12 03:37:48 +02:00
|
|
|
else if (flags & WSLE_PAGE_EXECUTE)
|
2002-05-28 03:55:40 +02:00
|
|
|
++*vmtext;
|
2002-05-12 03:37:48 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
++*vmdata;
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
2002-05-30 09:45:30 +02:00
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
2002-05-28 03:55:40 +02:00
|
|
|
ProcessVmCounters,
|
|
|
|
(PVOID) &vmc,
|
|
|
|
sizeof vmc, NULL);
|
2002-05-12 03:37:48 +02:00
|
|
|
if (ret != STATUS_SUCCESS)
|
|
|
|
{
|
2004-09-03 03:53:12 +02:00
|
|
|
debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %d",
|
2002-09-22 05:38:57 +02:00
|
|
|
ret, RtlNtStatusToDosError (ret));
|
2002-05-12 03:37:48 +02:00
|
|
|
res = false;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-05-24 22:14:19 +02:00
|
|
|
*vmsize = vmc.PagefileUsage / page_size;
|
2002-05-12 03:37:48 +02:00
|
|
|
out:
|
|
|
|
delete [] p;
|
|
|
|
CloseHandle (hProcess);
|
2002-05-02 06:26:05 +02:00
|
|
|
return res;
|
|
|
|
}
|