2002-05-02 12:26:05 +08:00
|
|
|
/* fhandler_process.cc: fhandler for /proc/<pid> virtual filesystem
|
|
|
|
|
Drop NT4 support.
* autoload.cc (DnsQuery_A): Fatal if not available.
(DnsRecordListFree): Ditto.
(DsGetDcNameW): Ditto.
(NetGetAnyDCName): Remove.
(NetGetDCName): Remove.
(EnumProcessModules): Fatal if not available.
(GetModuleFileNameExW): Ditto.
(GetModuleInformation): Ditto.
(GetProcessMemoryInfo): Ditto.
(QueryWorkingSet): Ditto.
(LsaRegisterLogonProcess): Ditto.
* fenv.cc (_feinitialise): Drop supports_sse condition.
* fhandler_disk_file.cc (path_conv::isgood_inode): Fix comment.
(fhandler_base::fstat_by_name): Drop has_fileid_dirinfo condition.
(fhandler_disk_file::opendir): Ditto.
* fhandler_netdrive.cc (fhandler_netdrive::readdir): Fix comment.
* fhandler_proc.cc (format_proc_partitions): Drop NT4-only code.
* fhandler_process.cc (get_process_state): Ditto.
* kernel32.cc (GetWindowsDirectoryW): Remove.
(GetWindowsDirectoryA): Remove.
* miscfuncs.cc (nice_to_winprio): Drop NT4-only code.
* mount.cc (fs_info::update): Fix comments.
* net.cc (get_2k_ifs): Drop NT4-only code.
* sec_auth.cc (get_logon_server): Ditto.
(lsaauth): Drop NT4-specific error handling.
* security.cc (alloc_sd): Set SE_DACL_PROTECTED unconditionally.
* select.cc (select_stuff::wait): Always use MWMO_INPUTAVAILABLE.
(peek_windows): Drop NT4-only condition in call to PeekMessage.
* syscalls.cc (gethostid): Remove NT4-only workaround.
* wincap.cc: Througout, drop has_dacl_protect,
has_broken_if_oper_status, has_process_io_counters,
has_terminal_services, has_extended_priority_class, has_guid_volumes,
has_fileid_dirinfo, has_mwmo_inputavailable and supports_sse from
wincaps.
(wincap_nt4sp4): Remove.
(wincap_minimal): Set to wincap_2000.
(wincapc::init): Rely on availability of OSVERSIONINFOEX structure.
Treat error from GetVersionEx as fatal. Treat NT4 as fatal.
* wincap.h (struct wincaps): Drop has_dacl_protect,
has_broken_if_oper_status, has_process_io_counters,
has_terminal_services, has_extended_priority_class, has_guid_volumes,
has_fileid_dirinfo, has_mwmo_inputavailable and supports_sse flags
and methods.
* winlean.h (GetWindowsDirectoryW) Define as GetSystemWindowsDirectoryW.
(GetWindowsDirectoryA): Define as GetSystemWindowsDirectoryA.
2011-04-04 20:23:36 +08:00
|
|
|
Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
|
|
|
2010, 2011 Red Hat, Inc.
|
2002-05-02 12:26:05 +08: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 <stdlib.h>
|
2009-02-05 00:40:04 +08:00
|
|
|
#include <stdio.h>
|
2002-05-02 12:26:05 +08:00
|
|
|
#include <sys/cygwin.h>
|
|
|
|
#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 08:37:18 +08:00
|
|
|
#include "path.h"
|
2002-05-02 12:26:05 +08:00
|
|
|
#include "fhandler.h"
|
2009-01-21 01:22:11 +08:00
|
|
|
#include "fhandler_virtual.h"
|
2002-05-02 12:26:05 +08:00
|
|
|
#include "pinfo.h"
|
|
|
|
#include "shared_info.h"
|
2002-05-04 11:24:35 +08:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2002-05-12 09:37:48 +08:00
|
|
|
#include "ntdll.h"
|
2008-02-16 01:53:11 +08:00
|
|
|
#include "cygtls.h"
|
2009-02-05 00:40:04 +08:00
|
|
|
#include "pwdgrp.h"
|
2008-03-07 19:24:51 +08:00
|
|
|
#include "tls_pbuf.h"
|
2002-09-01 00:37:51 +08:00
|
|
|
#include <sys/param.h>
|
2005-01-31 18:28:55 +08:00
|
|
|
#include <ctype.h>
|
2005-01-29 19:23:07 +08:00
|
|
|
#include <psapi.h>
|
2011-05-11 18:31:22 +08:00
|
|
|
#include <tlhelp32.h>
|
2002-05-02 12:26:05 +08:00
|
|
|
|
|
|
|
#define _COMPILING_NEWLIB
|
|
|
|
#include <dirent.h>
|
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
static _off64_t format_process_maps (void *, char *&);
|
|
|
|
static _off64_t format_process_stat (void *, char *&);
|
|
|
|
static _off64_t format_process_status (void *, char *&);
|
|
|
|
static _off64_t format_process_statm (void *, char *&);
|
|
|
|
static _off64_t format_process_winexename (void *, char *&);
|
|
|
|
static _off64_t format_process_winpid (void *, char *&);
|
|
|
|
static _off64_t format_process_exename (void *, char *&);
|
|
|
|
static _off64_t format_process_root (void *, char *&);
|
|
|
|
static _off64_t format_process_cwd (void *, char *&);
|
|
|
|
static _off64_t format_process_cmdline (void *, char *&);
|
|
|
|
static _off64_t format_process_ppid (void *, char *&);
|
|
|
|
static _off64_t format_process_uid (void *, char *&);
|
|
|
|
static _off64_t format_process_pgid (void *, char *&);
|
|
|
|
static _off64_t format_process_sid (void *, char *&);
|
|
|
|
static _off64_t format_process_gid (void *, char *&);
|
|
|
|
static _off64_t format_process_ctty (void *, char *&);
|
|
|
|
static _off64_t format_process_fd (void *, char *&);
|
2009-02-05 00:40:04 +08:00
|
|
|
static _off64_t format_process_mounts (void *, char *&);
|
2009-01-21 01:22:11 +08:00
|
|
|
|
|
|
|
static const virt_tab_t process_tab[] =
|
2002-07-02 09:36:15 +08:00
|
|
|
{
|
2010-09-06 17:47:01 +08:00
|
|
|
{ _VN ("."), FH_PROCESS, virt_directory, NULL },
|
|
|
|
{ _VN (".."), FH_PROCESS, virt_directory, NULL },
|
|
|
|
{ _VN ("cmdline"), FH_PROCESS, virt_file, format_process_cmdline },
|
|
|
|
{ _VN ("ctty"), FH_PROCESS, virt_file, format_process_ctty },
|
|
|
|
{ _VN ("cwd"), FH_PROCESS, virt_symlink, format_process_cwd },
|
|
|
|
{ _VN ("exe"), FH_PROCESS, virt_symlink, format_process_exename },
|
|
|
|
{ _VN ("exename"), FH_PROCESS, virt_file, format_process_exename },
|
|
|
|
{ _VN ("fd"), FH_PROCESSFD, virt_directory, format_process_fd },
|
|
|
|
{ _VN ("gid"), FH_PROCESS, virt_file, format_process_gid },
|
|
|
|
{ _VN ("maps"), FH_PROCESS, virt_file, format_process_maps },
|
|
|
|
{ _VN ("mounts"), FH_PROCESS, virt_file, format_process_mounts },
|
|
|
|
{ _VN ("pgid"), FH_PROCESS, virt_file, format_process_pgid },
|
|
|
|
{ _VN ("ppid"), FH_PROCESS, virt_file, format_process_ppid },
|
|
|
|
{ _VN ("root"), FH_PROCESS, virt_symlink, format_process_root },
|
|
|
|
{ _VN ("sid"), FH_PROCESS, virt_file, format_process_sid },
|
|
|
|
{ _VN ("stat"), FH_PROCESS, virt_file, format_process_stat },
|
|
|
|
{ _VN ("statm"), FH_PROCESS, virt_file, format_process_statm },
|
|
|
|
{ _VN ("status"), FH_PROCESS, virt_file, format_process_status },
|
|
|
|
{ _VN ("uid"), FH_PROCESS, virt_file, format_process_uid },
|
|
|
|
{ _VN ("winexename"), FH_PROCESS, virt_file, format_process_winexename },
|
|
|
|
{ _VN ("winpid"), FH_PROCESS, virt_file, format_process_winpid },
|
|
|
|
{ NULL, 0, 0, virt_none, NULL }
|
2002-05-02 12:26:05 +08:00
|
|
|
};
|
|
|
|
|
2002-07-02 09:36:15 +08:00
|
|
|
static const int PROCESS_LINK_COUNT =
|
2009-01-21 01:22:11 +08:00
|
|
|
(sizeof (process_tab) / sizeof (virt_tab_t)) - 1;
|
2011-04-01 17:00:21 +08:00
|
|
|
int get_process_state (DWORD dwProcessId);
|
2002-09-22 11:38:57 +08: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 09:37:48 +08:00
|
|
|
|
2002-05-02 12:26:05 +08:00
|
|
|
/* Returns 0 if path doesn't exist, >0 if path is a directory,
|
2005-02-01 23:11:47 +08:00
|
|
|
* -1 if path is a file, -2 if path is a symlink, -3 if path is a pipe,
|
|
|
|
* -4 if path is a socket.
|
2002-05-02 12:26:05 +08:00
|
|
|
*/
|
2010-09-06 17:47:01 +08:00
|
|
|
virtual_ftype_t
|
2002-05-23 06:09:58 +08:00
|
|
|
fhandler_process::exists ()
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2002-05-23 06:09:58 +08:00
|
|
|
const char *path = get_name ();
|
2002-05-02 12:26:05 +08:00
|
|
|
debug_printf ("exists (%s)", path);
|
|
|
|
path += proc_len + 1;
|
2003-01-09 16:22:05 +08:00
|
|
|
while (*path != 0 && !isdirsep (*path))
|
2002-05-02 12:26:05 +08:00
|
|
|
path++;
|
|
|
|
if (*path == 0)
|
2010-09-06 17:47:01 +08:00
|
|
|
return virt_rootdir;
|
2002-05-02 12:26:05 +08:00
|
|
|
|
2010-09-06 17:47:01 +08:00
|
|
|
virt_tab_t *entry = virt_tab_search (path + 1, true, process_tab,
|
|
|
|
PROCESS_LINK_COUNT);
|
|
|
|
if (entry)
|
2009-01-21 01:22:11 +08:00
|
|
|
{
|
2010-09-06 17:47:01 +08:00
|
|
|
if (!path[entry->name_len + 1])
|
2005-05-02 11:50:11 +08:00
|
|
|
{
|
2010-09-06 17:47:01 +08:00
|
|
|
fileid = entry - process_tab;
|
|
|
|
return entry->type;
|
2009-01-21 01:22:11 +08:00
|
|
|
}
|
2010-09-06 17:47:01 +08:00
|
|
|
if (entry->type == virt_directory)
|
2009-01-21 01:22:11 +08:00
|
|
|
{
|
2010-09-06 17:47:01 +08:00
|
|
|
fileid = entry - process_tab;
|
2009-01-21 01:22:11 +08:00
|
|
|
if (fill_filebuf ())
|
|
|
|
return virt_symlink;
|
|
|
|
/* Check for nameless device entries. */
|
|
|
|
path = strrchr (path, '/');
|
|
|
|
if (path && *++path)
|
|
|
|
{
|
|
|
|
if (!strncmp (path, "pipe:[", 6))
|
|
|
|
return virt_pipe;
|
|
|
|
else if (!strncmp (path, "socket:[", 8))
|
|
|
|
return virt_socket;
|
|
|
|
}
|
2005-02-01 23:11:47 +08:00
|
|
|
}
|
2005-01-31 18:28:55 +08:00
|
|
|
}
|
2009-01-21 01:22:11 +08:00
|
|
|
return virt_none;
|
2002-05-02 12:26:05 +08: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 08:37:18 +08:00
|
|
|
fhandler_proc ()
|
2002-05-02 12:26:05 +08: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 08:37:18 +08:00
|
|
|
fhandler_process::fstat (struct __stat64 *buf)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2002-05-12 09:37:48 +08:00
|
|
|
const char *path = get_name ();
|
2002-05-23 06:09:58 +08:00
|
|
|
int file_type = exists ();
|
2005-07-07 04:05:03 +08:00
|
|
|
fhandler_base::fstat (buf);
|
2002-05-12 09:37:48 +08:00
|
|
|
path += proc_len + 1;
|
2005-01-31 18:28:55 +08:00
|
|
|
pid = atoi (path);
|
2002-06-02 11:13:22 +08:00
|
|
|
pinfo p (pid);
|
|
|
|
if (!p)
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2002-07-01 07:02:58 +08:00
|
|
|
set_errno (ENOENT);
|
2002-06-02 11:13:22 +08:00
|
|
|
return -1;
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
2002-06-02 11:13:22 +08:00
|
|
|
|
2002-05-03 07:58:20 +08:00
|
|
|
buf->st_mode &= ~_IFMT & NO_W;
|
|
|
|
|
2002-05-02 12:26:05 +08:00
|
|
|
switch (file_type)
|
|
|
|
{
|
2009-01-21 01:22:11 +08:00
|
|
|
case virt_none:
|
2002-05-02 12:26:05 +08:00
|
|
|
set_errno (ENOENT);
|
|
|
|
return -1;
|
2009-01-21 01:22:11 +08:00
|
|
|
case virt_directory:
|
|
|
|
case virt_rootdir:
|
2007-03-06 22:48:25 +08:00
|
|
|
buf->st_ctime = buf->st_mtime = buf->st_birthtime = p->start_time;
|
|
|
|
buf->st_ctim.tv_nsec = buf->st_mtim.tv_nsec
|
|
|
|
= buf->st_birthtim.tv_nsec = 0;
|
2002-09-22 11:38:57 +08:00
|
|
|
time_as_timestruc_t (&buf->st_atim);
|
2002-05-12 09:37:48 +08:00
|
|
|
buf->st_uid = p->uid;
|
|
|
|
buf->st_gid = p->gid;
|
2002-05-03 07:58:20 +08:00
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
2005-01-31 18:28:55 +08:00
|
|
|
if (file_type == 1)
|
|
|
|
buf->st_nlink = 2;
|
|
|
|
else
|
|
|
|
buf->st_nlink = 3;
|
2002-05-02 12:26:05 +08:00
|
|
|
return 0;
|
2009-01-21 01:22:11 +08:00
|
|
|
case virt_symlink:
|
2005-01-29 19:23:07 +08:00
|
|
|
buf->st_uid = p->uid;
|
|
|
|
buf->st_gid = p->gid;
|
|
|
|
buf->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
|
|
|
|
return 0;
|
2009-01-21 01:22:11 +08:00
|
|
|
case virt_pipe:
|
2005-02-01 23:11:47 +08:00
|
|
|
buf->st_uid = p->uid;
|
|
|
|
buf->st_gid = p->gid;
|
|
|
|
buf->st_mode = S_IFIFO | S_IRUSR | S_IWUSR;
|
|
|
|
return 0;
|
2009-01-21 01:22:11 +08:00
|
|
|
case virt_socket:
|
2005-02-01 23:11:47 +08:00
|
|
|
buf->st_uid = p->uid;
|
|
|
|
buf->st_gid = p->gid;
|
|
|
|
buf->st_mode = S_IFSOCK | S_IRUSR | S_IWUSR;
|
|
|
|
return 0;
|
2009-01-21 01:22:11 +08:00
|
|
|
case virt_file:
|
2005-01-29 19:23:07 +08:00
|
|
|
default:
|
2002-05-12 09:37:48 +08: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 12:26:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-31 18:28:55 +08:00
|
|
|
DIR *
|
2007-06-29 23:13:01 +08:00
|
|
|
fhandler_process::opendir (int fd)
|
2005-01-31 18:28:55 +08:00
|
|
|
{
|
2007-06-29 23:13:01 +08:00
|
|
|
DIR *dir = fhandler_virtual::opendir (fd);
|
2009-01-21 01:22:11 +08:00
|
|
|
if (dir && process_tab[fileid].fhandler == FH_PROCESSFD)
|
2007-06-29 23:13:01 +08:00
|
|
|
fill_filebuf ();
|
2005-01-31 18:28:55 +08:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2005-08-20 14:19:55 +08:00
|
|
|
int
|
|
|
|
fhandler_process::readdir (DIR *dir, dirent *de)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2005-08-20 14:19:55 +08:00
|
|
|
int res = ENMFILE;
|
2009-01-21 01:22:11 +08:00
|
|
|
if (process_tab[fileid].fhandler == FH_PROCESSFD)
|
2005-01-31 18:28:55 +08:00
|
|
|
{
|
|
|
|
if (dir->__d_position >= 2 + filesize / sizeof (int))
|
2005-08-20 14:19:55 +08:00
|
|
|
goto out;
|
2005-01-31 18:28:55 +08:00
|
|
|
}
|
|
|
|
else if (dir->__d_position >= PROCESS_LINK_COUNT)
|
2005-08-20 14:19:55 +08:00
|
|
|
goto out;
|
2009-01-21 01:22:11 +08:00
|
|
|
if (process_tab[fileid].fhandler == FH_PROCESSFD && dir->__d_position > 1)
|
2005-01-31 18:28:55 +08:00
|
|
|
{
|
|
|
|
int *p = (int *) filebuf;
|
2005-08-20 14:19:55 +08:00
|
|
|
__small_sprintf (de->d_name, "%d", p[dir->__d_position++ - 2]);
|
2005-01-31 18:28:55 +08:00
|
|
|
}
|
|
|
|
else
|
2009-01-21 01:22:11 +08:00
|
|
|
strcpy (de->d_name, process_tab[dir->__d_position++].name);
|
2006-01-28 05:50:42 +08:00
|
|
|
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
|
2005-08-20 14:19:55 +08:00
|
|
|
res = 0;
|
|
|
|
out:
|
2006-01-04 11:43:55 +08:00
|
|
|
syscall_printf ("%d = readdir (%p, %p) (%s)", res, dir, de, de->d_name);
|
2005-08-20 14:19:55 +08:00
|
|
|
return res;
|
2002-05-02 12:26:05 +08: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 08:37:18 +08:00
|
|
|
fhandler_process::open (int flags, mode_t mode)
|
2002-05-02 12:26:05 +08: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 08:37:18 +08:00
|
|
|
int res = fhandler_virtual::open (flags, mode);
|
2002-05-02 12:26:05 +08:00
|
|
|
if (!res)
|
|
|
|
goto out;
|
|
|
|
|
2004-04-10 21:45:10 +08:00
|
|
|
nohandle (true);
|
2002-07-02 09:36:15 +08:00
|
|
|
|
2002-05-02 12:26:05 +08:00
|
|
|
const char *path;
|
2002-05-03 10:43:45 +08:00
|
|
|
path = get_name () + proc_len + 1;
|
2005-01-31 18:28:55 +08:00
|
|
|
pid = atoi (path);
|
2003-01-09 16:22:05 +08:00
|
|
|
while (*path != 0 && !isdirsep (*path))
|
2002-05-02 12:26:05 +08:00
|
|
|
path++;
|
|
|
|
|
|
|
|
if (*path == 0)
|
|
|
|
{
|
2002-05-04 11:24:35 +08:00
|
|
|
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
set_errno (EEXIST);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-04 11:24:35 +08:00
|
|
|
else if (flags & O_WRONLY)
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
else
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
flags |= O_DIROPEN;
|
|
|
|
goto success;
|
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
|
|
|
|
2010-09-06 17:47:01 +08:00
|
|
|
virt_tab_t *entry;
|
|
|
|
entry = virt_tab_search (path + 1, true, process_tab, PROCESS_LINK_COUNT);
|
|
|
|
if (!entry)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2010-09-06 17:47:01 +08:00
|
|
|
set_errno ((flags & O_CREAT) ? EROFS : ENOENT);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
2010-09-06 17:47:01 +08:00
|
|
|
if (entry->fhandler == FH_PROCESSFD)
|
2005-02-01 23:11:47 +08:00
|
|
|
{
|
2005-08-08 23:33:32 +08:00
|
|
|
flags |= O_DIROPEN;
|
|
|
|
goto success;
|
2005-02-01 23:11:47 +08:00
|
|
|
}
|
2002-05-04 11:24:35 +08:00
|
|
|
if (flags & O_WRONLY)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-09-06 17:47:01 +08:00
|
|
|
fileid = entry - process_tab;
|
2002-07-02 09:36:15 +08:00
|
|
|
if (!fill_filebuf ())
|
2002-09-19 11:30:20 +08:00
|
|
|
{
|
2002-07-02 09:36:15 +08:00
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-12 09:37:48 +08:00
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
|
|
|
position = filesize;
|
|
|
|
else
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
success:
|
|
|
|
res = 1;
|
2002-07-02 03:03:26 +08:00
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
2002-05-12 09:37:48 +08:00
|
|
|
set_open_status ();
|
|
|
|
out:
|
|
|
|
syscall_printf ("%d = fhandler_proc::open (%p, %d)", res, flags, mode);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
struct process_fd_t {
|
|
|
|
const char *path;
|
|
|
|
_pinfo *p;
|
|
|
|
};
|
|
|
|
|
2002-07-02 09:36:15 +08:00
|
|
|
bool
|
2002-07-01 01:05:48 +08:00
|
|
|
fhandler_process::fill_filebuf ()
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2005-01-31 18:28:55 +08:00
|
|
|
const char *path;
|
|
|
|
path = get_name () + proc_len + 1;
|
2005-01-29 19:23:07 +08:00
|
|
|
if (!pid)
|
2005-01-31 18:28:55 +08:00
|
|
|
pid = atoi (path);
|
|
|
|
|
2003-09-27 10:30:46 +08:00
|
|
|
pinfo p (pid);
|
2002-07-01 07:02:58 +08:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
{
|
2002-07-02 09:36:15 +08:00
|
|
|
set_errno (ENOENT);
|
|
|
|
return false;
|
2002-07-01 07:02:58 +08:00
|
|
|
}
|
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
if (process_tab[fileid].format_func)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2009-01-21 01:22:11 +08:00
|
|
|
if (process_tab[fileid].fhandler == FH_PROCESSFD)
|
|
|
|
{
|
|
|
|
process_fd_t fd = { path, p };
|
|
|
|
filesize = process_tab[fileid].format_func (&fd, filebuf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
filesize = process_tab[fileid].format_func (p, filebuf);
|
|
|
|
return !filesize ? false : true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_fd (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = ((process_fd_t *) data)->p;
|
|
|
|
const char *path = ((process_fd_t *) data)->path;
|
|
|
|
size_t fs = 0;
|
|
|
|
char *fdp = strrchr (path, '/');
|
|
|
|
|
|
|
|
if (!fdp || *++fdp == 'f') /* The "fd" directory itself. */
|
|
|
|
{
|
|
|
|
if (destbuf)
|
|
|
|
cfree (destbuf);
|
|
|
|
destbuf = p->fds (fs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (destbuf)
|
|
|
|
cfree (destbuf);
|
|
|
|
int fd = atoi (fdp);
|
|
|
|
if (fd < 0 || (fd == 0 && !isdigit (*fdp)))
|
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
destbuf = p->fd (fd, fs);
|
|
|
|
if (!destbuf || !*destbuf)
|
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_ppid (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 40);
|
|
|
|
return __small_sprintf (destbuf, "%d\n", p->ppid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_uid (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 40);
|
|
|
|
return __small_sprintf (destbuf, "%d\n", p->uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_pgid (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 40);
|
|
|
|
return __small_sprintf (destbuf, "%d\n", p->pgid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_sid (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 40);
|
|
|
|
return __small_sprintf (destbuf, "%d\n", p->sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_gid (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 40);
|
|
|
|
return __small_sprintf (destbuf, "%d\n", p->gid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_ctty (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 40);
|
|
|
|
return __small_sprintf (destbuf, "%d\n", p->ctty);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_root (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
size_t fs;
|
|
|
|
|
|
|
|
if (destbuf)
|
|
|
|
{
|
|
|
|
cfree (destbuf);
|
|
|
|
destbuf = NULL;
|
|
|
|
}
|
|
|
|
destbuf = p->root (fs);
|
|
|
|
if (!destbuf || !*destbuf)
|
|
|
|
{
|
|
|
|
destbuf = cstrdup ("<defunct>");
|
|
|
|
fs = strlen (destbuf) + 1;
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
2009-01-21 01:22:11 +08:00
|
|
|
return fs;
|
|
|
|
}
|
2002-07-01 07:02:58 +08:00
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
static _off64_t
|
|
|
|
format_process_cwd (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
size_t fs;
|
|
|
|
|
|
|
|
if (destbuf)
|
|
|
|
{
|
|
|
|
cfree (destbuf);
|
|
|
|
destbuf = NULL;
|
|
|
|
}
|
|
|
|
destbuf = p->cwd (fs);
|
|
|
|
if (!destbuf || !*destbuf)
|
|
|
|
{
|
|
|
|
destbuf = cstrdup ("<defunct>");
|
|
|
|
fs = strlen (destbuf) + 1;
|
|
|
|
}
|
|
|
|
return fs;
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
|
2005-01-29 19:23:07 +08:00
|
|
|
static _off64_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_process_cmdline (void *data, char *&destbuf)
|
2005-01-29 19:23:07 +08:00
|
|
|
{
|
2009-01-21 01:22:11 +08:00
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
size_t fs;
|
|
|
|
|
|
|
|
if (destbuf)
|
|
|
|
{
|
|
|
|
cfree (destbuf);
|
|
|
|
destbuf = NULL;
|
|
|
|
}
|
|
|
|
destbuf = p->cmdline (fs);
|
|
|
|
if (!destbuf || !*destbuf)
|
|
|
|
{
|
|
|
|
destbuf = cstrdup ("<defunct>");
|
|
|
|
fs = strlen (destbuf) + 1;
|
|
|
|
}
|
|
|
|
return fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_exename (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
int len;
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
if (p->process_state & PID_EXITED)
|
|
|
|
stpcpy (buf, "<defunct>");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mount_table->conv_to_posix_path (p->progname, buf, 1);
|
|
|
|
len = strlen (buf);
|
|
|
|
if (len > 4)
|
|
|
|
{
|
|
|
|
char *s = buf + len - 4;
|
|
|
|
if (ascii_strcasematch (s, ".exe"))
|
|
|
|
*s = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, (len = strlen (buf)) + 1);
|
|
|
|
stpcpy (destbuf, buf);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_winpid (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 20);
|
|
|
|
return __small_sprintf (destbuf, "%d\n", p->dwProcessId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_winexename (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
2010-05-18 22:30:51 +08:00
|
|
|
size_t len = sys_wcstombs (NULL, 0, p->progname);
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, len + 1);
|
|
|
|
sys_wcstombs (destbuf, len, p->progname);
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf[len] = '\n';
|
|
|
|
return len + 1;
|
|
|
|
}
|
|
|
|
|
2011-05-11 18:31:22 +08:00
|
|
|
struct dos_drive_mappings
|
|
|
|
{
|
|
|
|
struct mapping
|
|
|
|
{
|
|
|
|
mapping *next;
|
|
|
|
int len;
|
|
|
|
wchar_t drive_letter;
|
|
|
|
wchar_t mapping[1];
|
|
|
|
};
|
|
|
|
mapping *mappings;
|
|
|
|
|
|
|
|
dos_drive_mappings ()
|
|
|
|
: mappings(0)
|
|
|
|
{
|
|
|
|
/* The logical drive strings buffer holds a list of (at most 26)
|
|
|
|
drive names separated by nulls and terminated by a double-null:
|
|
|
|
|
|
|
|
"a:\\\0b:\\\0...z:\\\0"
|
|
|
|
|
|
|
|
The annoying part is, QueryDosDeviceW wants only "x:" rather
|
|
|
|
than the "x:\" we get back from GetLogicalDriveStringsW, so
|
|
|
|
we'll have to strip out the trailing slash for each mapping.
|
|
|
|
|
|
|
|
The returned mapping a native NT pathname (\Device\...) which
|
|
|
|
we can use to fix up the output of GetMappedFileNameW
|
|
|
|
*/
|
|
|
|
static unsigned const DBUFLEN = 26 * 4;
|
|
|
|
wchar_t dbuf[DBUFLEN + 1];
|
|
|
|
wchar_t pbuf[NT_MAX_PATH];
|
|
|
|
wchar_t drive[] = {L'x', L':', 0};
|
|
|
|
unsigned result = GetLogicalDriveStringsW (DBUFLEN * sizeof (wchar_t),
|
|
|
|
dbuf);
|
|
|
|
if (!result)
|
|
|
|
debug_printf ("Failed to get logical DOS drive names: %lu",
|
|
|
|
GetLastError ());
|
|
|
|
else if (result > DBUFLEN)
|
|
|
|
debug_printf ("Too many mapped drive letters: %u", result);
|
|
|
|
else
|
|
|
|
for (wchar_t *cur = dbuf; (*drive = *cur); cur = wcschr (cur, L'\0')+1)
|
|
|
|
if (QueryDosDeviceW (drive, pbuf, NT_MAX_PATH))
|
|
|
|
{
|
|
|
|
size_t plen = wcslen (pbuf);
|
|
|
|
size_t psize = plen * sizeof (wchar_t);
|
|
|
|
debug_printf ("DOS drive %ls maps to %ls", drive, pbuf);
|
2011-05-21 23:57:16 +08:00
|
|
|
mapping *m = (mapping*) malloc (sizeof (mapping) + psize);
|
|
|
|
if (m)
|
|
|
|
{
|
|
|
|
m->next = mappings;
|
|
|
|
m->len = plen;
|
|
|
|
m->drive_letter = *drive;
|
|
|
|
memcpy (m->mapping, pbuf, psize + sizeof (wchar_t));
|
|
|
|
mappings = m;
|
|
|
|
}
|
2011-05-11 18:31:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
debug_printf ("Unable to determine the native mapping for %ls "
|
|
|
|
"(error %lu)", drive, GetLastError ());
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar_t *fixup_if_match (wchar_t *path)
|
|
|
|
{
|
|
|
|
for (mapping *m = mappings; m; m = m->next)
|
|
|
|
if (!wcsncmp (m->mapping, path, m->len))
|
|
|
|
{
|
|
|
|
path += m->len - 2;
|
|
|
|
path[0] = m->drive_letter;
|
|
|
|
path[1] = L':';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
~dos_drive_mappings ()
|
|
|
|
{
|
|
|
|
mapping *n = 0;
|
|
|
|
for (mapping *m = mappings; m; m = n)
|
|
|
|
{
|
|
|
|
n = m->next;
|
2011-05-21 23:57:16 +08:00
|
|
|
free (m);
|
2011-05-11 18:31:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct heap_info
|
|
|
|
{
|
|
|
|
struct heap
|
|
|
|
{
|
|
|
|
heap *next;
|
2011-05-13 14:50:20 +08:00
|
|
|
unsigned heap_id;
|
2011-05-21 02:07:52 +08:00
|
|
|
char *base;
|
|
|
|
char *end;
|
2011-05-13 14:50:20 +08:00
|
|
|
unsigned long flags;
|
2011-05-11 18:31:22 +08:00
|
|
|
};
|
2011-05-13 14:50:20 +08:00
|
|
|
heap *heap_vm_chunks;
|
2011-05-11 18:31:22 +08:00
|
|
|
|
|
|
|
heap_info (DWORD pid)
|
2011-05-21 02:07:52 +08:00
|
|
|
: heap_vm_chunks (NULL)
|
2011-05-11 18:31:22 +08:00
|
|
|
{
|
2011-05-13 14:50:20 +08:00
|
|
|
PDEBUG_BUFFER buf;
|
|
|
|
NTSTATUS status;
|
|
|
|
PDEBUG_HEAP_ARRAY harray;
|
|
|
|
|
|
|
|
buf = RtlCreateQueryDebugBuffer (0, FALSE);
|
|
|
|
if (!buf)
|
|
|
|
return;
|
|
|
|
status = RtlQueryProcessDebugInformation (pid, PDI_HEAPS | PDI_HEAP_BLOCKS,
|
|
|
|
buf);
|
|
|
|
if (NT_SUCCESS (status)
|
|
|
|
&& (harray = (PDEBUG_HEAP_ARRAY) buf->HeapInformation) != NULL)
|
|
|
|
for (ULONG hcnt = 0; hcnt < harray->Count; ++hcnt)
|
|
|
|
{
|
|
|
|
PDEBUG_HEAP_BLOCK barray = (PDEBUG_HEAP_BLOCK)
|
|
|
|
harray->Heaps[hcnt].Blocks;
|
|
|
|
if (!barray)
|
|
|
|
continue;
|
|
|
|
for (ULONG bcnt = 0; bcnt < harray->Heaps[hcnt].BlockCount; ++bcnt)
|
|
|
|
if (barray[bcnt].Flags & 2)
|
|
|
|
{
|
2011-05-21 23:57:16 +08:00
|
|
|
heap *h = (heap *) malloc (sizeof (heap));
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
*h = (heap) { heap_vm_chunks,
|
|
|
|
hcnt, (char *) barray[bcnt].Address,
|
|
|
|
(char *) barray[bcnt].Address
|
|
|
|
+ barray[bcnt].Size,
|
|
|
|
harray->Heaps[hcnt].Flags };
|
|
|
|
heap_vm_chunks = h;
|
|
|
|
}
|
2011-05-13 14:50:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
RtlDestroyQueryDebugBuffer (buf);
|
2011-05-11 18:31:22 +08:00
|
|
|
}
|
|
|
|
|
2011-05-21 02:07:52 +08:00
|
|
|
char *fill_if_match (char *base, ULONG type, char *dest)
|
2011-05-11 18:31:22 +08:00
|
|
|
{
|
2011-05-13 14:50:20 +08:00
|
|
|
for (heap *h = heap_vm_chunks; h; h = h->next)
|
2011-05-21 02:07:52 +08:00
|
|
|
if (base >= h->base && base < h->end)
|
2011-05-11 18:31:22 +08:00
|
|
|
{
|
2011-05-21 02:07:52 +08:00
|
|
|
char *p = dest + __small_sprintf (dest, "[heap %ld", h->heap_id);
|
2011-05-13 14:50:20 +08:00
|
|
|
if (!(h->flags & HEAP_FLAG_NONDEFAULT))
|
|
|
|
p = stpcpy (p, " default");
|
|
|
|
if ((h->flags & HEAP_FLAG_SHAREABLE) && (type & MEM_MAPPED))
|
2011-05-21 02:07:52 +08:00
|
|
|
p = stpcpy (p, " shared");
|
2011-05-13 14:50:20 +08:00
|
|
|
if (h->flags & HEAP_FLAG_EXECUTABLE)
|
|
|
|
p = stpcpy (p, " exec");
|
|
|
|
if (h->flags & HEAP_FLAG_GROWABLE)
|
|
|
|
p = stpcpy (p, " grow");
|
|
|
|
if (h->flags & HEAP_FLAG_NOSERIALIZE)
|
|
|
|
p = stpcpy (p, " noserial");
|
|
|
|
if (h->flags == HEAP_FLAG_DEBUGGED)
|
|
|
|
p = stpcpy (p, " debug");
|
|
|
|
stpcpy (p, "]");
|
2011-05-11 18:31:22 +08:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~heap_info ()
|
|
|
|
{
|
|
|
|
heap *n = 0;
|
2011-05-13 14:50:20 +08:00
|
|
|
for (heap *m = heap_vm_chunks; m; m = n)
|
2011-05-11 18:31:22 +08:00
|
|
|
{
|
|
|
|
n = m->next;
|
2011-05-21 23:57:16 +08:00
|
|
|
free (m);
|
2011-05-11 18:31:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-21 23:57:16 +08:00
|
|
|
struct thread_info
|
2011-05-21 02:07:52 +08:00
|
|
|
{
|
2011-05-21 23:57:16 +08:00
|
|
|
struct region
|
2011-05-21 02:07:52 +08:00
|
|
|
{
|
2011-05-21 23:57:16 +08:00
|
|
|
region *next;
|
2011-05-21 02:07:52 +08:00
|
|
|
ULONG thread_id;
|
|
|
|
char *start;
|
|
|
|
char *end;
|
2011-05-21 23:57:16 +08:00
|
|
|
bool teb;
|
2011-05-21 02:07:52 +08:00
|
|
|
};
|
2011-05-21 23:57:16 +08:00
|
|
|
region *regions;
|
2011-05-21 02:07:52 +08:00
|
|
|
|
2011-05-21 23:57:16 +08:00
|
|
|
thread_info (DWORD pid, HANDLE process)
|
|
|
|
: regions (NULL)
|
2011-05-21 02:07:52 +08:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
PVOID buf = NULL;
|
|
|
|
size_t size = 50 * (sizeof (SYSTEM_PROCESSES)
|
|
|
|
+ 16 * sizeof (SYSTEM_THREADS));
|
|
|
|
PSYSTEM_PROCESSES proc;
|
|
|
|
PSYSTEM_THREADS thread;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
buf = realloc (buf, size);
|
|
|
|
status = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
|
|
|
|
buf, size, NULL);
|
|
|
|
size <<= 1;
|
|
|
|
}
|
|
|
|
while (status == STATUS_INFO_LENGTH_MISMATCH);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
|
|
|
if (buf)
|
|
|
|
free (buf);
|
|
|
|
debug_printf ("NtQuerySystemInformation, %p", status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
proc = (PSYSTEM_PROCESSES) buf;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (proc->ProcessId == pid)
|
|
|
|
break;
|
|
|
|
if (!proc->NextEntryDelta)
|
|
|
|
{
|
|
|
|
free (buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
proc = (PSYSTEM_PROCESSES) ((PBYTE) proc + proc->NextEntryDelta);
|
|
|
|
}
|
|
|
|
thread = proc->Threads;
|
|
|
|
for (ULONG i = 0; i < proc->ThreadCount; ++i)
|
|
|
|
{
|
|
|
|
THREAD_BASIC_INFORMATION tbi;
|
|
|
|
TEB teb;
|
|
|
|
HANDLE thread_h;
|
|
|
|
|
|
|
|
if (!(thread_h = OpenThread (THREAD_QUERY_INFORMATION, FALSE,
|
|
|
|
(ULONG) thread[i].ClientId.UniqueThread)))
|
|
|
|
continue;
|
|
|
|
status = NtQueryInformationThread (thread_h, ThreadBasicInformation,
|
|
|
|
&tbi, sizeof tbi, NULL);
|
|
|
|
CloseHandle (thread_h);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
continue;
|
2011-05-21 23:57:16 +08:00
|
|
|
region *r = (region *) malloc (sizeof (region));
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
*r = (region) { regions, (ULONG) thread[i].ClientId.UniqueThread,
|
|
|
|
(char *) tbi.TebBaseAddress,
|
|
|
|
(char *) tbi.TebBaseAddress + wincap.page_size (),
|
|
|
|
true };
|
|
|
|
regions = r;
|
|
|
|
}
|
2011-05-21 02:07:52 +08:00
|
|
|
if (!ReadProcessMemory (process, (PVOID) tbi.TebBaseAddress,
|
|
|
|
&teb, sizeof teb, NULL))
|
|
|
|
continue;
|
2011-05-21 23:57:16 +08:00
|
|
|
r = (region *) malloc (sizeof (region));
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
*r = (region) { regions, (ULONG) thread[i].ClientId.UniqueThread,
|
|
|
|
(char *) (teb.DeallocationStack
|
|
|
|
?: teb.Tib.StackLimit),
|
|
|
|
(char *) teb.Tib.StackBase,
|
|
|
|
false };
|
|
|
|
regions = r;
|
|
|
|
}
|
2011-05-21 02:07:52 +08:00
|
|
|
}
|
|
|
|
free (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *fill_if_match (char *base, ULONG type, char *dest)
|
|
|
|
{
|
2011-05-21 23:57:16 +08:00
|
|
|
for (region *r = regions; r; r = r->next)
|
|
|
|
if ((base >= r->start && base < r->end)
|
|
|
|
/* Special case WOW64. The TEB is 8K within the region reserved
|
|
|
|
for it. No idea what the lower 8K are used for. */
|
|
|
|
|| (r->teb && wincap.is_wow64 ()
|
|
|
|
&& r->start == base + 2 * wincap.page_size ()))
|
2011-05-21 02:07:52 +08:00
|
|
|
{
|
2011-05-21 23:57:16 +08:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = dest + __small_sprintf (dest, "[%s (tid %ld)",
|
|
|
|
r->teb ? "teb" : "stack",
|
|
|
|
r->thread_id);
|
2011-05-21 02:07:52 +08:00
|
|
|
if (type & MEM_MAPPED)
|
|
|
|
p = stpcpy (p, " shared");
|
|
|
|
stpcpy (p, "]");
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-21 23:57:16 +08:00
|
|
|
~thread_info ()
|
2011-05-21 02:07:52 +08:00
|
|
|
{
|
2011-05-21 23:57:16 +08:00
|
|
|
region *n = 0;
|
|
|
|
for (region *m = regions; m; m = n)
|
2011-05-21 02:07:52 +08:00
|
|
|
{
|
|
|
|
n = m->next;
|
2011-05-21 23:57:16 +08:00
|
|
|
free (m);
|
2011-05-21 02:07:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
static _off64_t
|
|
|
|
format_process_maps (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
2005-01-29 19:23:07 +08:00
|
|
|
HANDLE proc = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
|
|
|
|
FALSE,
|
|
|
|
p->dwProcessId);
|
|
|
|
if (!proc)
|
|
|
|
return 0;
|
|
|
|
|
2011-05-21 23:57:16 +08:00
|
|
|
NTSTATUS status;
|
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
|
|
|
PPEB peb = NULL;
|
|
|
|
|
|
|
|
status = NtQueryInformationProcess (proc, ProcessBasicInformation,
|
|
|
|
&pbi, sizeof pbi, NULL);
|
|
|
|
if (NT_SUCCESS (status))
|
|
|
|
peb = pbi.PebBaseAddress;
|
|
|
|
|
2005-01-29 19:23:07 +08:00
|
|
|
_off64_t len = 0;
|
2011-05-11 18:31:22 +08:00
|
|
|
|
|
|
|
union access
|
|
|
|
{
|
|
|
|
char flags[8];
|
|
|
|
_off64_t word;
|
|
|
|
} a;
|
|
|
|
|
|
|
|
struct region {
|
|
|
|
access a;
|
|
|
|
char *abase;
|
|
|
|
char *rbase;
|
|
|
|
char *rend;
|
|
|
|
} cur = {{{'\0'}}, (char *)1, 0, 0};
|
|
|
|
|
|
|
|
MEMORY_BASIC_INFORMATION mb;
|
|
|
|
dos_drive_mappings drive_maps;
|
|
|
|
heap_info heaps (p->dwProcessId);
|
2011-05-21 23:57:16 +08:00
|
|
|
thread_info threads (p->dwProcessId, proc);
|
2011-05-11 18:31:22 +08:00
|
|
|
struct __stat64 st;
|
|
|
|
long last_pass = 0;
|
2008-03-07 19:24:51 +08:00
|
|
|
|
|
|
|
tmp_pathbuf tp;
|
2011-05-11 18:31:22 +08:00
|
|
|
PMEMORY_SECTION_NAME msi = (PMEMORY_SECTION_NAME) tp.w_get ();
|
2008-03-07 19:24:51 +08:00
|
|
|
char *posix_modname = tp.c_get ();
|
2009-01-21 01:22:11 +08:00
|
|
|
size_t maxsize = 0;
|
2005-01-29 19:23:07 +08:00
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
if (destbuf)
|
|
|
|
{
|
|
|
|
cfree (destbuf);
|
|
|
|
destbuf = NULL;
|
|
|
|
}
|
2011-05-11 18:31:22 +08:00
|
|
|
|
|
|
|
/* Iterate over each VM region in the address space, coalescing
|
|
|
|
memory regions with the same permissions. Once we run out, do one
|
|
|
|
last_pass to trigger output of the last accumulated region. */
|
|
|
|
for (char *i = 0;
|
|
|
|
VirtualQueryEx (proc, i, &mb, sizeof(mb)) || (1 == ++last_pass);
|
|
|
|
i = cur.rend)
|
2005-01-29 19:23:07 +08:00
|
|
|
{
|
2011-05-21 23:57:16 +08:00
|
|
|
if (last_pass)
|
|
|
|
posix_modname[0] = '\0';
|
2011-05-11 18:31:22 +08:00
|
|
|
if (mb.State == MEM_FREE)
|
|
|
|
a.word = 0;
|
2011-05-21 23:57:16 +08:00
|
|
|
else if (mb.State == MEM_RESERVE)
|
|
|
|
{
|
|
|
|
char *p = stpcpy (a.flags, "===");
|
|
|
|
stpcpy (p, (mb.Type & MEM_MAPPED) ? "s" : "p");
|
|
|
|
}
|
2011-05-11 18:31:22 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
static DWORD const RW = (PAGE_EXECUTE_READWRITE | PAGE_READWRITE
|
|
|
|
| PAGE_EXECUTE_WRITECOPY | PAGE_WRITECOPY);
|
|
|
|
DWORD p = mb.Protect;
|
|
|
|
a = (access) {{
|
2011-05-21 23:57:16 +08:00
|
|
|
(p & (RW | PAGE_EXECUTE_READ | PAGE_READONLY)) ? 'r' : '-',
|
|
|
|
(p & (RW)) ? 'w' : '-',
|
2011-05-11 18:31:22 +08:00
|
|
|
(p & (PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ
|
2011-05-21 23:57:16 +08:00
|
|
|
| PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE)) ? 'x' : '-',
|
|
|
|
(mb.Type & MEM_MAPPED) ? 's'
|
|
|
|
: (p & PAGE_GUARD) ? 'g' : 'p',
|
2011-05-11 18:31:22 +08:00
|
|
|
'\0', // zero-fill the remaining bytes
|
|
|
|
}};
|
|
|
|
}
|
2005-01-29 19:23:07 +08:00
|
|
|
|
2011-05-11 18:31:22 +08:00
|
|
|
region next = { a,
|
|
|
|
(char *) mb.AllocationBase,
|
|
|
|
(char *) mb.BaseAddress,
|
|
|
|
(char *) mb.BaseAddress+mb.RegionSize
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Windows permissions are more fine-grained than the unix rwxp,
|
|
|
|
so we reduce clutter by manually coalescing regions sharing
|
|
|
|
the same allocation base and effective permissions. */
|
|
|
|
bool newbase = (next.abase != cur.abase);
|
|
|
|
if (!last_pass && !newbase && next.a.word == cur.a.word)
|
|
|
|
cur.rend = next.rend; // merge with previous
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// output the current region if it's "interesting"
|
|
|
|
if (cur.a.word)
|
|
|
|
{
|
|
|
|
size_t newlen = strlen (posix_modname) + 62;
|
|
|
|
if (len + newlen >= maxsize)
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf,
|
|
|
|
maxsize += roundup2 (newlen,
|
|
|
|
2048));
|
|
|
|
int written = __small_sprintf (destbuf + len,
|
|
|
|
"%08lx-%08lx %s %08lx %04x:%04x %U ",
|
|
|
|
cur.rbase, cur.rend, cur.a.flags,
|
|
|
|
cur.rbase - cur.abase,
|
|
|
|
st.st_dev >> 16,
|
|
|
|
st.st_dev & 0xffff,
|
|
|
|
st.st_ino);
|
|
|
|
while (written < 62)
|
|
|
|
destbuf[len + written++] = ' ';
|
|
|
|
len += written;
|
|
|
|
len += __small_sprintf (destbuf + len, "%s\n", posix_modname);
|
|
|
|
}
|
|
|
|
// start of a new region (but possibly still the same allocation)
|
|
|
|
cur = next;
|
|
|
|
// if a new allocation, figure out what kind it is
|
2011-05-21 23:57:16 +08:00
|
|
|
if (newbase && !last_pass && mb.State != MEM_FREE)
|
2005-01-29 19:23:07 +08:00
|
|
|
{
|
2011-05-11 18:31:22 +08:00
|
|
|
st.st_dev = 0;
|
|
|
|
st.st_ino = 0;
|
|
|
|
if ((mb.Type & (MEM_MAPPED | MEM_IMAGE))
|
|
|
|
&& NT_SUCCESS (NtQueryVirtualMemory (proc, cur.abase,
|
|
|
|
MemorySectionName,
|
|
|
|
msi, 65536, NULL)))
|
2005-01-29 19:23:07 +08:00
|
|
|
{
|
2011-05-11 18:31:22 +08:00
|
|
|
PWCHAR dosname =
|
|
|
|
drive_maps.fixup_if_match (msi->SectionFileName.Buffer);
|
|
|
|
if (mount_table->conv_to_posix_path (dosname,
|
|
|
|
posix_modname, 0))
|
|
|
|
sys_wcstombs (posix_modname, NT_MAX_PATH, dosname);
|
|
|
|
stat64 (posix_modname, &st);
|
2005-01-29 19:23:07 +08:00
|
|
|
}
|
2011-05-21 23:57:16 +08:00
|
|
|
else if (!threads.fill_if_match (cur.abase, mb.Type,
|
|
|
|
posix_modname)
|
2011-05-21 02:07:52 +08:00
|
|
|
&& !heaps.fill_if_match (cur.abase, mb.Type,
|
|
|
|
posix_modname))
|
2011-05-13 14:50:20 +08:00
|
|
|
{
|
2011-05-21 23:57:16 +08:00
|
|
|
if (cur.abase == (char *) peb)
|
|
|
|
strcpy (posix_modname, "[peb]");
|
|
|
|
else if (cur.abase == (char *) &SharedUserData)
|
|
|
|
strcpy (posix_modname, "[shared-user-data]");
|
2011-05-13 14:50:20 +08:00
|
|
|
else
|
|
|
|
posix_modname[0] = 0;
|
|
|
|
}
|
2005-01-29 19:23:07 +08:00
|
|
|
}
|
2011-05-11 18:31:22 +08:00
|
|
|
}
|
|
|
|
}
|
2005-01-29 19:23:07 +08:00
|
|
|
CloseHandle (proc);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2003-04-02 00:11:41 +08:00
|
|
|
static _off64_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_process_stat (void *data, char *&destbuf)
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2009-01-21 01:22:11 +08:00
|
|
|
_pinfo *p = (_pinfo *) data;
|
2007-12-03 22:13:03 +08:00
|
|
|
char cmd[NAME_MAX + 1];
|
2010-05-18 22:30:51 +08:00
|
|
|
WCHAR wcmd[NAME_MAX + 1];
|
2002-05-12 09:37:48 +08:00
|
|
|
int state = 'R';
|
|
|
|
unsigned long fault_count = 0UL,
|
2002-05-28 09:55:40 +08:00
|
|
|
utime = 0UL, stime = 0UL,
|
|
|
|
start_time = 0UL,
|
|
|
|
vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL;
|
2002-05-12 09:37:48 +08:00
|
|
|
int priority = 0;
|
2005-01-17 01:00:27 +08:00
|
|
|
if (p->process_state & PID_EXITED)
|
2002-07-02 09:36:15 +08:00
|
|
|
strcpy (cmd, "<defunct>");
|
2002-05-02 12:26:05 +08:00
|
|
|
else
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2010-05-18 22:30:51 +08:00
|
|
|
PWCHAR last_slash = wcsrchr (p->progname, L'\\');
|
|
|
|
wcscpy (wcmd, last_slash ? last_slash + 1 : p->progname);
|
|
|
|
sys_wcstombs (cmd, NAME_MAX + 1, wcmd);
|
2002-05-12 09:37:48 +08:00
|
|
|
int len = strlen (cmd);
|
|
|
|
if (len > 4)
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
char *s = cmd + len - 4;
|
2008-02-01 20:37:51 +08:00
|
|
|
if (ascii_strcasematch (s, ".exe"))
|
2002-05-28 09:55:40 +08:00
|
|
|
*s = 0;
|
|
|
|
}
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Note: under Windows, a _process_ is always running - it's only _threads_
|
|
|
|
* that get suspended. Therefore the default state is R (runnable).
|
|
|
|
*/
|
2005-01-17 01:00:27 +08:00
|
|
|
if (p->process_state & PID_EXITED)
|
2002-05-12 09:37:48 +08:00
|
|
|
state = 'Z';
|
|
|
|
else if (p->process_state & PID_STOPPED)
|
|
|
|
state = 'T';
|
2007-02-22 18:54:47 +08:00
|
|
|
else
|
2002-05-12 09:37:48 +08:00
|
|
|
state = get_process_state (p->dwProcessId);
|
2006-02-11 12:53:14 +08:00
|
|
|
start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ;
|
2007-02-22 18:54:47 +08: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,
|
|
|
|
FALSE, p->dwProcessId);
|
|
|
|
if (hProcess != NULL)
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2007-02-22 18:54:47 +08:00
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
|
|
|
ProcessVmCounters,
|
|
|
|
(PVOID) &vmc,
|
|
|
|
sizeof vmc, NULL);
|
2002-05-12 09:37:48 +08:00
|
|
|
if (ret == STATUS_SUCCESS)
|
2007-02-22 18:54:47 +08:00
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
|
|
|
ProcessTimes,
|
|
|
|
(PVOID) &put,
|
|
|
|
sizeof put, NULL);
|
2002-05-12 09:37:48 +08:00
|
|
|
if (ret == STATUS_SUCCESS)
|
2007-02-22 18:54:47 +08:00
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
|
|
|
ProcessBasicInformation,
|
|
|
|
(PVOID) &pbi,
|
|
|
|
sizeof pbi, NULL);
|
|
|
|
if (ret == STATUS_SUCCESS)
|
|
|
|
ret = NtQueryInformationProcess (hProcess,
|
|
|
|
ProcessQuotaLimits,
|
|
|
|
(PVOID) &ql,
|
|
|
|
sizeof ql, NULL);
|
|
|
|
CloseHandle (hProcess);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD error = GetLastError ();
|
|
|
|
__seterrno_from_win_error (error);
|
|
|
|
debug_printf ("OpenProcess: ret %d", error);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ret == STATUS_SUCCESS)
|
|
|
|
ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
|
|
|
|
(PVOID) &stodi,
|
|
|
|
sizeof stodi, NULL);
|
|
|
|
if (ret == STATUS_SUCCESS)
|
|
|
|
ret = NtQuerySystemInformation (SystemProcessorTimes,
|
|
|
|
(PVOID) &spt,
|
|
|
|
sizeof spt, NULL);
|
|
|
|
if (ret != STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
__seterrno_from_nt_status (ret);
|
|
|
|
debug_printf ("NtQueryInformationProcess: ret %d, Dos(ret) %E", ret);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fault_count = vmc.PageFaultCount;
|
|
|
|
utime = put.UserTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
|
2003-07-09 09:33:06 +08:00
|
|
|
#if 0
|
2007-02-22 18:54:47 +08:00
|
|
|
if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart)
|
|
|
|
start_time = (spt.KernelTime.QuadPart + spt.UserTime.QuadPart -
|
|
|
|
stodi.CurrentTime.QuadPart + put.CreateTime.QuadPart) * HZ / 10000000ULL;
|
|
|
|
else
|
|
|
|
/*
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
start_time = (spt.KernelTme.QuadPart + spt.UserTime.QuadPart) * HZ / 10000000ULL;
|
2003-07-09 09:33:06 +08:00
|
|
|
#endif
|
2007-02-22 18:54:47 +08:00
|
|
|
priority = pbi.BasePriority;
|
|
|
|
unsigned page_size = getsystempagesize ();
|
|
|
|
vmsize = vmc.PagefileUsage;
|
|
|
|
vmrss = vmc.WorkingSetSize / page_size;
|
|
|
|
vmmaxrss = ql.MaximumWorkingSetSize / page_size;
|
2003-07-09 09:33:06 +08:00
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
|
2002-05-12 09:37:48 +08:00
|
|
|
return __small_sprintf (destbuf, "%d (%s) %c "
|
2002-05-28 09:55:40 +08: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 20:24:23 +08: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 09:55:40 +08:00
|
|
|
utime, stime, priority, 0, 0, 0,
|
|
|
|
start_time, vmsize,
|
|
|
|
vmrss, vmmaxrss
|
|
|
|
);
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
|
2003-04-02 00:11:41 +08:00
|
|
|
static _off64_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_process_status (void *data, char *&destbuf)
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2009-01-21 01:22:11 +08:00
|
|
|
_pinfo *p = (_pinfo *) data;
|
2007-12-03 22:13:03 +08:00
|
|
|
char cmd[NAME_MAX + 1];
|
2010-05-18 22:30:51 +08:00
|
|
|
WCHAR wcmd[NAME_MAX + 1];
|
2002-05-12 09:37:48 +08:00
|
|
|
int state = 'R';
|
|
|
|
const char *state_str = "unknown";
|
|
|
|
unsigned long vmsize = 0UL, vmrss = 0UL, vmdata = 0UL, vmlib = 0UL, vmtext = 0UL,
|
2002-05-28 09:55:40 +08:00
|
|
|
vmshare = 0UL;
|
2005-01-17 01:00:27 +08:00
|
|
|
if (p->process_state & PID_EXITED)
|
2002-05-12 09:37:48 +08:00
|
|
|
strcpy (cmd, "<defunct>");
|
|
|
|
else
|
|
|
|
{
|
2010-05-18 22:30:51 +08:00
|
|
|
PWCHAR last_slash = wcsrchr (p->progname, L'\\');
|
|
|
|
wcscpy (wcmd, last_slash ? last_slash + 1 : p->progname);
|
|
|
|
sys_wcstombs (cmd, NAME_MAX + 1, wcmd);
|
2002-05-12 09:37:48 +08:00
|
|
|
int len = strlen (cmd);
|
|
|
|
if (len > 4)
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
char *s = cmd + len - 4;
|
2008-02-01 20:37:51 +08:00
|
|
|
if (ascii_strcasematch (s, ".exe"))
|
2002-05-28 09:55:40 +08:00
|
|
|
*s = 0;
|
|
|
|
}
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Note: under Windows, a _process_ is always running - it's only _threads_
|
|
|
|
* that get suspended. Therefore the default state is R (runnable).
|
|
|
|
*/
|
2005-01-17 01:00:27 +08:00
|
|
|
if (p->process_state & PID_EXITED)
|
2002-05-12 09:37:48 +08:00
|
|
|
state = 'Z';
|
|
|
|
else if (p->process_state & PID_STOPPED)
|
|
|
|
state = 'T';
|
2007-02-22 18:54:47 +08:00
|
|
|
else
|
2002-05-12 09:37:48 +08:00
|
|
|
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;
|
|
|
|
}
|
2007-02-22 18:54:47 +08:00
|
|
|
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
|
|
|
|
&vmlib, &vmshare))
|
|
|
|
return 0;
|
|
|
|
unsigned page_size = getsystempagesize ();
|
|
|
|
vmsize *= page_size; vmrss *= page_size; vmdata *= page_size;
|
|
|
|
vmtext *= page_size; vmlib *= page_size;
|
2002-09-25 20:24:23 +08: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.
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
|
2004-12-22 19:35:29 +08:00
|
|
|
return __small_sprintf (destbuf, "Name:\t%s\n"
|
|
|
|
"State:\t%c (%s)\n"
|
|
|
|
"Tgid:\t%d\n"
|
|
|
|
"Pid:\t%d\n"
|
|
|
|
"PPid:\t%d\n"
|
|
|
|
"Uid:\t%d %d %d %d\n"
|
|
|
|
"Gid:\t%d %d %d %d\n"
|
|
|
|
"VmSize:\t%8d kB\n"
|
|
|
|
"VmLck:\t%8d kB\n"
|
|
|
|
"VmRSS:\t%8d kB\n"
|
|
|
|
"VmData:\t%8d kB\n"
|
|
|
|
"VmStk:\t%8d kB\n"
|
|
|
|
"VmExe:\t%8d kB\n"
|
|
|
|
"VmLib:\t%8d kB\n"
|
|
|
|
"SigPnd:\t%016x\n"
|
|
|
|
"SigBlk:\t%016x\n"
|
|
|
|
"SigIgn:\t%016x\n",
|
2002-05-28 09:55:40 +08:00
|
|
|
cmd,
|
|
|
|
state, state_str,
|
|
|
|
p->pgid,
|
|
|
|
p->pid,
|
|
|
|
p->ppid,
|
2002-09-25 20:24:23 +08:00
|
|
|
p->uid, p->uid, p->uid, p->uid,
|
|
|
|
p->gid, p->gid, p->gid, p->gid,
|
2007-02-22 18:54:47 +08:00
|
|
|
vmsize >> 10, 0, vmrss >> 10, vmdata >> 10, 0,
|
|
|
|
vmtext >> 10, vmlib >> 10,
|
2008-02-16 01:53:11 +08:00
|
|
|
0, 0, _my_tls.sigmask
|
2002-05-28 09:55:40 +08:00
|
|
|
);
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
|
|
|
|
2003-04-02 00:11:41 +08:00
|
|
|
static _off64_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_process_statm (void *data, char *&destbuf)
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2009-01-21 01:22:11 +08:00
|
|
|
_pinfo *p = (_pinfo *) data;
|
2002-07-02 09:36:15 +08:00
|
|
|
unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL,
|
2002-09-19 11:30:20 +08:00
|
|
|
vmlib = 0UL, vmshare = 0UL;
|
2007-02-22 18:54:47 +08:00
|
|
|
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
|
|
|
|
&vmlib, &vmshare))
|
|
|
|
return 0;
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 96);
|
2002-05-12 09:37:48 +08:00
|
|
|
return __small_sprintf (destbuf, "%ld %ld %ld %ld %ld %ld %ld",
|
2007-02-22 18:54:47 +08:00
|
|
|
vmsize, vmrss, vmshare, vmtext, vmlib, vmdata, 0);
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
|
|
|
|
2009-02-05 00:40:04 +08:00
|
|
|
extern "C" {
|
|
|
|
FILE *setmntent (const char *, const char *);
|
|
|
|
struct mntent *getmntent (FILE *);
|
|
|
|
};
|
|
|
|
|
|
|
|
static _off64_t
|
|
|
|
format_process_mounts (void *data, char *&destbuf)
|
|
|
|
{
|
|
|
|
_pinfo *p = (_pinfo *) data;
|
|
|
|
user_info *u_shared = NULL;
|
|
|
|
HANDLE u_hdl = NULL;
|
|
|
|
_off64_t len = 0;
|
|
|
|
struct mntent *mnt;
|
|
|
|
|
|
|
|
if (p->pid != myself->pid)
|
|
|
|
{
|
|
|
|
WCHAR sid_string[UNLEN + 1] = L""; /* Large enough for SID */
|
|
|
|
|
|
|
|
cygsid p_sid;
|
|
|
|
|
|
|
|
if (!p_sid.getfrompw (internal_getpwuid (p->uid)))
|
|
|
|
return 0;
|
|
|
|
p_sid.string (sid_string);
|
|
|
|
u_shared = (user_info *) open_shared (sid_string, USER_VERSION, u_hdl,
|
2010-03-10 05:26:55 +08:00
|
|
|
sizeof (user_info), SH_JUSTOPEN,
|
2009-02-05 00:40:04 +08:00
|
|
|
&sec_none_nih);
|
|
|
|
if (!u_shared)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
u_shared = user_shared;
|
|
|
|
|
|
|
|
/* Store old value of _my_tls.locals here. */
|
|
|
|
int iteration = _my_tls.locals.iteration;
|
|
|
|
unsigned available_drives = _my_tls.locals.available_drives;
|
|
|
|
/* This reinitializes the above values in _my_tls. */
|
|
|
|
setmntent (NULL, NULL);
|
|
|
|
while ((mnt = getmntent (NULL)))
|
|
|
|
{
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, len
|
|
|
|
+ strlen (mnt->mnt_fsname)
|
|
|
|
+ strlen (mnt->mnt_dir)
|
|
|
|
+ strlen (mnt->mnt_type)
|
|
|
|
+ strlen (mnt->mnt_opts)
|
|
|
|
+ 28);
|
|
|
|
len += __small_sprintf (destbuf + len, "%s %s %s %s %d %d\n",
|
|
|
|
mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type,
|
|
|
|
mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno);
|
|
|
|
}
|
|
|
|
/* Restore old value of _my_tls.locals here. */
|
|
|
|
_my_tls.locals.iteration = iteration;
|
|
|
|
_my_tls.locals.available_drives = available_drives;
|
|
|
|
|
|
|
|
if (u_hdl) /* Only not-NULL if open_shared has been called. */
|
|
|
|
{
|
|
|
|
UnmapViewOfFile (u_shared);
|
|
|
|
CloseHandle (u_hdl);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2011-04-01 17:00:21 +08:00
|
|
|
int
|
2002-05-12 09:37:48 +08: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 15:45:30 +08:00
|
|
|
(ret = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
|
2002-05-28 09:55:40 +08:00
|
|
|
(PVOID) p,
|
|
|
|
n * sizeof *p, NULL)))
|
2002-05-12 09:37:48 +08:00
|
|
|
delete [] p, p = new ULONG[n *= 2];
|
|
|
|
if (ret != STATUS_SUCCESS)
|
|
|
|
{
|
2004-09-03 09:53:12 +08:00
|
|
|
debug_printf ("NtQuerySystemInformation: ret %d, Dos(ret) %d",
|
|
|
|
ret, RtlNtStatusToDosError (ret));
|
2002-05-12 09:37:48 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
state = 'Z';
|
|
|
|
sp = (SYSTEM_PROCESSES *) p;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (sp->ProcessId == dwProcessId)
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
SYSTEM_THREADS *st;
|
Drop NT4 support.
* autoload.cc (DnsQuery_A): Fatal if not available.
(DnsRecordListFree): Ditto.
(DsGetDcNameW): Ditto.
(NetGetAnyDCName): Remove.
(NetGetDCName): Remove.
(EnumProcessModules): Fatal if not available.
(GetModuleFileNameExW): Ditto.
(GetModuleInformation): Ditto.
(GetProcessMemoryInfo): Ditto.
(QueryWorkingSet): Ditto.
(LsaRegisterLogonProcess): Ditto.
* fenv.cc (_feinitialise): Drop supports_sse condition.
* fhandler_disk_file.cc (path_conv::isgood_inode): Fix comment.
(fhandler_base::fstat_by_name): Drop has_fileid_dirinfo condition.
(fhandler_disk_file::opendir): Ditto.
* fhandler_netdrive.cc (fhandler_netdrive::readdir): Fix comment.
* fhandler_proc.cc (format_proc_partitions): Drop NT4-only code.
* fhandler_process.cc (get_process_state): Ditto.
* kernel32.cc (GetWindowsDirectoryW): Remove.
(GetWindowsDirectoryA): Remove.
* miscfuncs.cc (nice_to_winprio): Drop NT4-only code.
* mount.cc (fs_info::update): Fix comments.
* net.cc (get_2k_ifs): Drop NT4-only code.
* sec_auth.cc (get_logon_server): Ditto.
(lsaauth): Drop NT4-specific error handling.
* security.cc (alloc_sd): Set SE_DACL_PROTECTED unconditionally.
* select.cc (select_stuff::wait): Always use MWMO_INPUTAVAILABLE.
(peek_windows): Drop NT4-only condition in call to PeekMessage.
* syscalls.cc (gethostid): Remove NT4-only workaround.
* wincap.cc: Througout, drop has_dacl_protect,
has_broken_if_oper_status, has_process_io_counters,
has_terminal_services, has_extended_priority_class, has_guid_volumes,
has_fileid_dirinfo, has_mwmo_inputavailable and supports_sse from
wincaps.
(wincap_nt4sp4): Remove.
(wincap_minimal): Set to wincap_2000.
(wincapc::init): Rely on availability of OSVERSIONINFOEX structure.
Treat error from GetVersionEx as fatal. Treat NT4 as fatal.
* wincap.h (struct wincaps): Drop has_dacl_protect,
has_broken_if_oper_status, has_process_io_counters,
has_terminal_services, has_extended_priority_class, has_guid_volumes,
has_fileid_dirinfo, has_mwmo_inputavailable and supports_sse flags
and methods.
* winlean.h (GetWindowsDirectoryW) Define as GetSystemWindowsDirectoryW.
(GetWindowsDirectoryA): Define as GetSystemWindowsDirectoryA.
2011-04-04 20:23:36 +08:00
|
|
|
st = &sp->Threads[0];
|
2002-05-28 09:55:40 +08:00
|
|
|
state = 'S';
|
|
|
|
for (unsigned i = 0; i < sp->ThreadCount; i++)
|
|
|
|
{
|
2011-04-01 17:00:21 +08:00
|
|
|
/* FIXME: at some point we should consider generating 'O' */
|
2002-05-28 09:55:40 +08:00
|
|
|
if (st->State == StateRunning ||
|
|
|
|
st->State == StateReady)
|
|
|
|
{
|
|
|
|
state = 'R';
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
st++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-05-12 09:37:48 +08:00
|
|
|
if (!sp->NextEntryDelta)
|
2002-05-28 09:55:40 +08:00
|
|
|
break;
|
2002-05-12 09:37:48 +08:00
|
|
|
sp = (SYSTEM_PROCESSES *) ((char *) sp + sp->NextEntryDelta);
|
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
out:
|
2002-05-12 09:37:48 +08:00
|
|
|
delete [] p;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2003-03-09 01:56:13 +08:00
|
|
|
static bool
|
2002-09-22 11:38:57 +08: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 09:37:48 +08:00
|
|
|
{
|
2010-09-13 21:02:19 +08:00
|
|
|
bool res = false;
|
2002-05-12 09:37:48 +08:00
|
|
|
NTSTATUS ret;
|
|
|
|
HANDLE hProcess;
|
|
|
|
VM_COUNTERS vmc;
|
|
|
|
MEMORY_WORKING_SET_LIST *mwsl;
|
2010-09-13 21:02:19 +08:00
|
|
|
ULONG n = 0x4000, length;
|
|
|
|
PMEMORY_WORKING_SET_LIST p = (PMEMORY_WORKING_SET_LIST) malloc (n);
|
2005-11-29 06:32:29 +08:00
|
|
|
unsigned page_size = getsystempagesize ();
|
2002-05-12 09:37:48 +08:00
|
|
|
hProcess = OpenProcess (PROCESS_QUERY_INFORMATION,
|
2002-05-28 09:55:40 +08:00
|
|
|
FALSE, dwProcessId);
|
2002-05-12 09:37:48 +08:00
|
|
|
if (hProcess == NULL)
|
|
|
|
{
|
2010-09-13 21:02:19 +08:00
|
|
|
__seterrno ();
|
|
|
|
debug_printf ("OpenProcess, %E");
|
2002-05-12 09:37:48 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-09-13 21:02:19 +08:00
|
|
|
do
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2010-09-13 21:02:19 +08:00
|
|
|
ret = NtQueryVirtualMemory (hProcess, 0, MemoryWorkingSetList,
|
|
|
|
(PVOID) p, n, (length = ULONG_MAX, &length));
|
|
|
|
if (ret == STATUS_INFO_LENGTH_MISMATCH
|
|
|
|
|| (!NT_SUCCESS (ret) && length > n))
|
|
|
|
{
|
|
|
|
ret = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
n <<= 1;
|
|
|
|
PMEMORY_WORKING_SET_LIST new_p = (PMEMORY_WORKING_SET_LIST)
|
|
|
|
realloc (p, n);
|
|
|
|
if (!new_p)
|
|
|
|
goto out;
|
|
|
|
p = new_p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!NT_SUCCESS (ret));
|
|
|
|
if (!NT_SUCCESS (ret))
|
|
|
|
{
|
|
|
|
debug_printf ("NtQueryVirtualMemory: ret %p", ret);
|
|
|
|
__seterrno_from_nt_status (ret);
|
2002-05-12 09:37:48 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
mwsl = (MEMORY_WORKING_SET_LIST *) p;
|
|
|
|
for (unsigned long i = 0; i < mwsl->NumberOfPages; i++)
|
|
|
|
{
|
|
|
|
++*vmrss;
|
|
|
|
unsigned flags = mwsl->WorkingSetList[i] & 0x0FFF;
|
2010-09-13 21:02:19 +08:00
|
|
|
if ((flags & (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE))
|
|
|
|
== (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE))
|
2005-08-24 12:38:39 +08:00
|
|
|
++*vmlib;
|
2002-05-12 09:37:48 +08:00
|
|
|
else if (flags & WSLE_PAGE_SHAREABLE)
|
2005-08-24 12:38:39 +08:00
|
|
|
++*vmshare;
|
2002-05-12 09:37:48 +08:00
|
|
|
else if (flags & WSLE_PAGE_EXECUTE)
|
2005-08-24 12:38:39 +08:00
|
|
|
++*vmtext;
|
2002-05-12 09:37:48 +08:00
|
|
|
else
|
2005-08-24 12:38:39 +08:00
|
|
|
++*vmdata;
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
2005-08-24 12:38:39 +08:00
|
|
|
ret = NtQueryInformationProcess (hProcess, ProcessVmCounters, (PVOID) &vmc,
|
2002-05-28 09:55:40 +08:00
|
|
|
sizeof vmc, NULL);
|
2010-09-13 21:02:19 +08:00
|
|
|
if (!NT_SUCCESS (ret))
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2010-09-13 21:02:19 +08:00
|
|
|
debug_printf ("NtQueryInformationProcess: ret %p", ret);
|
|
|
|
__seterrno_from_nt_status (ret);
|
2002-05-12 09:37:48 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2003-05-25 04:14:19 +08:00
|
|
|
*vmsize = vmc.PagefileUsage / page_size;
|
2010-09-13 21:02:19 +08:00
|
|
|
res = true;
|
2002-05-12 09:37:48 +08:00
|
|
|
out:
|
2005-08-24 12:38:39 +08:00
|
|
|
free (p);
|
2002-05-12 09:37:48 +08:00
|
|
|
CloseHandle (hProcess);
|
2002-05-02 12:26:05 +08:00
|
|
|
return res;
|
|
|
|
}
|