libc/winsup/cygwin/fhandler_process.cc

1514 lines
41 KiB
C++
Raw Normal View History

2002-05-02 06:26:05 +02:00
/* fhandler_process.cc: fhandler for /proc/<pid> virtual filesystem
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>
#include <stdio.h>
2002-05-02 06:26:05 +02: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 02:37:18 +02:00
#include "path.h"
2002-05-02 06:26:05 +02:00
#include "fhandler.h"
#include "fhandler_virtual.h"
2002-05-02 06:26:05 +02:00
#include "pinfo.h"
#include "shared_info.h"
* net.cc (getdomainname): Change second argument of getdomainname to size_t. * fhandler_proc.cc (proc_listing): Add '.' and '..' to directory listing. (fhandler_proc::open): Change use of mode to flags. If the file does not exist already, fail with EROFS if O_CREAT flag is set. Change EROFS error to EACCES error when writing to a file. Use cmalloc to allocate memory for filebuf. (fhandler_proc::close): Use cfree to free filebuf. (fhandler_proc::get_proc_fhandler): Properly detect attempts to access unknown subdir. * fhandler_process.cc (process_listing): Add '.' and '..' to directory listing. (fhandler_process::open): Use cmalloc to allocate memory for filebuf. (fhandler_process::close): Use cfree to free filebuf. * fhandler_registry.cc (registry_listing): Add . and '..' to directory listing. (fhandler_registry::open): Move check for open for writing before open_key. Use cmalloc to allocate memory for filebuf. (fhandler_registry::close): Use cfree to free filebuf. (fhandler_registry::telldir): Use lower 16 bits of __d_position as position in directory. (fhandler_registry::seekdir): Ditto. * fhandler_virtual.cc (fhandler_virtual::write): Change EROFS error to EACCES error. (fhandler_virtual::open): Set the NOHANDLE flag. (fhandler_virtual::dup): Add call to fhandler_base::dup. Allocate child's filebuf using cmalloc. Copy filebuf from parent to child. (fhandler_virtual::close): Use cfree to free filebuf. (fhandler_virtual::~fhandler_virtual): Ditto. (from Chris Faylor <cgf@redhat.com>). (fhandler_registry::readdir): Add support for '.' and '..' files in subdirectories of /proc/registry. * path.cc (path_conv::check): Do not return ENOENT if a file is not found in /proc.
2002-05-04 05:24:35 +02:00
#include "dtable.h"
#include "cygheap.h"
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
#include "ntdll.h"
#include "cygtls.h"
#include "mount.h"
* Makefile.in (DLL_OFILES): Add tls_pbuf.o. * autoload.cc (CreateDesktopW): Replace CreateDesktopA. (CreateWindowStationW): Replace CreateWindowStationA. (GetUserObjectInformationW): Replace GetUserObjectInformationA. * cygheap.h (cwdstuff::get): Assume default buffer size NT_MAX_PATH. * cygtls.cc (_cygtls::remove): Free temporary TLS path buffers. * cygtls.h (TP_NUM_C_BUFS): Define. (TP_NUM_W_BUFS): Define. (class tls_pathbuf): New class to store pointers to thread local temporary path buffers. (_local_storage::pathbufs): New member. * environ.cc (win_env::add_cache): Use temporary TLS path buffer instead of stack based buffer. (posify): Get temporary outenv buffer from calling function. (environ_init): Create temporary TLS path buffer for posify. (build_env): Create Windows environment block as WCHAR buffer. * environ.h (build_env): Change declaration accordingly. * external.cc (sync_winenv): Accommodate build_env change. * fhandler_console.cc (fhandler_console::need_invisible): Use GetUserObjectInformationW and CreateWindowStationW. * fhandler_process.cc (format_process_maps): Use temporary TLS path buffer instead of stack based buffer. * fork.cc (frok::parent): Convert to use CreateProcessW. * path.cc: Throughout use temporary TLS path buffers instead of stack based buffer. Replace checks for CYG_MAX_PATH by checks for NT_MAX_PATH. (getfileattr): New function to replace GetFileAttributesA. (normalize_win32_path): Remove Win32 and NT long path prefixes. (getwd): Assume PATH_MAX + 1 buffer per SUSv3. * path.h (class path_conv): Set path buffer to size NT_MAX_PATH. (iswdrive): Define. * pinfo.cc (commune_process): Use temporary TLS path buffer instead of stack based buffer. * registry.cc (get_registry_hive_path): Ditto. (load_registry_hive): Ditto. * spawn.cc (spawn_guts): Convert to use CreateProcessW and CreateProcessAsUserW. (av::fixup): Open/close file using NtOpenFile/NtClose. * syscalls.cc (mknod_worker): Allow PATH_MAX file name. (mknod32): Ditto. (getusershell): Ditto. * tls_pbuf.cc: New file implementing tls_pathbuf and tmp_pathbuf methods. * tls_pbuf.h: New header for files using tmp_pathbuf. * tlsoffsets.h: Regenerate. * winsup.h (NT_MAX_PATH): Define as 32767 to avoid USHORT overflow.
2008-03-07 12:24:51 +01:00
#include "tls_pbuf.h"
#include <sys/sysmacros.h>
#include <sys/param.h>
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
#include <ctype.h>
2002-05-02 06:26:05 +02:00
#define _COMPILING_NEWLIB
#include <dirent.h>
2013-04-23 11:44:36 +02:00
static off_t format_process_maps (void *, char *&);
static off_t format_process_stat (void *, char *&);
static off_t format_process_status (void *, char *&);
static off_t format_process_statm (void *, char *&);
static off_t format_process_winexename (void *, char *&);
static off_t format_process_winpid (void *, char *&);
static off_t format_process_exename (void *, char *&);
static off_t format_process_root (void *, char *&);
static off_t format_process_cwd (void *, char *&);
static off_t format_process_cmdline (void *, char *&);
static off_t format_process_ppid (void *, char *&);
static off_t format_process_uid (void *, char *&);
static off_t format_process_pgid (void *, char *&);
static off_t format_process_sid (void *, char *&);
static off_t format_process_gid (void *, char *&);
static off_t format_process_ctty (void *, char *&);
static off_t format_process_fd (void *, char *&);
static off_t format_process_mounts (void *, char *&);
static off_t format_process_mountinfo (void *, char *&);
static const virt_tab_t process_tab[] =
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
{
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02: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 ("mountinfo"), FH_PROCESS, virt_file, format_process_mountinfo },
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
{ _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, FH_NADA, virt_none, NULL }
2002-05-02 06:26:05 +02:00
};
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
static const int PROCESS_LINK_COUNT =
(sizeof (process_tab) / sizeof (virt_tab_t)) - 1;
int get_process_state (DWORD dwProcessId);
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);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
2002-05-02 06:26:05 +02:00
/* Returns 0 if path doesn't exist, >0 if path is a directory,
-1 if path is a file, -2 if path is a symlink, -3 if path is a pipe,
-4 if path is a socket. */
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
virtual_ftype_t
fhandler_process::exists ()
2002-05-02 06:26:05 +02:00
{
const char *path = get_name ();
2002-05-02 06:26:05 +02:00
debug_printf ("exists (%s)", path);
path += proc_len + 1;
while (*path != 0 && !isdirsep (*path))
2002-05-02 06:26:05 +02:00
path++;
if (*path == 0)
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
return virt_rootdir;
2002-05-02 06:26:05 +02:00
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
virt_tab_t *entry = virt_tab_search (path + 1, true, process_tab,
PROCESS_LINK_COUNT);
if (entry)
{
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
if (!path[entry->name_len + 1])
2005-05-02 05:50:11 +02:00
{
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
fileid = entry - process_tab;
return entry->type;
}
if (entry->type == virt_directory) /* fd subdir only */
{
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
fileid = entry - process_tab;
if (fill_filebuf ())
return fd_type;
/* 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;
}
}
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
}
return virt_none;
2002-05-02 06:26:05 +02:00
}
fhandler_process::fhandler_process ():
* devices.cc: New file. * devices.gperf: New file. * devices.shilka: New file. * cygwin-gperf: New file. * cygwin-shilka: New file. * fhandler_fifo.cc: New file. * fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes fhandler.h throughout. Remove device argument and unit arguments from fhandler constructors throughout. Remove pc arguments to fhandler functions and use internal pc element instead, throughout. Use dev element in pc throughout. Use major/minor elements rather than units and device numbers previously in fhandler class. Use correct methods for fhandler file names rather than directly accessing file name variables, throughout. * Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o * dcrt0.cc (dll_crt0_1): Call device::init. * devices.h: Renumber devices based on more Linux-like major/minor numbers. Add more devices. Declare standard device storage. (device): Declare struct. * dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type. * dtable.cc (dtable::get_debugger_info): Ditto. (cygwin_attach_handle_to_fd): Ditto. (dtable::release): Remove special FH_SOCKET case in favor of generic "need_fixup_before" test. (dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name to build standard fhandler. (dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move out of dtable class. Don't accept a path_conv argument. Just build it here and pass it to: (build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class. Use intrinsic device type in path_conv to create new fhandler. (build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class. Simplify arguments to just take new 'device' type and a name. Just return pointer to fhandler rather than trying to insert into dtable. (dtable::dup_worker): Accommodate above build_fh name changes. (dtable::find_fifo): New (currently broken) function. (handle_to_fn): Use strechr for efficiency. * dtable.h: Reflect above build_fh name changes and argument differences. (fhandler_base *&operator []): Return self rather than copy of self. * fhandler.cc (fhandler_base::operator =): Use pc element to set normalized path. (fhandler_base::set_name): Ditto. (fhandler_base::raw_read): Use method to access name. (fhandler_base::write): Correctly use get_output_handle rather than get_handle. (handler_base::device_access_denied): New function. (fhandler_base::open): Eliminate pc argument and use pc element of fhandler_base throughout. (fhandler_base::fstat): Detect if device is based in filesystem and use fstat_fs to calculate stat, if so. (fhandler_base::fhandler_base): Eliminate handling of file names and, instead, just free appropriate component from pc. (fhandler_base::opendir): Remove path_conv parameter. * fhandler.h: Remove all device flags. (fhandler_base::pc): New element. (fhandler_base::set_name): Change argument to path_conv. (fhandler_base::error): New function. (fhandler_base::exists): New function. (fhandler_base::pc_binmode): New function. (fhandler_base::dev): New function. (fhandler_base::open_fs): New function. (fhandler_base::fstat_fs): New function. (fhandler_base::fstat_by_name): New function. (fhandler_base::fstat_by_handle): New function. (fhandler_base::isfifo): New function. (fhandler_base::is_slow): New function. (fhandler_base::is_auto_device): New function. (fhandler_base::is_fs_special): New function. (fhandler_base::device_access_denied): New function. (fhandler_base::operator DWORD&): New operator. (fhandler_base::get_name): Return normalized path from pc. (fhandler_base::get_win32_name): Return windows path from pc. (fhandler_base::isdevice): Renamed from is_device. (fhandler_base::get_native_name): Return device format. (fhandler_fifo): New class. (fhandler_nodevice): New class. (select_stuff::device_specific): Remove array. (select_stuff::device_specific_pipe): New class element. (select_stuff::device_specific_socket): New class element. (select_stuff::device_specific_serial): New class element. (select_stuff::select_stuff): Initialize new elements. * fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class from fhandler_disk_file. (fhandler_base::fstat_by_name): Ditto. (fhandler_base::fstat_by_name): Ditto. (fhandler_disk_file::open): Move most functionality into fhandler_base::open_fs. (fhandler_base::open_fs): New function. (fhandler_disk_file::close): Move most functionality into fhandler_base::close_fs. (fhandler_base::close_fs): New function. * fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging output. * fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard urandom device into appropriate place. (fhandler_socket::accept): Reflect change in fdsock return value. * fhandler_tty.cc: See "throughouts" above. * net.cc: Accommodate fdsock change throughout. (fdsock): Return success or failure, accept fd argument and device argument. * path.cc (symlink_info::major): New element. (symlink_info::minor): New element. (symlink_info::parse_device): Declare new function. (fs_info::update): Accommodate changes in path_conv class. (path_conv::fillin): Ditto. (path_conv::return_and_clear_normalized_path): Eliminate. (path_conv::set_normalized_path): New function. (path_conv::path_conv): Set info in dev element. Use path_conv methods Check for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff. where appropriate rather than direct access. Use set_normalized_path to set normalized path. (windows_device_names): Eliminate. (get_dev): Ditto. (get_raw_device_number): Ditto. (get_device_number): Ditto. (win32_device_name): Call new device name parser to do most of the heavy lifting. (mount_info::conv_to_win32_path): Fill in dev field as appropriate. (symlink_worker): Handle new device files. (symlink_info::check): Ditto. (symlink_info::parse_device): Define new function. * path.h (executable_states): Move here from fhandler.h. (fs_info): Rename variables to *_storage and create methods for accessing same. (path_conv): Add dev element, remove devn and unit and adjust inline methods to accommodate. (set_normalized_path): Declare new function. * pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos. (_pinfo::commune_send): Ditto. * pipe.cc (fhandler_pipe::close): check for existence of handle before closing it. (handler_pipe::create): Rename from make_pipe. Change arguments to accept fhandler_pipe array. Accommodate fifos. (pipe): Rework to deal with fhandler_pipe::create changes. (_pipe): Ditto. * select.cc: Use individual device_specific types throughout rather than indexing with obsolete device number. (set_bits): Use is_socket call rather than checking device number. * shared_info.h (CURR_MOUNT_MAGIC): Update. (conv_to_win32_path): Reflect addition of device argument. * syscalls.cc (mknod_worker): New function. (open): Use build_fh_name to build fhandler. (chown_worker): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. (chmod_device): New function. (chmod): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. Use chmod_device to set mode of in-filesystem devices. (stat_worker): Eliminate path_conv argument. Call build_fh_name to construct fhandler. Use fh->error() rather than pc->error to detect errors in fhandler construction. (access_worker): New function pulled from access. Accommodate in-filesystem devices. (access): Use access_worker. (fpathconf): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. (mknod_worker): New function. (mknod32): New function. (chroot): Free normalized path -- assuming it was actually cmalloced. * tty.cc (create_tty_master): Tweak for new device class. (tty::common_init): Ditto. * winsup.h (stat_worker): Remove. (symlink_worker): Declare. * exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't worry about pending_signals since sig_dispatch_pending should always do the right thing now. (sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3. * pinfo.h: Move __SIG enum to sigproc.h. (PICOM_FIFO): New enum element. (_pinfo): Remove 'thread2signal' stuff throughout class. (_pinfo::commune_send): Make varargs. (_pinfo::sigtodo): Eliminate. (_pinfo::thread2signal): Ditto. * signal.cc (kill_worker): Eliminate call to setthread2signal. * sigproc.cc (local_sigtodo): Eliminate. (getlocal_sigtodo): Ditto. (sigelem): New class. (pending_signals): New class. (sigqueue): New variable, start of sigqueue linked list. (sigcatch_nonmain): Eliminate. (sigcatch_main): Eliminate. (sigcatch_nosync): Eliminate. (sigcomplete_nonmain): Eliminate. (pending_signals): Eliminate. (sig_clear): Call signal thread to clear pending signals, unless already in signal thread. (sigpending): Call signal thread to get pending signals. (sig_dispatch_pending): Eliminate use of pending_signals and just check sigqueue. (sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close signal pipe handle. (sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send signals. (getevent): Eliminate. (pending_signals::add): New function. (pending_signals::del): New function. (pending_signals::next): New function. (wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to communicate and maintain a linked list of signals. * sigproc.h: Move __SIG defines here. Add __SIGPENDING. (sig_dispatch_pending): Remove "C" specifier. (sig_handle): Accept a mask argument. * thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
fhandler_proc ()
2002-05-02 06:26:05 +02:00
{
}
int __reg2
2013-04-23 11:44:36 +02:00
fhandler_process::fstat (struct stat *buf)
2002-05-02 06:26:05 +02:00
{
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
const char *path = get_name ();
int file_type = exists ();
fhandler_base::fstat (buf);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
path += proc_len + 1;
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
pid = atoi (path);
pinfo p (pid);
/* If p->pid != pid, then pid is actually the Windows PID for an execed
Cygwin process, and the pinfo entry is the additional entry created
at exec time. We don't want to enable the user to access a process
entry by using the Win32 PID, though. */
if (!p || p->pid != pid)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
set_errno (ENOENT);
return -1;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
}
buf->st_mode &= ~_IFMT & NO_W;
2002-05-02 06:26:05 +02:00
switch (file_type)
{
case virt_none:
2002-05-02 06:26:05 +02:00
set_errno (ENOENT);
return -1;
case virt_directory:
case virt_rootdir:
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;
time_as_timestruc_t (&buf->st_atim);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
buf->st_uid = p->uid;
buf->st_gid = p->gid;
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
if (file_type == 1)
buf->st_nlink = 2;
else
buf->st_nlink = 3;
2002-05-02 06:26:05 +02:00
return 0;
case virt_symlink:
buf->st_uid = p->uid;
buf->st_gid = p->gid;
buf->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
return 0;
case virt_pipe:
buf->st_uid = p->uid;
buf->st_gid = p->gid;
buf->st_mode = S_IFIFO | S_IRUSR | S_IWUSR;
return 0;
case virt_socket:
buf->st_uid = p->uid;
buf->st_gid = p->gid;
buf->st_mode = S_IFSOCK | S_IRUSR | S_IWUSR;
return 0;
case virt_file:
default:
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
buf->st_uid = p->uid;
buf->st_gid = p->gid;
buf->st_mode |= S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
2002-05-02 06:26:05 +02:00
return 0;
}
}
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
DIR *
fhandler_process::opendir (int fd)
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
{
DIR *dir = fhandler_virtual::opendir (fd);
if (dir && process_tab[fileid].fhandler == FH_PROCESSFD)
fill_filebuf ();
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
return dir;
}
int
fhandler_process::closedir (DIR *dir)
{
return fhandler_virtual::closedir (dir);
}
int
fhandler_process::readdir (DIR *dir, dirent *de)
2002-05-02 06:26:05 +02:00
{
int res = ENMFILE;
if (process_tab[fileid].fhandler == FH_PROCESSFD)
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
{
2013-04-23 11:44:36 +02:00
if ((size_t) dir->__d_position >= 2 + filesize / sizeof (int))
goto out;
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
}
else if (dir->__d_position >= PROCESS_LINK_COUNT)
goto out;
if (process_tab[fileid].fhandler == FH_PROCESSFD && dir->__d_position > 1)
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
{
int *p = (int *) filebuf;
__small_sprintf (de->d_name, "%d", p[dir->__d_position++ - 2]);
de->d_type = DT_LNK;
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
}
else
{
strcpy (de->d_name, process_tab[dir->__d_position].name);
de->d_type = virt_ftype_to_dtype (process_tab[dir->__d_position].type);
dir->__d_position++;
}
* autoload.cc (NtQueryDirectoryFile): Define. * dir.cc (__opendir_with_d_ino): Just call opendir. (opendir): Remove CYGWIN_VERSION_CHECK_FOR_NEEDS_D_INO handling. (readdir_worker): Only try generating d_ino if it's 0. Utilize namehash of directories fhandler. Call readdir_get_ino to generate d_ino for "..". (seekdir64): Keep dirent_set_d_ino flag. * fhandler.h (enum dirent_states): Add dirent_get_d_ino. (class fhandler_disk_file): Declare new private methods readdir_helper and readdir_9x. * fhandler_disk_file.cc (path_conv::hasgood_inode): New method to evaluate if a filesystem has reliable inode numbers. (fhandler_base::fstat_by_handle): Accomodate structure member name change from IndexNumber to FileId. (fhandler_base::fstat_helper): Call hasgood_inode here. (fhandler_disk_file::opendir): Call fhaccess only for real files. Don't append '*' to __d_dirname here, move to readdir_9x. On NT, open directory handle here. Set dirent_get_d_ino and dirent_set_d_ino flags according to wincap and filesystem. (fhandler_disk_file::readdir_helper): New method to implement readdir postprocessing only once. (readdir_get_ino_by_handle): New static function. (readdir_get_ino): New function to centralize inode number evaluation in case inode number hasn't been returned by NtQueryDirectoryFile. (fhandler_disk_file::readdir): Move old functionality to readdir_9x. Call readdir_9x when on 9x/Me. Implement NT specific readdir here. (fhandler_disk_file::readdir_9x): Move 9x specific readdir here. (fhandler_disk_file::seekdir): Accomodate new NT readdir method. (fhandler_disk_file::closedir): Ditto. (fhandler_cygdrive::fstat): Set d_ino to namehash. Add comment. (fhandler_cygdrive::opendir): Call get_namehash to prepare later correct evaluation of d_ino. (fhandler_cygdrive::readdir): Replace recursion with loop. Evaluate drive's d_ino by calling readdir_get_ino. * fhandler_proc.cc (fhandler_proc::readdir): Set dirent_saw_dot and dirent_saw_dot_dot to avoid seeing . and .. entries twice. * fhandler_process.cc (fhandler_process::readdir): Ditto. * fhandler_registry.cc (fhandler_registry::readdir): Ditto. * ntdll.h (STATUS_INVALID_PARAMETER): New define. (STATUS_INVALID_LEVEL): New define. (struct _FILE_INTERNAL_INFORMATION): Rename member IndexNumber to FileId (as in Nebbitt). * path.h (path_conv::hasgood_inode): Now implemented in fhandler_disk_file.cc. * wincap.h (wincaps::has_fileid_dirinfo): New element. * wincap.cc: Implement above element throughout. * winsup.h (readdir_get_ino): Add declaration. * include/sys/dirent.h (struct dirent): Slightly rename structure members to accomodate changes. Remove __USE_EXPENSIVE_CYGWIN_D_INO handling and declaration of __opendir_with_d_ino.
2006-01-27 22:50:42 +01:00
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
res = 0;
out:
syscall_printf ("%d = readdir(%p, %p) (%s)", res, dir, de, de->d_name);
return res;
2002-05-02 06:26:05 +02:00
}
int
* devices.cc: New file. * devices.gperf: New file. * devices.shilka: New file. * cygwin-gperf: New file. * cygwin-shilka: New file. * fhandler_fifo.cc: New file. * fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes fhandler.h throughout. Remove device argument and unit arguments from fhandler constructors throughout. Remove pc arguments to fhandler functions and use internal pc element instead, throughout. Use dev element in pc throughout. Use major/minor elements rather than units and device numbers previously in fhandler class. Use correct methods for fhandler file names rather than directly accessing file name variables, throughout. * Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o * dcrt0.cc (dll_crt0_1): Call device::init. * devices.h: Renumber devices based on more Linux-like major/minor numbers. Add more devices. Declare standard device storage. (device): Declare struct. * dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type. * dtable.cc (dtable::get_debugger_info): Ditto. (cygwin_attach_handle_to_fd): Ditto. (dtable::release): Remove special FH_SOCKET case in favor of generic "need_fixup_before" test. (dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name to build standard fhandler. (dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move out of dtable class. Don't accept a path_conv argument. Just build it here and pass it to: (build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class. Use intrinsic device type in path_conv to create new fhandler. (build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class. Simplify arguments to just take new 'device' type and a name. Just return pointer to fhandler rather than trying to insert into dtable. (dtable::dup_worker): Accommodate above build_fh name changes. (dtable::find_fifo): New (currently broken) function. (handle_to_fn): Use strechr for efficiency. * dtable.h: Reflect above build_fh name changes and argument differences. (fhandler_base *&operator []): Return self rather than copy of self. * fhandler.cc (fhandler_base::operator =): Use pc element to set normalized path. (fhandler_base::set_name): Ditto. (fhandler_base::raw_read): Use method to access name. (fhandler_base::write): Correctly use get_output_handle rather than get_handle. (handler_base::device_access_denied): New function. (fhandler_base::open): Eliminate pc argument and use pc element of fhandler_base throughout. (fhandler_base::fstat): Detect if device is based in filesystem and use fstat_fs to calculate stat, if so. (fhandler_base::fhandler_base): Eliminate handling of file names and, instead, just free appropriate component from pc. (fhandler_base::opendir): Remove path_conv parameter. * fhandler.h: Remove all device flags. (fhandler_base::pc): New element. (fhandler_base::set_name): Change argument to path_conv. (fhandler_base::error): New function. (fhandler_base::exists): New function. (fhandler_base::pc_binmode): New function. (fhandler_base::dev): New function. (fhandler_base::open_fs): New function. (fhandler_base::fstat_fs): New function. (fhandler_base::fstat_by_name): New function. (fhandler_base::fstat_by_handle): New function. (fhandler_base::isfifo): New function. (fhandler_base::is_slow): New function. (fhandler_base::is_auto_device): New function. (fhandler_base::is_fs_special): New function. (fhandler_base::device_access_denied): New function. (fhandler_base::operator DWORD&): New operator. (fhandler_base::get_name): Return normalized path from pc. (fhandler_base::get_win32_name): Return windows path from pc. (fhandler_base::isdevice): Renamed from is_device. (fhandler_base::get_native_name): Return device format. (fhandler_fifo): New class. (fhandler_nodevice): New class. (select_stuff::device_specific): Remove array. (select_stuff::device_specific_pipe): New class element. (select_stuff::device_specific_socket): New class element. (select_stuff::device_specific_serial): New class element. (select_stuff::select_stuff): Initialize new elements. * fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class from fhandler_disk_file. (fhandler_base::fstat_by_name): Ditto. (fhandler_base::fstat_by_name): Ditto. (fhandler_disk_file::open): Move most functionality into fhandler_base::open_fs. (fhandler_base::open_fs): New function. (fhandler_disk_file::close): Move most functionality into fhandler_base::close_fs. (fhandler_base::close_fs): New function. * fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging output. * fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard urandom device into appropriate place. (fhandler_socket::accept): Reflect change in fdsock return value. * fhandler_tty.cc: See "throughouts" above. * net.cc: Accommodate fdsock change throughout. (fdsock): Return success or failure, accept fd argument and device argument. * path.cc (symlink_info::major): New element. (symlink_info::minor): New element. (symlink_info::parse_device): Declare new function. (fs_info::update): Accommodate changes in path_conv class. (path_conv::fillin): Ditto. (path_conv::return_and_clear_normalized_path): Eliminate. (path_conv::set_normalized_path): New function. (path_conv::path_conv): Set info in dev element. Use path_conv methods Check for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff. where appropriate rather than direct access. Use set_normalized_path to set normalized path. (windows_device_names): Eliminate. (get_dev): Ditto. (get_raw_device_number): Ditto. (get_device_number): Ditto. (win32_device_name): Call new device name parser to do most of the heavy lifting. (mount_info::conv_to_win32_path): Fill in dev field as appropriate. (symlink_worker): Handle new device files. (symlink_info::check): Ditto. (symlink_info::parse_device): Define new function. * path.h (executable_states): Move here from fhandler.h. (fs_info): Rename variables to *_storage and create methods for accessing same. (path_conv): Add dev element, remove devn and unit and adjust inline methods to accommodate. (set_normalized_path): Declare new function. * pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos. (_pinfo::commune_send): Ditto. * pipe.cc (fhandler_pipe::close): check for existence of handle before closing it. (handler_pipe::create): Rename from make_pipe. Change arguments to accept fhandler_pipe array. Accommodate fifos. (pipe): Rework to deal with fhandler_pipe::create changes. (_pipe): Ditto. * select.cc: Use individual device_specific types throughout rather than indexing with obsolete device number. (set_bits): Use is_socket call rather than checking device number. * shared_info.h (CURR_MOUNT_MAGIC): Update. (conv_to_win32_path): Reflect addition of device argument. * syscalls.cc (mknod_worker): New function. (open): Use build_fh_name to build fhandler. (chown_worker): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. (chmod_device): New function. (chmod): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. Use chmod_device to set mode of in-filesystem devices. (stat_worker): Eliminate path_conv argument. Call build_fh_name to construct fhandler. Use fh->error() rather than pc->error to detect errors in fhandler construction. (access_worker): New function pulled from access. Accommodate in-filesystem devices. (access): Use access_worker. (fpathconf): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. (mknod_worker): New function. (mknod32): New function. (chroot): Free normalized path -- assuming it was actually cmalloced. * tty.cc (create_tty_master): Tweak for new device class. (tty::common_init): Ditto. * winsup.h (stat_worker): Remove. (symlink_worker): Declare. * exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't worry about pending_signals since sig_dispatch_pending should always do the right thing now. (sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3. * pinfo.h: Move __SIG enum to sigproc.h. (PICOM_FIFO): New enum element. (_pinfo): Remove 'thread2signal' stuff throughout class. (_pinfo::commune_send): Make varargs. (_pinfo::sigtodo): Eliminate. (_pinfo::thread2signal): Ditto. * signal.cc (kill_worker): Eliminate call to setthread2signal. * sigproc.cc (local_sigtodo): Eliminate. (getlocal_sigtodo): Ditto. (sigelem): New class. (pending_signals): New class. (sigqueue): New variable, start of sigqueue linked list. (sigcatch_nonmain): Eliminate. (sigcatch_main): Eliminate. (sigcatch_nosync): Eliminate. (sigcomplete_nonmain): Eliminate. (pending_signals): Eliminate. (sig_clear): Call signal thread to clear pending signals, unless already in signal thread. (sigpending): Call signal thread to get pending signals. (sig_dispatch_pending): Eliminate use of pending_signals and just check sigqueue. (sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close signal pipe handle. (sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send signals. (getevent): Eliminate. (pending_signals::add): New function. (pending_signals::del): New function. (pending_signals::next): New function. (wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to communicate and maintain a linked list of signals. * sigproc.h: Move __SIG defines here. Add __SIGPENDING. (sig_dispatch_pending): Remove "C" specifier. (sig_handle): Accept a mask argument. * thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
fhandler_process::open (int flags, mode_t mode)
2002-05-02 06:26:05 +02:00
{
* devices.cc: New file. * devices.gperf: New file. * devices.shilka: New file. * cygwin-gperf: New file. * cygwin-shilka: New file. * fhandler_fifo.cc: New file. * fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes fhandler.h throughout. Remove device argument and unit arguments from fhandler constructors throughout. Remove pc arguments to fhandler functions and use internal pc element instead, throughout. Use dev element in pc throughout. Use major/minor elements rather than units and device numbers previously in fhandler class. Use correct methods for fhandler file names rather than directly accessing file name variables, throughout. * Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o * dcrt0.cc (dll_crt0_1): Call device::init. * devices.h: Renumber devices based on more Linux-like major/minor numbers. Add more devices. Declare standard device storage. (device): Declare struct. * dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type. * dtable.cc (dtable::get_debugger_info): Ditto. (cygwin_attach_handle_to_fd): Ditto. (dtable::release): Remove special FH_SOCKET case in favor of generic "need_fixup_before" test. (dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name to build standard fhandler. (dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move out of dtable class. Don't accept a path_conv argument. Just build it here and pass it to: (build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class. Use intrinsic device type in path_conv to create new fhandler. (build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class. Simplify arguments to just take new 'device' type and a name. Just return pointer to fhandler rather than trying to insert into dtable. (dtable::dup_worker): Accommodate above build_fh name changes. (dtable::find_fifo): New (currently broken) function. (handle_to_fn): Use strechr for efficiency. * dtable.h: Reflect above build_fh name changes and argument differences. (fhandler_base *&operator []): Return self rather than copy of self. * fhandler.cc (fhandler_base::operator =): Use pc element to set normalized path. (fhandler_base::set_name): Ditto. (fhandler_base::raw_read): Use method to access name. (fhandler_base::write): Correctly use get_output_handle rather than get_handle. (handler_base::device_access_denied): New function. (fhandler_base::open): Eliminate pc argument and use pc element of fhandler_base throughout. (fhandler_base::fstat): Detect if device is based in filesystem and use fstat_fs to calculate stat, if so. (fhandler_base::fhandler_base): Eliminate handling of file names and, instead, just free appropriate component from pc. (fhandler_base::opendir): Remove path_conv parameter. * fhandler.h: Remove all device flags. (fhandler_base::pc): New element. (fhandler_base::set_name): Change argument to path_conv. (fhandler_base::error): New function. (fhandler_base::exists): New function. (fhandler_base::pc_binmode): New function. (fhandler_base::dev): New function. (fhandler_base::open_fs): New function. (fhandler_base::fstat_fs): New function. (fhandler_base::fstat_by_name): New function. (fhandler_base::fstat_by_handle): New function. (fhandler_base::isfifo): New function. (fhandler_base::is_slow): New function. (fhandler_base::is_auto_device): New function. (fhandler_base::is_fs_special): New function. (fhandler_base::device_access_denied): New function. (fhandler_base::operator DWORD&): New operator. (fhandler_base::get_name): Return normalized path from pc. (fhandler_base::get_win32_name): Return windows path from pc. (fhandler_base::isdevice): Renamed from is_device. (fhandler_base::get_native_name): Return device format. (fhandler_fifo): New class. (fhandler_nodevice): New class. (select_stuff::device_specific): Remove array. (select_stuff::device_specific_pipe): New class element. (select_stuff::device_specific_socket): New class element. (select_stuff::device_specific_serial): New class element. (select_stuff::select_stuff): Initialize new elements. * fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class from fhandler_disk_file. (fhandler_base::fstat_by_name): Ditto. (fhandler_base::fstat_by_name): Ditto. (fhandler_disk_file::open): Move most functionality into fhandler_base::open_fs. (fhandler_base::open_fs): New function. (fhandler_disk_file::close): Move most functionality into fhandler_base::close_fs. (fhandler_base::close_fs): New function. * fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging output. * fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard urandom device into appropriate place. (fhandler_socket::accept): Reflect change in fdsock return value. * fhandler_tty.cc: See "throughouts" above. * net.cc: Accommodate fdsock change throughout. (fdsock): Return success or failure, accept fd argument and device argument. * path.cc (symlink_info::major): New element. (symlink_info::minor): New element. (symlink_info::parse_device): Declare new function. (fs_info::update): Accommodate changes in path_conv class. (path_conv::fillin): Ditto. (path_conv::return_and_clear_normalized_path): Eliminate. (path_conv::set_normalized_path): New function. (path_conv::path_conv): Set info in dev element. Use path_conv methods Check for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff. where appropriate rather than direct access. Use set_normalized_path to set normalized path. (windows_device_names): Eliminate. (get_dev): Ditto. (get_raw_device_number): Ditto. (get_device_number): Ditto. (win32_device_name): Call new device name parser to do most of the heavy lifting. (mount_info::conv_to_win32_path): Fill in dev field as appropriate. (symlink_worker): Handle new device files. (symlink_info::check): Ditto. (symlink_info::parse_device): Define new function. * path.h (executable_states): Move here from fhandler.h. (fs_info): Rename variables to *_storage and create methods for accessing same. (path_conv): Add dev element, remove devn and unit and adjust inline methods to accommodate. (set_normalized_path): Declare new function. * pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos. (_pinfo::commune_send): Ditto. * pipe.cc (fhandler_pipe::close): check for existence of handle before closing it. (handler_pipe::create): Rename from make_pipe. Change arguments to accept fhandler_pipe array. Accommodate fifos. (pipe): Rework to deal with fhandler_pipe::create changes. (_pipe): Ditto. * select.cc: Use individual device_specific types throughout rather than indexing with obsolete device number. (set_bits): Use is_socket call rather than checking device number. * shared_info.h (CURR_MOUNT_MAGIC): Update. (conv_to_win32_path): Reflect addition of device argument. * syscalls.cc (mknod_worker): New function. (open): Use build_fh_name to build fhandler. (chown_worker): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. (chmod_device): New function. (chmod): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. Use chmod_device to set mode of in-filesystem devices. (stat_worker): Eliminate path_conv argument. Call build_fh_name to construct fhandler. Use fh->error() rather than pc->error to detect errors in fhandler construction. (access_worker): New function pulled from access. Accommodate in-filesystem devices. (access): Use access_worker. (fpathconf): Detect if this is an 'auto' device rather than an on-filesystem device and handle appropriately. (mknod_worker): New function. (mknod32): New function. (chroot): Free normalized path -- assuming it was actually cmalloced. * tty.cc (create_tty_master): Tweak for new device class. (tty::common_init): Ditto. * winsup.h (stat_worker): Remove. (symlink_worker): Declare. * exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't worry about pending_signals since sig_dispatch_pending should always do the right thing now. (sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3. * pinfo.h: Move __SIG enum to sigproc.h. (PICOM_FIFO): New enum element. (_pinfo): Remove 'thread2signal' stuff throughout class. (_pinfo::commune_send): Make varargs. (_pinfo::sigtodo): Eliminate. (_pinfo::thread2signal): Ditto. * signal.cc (kill_worker): Eliminate call to setthread2signal. * sigproc.cc (local_sigtodo): Eliminate. (getlocal_sigtodo): Ditto. (sigelem): New class. (pending_signals): New class. (sigqueue): New variable, start of sigqueue linked list. (sigcatch_nonmain): Eliminate. (sigcatch_main): Eliminate. (sigcatch_nosync): Eliminate. (sigcomplete_nonmain): Eliminate. (pending_signals): Eliminate. (sig_clear): Call signal thread to clear pending signals, unless already in signal thread. (sigpending): Call signal thread to get pending signals. (sig_dispatch_pending): Eliminate use of pending_signals and just check sigqueue. (sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close signal pipe handle. (sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send signals. (getevent): Eliminate. (pending_signals::add): New function. (pending_signals::del): New function. (pending_signals::next): New function. (wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to communicate and maintain a linked list of signals. * sigproc.h: Move __SIG defines here. Add __SIGPENDING. (sig_dispatch_pending): Remove "C" specifier. (sig_handle): Accept a mask argument. * thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
int res = fhandler_virtual::open (flags, mode);
2002-05-02 06:26:05 +02:00
if (!res)
goto out;
* Use new unified status_flag accessor methods from classes fhandler_*, tty_min, mtinfo and fs_info thoroughout. * fhandler.h: Redefine all set_close_on_exec methods to take a bool argument. (enum conn_state): Rename from connect_state. (class fhandler_base): Rename some status flags to align with accessor method names. Drop encoded flag entirely. Unify status accessor methods. Const'ify all read accessor methods. (class fhandler_socket): Ditto. (class fhandler_dev_raw): Ditto. * fhandler_disk_file.cc (fhandler_base::fstat_fs): Use fs.fs_is_fat() instead of evaluating FATness of file system here. (fhandler_disk_file::opendir): Drop call to set_encoded(). (fhandler_disk_file::readdir): Use pc.isencoded() directly. * mtinfo.h (class mtinfo_drive): Const'ify all read accessor methods. * path.cc (fsinfo_cnt): Add. (fs_info::update): Accomodate class changes. Evaluate file system name specific flags right here. Add thread safety for reading and writing global fsinfo array. * path.h (enum path_types): Drop values for flags kept in fs already. (struct fs_info): Move status informatin into private struct type status_flags. Add accessor methods. Remove path and file system name string arrays in favor of status bits. (class path_conv): Use new fs_info status information where appropriate. (path_conf::fs_has_ea): Rename from fs_fast_ea. (path_conf::fs_has_acls): New method. (path_conf::root_dir): Remove. (path_conf::volname): Remove. * syscalls (statfs): Evaluate root dir locally. * tty.h (class tty_min): Unify status accessor methods. Const'ify all read accessor methods.
2004-04-10 15:45:10 +02:00
nohandle (true);
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
2002-05-02 06:26:05 +02:00
const char *path;
path = get_name () + proc_len + 1;
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
pid = atoi (path);
while (*path != 0 && !isdirsep (*path))
2002-05-02 06:26:05 +02:00
path++;
if (*path == 0)
{
* net.cc (getdomainname): Change second argument of getdomainname to size_t. * fhandler_proc.cc (proc_listing): Add '.' and '..' to directory listing. (fhandler_proc::open): Change use of mode to flags. If the file does not exist already, fail with EROFS if O_CREAT flag is set. Change EROFS error to EACCES error when writing to a file. Use cmalloc to allocate memory for filebuf. (fhandler_proc::close): Use cfree to free filebuf. (fhandler_proc::get_proc_fhandler): Properly detect attempts to access unknown subdir. * fhandler_process.cc (process_listing): Add '.' and '..' to directory listing. (fhandler_process::open): Use cmalloc to allocate memory for filebuf. (fhandler_process::close): Use cfree to free filebuf. * fhandler_registry.cc (registry_listing): Add . and '..' to directory listing. (fhandler_registry::open): Move check for open for writing before open_key. Use cmalloc to allocate memory for filebuf. (fhandler_registry::close): Use cfree to free filebuf. (fhandler_registry::telldir): Use lower 16 bits of __d_position as position in directory. (fhandler_registry::seekdir): Ditto. * fhandler_virtual.cc (fhandler_virtual::write): Change EROFS error to EACCES error. (fhandler_virtual::open): Set the NOHANDLE flag. (fhandler_virtual::dup): Add call to fhandler_base::dup. Allocate child's filebuf using cmalloc. Copy filebuf from parent to child. (fhandler_virtual::close): Use cfree to free filebuf. (fhandler_virtual::~fhandler_virtual): Ditto. (from Chris Faylor <cgf@redhat.com>). (fhandler_registry::readdir): Add support for '.' and '..' files in subdirectories of /proc/registry. * path.cc (path_conv::check): Do not return ENOENT if a file is not found in /proc.
2002-05-04 05:24:35 +02:00
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
{
set_errno (EEXIST);
res = 0;
goto out;
}
* net.cc (getdomainname): Change second argument of getdomainname to size_t. * fhandler_proc.cc (proc_listing): Add '.' and '..' to directory listing. (fhandler_proc::open): Change use of mode to flags. If the file does not exist already, fail with EROFS if O_CREAT flag is set. Change EROFS error to EACCES error when writing to a file. Use cmalloc to allocate memory for filebuf. (fhandler_proc::close): Use cfree to free filebuf. (fhandler_proc::get_proc_fhandler): Properly detect attempts to access unknown subdir. * fhandler_process.cc (process_listing): Add '.' and '..' to directory listing. (fhandler_process::open): Use cmalloc to allocate memory for filebuf. (fhandler_process::close): Use cfree to free filebuf. * fhandler_registry.cc (registry_listing): Add . and '..' to directory listing. (fhandler_registry::open): Move check for open for writing before open_key. Use cmalloc to allocate memory for filebuf. (fhandler_registry::close): Use cfree to free filebuf. (fhandler_registry::telldir): Use lower 16 bits of __d_position as position in directory. (fhandler_registry::seekdir): Ditto. * fhandler_virtual.cc (fhandler_virtual::write): Change EROFS error to EACCES error. (fhandler_virtual::open): Set the NOHANDLE flag. (fhandler_virtual::dup): Add call to fhandler_base::dup. Allocate child's filebuf using cmalloc. Copy filebuf from parent to child. (fhandler_virtual::close): Use cfree to free filebuf. (fhandler_virtual::~fhandler_virtual): Ditto. (from Chris Faylor <cgf@redhat.com>). (fhandler_registry::readdir): Add support for '.' and '..' files in subdirectories of /proc/registry. * path.cc (path_conv::check): Do not return ENOENT if a file is not found in /proc.
2002-05-04 05:24:35 +02:00
else if (flags & O_WRONLY)
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
{
set_errno (EISDIR);
res = 0;
goto out;
}
2002-05-02 06:26:05 +02:00
else
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
{
flags |= O_DIROPEN;
goto success;
}
2002-05-02 06:26:05 +02:00
}
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
virt_tab_t *entry;
entry = virt_tab_search (path + 1, true, process_tab, PROCESS_LINK_COUNT);
if (!entry)
2002-05-02 06:26:05 +02:00
{
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
set_errno ((flags & O_CREAT) ? EROFS : ENOENT);
res = 0;
goto out;
2002-05-02 06:26:05 +02:00
}
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
if (entry->fhandler == FH_PROCESSFD)
{
flags |= O_DIROPEN;
goto success;
}
* net.cc (getdomainname): Change second argument of getdomainname to size_t. * fhandler_proc.cc (proc_listing): Add '.' and '..' to directory listing. (fhandler_proc::open): Change use of mode to flags. If the file does not exist already, fail with EROFS if O_CREAT flag is set. Change EROFS error to EACCES error when writing to a file. Use cmalloc to allocate memory for filebuf. (fhandler_proc::close): Use cfree to free filebuf. (fhandler_proc::get_proc_fhandler): Properly detect attempts to access unknown subdir. * fhandler_process.cc (process_listing): Add '.' and '..' to directory listing. (fhandler_process::open): Use cmalloc to allocate memory for filebuf. (fhandler_process::close): Use cfree to free filebuf. * fhandler_registry.cc (registry_listing): Add . and '..' to directory listing. (fhandler_registry::open): Move check for open for writing before open_key. Use cmalloc to allocate memory for filebuf. (fhandler_registry::close): Use cfree to free filebuf. (fhandler_registry::telldir): Use lower 16 bits of __d_position as position in directory. (fhandler_registry::seekdir): Ditto. * fhandler_virtual.cc (fhandler_virtual::write): Change EROFS error to EACCES error. (fhandler_virtual::open): Set the NOHANDLE flag. (fhandler_virtual::dup): Add call to fhandler_base::dup. Allocate child's filebuf using cmalloc. Copy filebuf from parent to child. (fhandler_virtual::close): Use cfree to free filebuf. (fhandler_virtual::~fhandler_virtual): Ditto. (from Chris Faylor <cgf@redhat.com>). (fhandler_registry::readdir): Add support for '.' and '..' files in subdirectories of /proc/registry. * path.cc (path_conv::check): Do not return ENOENT if a file is not found in /proc.
2002-05-04 05:24:35 +02:00
if (flags & O_WRONLY)
2002-05-02 06:26:05 +02:00
{
set_errno (EROFS);
res = 0;
goto out;
}
* Makefile.in (DLL_OFILES): Add fhandler_procsys.o. * devices.h (enum fh_devices): Add FH_PROCSYS. * devices.in (dev_procsys_storage): New device. * devices.cc: Regenerate. * dtable.cc (build_fh_pc): Add code to allocate fhandler_procsys. * fhandler.h (proc_len): Convert to size_t. (procsys): Declare. (procsys_len): Declare. (enum virtual_ftype_t): Move here from fhandler_virtual.h. Add members supported by fhandler_procsys. (fhandler_virtual::exists): Return virtual_ftype_t. Change in all derived classes. (class fhandler_procsys): New class. (fhandler_union): Add fhandler_procnet and fhandler_procsys members. * fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use ro_u_proc. (fhandler_base::fstat_by_handle): Don't copy attributes if file is an NT device. (fhandler_base::fstat_by_name): Ditto. * fhandler_netdrive.cc (fhandler_netdrive::exists): Return virtual_ftype_t. * fhandler_proc.cc (proc_tab): Sort alphabetically. Use _VN macro to store length. (proc_len): Change to size_t. (proc_tab_cmp): New static function. (virt_tab_search): New function to search entry in virt_tab_t arrays. Use throughout in /proc and sibling classes instead of loop. (fhandler_proc::exists): Return virtual_ftype_t. * fhandler_process.cc (process_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_process::exists): Return virtual_ftype_t. (fhandler_process::open): Simplify code. * fhandler_procnet.cc (procnet_tab): Sort alphabetically. Use _VN macro to store length. (fhandler_procnet::exists): Return virtual_ftype_t. (fhandler_procnet::open): Simplify. * fhandler_procsys.cc: New file. * fhandler_registry.cc (fhandler_registry::exists): Return virtual_ftype_t. * fhandler_virtual.cc (fhandler_virtual::exists): Ditto. * fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h. (virt_tab_t): Add name_len member. (_VN): New macro. (virt_tab_search): Declare. * mount.cc (mount_info::conv_to_win32_path): Fix comment. Backslashify isprocsys_dev paths. * ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define (STATUS_INSTANCE_NOT_AVAILABLE): Define. (STATUS_PIPE_NOT_AVAILABLE): Define. (STATUS_INVALID_PIPE_STATE): Define. (STATUS_PIPE_BUSY): Define. (SYMBOLIC_LINK_QUERY): Define. (NtOpenSymbolicLinkObject): Declare. (NtQuerySymbolicLinkObject): Declare. * path.cc (path_conv::check): Accommodate fact that exists method returns virtual_ftype_t now. Add cases for new virtual_ftype_t types. (cygwin_conv_path): Add GLOBALROOT prefix to native device paths. Make sure to strip \\?\ prefix only for actual filesystem-based paths, not for all paths. * path.h (isproc_dev): Add FH_PROCSYS. (isprocsys_dev): Define.
2010-09-06 11:47:01 +02:00
fileid = entry - process_tab;
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
if (!fill_filebuf ())
{
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
res = 0;
goto out;
}
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
if (flags & O_APPEND)
position = filesize;
else
position = 0;
success:
res = 1;
set_flags ((flags & ~O_TEXT) | O_BINARY);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
set_open_status ();
out:
2013-04-23 11:44:36 +02:00
syscall_printf ("%d = fhandler_proc::open(%y, 0%o)", res, flags, mode);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
return res;
}
struct process_fd_t {
const char *path;
_pinfo *p;
virtual_ftype_t *fd_type;
};
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
bool
fhandler_process::fill_filebuf ()
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
const char *path;
path = get_name () + proc_len + 1;
if (!pid)
* cygheap.h (class cygheap_fdenum): New class to enumerate used fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
2005-01-31 11:28:55 +01:00
pid = atoi (path);
pinfo p (pid);
/* If p->pid != pid, then pid is actually the Windows PID for an execed
Cygwin process, and the pinfo entry is the additional entry created
at exec time. We don't want to enable the user to access a process
entry by using the Win32 PID, though. */
if (!p || p->pid != pid)
{
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
set_errno (ENOENT);
return false;
}
if (process_tab[fileid].format_func)
2002-05-02 06:26:05 +02:00
{
if (process_tab[fileid].fhandler == FH_PROCESSFD)
2011-06-06 07:02:13 +02:00
{
process_fd_t fd = { path, p , &fd_type };
filesize = process_tab[fileid].format_func (&fd, filebuf);
}
else
filesize = process_tab[fileid].format_func (p, filebuf);
return !filesize ? false : true;
}
return false;
}
2013-04-23 11:44:36 +02:00
static off_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;
/* path looks like "$PID/fd", "$PID/fd/", "$PID/fd/[0-9]*". In the latter
case a trailing slash and more followup chars are allowed, provided the
descriptor symlink points to a directory. */
char *fdp = strchr (path, '/') + 3;
/* The "fd" directory itself? */
if (fdp[0] =='\0' || (fdp[0] == '/' && fdp[1] == '\0'))
{
if (destbuf)
cfree (destbuf);
destbuf = p->fds (fs);
*((process_fd_t *) data)->fd_type = virt_symlink;
}
else
{
char *e;
int fd;
if (destbuf)
cfree (destbuf);
fd = strtol (++fdp, &e, 10);
if (fd < 0 || e == fdp || (*e != '/' && *e != '\0'))
{
set_errno (ENOENT);
return 0;
}
destbuf = p->fd (fd, fs);
if (!destbuf || !*destbuf)
{
set_errno (ENOENT);
return 0;
}
if (*e == '\0')
*((process_fd_t *) data)->fd_type = virt_symlink;
else /* trailing path */
{
char *newbuf = (char *) cmalloc_abort (HEAP_STR, strlen (destbuf)
+ strlen (e) + 1);
stpcpy (stpcpy (newbuf, destbuf), e);
cfree (destbuf);
destbuf = newbuf;
*((process_fd_t *) data)->fd_type = virt_fsdir;
}
}
return fs;
}
2013-04-23 11:44:36 +02:00
static off_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);
}
2013-04-23 11:44:36 +02:00
static off_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);
}
2013-04-23 11:44:36 +02:00
static off_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);
}
2013-04-23 11:44:36 +02:00
static off_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);
}
2013-04-23 11:44:36 +02:00
static off_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);
}
2013-04-23 11:44:36 +02:00
static off_t
format_process_ctty (void *data, char *&destbuf)
{
_pinfo *p = (_pinfo *) data;
if (p->ctty < 0)
{
destbuf = (char *) crealloc_abort (destbuf, 2);
return __small_sprintf (destbuf, "\n");
}
device d;
* autoload.cc: Call _api_fatal in asm. * child_info.h: Redefine CURR_CHILD_INFO_MAGIC. (child_info_fork::abort): Rename from handle_failure. Change arguments. * cygtls.h (_local_storage::ttybuf): New field. * dcrt0.cc (vapi_fatal): Split api_fatal. Add "in forked process" to message when appropriate. (api_fatal): Use vapi_fatal. * devices.h: Make multiple inclusion safe. (fh_devices): Add FH_CONS* stuff. Reorder slightly. (device): Eliminate anonymous union. Add more ways to access minor/major. (device::setunit): Accommodate no-longer-anonymous union. (device::is_fs): Ditto. (device::is_fs_special): Ditto. (device::major): New function. (device::minor): Ditto. (device::is_device): New function. (device::not_device): Ditto. (device::operator int): New operator. (device::operator fh_devices): Ditto. (device::operator bool): Ditto. (device::operator DWORD): Ditto. (device::operator =): Ditto. (isproc_dev): New function. (isprocsys_dev): Ditto. (iscons_dev): Ditto. (istty_slave_dev): Ditto. * devices.in: Add new "/dev/cons*" strings. Accommodate no-longer-anonymous union throughout. (BRACK): Use more precise method for initialization. * devices.cc: Regenerate. * dtable.cc (dtable::stdio_init): Use get_cttyp instead of get_tty. (dtable::find_archetype): Use new DWORD operator in device to test archetypes. (dtable::init_std_file_from_handle): Use different method to initialize 'dev'. Adapt to different ctty handling and accommodate /dev/cons*. (fh_alloc): Accommodate no-longer-anonymous union. Adapt to new /dev/cons*. (build_fh_pc): Make debugging output more useful. * exceptions.cc (ctrl_c_handler): Use get_cttyp instead of get_tty. * external.cc (fillout_pinfo): Accommodate new cons* stuff. * fhandler.cc (fhandler_base::read): Eliminate is_slow() test. * fhandler.h (fhandler_base::*): Adapt to changes in device.h. (fhandler_*::is_slow): Delete. ( fhandler_proc::get_proc_fhandler): Return fh_devices type. * fhandler_console.cc (open_shared_console): New function. (console_unit): New class. (console_unit::console_unit): New constructor. (enum_windows): New function. Declare as friend to console_unit. (fhandler_console::set_unit): New function. (fhandler_console::get_tty_stuff): Call set_unit to set the unit number and determine if initialization is needed. Eliminate flags parameter. (tty_list::get_cttyp): Rename (sorta) from get_tty. Return pointer to correct tty_min. (fhandler_console::open): Adapt to elimination of argument to get_tty_stuff. (fhandler_console::output_tcsetattr): Properly detect error condition. (fhandler_console::fixup_after_fork_exec): Adapt to get_tty_stuff() setting tc automatically. * fhandler_proc.cc: Use FH_BAD rather than 0 throughout where using fh_devices enum. (fhandler_proc::get_proc_fhandler): Return fh_devices. Adapt to devices.h changes. * fhandler_process.cc: Adapt to devices.h changes. Use FH_BAD rather than 0 throughout where using fh_devices enum. * fhandler_procnet.cc: Ditto. * fhandler_procsys.cc: Ditto. * fhandler_procsysvipc.cc: Ditto. * fhandler_tape.cc (fhandler_dev_tape::fhandler_dev_tape): Ditto. * fhandler_termios.cc (handler_termios::bg_check): Use tc->ttyname() rather than assuming that we can construct a tty. * fhandler_tty.cc (fhandler_tty_master::fhandler_tty_master): Just return get_minor() of dev. (fhandler_pty_master::process_slave_output): Add slightly more debugging info. (fhandler_tty_slave::fhandler_tty_slave): Change name from ntty to unit. (fhandler_pty_master::open): Ditto. (fhandler_tty_slave::ioctl): Adapt to change which causes ctty to represent a complete device. (fhandler_tty_master::init_console): Add debugging for failure path. (fhandler_pty_master::setup): Use get_unit() to retrieve unit number rather than relying on raw ntty. (fhandler_pty_master::setup): Ditto. * fhandler_virtual.h (virt_tab_t): Redefine fhandler as fh_devices. * fork.cc: Remove obsolete vfork stuff. (frok::child): Don't assume that a ctty == 0 is valid. * mount.cc (mount_info::conv_to_win32_path): Adapt to device struct changes. (mount_info::conv_to_win32_path): Ditto. * path.cc (path_conv::check): Retrive major/minor numbers via a method rather than accessing them directly from device. Rely on dev operators to set/retrieve device information as required by device struct change. * path.h (isproc_dev): Move to devices.h. (isprocsys_dev): Ditto. (isvirtual_dev): Ditto. (path_conv:{isdevice,isfifo,isspecial,iscygdrive,issocket,get_devn,get_unitn}): Use device methods to access/manipulate devices. * pinfo.cc (pinfo::exit): Don't assume that ctty == 0 is valid. Use iscons_dev to determine if a device is a console. (_pinfo::_ctty): Use device::parse to generate tty/cons name. (_pinfo::set_ctty): Don't assume that ctty == 0 is valid. Remove redundant info from debugging. * shared.cc (offsets): Remove console offset. * shared_info.h (shared_locations): Ditto. * syscalls.cc (umask): Use device methods to manipulate device information. (ctermid): Use device::parse to generate term device name. * tlsoffsets.h: Regenerate. * tty.cc (ttyslot): Return minor number of ctty since ctty now represents a full device. (tty::create_master): Set ctty to a complete device. (tty_list::attach): Rework to detect new /dev/cons* stuff. (tty_list::terminate): Adapt to changes to ctty. (tty_list::init): Adapt to change to setntty - pass in device major number. (tty::exists): Use get_unit() to retrive tty unit number. (tty::open_mutex): Ditto. (tty::open_inuse): Ditto. (tty::create_inuse): Ditto. (tty::get_event): Ditto. (tty_min::ttyname): Define new function. * tty.h (tty_min::ntty): Redefine as fh_devices. (tty::exists): Use get_unit() to retrive tty unit number. (tty::open_mutex): Ditto. (tty::open_inuse): Ditto. (tty::create_inuse): Ditto. (tty::get_event): Ditto. (tty_min::ttyname): Declare new function. (tty::getntty): Declare as const. (tty_list::operator []): Assure that only minor part of argument is used. * dll_init.cc (dll_list::alloc): Detect mismatch of data segments early issuing an explicit error message if necessary. * heap.cc (heap_init): Adapt to changes from fork->handle_failure to fork->abort. * pinfo.h (EXITCODE_FORK_FAILED): New enum. (from Ryan Johnson) * sigproc.cc (child_info_fork::abort): Rename from handle_failure. Change arguments to allow passing in a printf-like message. * winsup.h (api_fatal): Delete macro definition. (api_fatal): Redefine from __api_fatal. (vapi_fatal): Declare new function. * include/sys/strace.h (strace_vprintf): Define new macro. * ntdll.h (_SYSTEM_INFORMATION_CLASS): Add SystemHandleInformation.
2011-05-28 20:17:09 +02:00
d.parse (p->ctty);
destbuf = (char *) crealloc_abort (destbuf, strlen (d.name ()) + 2);
return __small_sprintf (destbuf, "%s\n", d.name ());
}
2013-04-23 11:44:36 +02:00
static off_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 06:26:05 +02:00
}
return fs;
}
2013-04-23 11:44:36 +02:00
static off_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;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
}
2002-05-02 06:26:05 +02:00
2013-04-23 11:44:36 +02:00
static off_t
format_process_cmdline (void *data, char *&destbuf)
{
_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;
}
2013-04-23 11:44:36 +02:00
static off_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
{
Allow cygwin_conv_path(3) and cygpath(1) to emit /proc/cygdrive prefixed path * include/sys/cygwin.h (CCP_PROC_CYGDRIVE): New flag. * mount.cc (mount_info::cygdrive_posix_path): Take flag values rather than just a trailing_slash_p bool. Emit /proc/cygdrive path if CCP_PROC_CYGDRIVE flag is given. (mount_info::conv_to_posix_path): Take flag values rather than just a keep_rel_p bool. Rename _p variables. Print flag value as hex in debug_printf. Call cygdrive_posix_path with flag values. * mount.h (mount_info::cygdrive_posix_path): Accommodate above change in declaration. (mount_info::conv_to_posix_path): Ditto. * fhandler_process.cc (format_process_exename): Accommodate change to mount_info::conv_to_posix_path. * path.cc (cygwin_conv_path): Ditto. * cygpath.cc (absolute_flag): Initialize to CCP_RELATIVE to simplify expressions. (cygdrive_flag): New global flag. (long_options): Add --proc-cygdrive option. (options): Add -U option. (usage): Add description for -U option. (do_sysfolders): Or cygdrive_flag to cygwin_conv_path call. (do_pathconv): Simply or absolute_flag to conv_func. Or cygdrive_flag to conv_func. (do_options): Initalize absolute_flag to CCP_RELATIVE. Initialize new cygdrive_flag. Set absolute_flag to CCP_ABSOLUTE on -a. Set cygdrive_flag to CCP_PROC_CYGDRIVE on -U. * new-features.xml (ov-new2.4): Document cygpath -U option. * utils.xml (cygpath): Ditto. * path.xml (func-cygwin-path): Add CCP_PROC_CYGDRIVE description. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-12-06 17:25:48 +01:00
mount_table->conv_to_posix_path (p->progname, buf, CCP_RELATIVE);
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;
}
2013-04-23 11:44:36 +02:00
static off_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);
}
2013-04-23 11:44:36 +02:00
static off_t
format_process_winexename (void *data, char *&destbuf)
{
_pinfo *p = (_pinfo *) data;
size_t len = sys_wcstombs (NULL, 0, p->progname);
destbuf = (char *) crealloc_abort (destbuf, len + 1);
/* With trailing \0 for backward compat reasons. */
sys_wcstombs (destbuf, len + 1, p->progname);
return len;
}
struct heap_info
{
struct heap
{
heap *next;
unsigned heap_id;
char *base;
char *end;
unsigned long flags;
};
heap *heap_vm_chunks;
heap_info (DWORD pid)
: heap_vm_chunks (NULL)
{
PDEBUG_BUFFER buf;
NTSTATUS status;
PDEBUG_HEAP_ARRAY harray;
buf = RtlCreateQueryDebugBuffer (16 * 65536, 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)
2011-06-06 07:02:13 +02:00
{
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)
{
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;
}
}
}
RtlDestroyQueryDebugBuffer (buf);
}
2011-06-06 07:02:13 +02:00
char *fill_if_match (char *base, ULONG type, char *dest)
{
for (heap *h = heap_vm_chunks; h; h = h->next)
if (base >= h->base && base < h->end)
{
char *p = dest + __small_sprintf (dest, "[win heap %ld", h->heap_id);
if (!(h->flags & HEAP_FLAG_NONDEFAULT))
p = stpcpy (p, " default");
if ((h->flags & HEAP_FLAG_SHAREABLE) && (type & MEM_MAPPED))
p = stpcpy (p, " shared");
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, "]");
return dest;
}
return NULL;
}
2011-06-06 07:02:13 +02:00
~heap_info ()
{
heap *n = 0;
for (heap *m = heap_vm_chunks; m; m = n)
{
n = m->next;
free (m);
}
}
};
struct thread_info
{
struct region
{
region *next;
ULONG thread_id;
char *start;
char *end;
bool teb;
};
region *regions;
thread_info (DWORD pid, HANDLE process)
: regions (NULL)
{
NTSTATUS status;
PVOID buf = NULL;
2013-04-23 11:44:36 +02:00
ULONG size = 50 * (sizeof (SYSTEM_PROCESS_INFORMATION)
+ 16 * sizeof (SYSTEM_THREADS));
PSYSTEM_PROCESS_INFORMATION proc;
PSYSTEM_THREADS thread;
do
{
buf = realloc (buf, size);
2013-04-23 11:44:36 +02:00
status = NtQuerySystemInformation (SystemProcessInformation,
buf, size, NULL);
2011-06-06 07:02:13 +02:00
size <<= 1;
}
while (status == STATUS_INFO_LENGTH_MISMATCH);
if (!NT_SUCCESS (status))
{
if (buf)
free (buf);
2013-04-23 11:44:36 +02:00
debug_printf ("NtQuerySystemInformation, %y", status);
return;
}
2013-04-23 11:44:36 +02:00
proc = (PSYSTEM_PROCESS_INFORMATION) buf;
while (true)
{
2013-04-23 11:44:36 +02:00
if ((DWORD) (uintptr_t) proc->UniqueProcessId == pid)
break;
2013-04-23 11:44:36 +02:00
if (!proc->NextEntryOffset)
{
free (buf);
return;
}
proc = (PSYSTEM_PROCESS_INFORMATION) ((PBYTE) proc
+ proc->NextEntryOffset);
}
thread = proc->Threads;
2013-04-23 11:44:36 +02:00
for (ULONG i = 0; i < proc->NumberOfThreads; ++i)
{
THREAD_BASIC_INFORMATION tbi;
TEB teb;
HANDLE thread_h;
2011-06-06 07:02:13 +02:00
thread_h = OpenThread (THREAD_QUERY_LIMITED_INFORMATION, FALSE,
(ULONG) (ULONG_PTR) thread[i].ClientId.UniqueThread);
if (!thread_h)
continue;
status = NtQueryInformationThread (thread_h, ThreadBasicInformation,
&tbi, sizeof tbi, NULL);
CloseHandle (thread_h);
if (!NT_SUCCESS (status))
continue;
region *r = (region *) malloc (sizeof (region));
if (r)
{
*r = (region) { regions,
(ULONG) (ULONG_PTR) thread[i].ClientId.UniqueThread,
(char *) tbi.TebBaseAddress,
(char *) tbi.TebBaseAddress
+ 2 * wincap.page_size (),
true };
regions = r;
}
if (!ReadProcessMemory (process, (PVOID) tbi.TebBaseAddress,
&teb, sizeof teb, NULL))
continue;
r = (region *) malloc (sizeof (region));
if (r)
{
*r = (region) { regions,
(ULONG) (ULONG_PTR) thread[i].ClientId.UniqueThread,
(char *) (teb.DeallocationStack
?: teb.Tib.StackLimit),
(char *) teb.Tib.StackBase,
false };
regions = r;
}
}
free (buf);
}
2011-06-06 07:02:13 +02:00
char *fill_if_match (char *base, ULONG type, char *dest)
{
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 ()))
{
char *p = dest + __small_sprintf (dest, "[%s (tid %ld)",
r->teb ? "teb" : "stack",
r->thread_id);
if (type & MEM_MAPPED)
p = stpcpy (p, " shared");
stpcpy (p, "]");
return dest;
}
return NULL;
}
/* Helper to look for TEBs inside single allocated region since W10 1511. */
char *fill_if_match (char *start, char *dest)
{
for (region *r = regions; r; r = r->next)
if (r->teb && start == r->start)
{
__small_sprintf (dest, "[teb (tid %ld)]", r->thread_id);
return r->end;
}
return NULL;
}
2011-06-06 07:02:13 +02:00
~thread_info ()
{
region *n = 0;
for (region *m = regions; m; m = n)
{
n = m->next;
free (m);
}
}
};
2013-04-23 11:44:36 +02:00
static off_t
format_process_maps (void *data, char *&destbuf)
{
_pinfo *p = (_pinfo *) data;
HANDLE proc = OpenProcess (PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ, FALSE, p->dwProcessId);
if (!proc)
return 0;
NTSTATUS status;
PROCESS_BASIC_INFORMATION pbi;
PPEB peb = NULL;
memset (&pbi, 0, sizeof (pbi));
status = NtQueryInformationProcess (proc, ProcessBasicInformation,
&pbi, sizeof pbi, NULL);
if (NT_SUCCESS (status))
peb = pbi.PebBaseAddress;
/* myself is in the same spot in every process, so is the pointer to the
procinfo. But make sure the destructor doesn't try to release procinfo! */
pinfo proc_pinfo;
if (ReadProcessMemory (proc, &myself, &proc_pinfo, sizeof proc_pinfo, NULL))
proc_pinfo.preserve ();
/* The heap info on the cygheap is also in the same spot in each process
because the cygheap is located at the same address. */
user_heap_info user_heap;
ReadProcessMemory (proc, &cygheap->user_heap, &user_heap,
sizeof user_heap, NULL);
2013-04-23 11:44:36 +02:00
off_t len = 0;
2011-06-06 07:02:13 +02:00
union access
{
char flags[8];
2013-04-23 11:44:36 +02:00
off_t word;
} a;
struct region {
access a;
char *abase;
char *rbase;
char *rend;
DWORD state;
} cur = {{{'\0'}}, (char *)1, 0, 0};
2011-06-06 07:02:13 +02:00
MEMORY_BASIC_INFORMATION mb;
dos_drive_mappings drive_maps;
heap_info heaps (p->dwProcessId);
thread_info threads (p->dwProcessId, proc);
2013-04-23 11:44:36 +02:00
struct stat st;
long last_pass = 0;
* Makefile.in (DLL_OFILES): Add tls_pbuf.o. * autoload.cc (CreateDesktopW): Replace CreateDesktopA. (CreateWindowStationW): Replace CreateWindowStationA. (GetUserObjectInformationW): Replace GetUserObjectInformationA. * cygheap.h (cwdstuff::get): Assume default buffer size NT_MAX_PATH. * cygtls.cc (_cygtls::remove): Free temporary TLS path buffers. * cygtls.h (TP_NUM_C_BUFS): Define. (TP_NUM_W_BUFS): Define. (class tls_pathbuf): New class to store pointers to thread local temporary path buffers. (_local_storage::pathbufs): New member. * environ.cc (win_env::add_cache): Use temporary TLS path buffer instead of stack based buffer. (posify): Get temporary outenv buffer from calling function. (environ_init): Create temporary TLS path buffer for posify. (build_env): Create Windows environment block as WCHAR buffer. * environ.h (build_env): Change declaration accordingly. * external.cc (sync_winenv): Accommodate build_env change. * fhandler_console.cc (fhandler_console::need_invisible): Use GetUserObjectInformationW and CreateWindowStationW. * fhandler_process.cc (format_process_maps): Use temporary TLS path buffer instead of stack based buffer. * fork.cc (frok::parent): Convert to use CreateProcessW. * path.cc: Throughout use temporary TLS path buffers instead of stack based buffer. Replace checks for CYG_MAX_PATH by checks for NT_MAX_PATH. (getfileattr): New function to replace GetFileAttributesA. (normalize_win32_path): Remove Win32 and NT long path prefixes. (getwd): Assume PATH_MAX + 1 buffer per SUSv3. * path.h (class path_conv): Set path buffer to size NT_MAX_PATH. (iswdrive): Define. * pinfo.cc (commune_process): Use temporary TLS path buffer instead of stack based buffer. * registry.cc (get_registry_hive_path): Ditto. (load_registry_hive): Ditto. * spawn.cc (spawn_guts): Convert to use CreateProcessW and CreateProcessAsUserW. (av::fixup): Open/close file using NtOpenFile/NtClose. * syscalls.cc (mknod_worker): Allow PATH_MAX file name. (mknod32): Ditto. (getusershell): Ditto. * tls_pbuf.cc: New file implementing tls_pathbuf and tmp_pathbuf methods. * tls_pbuf.h: New header for files using tmp_pathbuf. * tlsoffsets.h: Regenerate. * winsup.h (NT_MAX_PATH): Define as 32767 to avoid USHORT overflow.
2008-03-07 12:24:51 +01:00
tmp_pathbuf tp;
PMEMORY_SECTION_NAME msi = (PMEMORY_SECTION_NAME) tp.w_get ();
* Makefile.in (DLL_OFILES): Add tls_pbuf.o. * autoload.cc (CreateDesktopW): Replace CreateDesktopA. (CreateWindowStationW): Replace CreateWindowStationA. (GetUserObjectInformationW): Replace GetUserObjectInformationA. * cygheap.h (cwdstuff::get): Assume default buffer size NT_MAX_PATH. * cygtls.cc (_cygtls::remove): Free temporary TLS path buffers. * cygtls.h (TP_NUM_C_BUFS): Define. (TP_NUM_W_BUFS): Define. (class tls_pathbuf): New class to store pointers to thread local temporary path buffers. (_local_storage::pathbufs): New member. * environ.cc (win_env::add_cache): Use temporary TLS path buffer instead of stack based buffer. (posify): Get temporary outenv buffer from calling function. (environ_init): Create temporary TLS path buffer for posify. (build_env): Create Windows environment block as WCHAR buffer. * environ.h (build_env): Change declaration accordingly. * external.cc (sync_winenv): Accommodate build_env change. * fhandler_console.cc (fhandler_console::need_invisible): Use GetUserObjectInformationW and CreateWindowStationW. * fhandler_process.cc (format_process_maps): Use temporary TLS path buffer instead of stack based buffer. * fork.cc (frok::parent): Convert to use CreateProcessW. * path.cc: Throughout use temporary TLS path buffers instead of stack based buffer. Replace checks for CYG_MAX_PATH by checks for NT_MAX_PATH. (getfileattr): New function to replace GetFileAttributesA. (normalize_win32_path): Remove Win32 and NT long path prefixes. (getwd): Assume PATH_MAX + 1 buffer per SUSv3. * path.h (class path_conv): Set path buffer to size NT_MAX_PATH. (iswdrive): Define. * pinfo.cc (commune_process): Use temporary TLS path buffer instead of stack based buffer. * registry.cc (get_registry_hive_path): Ditto. (load_registry_hive): Ditto. * spawn.cc (spawn_guts): Convert to use CreateProcessW and CreateProcessAsUserW. (av::fixup): Open/close file using NtOpenFile/NtClose. * syscalls.cc (mknod_worker): Allow PATH_MAX file name. (mknod32): Ditto. (getusershell): Ditto. * tls_pbuf.cc: New file implementing tls_pathbuf and tmp_pathbuf methods. * tls_pbuf.h: New header for files using tmp_pathbuf. * tlsoffsets.h: Regenerate. * winsup.h (NT_MAX_PATH): Define as 32767 to avoid USHORT overflow.
2008-03-07 12:24:51 +01:00
char *posix_modname = tp.c_get ();
size_t maxsize = 0;
char *peb_teb_abase = NULL;
if (destbuf)
{
cfree (destbuf);
destbuf = NULL;
}
2011-06-06 07:02:13 +02: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)
{
if (last_pass)
2011-06-06 07:02:13 +02:00
posix_modname[0] = '\0';
if (mb.State == MEM_FREE)
a.word = 0;
else if (mb.State == MEM_RESERVE)
{
char *p = stpcpy (a.flags, "===");
stpcpy (p, (mb.Type & MEM_MAPPED) ? "s" : "p");
}
else
{
static DWORD const RO = (PAGE_EXECUTE_READ | PAGE_READONLY);
static DWORD const RW = (PAGE_EXECUTE_READWRITE | PAGE_READWRITE
| PAGE_EXECUTE_WRITECOPY | PAGE_WRITECOPY);
static DWORD const X = (PAGE_EXECUTE | PAGE_EXECUTE_READ
| PAGE_EXECUTE_READWRITE
| PAGE_EXECUTE_WRITECOPY);
static DWORD const WC = (PAGE_EXECUTE_WRITECOPY | PAGE_WRITECOPY);
DWORD p = mb.Protect;
a = (access) {{
(p & (RO | RW)) ? 'r' : '-',
(p & (RW)) ? 'w' : '-',
(p & (X)) ? 'x' : '-',
(mb.Type & MEM_MAPPED) && !(p & (WC)) ? 's'
: (p & PAGE_GUARD) ? 'g' : 'p',
'\0', // zero-fill the remaining bytes
}};
}
region next = { a,
(char *) mb.AllocationBase,
(char *) mb.BaseAddress,
(char *) mb.BaseAddress+mb.RegionSize,
mb.State
};
2011-06-06 07:02:13 +02:00
/* 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
{
char *peb_teb_end = NULL;
peb_teb_rinse_repeat:
/* Starting with W10 1511, PEB and TEBs don't get allocated
separately. Rather they are created in a single region. Examine
the region starting at the PEB address page-wise. */
if (wincap.has_new_pebteb_region ())
{
if (peb_teb_abase && !peb_teb_end && cur.abase == peb_teb_abase)
{
posix_modname[0] = '\0';
peb_teb_end = cur.rend;
if (cur.state == MEM_COMMIT)
cur.rend = cur.rbase + wincap.page_size ();
}
if (cur.state == MEM_COMMIT)
{
if (!peb_teb_abase && cur.rbase == (char *) peb)
{
peb_teb_abase = cur.abase;
peb_teb_end = cur.rend;
cur.rend = cur.rbase + wincap.page_size ();
strcpy (posix_modname, "[peb]");
}
else if (peb_teb_end)
{
char *end;
posix_modname[0] = '\0';
end = threads.fill_if_match (cur.rbase, posix_modname);
if (end)
cur.rend = end;
else
{
char *base = cur.rbase;
do
{
base += wincap.page_size ();
}
while (!threads.fill_if_match (base, posix_modname)
&& base < peb_teb_end);
if (posix_modname[0])
{
posix_modname[0] = '\0';
cur.rend = base;
}
else
cur.rend = peb_teb_end;
}
}
}
}
/* output the current region if it's "interesting". */
if (cur.a.word)
{
size_t newlen = strlen (posix_modname) + 62;
if (len + newlen >= maxsize)
2013-04-23 11:44:36 +02:00
destbuf = (char *)
crealloc_abort (destbuf,
maxsize += roundup2 (newlen, 2048UL));
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);
}
if (peb_teb_end && cur.state == MEM_COMMIT)
{
cur.rbase = cur.rend;
cur.rend += wincap.page_size ();
if (cur.rbase < peb_teb_end)
goto peb_teb_rinse_repeat;
}
/* start of a new region (but possibly still the same allocation). */
cur = next;
/* if a new allocation, figure out what kind it is. */
if (newbase && !last_pass && cur.state != MEM_FREE)
{
/* If the return length pointer is missing, NtQueryVirtualMemory
returns with STATUS_ACCESS_VIOLATION on Windows 2000. */
2013-04-23 11:44:36 +02:00
SIZE_T ret_len = 0;
st.st_dev = 0;
st.st_ino = 0;
if ((mb.Type & (MEM_MAPPED | MEM_IMAGE))
&& NT_SUCCESS (status = NtQueryVirtualMemory (proc, cur.abase,
MemorySectionName,
msi, 65536, &ret_len)))
{
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);
}
else if (!threads.fill_if_match (cur.abase, mb.Type,
posix_modname)
&& !heaps.fill_if_match (cur.abase, mb.Type,
posix_modname))
{
if (cur.abase == (char *) peb)
strcpy (posix_modname, "[peb]");
else if (cur.abase == (char *) &SharedUserData)
strcpy (posix_modname, "[shared-user-data]");
else if (cur.abase == (char *) cygwin_shared)
strcpy (posix_modname, "[cygwin-shared]");
else if (cur.abase == (char *) user_shared)
strcpy (posix_modname, "[cygwin-user-shared]");
else if (cur.abase == (char *) *proc_pinfo)
strcpy (posix_modname, "[procinfo]");
else if (cur.abase == user_heap.base)
strcpy (posix_modname, "[heap]");
else
posix_modname[0] = 0;
}
}
}
}
CloseHandle (proc);
return len;
}
2013-04-23 11:44:36 +02:00
static off_t
format_process_stat (void *data, char *&destbuf)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
_pinfo *p = (_pinfo *) data;
char cmd[NAME_MAX + 1];
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
int state = 'R';
unsigned long fault_count = 0UL,
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
utime = 0UL, stime = 0UL,
start_time = 0UL,
vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
int priority = 0;
if (p->process_state & PID_EXITED)
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
strcpy (cmd, "<defunct>");
2002-05-02 06:26:05 +02:00
else
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
PWCHAR last_slash = wcsrchr (p->progname, L'\\');
sys_wcstombs (cmd, NAME_MAX + 1,
last_slash ? last_slash + 1 : p->progname);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
int len = strlen (cmd);
if (len > 4)
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
{
char *s = cmd + len - 4;
if (ascii_strcasematch (s, ".exe"))
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
*s = 0;
}
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
}
/* Note: under Windows, a process is always running - it's only threads
that get suspended. Therefore the default state is R (runnable). */
if (p->process_state & PID_EXITED)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
state = 'Z';
else if (p->process_state & PID_STOPPED)
state = 'T';
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
else
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
state = get_process_state (p->dwProcessId);
start_time = (GetTickCount () / 1000 - time (NULL) + p->start_time) * HZ;
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
NTSTATUS status;
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
HANDLE hProcess;
VM_COUNTERS vmc;
KERNEL_USER_TIMES put;
PROCESS_BASIC_INFORMATION pbi;
QUOTA_LIMITS ql;
2013-04-23 11:44:36 +02:00
SYSTEM_TIMEOFDAY_INFORMATION stodi;
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION spt;
hProcess = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ,
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
FALSE, p->dwProcessId);
if (hProcess != NULL)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
status = NtQueryInformationProcess (hProcess, ProcessVmCounters,
(PVOID) &vmc, sizeof vmc, NULL);
if (NT_SUCCESS (status))
status = NtQueryInformationProcess (hProcess, ProcessTimes,
(PVOID) &put, sizeof put, NULL);
if (NT_SUCCESS (status))
status = NtQueryInformationProcess (hProcess, ProcessBasicInformation,
(PVOID) &pbi, sizeof pbi, NULL);
if (NT_SUCCESS (status))
status = NtQueryInformationProcess (hProcess, ProcessQuotaLimits,
(PVOID) &ql, sizeof ql, NULL);
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
CloseHandle (hProcess);
}
else
{
DWORD error = GetLastError ();
__seterrno_from_win_error (error);
2013-04-23 11:44:36 +02:00
debug_printf ("OpenProcess: ret %u", error);
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
return 0;
}
if (NT_SUCCESS (status))
status = NtQuerySystemInformation (SystemTimeOfDayInformation,
(PVOID) &stodi, sizeof stodi, NULL);
if (NT_SUCCESS (status))
2013-04-23 11:44:36 +02:00
status = NtQuerySystemInformation (SystemProcessorPerformanceInformation,
(PVOID) &spt, sizeof spt, NULL);
if (!NT_SUCCESS (status))
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
{
__seterrno_from_nt_status (status);
2013-04-23 11:44:36 +02:00
debug_printf ("NtQueryInformationProcess: status %y, %E", status);
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
return 0;
}
fault_count = vmc.PageFaultCount;
utime = put.UserTime.QuadPart * HZ / 10000000ULL;
stime = put.KernelTime.QuadPart * HZ / 10000000ULL;
#if 0
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01: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;
#endif
2013-04-23 11:44:36 +02:00
/* The BasePriority returned to a 32 bit process under WOW64 is
apparently broken, for 32 and 64 bit target processes. 64 bit
processes get the correct base priority, even for 32 bit processes. */
if (wincap.is_wow64 ())
priority = 8; /* Default value. */
else
priority = pbi.BasePriority;
unsigned page_size = wincap.page_size ();
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
vmsize = vmc.PagefileUsage;
vmrss = vmc.WorkingSetSize / page_size;
vmmaxrss = ql.MaximumWorkingSetSize / page_size;
destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
return __small_sprintf (destbuf, "%d (%s) %c "
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
"%d %d %d %d %d "
2013-04-23 11:44:36 +02:00
"%u %lu %lu %u %u %lu %lu "
"%ld %ld %d %d %d %d "
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
"%lu %lu "
2013-04-23 11:44:36 +02:00
"%ld %lu",
p->pid, cmd, state,
p->ppid, p->pgid, p->sid, p->ctty, -1,
0, fault_count, fault_count, 0, 0, utime, stime,
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
utime, stime, priority, 0, 0, 0,
start_time, vmsize,
vmrss, vmmaxrss
);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
}
2002-05-02 06:26:05 +02:00
2013-04-23 11:44:36 +02:00
static off_t
format_process_status (void *data, char *&destbuf)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
_pinfo *p = (_pinfo *) data;
char cmd[NAME_MAX + 1];
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
int state = 'R';
const char *state_str = "unknown";
unsigned long vmsize = 0UL, vmrss = 0UL, vmdata = 0UL, vmlib = 0UL,
vmtext = 0UL, vmshare = 0UL;
PWCHAR last_slash = wcsrchr (p->progname, L'\\');
sys_wcstombs (cmd, NAME_MAX + 1, last_slash ? last_slash + 1 : p->progname);
int len = strlen (cmd);
if (len > 4)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
char *s = cmd + len - 4;
if (ascii_strcasematch (s, ".exe"))
*s = 0;
}
/* Note: under Windows, a process is always running - it's only threads
that get suspended. Therefore the default state is R (runnable). */
if (p->process_state & PID_EXITED)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
state = 'Z';
else if (p->process_state & PID_STOPPED)
state = 'T';
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
else
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02: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;
}
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
&vmlib, &vmshare))
return 0;
unsigned page_size = wincap.allocation_granularity ();
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
vmsize *= page_size; vmrss *= page_size; vmdata *= page_size;
vmtext *= page_size; vmlib *= page_size;
/* 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. */
destbuf = (char *) crealloc_abort (destbuf, strlen (cmd) + 320);
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",
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
cmd,
state, state_str,
p->pgid,
p->pid,
p->ppid,
p->uid, p->uid, p->uid, p->uid,
p->gid, p->gid, p->gid, p->gid,
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
vmsize >> 10, 0, vmrss >> 10, vmdata >> 10, 0,
vmtext >> 10, vmlib >> 10,
0, 0, _my_tls.sigmask
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
}
2013-04-23 11:44:36 +02:00
static off_t
format_process_statm (void *data, char *&destbuf)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
_pinfo *p = (_pinfo *) data;
* autoload.cc (GetSecurityInfo): Define new autoload function. (RegQueryInfoKeyA): Ditto. * fhandler.h (fhandler_virtual::fill_filebuf): Change return type to bool. (fhandler_proc::fill_filebuf): Ditto. (fhandler_registry::fill_filebuf): Ditto. (fhandler_process::fill_filebuf): Ditto. (fhandler_registry::value_name): Add new member. (fhandler_registry::close): Add new method. (fhandler_process::p): Remove member. * fhandler_proc.cc (fhandler_proc::open): Add set_nohandle after calling superclass method. Check return value of fill_filebuf. (fhandler_proc::fill_filebuf): Change return type to bool. Add return statement. * fhandler_process.cc (fhandler_process::open): Add set_nohandle after calling superclass method. Remove references to p. Check return value of fill_filebuf. (fhandler_process::fill_filebuf): Change return type to bool. Don't use dereference operator on p. Add return statement. (fhandler_process::format_process_stat): Fix typo. * fhandler_registry.cc: Add static open_key declaration. (fhandler_registry::exists): Assume path is already normalised. Try opening the path as a key in its own right first, before reverting to enumerating subkeys and values of the parent key. (fhandler_registry::fstat): Add additional code to return more relevant information about the registry key/value. (fhandler_registry::readdir): Explicitly set desired access when opening registry key. Remove output of buf from debug_printf format string. (fhandler_registry::open): Use set_io_handle to store registry key handle. Set value_name member. Move code to read a value from the registry to fill_filebuf. Add call to fill_filebuf. (fhandler_registry::close): New method. (fhandler_registry::fill_filebuf): Change return type to bool. Add code to read a value from registry. (fhandler_registry::open_key): Make function static. Use KEY_READ as desired access unless this is the last path component. Check the return value of RegOpenKeyEx for an error instead of hKey. * fhandler_virtual.cc (fhandler_virtual::lseek): Check the return value of fill_filebuf. (fhandler_virtual::open): Remove call to set_nohandle. (fhandler_virtual::fill_filebuf): Change return type to bool. Add return statement. * security.cc (get_nt_object_attribute): New function. (get_object_attribute): New function. * security.h (get_object_attribute): New function declaration.
2002-07-02 03:36:15 +02:00
unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL,
vmlib = 0UL, vmshare = 0UL;
size_t page_scale;
* Makefile.in (DLL_IMPORTS): Add libntdll.a. * autoload.cc: Remove all symbols from advapi32.dll, kernel32.dll and ntdll.dll available on all platforms since NT4. Throughout remove all usage of wincap.is_winnt. * dcrt0.cc (dll_crt0_0): Remove call to mmap_init. * fhandler.h (class fhandler_base): Remove has_changed flag. (fhandler_disk_file::touch_ctime): Remove declaration. (fhandler_disk_file::readdir_9x): Ditto. (fhandler_disk_file::touch_ctime): Remove. (fhandler_disk_file::readdir_9x): Remove. (fhandler_disk_file::closedir): Call NtClose instead of CloseHandle. * mmap.cc: Throughout call CreateMapping and MapView directly. (VirtualProt9x): Remove. (VirtualProtNT): Remove. (VirtualProtEx9x): Remove. (VirtualProtExNT): Remove. (VirtualProtect): Remove define. (VirtualProtectEx): Remove define. (CreateMapping9x): Remove. (CreateMappingNT): Rename to CreateMapping. (MapView9x): Remove. (MapViewNT): Rename to MapView. (struct mmap_func_t): Remove definition. (mmap_funcs_9x): Remove. (mmap_funcs_nt): Remove. (mmap_func): Remove. (mmap_init): Remove. * net.cc (getdomainname): Drop comment. Use NT4 registry key only. (get_95_ifconf): Remove. * pinfo.cc (winpids::enumNT): Rename to winpids::enum_processes. (winpids::enum9x): Remove. (winpids::set): Just call enum_processes directly. (winpids::enum_init): Ditto. * pinfo.h (class winpids): Drop enum_processes pointer. Rename enumNT to enum_processes. Drop enum9x declaration. Drop initialization of enum_processes throughout. * registry.cc (get_registry_hive_path): Just create NT key. (load_registry_hive): Only load NT specific file. * syscalls.cc (unlink_9x): Remove. (unlink): Just call unlink_nt. * wincap.cc: Remove is_winnt flag throughout. * wincap.h: Ditto. * winsup.h: Remove mmap_init declaration.
2007-02-22 11:54:47 +01:00
if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata,
&vmlib, &vmshare))
return 0;
page_scale = wincap.allocation_granularity() / wincap.page_size();
destbuf = (char *) crealloc_abort (destbuf, 96);
return __small_sprintf (destbuf, "%ld %ld %ld %ld %ld %ld 0\n",
vmsize / page_scale, vmrss / page_scale, vmshare / page_scale,
vmtext / page_scale, vmlib / page_scale, vmdata / page_scale);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
}
extern "C" {
FILE *setmntent (const char *, const char *);
struct mntent *getmntent (FILE *);
};
2013-04-23 11:44:36 +02:00
static off_t
format_process_mountstuff (void *data, char *&destbuf, bool mountinfo)
{
_pinfo *p = (_pinfo *) data;
user_info *u_shared = NULL;
HANDLE u_hdl = NULL;
2013-04-23 11:44:36 +02:00
off_t len = 0;
struct mntent *mnt;
if (p->uid != myself->uid)
{
WCHAR sid_string[UNLEN + 1] = L""; /* Large enough for SID */
cygsid p_sid;
if (!p_sid.getfrompw (internal_getpwuid (p->uid)))
2011-06-06 07:02:13 +02:00
return 0;
p_sid.string (sid_string);
u_shared = (user_info *) open_shared (sid_string, USER_VERSION, u_hdl,
sizeof (user_info), SH_JUSTOPEN,
&sec_none_nih);
if (!u_shared)
return 0;
}
else
u_shared = user_shared;
mount_info *mtab = &u_shared->mountinfo;
/* 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);
/* Restore iteration immediately since it's not used below. We use the
local iteration variable instead*/
_my_tls.locals.iteration = iteration;
for (iteration = 0; (mnt = mtab->getmntent (iteration)); ++iteration)
{
/* We have no access to the drives mapped into another user session and
_my_tls.locals.available_drives contains the mappings of the current
user. So, when printing the mount table of another user, we check
each cygdrive entry if it's a remote drive. If so, ignore it. */
if (iteration >= mtab->nmounts && u_hdl)
{
2013-04-23 11:44:36 +02:00
WCHAR drive[3] = { (WCHAR) mnt->mnt_fsname[0], L':', L'\0' };
disk_type dt = get_disk_type (drive);
2012-08-17 01:34:45 +02:00
if (dt == DT_SHARE_SMB || dt == DT_SHARE_NFS)
continue;
}
destbuf = (char *) crealloc_abort (destbuf, len
+ strlen (mnt->mnt_fsname)
+ strlen (mnt->mnt_dir)
+ strlen (mnt->mnt_type)
+ strlen (mnt->mnt_opts)
+ 30);
if (mountinfo)
{
path_conv pc (mnt->mnt_dir, PC_SYM_NOFOLLOW | PC_POSIX);
dev_t dev = pc.exists () ? pc.fs_serial_number () : -1;
len += __small_sprintf (destbuf + len,
"%d %d %d:%d / %s %s - %s %s %s\n",
iteration, iteration,
major (dev), minor (dev),
mnt->mnt_dir, mnt->mnt_opts,
mnt->mnt_type, mnt->mnt_fsname,
(pc.fs_flags () & FILE_READ_ONLY_VOLUME)
? "ro" : "rw");
}
else
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 available_drives */
_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;
}
2013-04-23 11:44:36 +02:00
static off_t
format_process_mounts (void *data, char *&destbuf)
{
return format_process_mountstuff (data, destbuf, false);
}
2013-04-23 11:44:36 +02:00
static off_t
format_process_mountinfo (void *data, char *&destbuf)
{
return format_process_mountstuff (data, destbuf, true);
}
int
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
get_process_state (DWORD dwProcessId)
{
/* This isn't really heavy magic - just go through the processes' threads
one by one and return a value accordingly. Errors are silently ignored. */
NTSTATUS status;
2013-04-23 11:44:36 +02:00
PSYSTEM_PROCESS_INFORMATION p, sp;
ULONG n = 0x4000;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
int state =' ';
2013-04-23 11:44:36 +02:00
p = (PSYSTEM_PROCESS_INFORMATION) malloc (n);
if (!p)
return state;
while (true)
{
2013-04-23 11:44:36 +02:00
status = NtQuerySystemInformation (SystemProcessInformation,
(PVOID) p, n, NULL);
if (status != STATUS_INFO_LENGTH_MISMATCH)
break;
n <<= 1;
2013-04-23 11:44:36 +02:00
PSYSTEM_PROCESS_INFORMATION new_p = (PSYSTEM_PROCESS_INFORMATION) realloc (p, n);
if (!new_p)
goto out;
p = new_p;
}
if (!NT_SUCCESS (status))
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
2013-04-23 11:44:36 +02:00
debug_printf ("NtQuerySystemInformation: status %y, %u",
status, RtlNtStatusToDosError (status));
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
goto out;
}
state = 'Z';
sp = p;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
for (;;)
{
2013-04-23 11:44:36 +02:00
if ((DWORD) (uintptr_t) sp->UniqueProcessId == dwProcessId)
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02: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 14:23:36 +02:00
st = &sp->Threads[0];
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
state = 'S';
2013-04-23 11:44:36 +02:00
for (unsigned i = 0; i < sp->NumberOfThreads; i++)
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
{
2011-06-06 07:02:13 +02:00
/* FIXME: at some point we should consider generating 'O' */
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
if (st->State == StateRunning ||
st->State == StateReady)
{
state = 'R';
goto out;
}
st++;
}
break;
}
2013-04-23 11:44:36 +02:00
if (!sp->NextEntryOffset)
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 03:55:40 +02:00
break;
2013-04-23 11:44:36 +02:00
sp = (PSYSTEM_PROCESS_INFORMATION) ((char *) sp + sp->NextEntryOffset);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
}
2002-05-02 06:26:05 +02:00
out:
free (p);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
return state;
}
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)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
bool res = false;
NTSTATUS status;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
HANDLE hProcess;
VM_COUNTERS vmc;
PMEMORY_WORKING_SET_LIST p;
2013-04-23 11:44:36 +02:00
SIZE_T n = 0x4000, length;
/* This appears to work despite MSDN claiming that QueryWorkingSet requires
PROCESS_QUERY_INFORMATION *and* PROCESS_VM_READ. Since we're trying to do
everything with least perms, we stick to PROCESS_QUERY_INFORMATION only
unless this changes in Windows for some reason. */
hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
if (hProcess == NULL)
{
__seterrno ();
debug_printf ("OpenProcess, %E");
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
return false;
}
p = (PMEMORY_WORKING_SET_LIST) malloc (n);
if (!p)
goto out;
while (true)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
status = NtQueryVirtualMemory (hProcess, 0, MemoryWorkingSetList,
(PVOID) p, n,
2013-04-23 11:44:36 +02:00
(length = (SIZE_T) -1, &length));
if (status != STATUS_INFO_LENGTH_MISMATCH)
break;
n <<= 1;
PMEMORY_WORKING_SET_LIST new_p = (PMEMORY_WORKING_SET_LIST)
realloc (p, n);
if (!new_p)
goto out;
p = new_p;
}
if (!NT_SUCCESS (status))
{
2013-04-23 11:44:36 +02:00
debug_printf ("NtQueryVirtualMemory: status %y", status);
if (status == STATUS_PROCESS_IS_TERMINATING)
{
*vmsize = *vmrss = *vmtext = *vmdata = *vmlib = *vmshare = 0;
res = true;
}
else
__seterrno_from_nt_status (status);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
goto out;
}
for (unsigned long i = 0; i < p->NumberOfPages; i++)
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
++*vmrss;
unsigned flags = p->WorkingSetList[i] & 0x0FFF;
if ((flags & (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE))
== (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE))
++*vmlib;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
else if (flags & WSLE_PAGE_SHAREABLE)
++*vmshare;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
else if (flags & WSLE_PAGE_EXECUTE)
++*vmtext;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
else
++*vmdata;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
}
status = NtQueryInformationProcess (hProcess, ProcessVmCounters, (PVOID) &vmc,
sizeof vmc, NULL);
if (!NT_SUCCESS (status))
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
{
2013-04-23 11:44:36 +02:00
debug_printf ("NtQueryInformationProcess: status %y", status);
__seterrno_from_nt_status (status);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
goto out;
}
*vmsize = vmc.PagefileUsage / wincap.page_size ();
res = true;
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
out:
free (p);
* autoload.cc: Add dynamic load statements for 'ZwQueryInformationProcess' and 'ZwQueryVirtualMemory'. * fhandler.h: Change type of bufalloc and filesize members of fhandler_virtual from int to size_t. Change type of position member from __off32_t to __off64_t. Add new fileid member to fhandler_virtual class. Make seekdir take an __off64_t argument. Make lseek take an __off64_t argument. Add fill_filebuf method to fhandler_virtual. Add fill_filebuf method to fhandler_proc. Add fill_filebuf method to fhandler_registry. Add fill_filebuf method to fhandler_process. Add saved_pid and saved_p members to fhandler_process. * fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'. (proc_fhandlers array): Ditto. (fhandler_proc::open): Use fill_filebuf to flesh out the file contents. (fhandler_proc::fill_filebuf): New method. (fhandler_proc::format_proc_meminfo): Ditto. (fhandler_proc::format_proc_stat): Ditto. (fhandler_proc::format_proc_uptime): Ditto. * fhandler_process.cc (process_listing): Add 'stat' and 'statm'. (fhandler_process::fstat): Find the _pinfo structure for the process named in the filename. Return ENOENT if the process is no longer around. Set the gid and uid fields of the stat structure. (fhandler_process::open): Store pid and pointer to _pinfo structure in saved_pid and saved_p respectively. Use fill_filebuf to flesh out file contents. (fhandler_proc::fill_filebuf): New method. (format_process_stat): New function. (format_process_status): Ditto. (format_process_statm): Ditto. (get_process_state): Ditto. (get_mem_values): Ditto. * fhandler_registry.cc (fhandler_registry::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_registry::fill_filebuf): New method. * fhandler_virtual.cc (fhandler_virtual::seekdir): Change argument type from __off32_t to __off64_t. (fhandler_virtual::lseek): Ditto. (fhandler_virtual::fill_filebuf): New method. (fhandler_virtual::fhandler_virtual): Initialise fileid to -1. * wincap.cc: Set flag has_process_io_counters appropriately. * wincap.h: Add flag has_process_io_counters.
2002-05-12 03:37:48 +02:00
CloseHandle (hProcess);
2002-05-02 06:26:05 +02:00
return res;
}