2002-05-02 06:26:05 +02:00
|
|
|
/* fhandler_proc.cc: fhandler for /proc 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"
|
2008-04-07 18:15:45 +02:00
|
|
|
#include "miscfuncs.h"
|
2002-05-02 06:26:05 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2011-04-11 04:09:43 +02:00
|
|
|
#include <stdio.h>
|
2002-05-02 06:26:05 +02:00
|
|
|
#include "cygerrno.h"
|
|
|
|
#include "security.h"
|
|
|
|
#include "path.h"
|
2014-09-05 21:11:01 +02:00
|
|
|
#include "shared_info.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 "fhandler.h"
|
2009-01-20 18:22:11 +01:00
|
|
|
#include "fhandler_virtual.h"
|
2002-05-02 06:26:05 +02:00
|
|
|
#include "pinfo.h"
|
2002-05-04 05:24:35 +02:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2009-01-20 18:22:11 +01:00
|
|
|
#include "tls_pbuf.h"
|
2002-05-02 06:26:05 +02:00
|
|
|
#include <sys/utsname.h>
|
2002-08-31 18:37:51 +02:00
|
|
|
#include <sys/param.h>
|
2011-05-12 13:13:02 +02:00
|
|
|
#include <sys/sysinfo.h>
|
2002-05-12 03:37:48 +02:00
|
|
|
#include "ntdll.h"
|
2003-03-09 21:10:25 +01:00
|
|
|
#include <winioctl.h>
|
2006-03-09 10:01:08 +01:00
|
|
|
#include <wchar.h>
|
2011-01-17 14:38:06 +01:00
|
|
|
#include <wctype.h>
|
2003-04-16 05:03:45 +02:00
|
|
|
#include "cpuid.h"
|
2010-08-09 10:18:30 +02:00
|
|
|
#include "mount.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_proc_loadavg (void *, char *&);
|
|
|
|
static off_t format_proc_meminfo (void *, char *&);
|
|
|
|
static off_t format_proc_stat (void *, char *&);
|
|
|
|
static off_t format_proc_version (void *, char *&);
|
|
|
|
static off_t format_proc_uptime (void *, char *&);
|
|
|
|
static off_t format_proc_cpuinfo (void *, char *&);
|
|
|
|
static off_t format_proc_partitions (void *, char *&);
|
|
|
|
static off_t format_proc_self (void *, char *&);
|
2014-09-05 21:11:01 +02:00
|
|
|
static off_t format_proc_cygdrive (void *, char *&);
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t format_proc_mounts (void *, char *&);
|
|
|
|
static off_t format_proc_filesystems (void *, char *&);
|
|
|
|
static off_t format_proc_swaps (void *, char *&);
|
|
|
|
static off_t format_proc_devices (void *, char *&);
|
|
|
|
static off_t format_proc_misc (void *, char *&);
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
/* names of objects in /proc */
|
2009-01-20 18:22:11 +01:00
|
|
|
static const virt_tab_t proc_tab[] = {
|
2010-09-06 11:47:01 +02:00
|
|
|
{ _VN ("."), FH_PROC, virt_directory, NULL },
|
|
|
|
{ _VN (".."), FH_PROC, virt_directory, NULL },
|
|
|
|
{ _VN ("cpuinfo"), FH_PROC, virt_file, format_proc_cpuinfo },
|
2014-09-05 21:11:01 +02:00
|
|
|
{ _VN ("cygdrive"), FH_PROC, virt_symlink, format_proc_cygdrive },
|
2011-08-19 22:05:15 +02:00
|
|
|
{ _VN ("devices"), FH_PROC, virt_file, format_proc_devices },
|
2010-09-06 11:47:01 +02:00
|
|
|
{ _VN ("filesystems"), FH_PROC, virt_file, format_proc_filesystems },
|
|
|
|
{ _VN ("loadavg"), FH_PROC, virt_file, format_proc_loadavg },
|
|
|
|
{ _VN ("meminfo"), FH_PROC, virt_file, format_proc_meminfo },
|
2011-08-19 22:05:15 +02:00
|
|
|
{ _VN ("misc"), FH_PROC, virt_file, format_proc_misc },
|
2010-09-06 11:47:01 +02:00
|
|
|
{ _VN ("mounts"), FH_PROC, virt_symlink, format_proc_mounts },
|
|
|
|
{ _VN ("net"), FH_PROCNET, virt_directory, NULL },
|
|
|
|
{ _VN ("partitions"), FH_PROC, virt_file, format_proc_partitions },
|
|
|
|
{ _VN ("registry"), FH_REGISTRY, virt_directory, NULL },
|
|
|
|
{ _VN ("registry32"), FH_REGISTRY, virt_directory, NULL },
|
|
|
|
{ _VN ("registry64"), FH_REGISTRY, virt_directory, NULL },
|
|
|
|
{ _VN ("self"), FH_PROC, virt_symlink, format_proc_self },
|
|
|
|
{ _VN ("stat"), FH_PROC, virt_file, format_proc_stat },
|
2011-04-11 04:09:43 +02:00
|
|
|
{ _VN ("swaps"), FH_PROC, virt_file, format_proc_swaps },
|
2010-09-06 11:47:01 +02:00
|
|
|
{ _VN ("sys"), FH_PROCSYS, virt_directory, NULL },
|
2011-04-01 21:48:19 +02:00
|
|
|
{ _VN ("sysvipc"), FH_PROCSYSVIPC, virt_directory, NULL },
|
2010-09-06 11:47:01 +02:00
|
|
|
{ _VN ("uptime"), FH_PROC, virt_file, format_proc_uptime },
|
|
|
|
{ _VN ("version"), FH_PROC, virt_file, format_proc_version },
|
2011-06-12 22:15:26 +02:00
|
|
|
{ NULL, 0, FH_NADA, virt_none, NULL }
|
2002-05-02 06:26:05 +02:00
|
|
|
};
|
|
|
|
|
2007-07-26 19:30:54 +02:00
|
|
|
#define PROC_DIR_COUNT 4
|
|
|
|
|
2009-01-20 18:22:11 +01:00
|
|
|
static const int PROC_LINK_COUNT = (sizeof (proc_tab) / sizeof (virt_tab_t)) - 1;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
/* name of the /proc filesystem */
|
|
|
|
const char proc[] = "/proc";
|
2010-09-06 11:47:01 +02:00
|
|
|
const size_t proc_len = sizeof (proc) - 1;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2010-09-06 11:47:01 +02:00
|
|
|
/* bsearch compare function. */
|
|
|
|
static int
|
|
|
|
proc_tab_cmp (const void *key, const void *memb)
|
|
|
|
{
|
|
|
|
int ret = strncmp (((virt_tab_t *) key)->name, ((virt_tab_t *) memb)->name,
|
|
|
|
((virt_tab_t *) memb)->name_len);
|
|
|
|
if (!ret && ((virt_tab_t *) key)->name[((virt_tab_t *) memb)->name_len] != '\0' && ((virt_tab_t *) key)->name[((virt_tab_t *) memb)->name_len] != '/')
|
|
|
|
return 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:38:06 +01:00
|
|
|
/* Helper function to perform a binary search of the incoming pathname
|
2010-09-06 11:47:01 +02:00
|
|
|
against the alpha-sorted virtual file table. */
|
|
|
|
virt_tab_t *
|
|
|
|
virt_tab_search (const char *path, bool prefix, const virt_tab_t *table,
|
|
|
|
size_t nelem)
|
|
|
|
{
|
2011-06-12 22:15:26 +02:00
|
|
|
virt_tab_t key = { path, 0, FH_NADA, virt_none, NULL };
|
2010-09-06 11:47:01 +02:00
|
|
|
virt_tab_t *entry = (virt_tab_t *) bsearch (&key, table, nelem,
|
|
|
|
sizeof (virt_tab_t),
|
|
|
|
proc_tab_cmp);
|
|
|
|
if (entry && (path[entry->name_len] == '\0'
|
|
|
|
|| (prefix && path[entry->name_len] == '/')))
|
|
|
|
return entry;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Auxillary function that returns the fhandler associated with the given
|
|
|
|
path. */
|
2011-05-28 20:17:09 +02:00
|
|
|
fh_devices
|
2002-05-02 06:26:05 +02:00
|
|
|
fhandler_proc::get_proc_fhandler (const char *path)
|
|
|
|
{
|
|
|
|
debug_printf ("get_proc_fhandler(%s)", path);
|
|
|
|
path += proc_len;
|
|
|
|
/* Since this method is called from path_conv::check we can't rely on
|
2003-03-09 21:10:25 +01:00
|
|
|
it being normalised and therefore the path may have runs of slashes
|
|
|
|
in it. */
|
2003-01-09 09:22:05 +01:00
|
|
|
while (isdirsep (*path))
|
2002-05-02 06:26:05 +02:00
|
|
|
path++;
|
|
|
|
|
|
|
|
/* Check if this is the root of the virtual filesystem (i.e. /proc). */
|
|
|
|
if (*path == 0)
|
|
|
|
return FH_PROC;
|
|
|
|
|
2010-09-06 11:47:01 +02:00
|
|
|
virt_tab_t *entry = virt_tab_search (path, true, proc_tab,
|
|
|
|
PROC_LINK_COUNT);
|
|
|
|
if (entry)
|
|
|
|
return entry->fhandler;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2011-08-11 18:43:26 +02:00
|
|
|
int 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)
|
2002-06-02 08:07:01 +02:00
|
|
|
return FH_PROCESS;
|
2002-05-04 05:24:35 +02:00
|
|
|
|
2002-06-02 08:07:01 +02:00
|
|
|
bool has_subdir = false;
|
|
|
|
while (*path)
|
2003-01-09 09:22:05 +01:00
|
|
|
if (isdirsep (*path++))
|
2002-06-02 08:07:01 +02:00
|
|
|
{
|
|
|
|
has_subdir = true;
|
|
|
|
break;
|
|
|
|
}
|
2002-05-04 05:24:35 +02:00
|
|
|
|
2002-06-02 08:07:01 +02:00
|
|
|
if (has_subdir)
|
|
|
|
/* The user is trying to access a non-existent subdirectory of /proc. */
|
2011-06-12 22:15:26 +02:00
|
|
|
return FH_NADA;
|
2002-06-02 08:07:01 +02:00
|
|
|
else
|
2007-03-07 15:03:29 +01:00
|
|
|
/* Return FH_PROC so that we can return EROFS if the user is trying to
|
|
|
|
create a file. */
|
2002-06-02 08:07:01 +02:00
|
|
|
return FH_PROC;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 if path doesn't exist, >0 if path is a directory,
|
2005-02-01 16:11:47 +01:00
|
|
|
-1 if path is a file, -2 if it's a symlink. */
|
2010-09-06 11:47:01 +02:00
|
|
|
virtual_ftype_t
|
2002-05-23 00:09:58 +02:00
|
|
|
fhandler_proc::exists ()
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2002-05-23 00:09:58 +02:00
|
|
|
const char *path = get_name ();
|
2002-05-02 06:26:05 +02:00
|
|
|
debug_printf ("exists (%s)", path);
|
|
|
|
path += proc_len;
|
|
|
|
if (*path == 0)
|
2009-01-20 18:22:11 +01:00
|
|
|
return virt_rootdir;
|
2010-09-06 11:47:01 +02:00
|
|
|
virt_tab_t *entry = virt_tab_search (path + 1, false, proc_tab,
|
|
|
|
PROC_LINK_COUNT);
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
fileid = entry - proc_tab;
|
|
|
|
return entry->type;
|
|
|
|
}
|
2009-01-20 18:22:11 +01:00
|
|
|
return virt_none;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fhandler_proc::fhandler_proc ():
|
* 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_virtual ()
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-21 05:34:52 +01:00
|
|
|
int __reg2
|
2013-04-23 11:44:36 +02:00
|
|
|
fhandler_proc::fstat (struct stat *buf)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
const char *path = get_name ();
|
2002-06-02 05:13:22 +02:00
|
|
|
debug_printf ("fstat (%s)", path);
|
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
path += proc_len;
|
2005-07-06 22:05:03 +02:00
|
|
|
fhandler_base::fstat (buf);
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
buf->st_mode &= ~_IFMT & NO_W;
|
|
|
|
|
|
|
|
if (!*path)
|
|
|
|
{
|
2007-07-26 19:30:54 +02:00
|
|
|
winpids pids ((DWORD) 0);
|
|
|
|
buf->st_ino = 2;
|
2002-05-02 06:26:05 +02:00
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
2007-07-26 19:30:54 +02:00
|
|
|
buf->st_nlink = PROC_DIR_COUNT + 2 + pids.npids;
|
2002-05-02 06:26:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-06 11:47:01 +02:00
|
|
|
virt_tab_t *entry = virt_tab_search (path + 1, false, proc_tab,
|
|
|
|
PROC_LINK_COUNT);
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
if (entry->type == virt_directory)
|
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
|
|
|
else if (entry->type == virt_symlink)
|
|
|
|
buf->st_mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf->st_mode &= NO_X;
|
|
|
|
buf->st_mode |= S_IFREG;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-08-12 14:31:08 +02:00
|
|
|
DIR *
|
|
|
|
fhandler_proc::opendir (int fd)
|
|
|
|
{
|
|
|
|
DIR *dir = fhandler_virtual::opendir (fd);
|
|
|
|
if (dir && !(dir->__handle = (void *) new winpids ((DWORD) 0)))
|
|
|
|
{
|
|
|
|
free (dir);
|
|
|
|
dir = NULL;
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
}
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_proc::closedir (DIR *dir)
|
|
|
|
{
|
2011-08-12 14:35:37 +02:00
|
|
|
delete (winpids *) dir->__handle;
|
2011-08-12 14:31:08 +02:00
|
|
|
return fhandler_virtual::closedir (dir);
|
|
|
|
}
|
|
|
|
|
2005-08-20 08:19:55 +02:00
|
|
|
int
|
|
|
|
fhandler_proc::readdir (DIR *dir, dirent *de)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2005-08-20 08:19:55 +02:00
|
|
|
int res;
|
|
|
|
if (dir->__d_position < PROC_LINK_COUNT)
|
|
|
|
{
|
2014-10-09 15:24:37 +02:00
|
|
|
strcpy (de->d_name, proc_tab[dir->__d_position].name);
|
|
|
|
de->d_type = virt_ftype_to_dtype (proc_tab[dir->__d_position].type);
|
|
|
|
dir->__d_position++;
|
2006-01-27 22:50:42 +01:00
|
|
|
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
|
2005-08-20 08:19:55 +02:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2011-08-12 14:31:08 +02:00
|
|
|
winpids &pids = *(winpids *) dir->__handle;
|
2002-05-02 06:26:05 +02:00
|
|
|
int found = 0;
|
2005-08-20 08:19:55 +02:00
|
|
|
res = ENMFILE;
|
2002-05-02 06:26:05 +02:00
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
2002-06-02 08:07:01 +02:00
|
|
|
if (found++ == dir->__d_position - PROC_LINK_COUNT)
|
|
|
|
{
|
2005-08-20 08:19:55 +02:00
|
|
|
__small_sprintf (de->d_name, "%d", pids[i]->pid);
|
2014-10-09 15:24:37 +02:00
|
|
|
de->d_type = DT_DIR;
|
2002-06-02 08:07:01 +02:00
|
|
|
dir->__d_position++;
|
2005-08-20 08:19:55 +02:00
|
|
|
res = 0;
|
|
|
|
break;
|
2002-06-02 08:07:01 +02:00
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
2011-12-03 22:43:27 +01:00
|
|
|
syscall_printf ("%d = readdir(%p, %p) (%s)", res, dir, de, de->d_name);
|
2005-08-20 08:19:55 +02:00
|
|
|
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_proc::open (int flags, mode_t mode)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
int proc_file_no = -1;
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
int res = fhandler_virtual::open (flags, mode);
|
2002-05-02 06:26:05 +02:00
|
|
|
if (!res)
|
|
|
|
goto out;
|
|
|
|
|
2004-04-10 15:45:10 +02:00
|
|
|
nohandle (true);
|
2002-07-02 03:36:15 +02:00
|
|
|
|
2002-05-02 06:26:05 +02:00
|
|
|
const char *path;
|
|
|
|
|
2002-05-03 04:43:45 +02:00
|
|
|
path = get_name () + proc_len;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
|
|
|
if (!*path)
|
|
|
|
{
|
2002-05-04 05:24:35 +02:00
|
|
|
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EEXIST);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-04 05:24:35 +02:00
|
|
|
else if (flags & O_WRONLY)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
flags |= O_DIROPEN;
|
|
|
|
goto success;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
proc_file_no = -1;
|
2009-01-17 11:16:42 +01:00
|
|
|
for (int i = 0; proc_tab[i].name; i++)
|
|
|
|
if (path_prefix_p (proc_tab[i].name, path + 1, strlen (proc_tab[i].name),
|
2008-07-16 22:20:45 +02:00
|
|
|
false))
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2002-05-28 03:55:40 +02:00
|
|
|
proc_file_no = i;
|
2009-01-17 11:16:42 +01:00
|
|
|
if (proc_tab[i].fhandler != FH_PROC)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
|
|
|
{
|
|
|
|
set_errno (EEXIST);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else if (flags & O_WRONLY)
|
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flags |= O_DIROPEN;
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proc_file_no == -1)
|
|
|
|
{
|
2002-05-04 05:24:35 +02:00
|
|
|
if (flags & O_CREAT)
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
else
|
2002-05-28 03:55:40 +02:00
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2002-05-04 05:24:35 +02:00
|
|
|
if (flags & O_WRONLY)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
|
|
|
|
fileid = proc_file_no;
|
2002-07-02 03:36:15 +02:00
|
|
|
if (!fill_filebuf ())
|
|
|
|
{
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
2009-01-17 11:16:42 +01:00
|
|
|
}
|
2002-05-12 03:37:48 +02:00
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
|
|
|
position = filesize;
|
|
|
|
else
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
success:
|
|
|
|
res = 1;
|
2002-07-01 21:03:26 +02:00
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
2002-05-12 03:37:48 +02:00
|
|
|
set_open_status ();
|
|
|
|
out:
|
2013-04-23 11:44:36 +02:00
|
|
|
syscall_printf ("%d = fhandler_proc::open(%y, 0%o)", res, flags, mode);
|
2002-05-12 03:37:48 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
bool
|
2002-05-12 03:37:48 +02:00
|
|
|
fhandler_proc::fill_filebuf ()
|
|
|
|
{
|
2009-01-17 11:16:42 +01:00
|
|
|
if (fileid < PROC_LINK_COUNT && proc_tab[fileid].format_func)
|
2002-05-02 06:26:05 +02:00
|
|
|
{
|
2009-01-20 18:22:11 +01:00
|
|
|
filesize = proc_tab[fileid].format_func (NULL, filebuf);
|
2011-01-17 14:38:06 +01:00
|
|
|
if (filesize > 0)
|
|
|
|
return true;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2009-01-17 11:16:42 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2009-01-20 18:22:11 +01:00
|
|
|
format_proc_version (void *, char *&destbuf)
|
2009-01-17 11:16:42 +01:00
|
|
|
{
|
2011-04-04 13:12:48 +02:00
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
2009-01-17 11:16:42 +01:00
|
|
|
struct utsname uts_name;
|
|
|
|
|
|
|
|
uname (&uts_name);
|
2011-04-04 13:12:48 +02:00
|
|
|
bufptr += __small_sprintf (bufptr, "%s version %s (%s@%s) (%s) %s\n",
|
|
|
|
uts_name.sysname, uts_name.release, USERNAME, HOSTNAME,
|
|
|
|
GCC_VERSION, uts_name.version);
|
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
2009-01-17 11:16:42 +01:00
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2009-01-20 18:22:11 +01:00
|
|
|
format_proc_loadavg (void *, char *&destbuf)
|
2009-01-17 11:16:42 +01:00
|
|
|
{
|
2011-04-01 11:00:21 +02:00
|
|
|
extern int get_process_state (DWORD dwProcessId);
|
|
|
|
unsigned running = 0;
|
|
|
|
winpids pids ((DWORD) 0);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
|
|
|
switch (get_process_state (i)) {
|
|
|
|
case 'O':
|
|
|
|
case 'R':
|
2011-06-06 07:02:13 +02:00
|
|
|
running++;
|
|
|
|
break;
|
2011-04-01 11:00:21 +02:00
|
|
|
}
|
|
|
|
|
2013-04-03 21:54:58 +02:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 48);
|
2011-04-01 11:00:21 +02:00
|
|
|
return __small_sprintf (destbuf, "%u.%02u %u.%02u %u.%02u %u/%u\n",
|
|
|
|
0, 0, 0, 0, 0, 0, running, pids.npids);
|
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
|
2009-01-20 18:22:11 +01:00
|
|
|
format_proc_meminfo (void *, char *&destbuf)
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
2011-05-12 13:13:02 +02:00
|
|
|
unsigned long long mem_total, mem_free, swap_total, swap_free;
|
|
|
|
struct sysinfo info;
|
|
|
|
|
|
|
|
sysinfo (&info);
|
|
|
|
mem_total = (unsigned long long) info.totalram * info.mem_unit;
|
|
|
|
mem_free = (unsigned long long) info.freeram * info.mem_unit;
|
|
|
|
swap_total = (unsigned long long) info.totalswap * info.mem_unit;
|
|
|
|
swap_free = (unsigned long long) info.freeswap * info.mem_unit;
|
2009-01-20 18:22:11 +01:00
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 512);
|
2011-05-12 13:13:02 +02:00
|
|
|
return sprintf (destbuf, "MemTotal: %10llu kB\n"
|
|
|
|
"MemFree: %10llu kB\n"
|
|
|
|
"HighTotal: 0 kB\n"
|
|
|
|
"HighFree: 0 kB\n"
|
|
|
|
"LowTotal: %10llu kB\n"
|
|
|
|
"LowFree: %10llu kB\n"
|
|
|
|
"SwapTotal: %10llu kB\n"
|
|
|
|
"SwapFree: %10llu kB\n",
|
|
|
|
mem_total >> 10, mem_free >> 10,
|
|
|
|
mem_total >> 10, mem_free >> 10,
|
|
|
|
swap_total >> 10, swap_free >> 10);
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2009-01-20 18:22:11 +01:00
|
|
|
format_proc_uptime (void *, char *&destbuf)
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
|
|
|
unsigned long long uptime = 0ULL, idle_time = 0ULL;
|
2011-12-22 12:02:36 +01:00
|
|
|
NTSTATUS status;
|
2013-04-23 11:44:36 +02:00
|
|
|
SYSTEM_TIMEOFDAY_INFORMATION stodi;
|
2009-06-09 11:45:29 +02:00
|
|
|
/* Sizeof SYSTEM_PERFORMANCE_INFORMATION on 64 bit systems. It
|
|
|
|
appears to contain some trailing additional information from
|
|
|
|
what I can tell after examining the content.
|
|
|
|
FIXME: It would be nice if this could be verified somehow. */
|
|
|
|
const size_t sizeof_spi = sizeof (SYSTEM_PERFORMANCE_INFORMATION) + 16;
|
|
|
|
PSYSTEM_PERFORMANCE_INFORMATION spi = (PSYSTEM_PERFORMANCE_INFORMATION)
|
|
|
|
alloca (sizeof_spi);
|
2007-02-22 11:54:47 +01:00
|
|
|
|
2011-12-22 12:02:36 +01:00
|
|
|
status = NtQuerySystemInformation (SystemTimeOfDayInformation, &stodi,
|
|
|
|
sizeof stodi, NULL);
|
|
|
|
if (NT_SUCCESS (status))
|
2007-03-07 15:03:29 +01:00
|
|
|
uptime = (stodi.CurrentTime.QuadPart - stodi.BootTime.QuadPart) / 100000ULL;
|
2009-06-08 22:04:37 +02:00
|
|
|
else
|
|
|
|
debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
|
2013-04-23 11:44:36 +02:00
|
|
|
"status %y", status);
|
2009-06-08 22:04:37 +02:00
|
|
|
|
2009-06-09 11:45:29 +02:00
|
|
|
if (NT_SUCCESS (NtQuerySystemInformation (SystemPerformanceInformation,
|
|
|
|
spi, sizeof_spi, NULL)))
|
2011-05-10 17:39:02 +02:00
|
|
|
idle_time = (spi->IdleTime.QuadPart / wincap.cpu_count ())
|
2009-06-09 11:45:29 +02:00
|
|
|
/ 100000ULL;
|
2002-05-02 06:26:05 +02:00
|
|
|
|
2009-01-20 18:22:11 +01:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 80);
|
2002-05-12 03:37:48 +02:00
|
|
|
return __small_sprintf (destbuf, "%U.%02u %U.%02u\n",
|
2002-05-28 03:55:40 +02:00
|
|
|
uptime / 100, long (uptime % 100),
|
|
|
|
idle_time / 100, long (idle_time % 100));
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2009-01-20 18:22:11 +01:00
|
|
|
format_proc_stat (void *, char *&destbuf)
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
|
|
|
unsigned long pages_in = 0UL, pages_out = 0UL, interrupt_count = 0UL,
|
2002-05-28 03:55:40 +02:00
|
|
|
context_switches = 0UL, swap_in = 0UL, swap_out = 0UL;
|
2002-05-12 03:37:48 +02:00
|
|
|
time_t boot_time = 0;
|
2011-12-22 12:02:36 +01:00
|
|
|
NTSTATUS status;
|
2009-06-09 11:45:29 +02:00
|
|
|
/* Sizeof SYSTEM_PERFORMANCE_INFORMATION on 64 bit systems. It
|
|
|
|
appears to contain some trailing additional information from
|
|
|
|
what I can tell after examining the content.
|
|
|
|
FIXME: It would be nice if this could be verified somehow. */
|
|
|
|
const size_t sizeof_spi = sizeof (SYSTEM_PERFORMANCE_INFORMATION) + 16;
|
|
|
|
PSYSTEM_PERFORMANCE_INFORMATION spi = (PSYSTEM_PERFORMANCE_INFORMATION)
|
|
|
|
alloca (sizeof_spi);
|
2013-04-23 11:44:36 +02:00
|
|
|
SYSTEM_TIMEOFDAY_INFORMATION stodi;
|
2009-01-20 18:22:11 +01:00
|
|
|
tmp_pathbuf tp;
|
|
|
|
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *eobuf = buf;
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION spt[wincap.cpu_count ()];
|
|
|
|
status = NtQuerySystemInformation (SystemProcessorPerformanceInformation,
|
|
|
|
(PVOID) spt,
|
2011-12-22 12:02:36 +01:00
|
|
|
sizeof spt[0] * wincap.cpu_count (), NULL);
|
|
|
|
if (!NT_SUCCESS (status))
|
2013-04-23 11:44:36 +02:00
|
|
|
debug_printf ("NtQuerySystemInformation(SystemProcessorPerformanceInformation), "
|
|
|
|
"status %y", status);
|
2009-06-08 22:04:37 +02:00
|
|
|
else
|
2002-05-12 03:37:48 +02:00
|
|
|
{
|
2007-02-22 11:54:47 +01:00
|
|
|
unsigned long long user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
|
2011-05-10 17:39:02 +02:00
|
|
|
for (unsigned long i = 0; i < wincap.cpu_count (); i++)
|
2003-07-10 03:09:24 +02:00
|
|
|
{
|
2007-02-22 11:54:47 +01:00
|
|
|
kernel_time += (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart)
|
|
|
|
* HZ / 10000000ULL;
|
|
|
|
user_time += spt[i].UserTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
idle_time += spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
|
2003-07-10 03:09:24 +02:00
|
|
|
}
|
|
|
|
|
2007-02-22 11:54:47 +01:00
|
|
|
eobuf += __small_sprintf (eobuf, "cpu %U %U %U %U\n",
|
|
|
|
user_time, 0ULL, kernel_time, idle_time);
|
|
|
|
user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
|
2011-05-10 17:39:02 +02:00
|
|
|
for (unsigned long i = 0; i < wincap.cpu_count (); i++)
|
2003-07-10 03:09:24 +02:00
|
|
|
{
|
2007-02-22 11:54:47 +01:00
|
|
|
interrupt_count += spt[i].InterruptCount;
|
|
|
|
kernel_time = (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / 10000000ULL;
|
|
|
|
user_time = spt[i].UserTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
idle_time = spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
|
|
|
|
eobuf += __small_sprintf (eobuf, "cpu%d %U %U %U %U\n", i,
|
2003-07-10 03:09:24 +02:00
|
|
|
user_time, 0ULL, kernel_time, idle_time);
|
2002-05-28 03:55:40 +02:00
|
|
|
}
|
2007-02-22 11:54:47 +01:00
|
|
|
|
2011-12-22 12:02:36 +01:00
|
|
|
status = NtQuerySystemInformation (SystemPerformanceInformation,
|
|
|
|
(PVOID) spi, sizeof_spi, NULL);
|
|
|
|
if (!NT_SUCCESS (status))
|
2009-06-08 22:04:37 +02:00
|
|
|
{
|
|
|
|
debug_printf ("NtQuerySystemInformation(SystemPerformanceInformation)"
|
2013-04-23 11:44:36 +02:00
|
|
|
", status %y", status);
|
2009-06-09 11:45:29 +02:00
|
|
|
memset (spi, 0, sizeof_spi);
|
2009-06-08 22:04:37 +02:00
|
|
|
}
|
2011-12-22 12:02:36 +01:00
|
|
|
status = NtQuerySystemInformation (SystemTimeOfDayInformation,
|
|
|
|
(PVOID) &stodi, sizeof stodi, NULL);
|
|
|
|
if (!NT_SUCCESS (status))
|
2009-06-08 22:04:37 +02:00
|
|
|
debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
|
2013-04-23 11:44:36 +02:00
|
|
|
"status %y", status);
|
2002-05-12 03:37:48 +02:00
|
|
|
}
|
2011-12-22 12:02:36 +01:00
|
|
|
if (!NT_SUCCESS (status))
|
2011-01-17 14:38:06 +01:00
|
|
|
{
|
2011-12-22 12:02:36 +01:00
|
|
|
__seterrno_from_nt_status (status);
|
2011-01-17 14:38:06 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2009-06-08 22:04:37 +02:00
|
|
|
|
2009-06-09 11:45:29 +02:00
|
|
|
pages_in = spi->PagesRead;
|
|
|
|
pages_out = spi->PagefilePagesWritten + spi->MappedFilePagesWritten;
|
2011-12-22 12:02:36 +01:00
|
|
|
/* Note: there is no distinction made in this structure between pages read
|
|
|
|
from the page file and pages read from mapped files, but there is such
|
|
|
|
a distinction made when it comes to writing. Goodness knows why. The
|
|
|
|
value of swap_in, then, will obviously be wrong but its our best guess. */
|
2009-06-09 11:45:29 +02:00
|
|
|
swap_in = spi->PagesRead;
|
|
|
|
swap_out = spi->PagefilePagesWritten;
|
|
|
|
context_switches = spi->ContextSwitches;
|
2013-06-14 11:09:41 +02:00
|
|
|
boot_time = to_time_t (&stodi.BootTime);
|
2007-02-22 11:54:47 +01:00
|
|
|
|
2003-07-10 03:09:24 +02:00
|
|
|
eobuf += __small_sprintf (eobuf, "page %u %u\n"
|
2002-05-28 03:55:40 +02:00
|
|
|
"swap %u %u\n"
|
|
|
|
"intr %u\n"
|
|
|
|
"ctxt %u\n"
|
|
|
|
"btime %u\n",
|
2003-07-10 03:09:24 +02:00
|
|
|
pages_in, pages_out,
|
|
|
|
swap_in, swap_out,
|
|
|
|
interrupt_count,
|
|
|
|
context_switches,
|
|
|
|
boot_time);
|
2009-01-20 18:22:11 +01:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, eobuf - buf);
|
|
|
|
memcpy (destbuf, buf, eobuf - buf);
|
|
|
|
return eobuf - buf;
|
2002-05-02 06:26:05 +02:00
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
#define add_size(p,s) ((p) = ((__typeof__(p))((PBYTE)(p)+(s))))
|
2011-04-19 10:39:38 +02:00
|
|
|
#define print(x) { bufptr = stpcpy (bufptr, (x)); }
|
2003-03-09 21:10:25 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
static inline uint32_t
|
|
|
|
get_msb (uint32_t in)
|
|
|
|
{
|
|
|
|
return 32 - __builtin_clz (in);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
mask_bits (uint32_t in)
|
|
|
|
{
|
|
|
|
uint32_t bits = get_msb (in) - 1;
|
|
|
|
if (in & (in - 1))
|
|
|
|
++bits;
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2009-01-20 18:22:11 +01:00
|
|
|
format_proc_cpuinfo (void *, char *&destbuf)
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2015-08-13 17:59:47 +02:00
|
|
|
WCHAR cpu_key[128], *cpu_num_p;
|
|
|
|
DWORD orig_affinity_mask = 0;
|
|
|
|
GROUP_AFFINITY orig_group_affinity;
|
2003-03-09 21:10:25 +01:00
|
|
|
int cpu_number;
|
|
|
|
const int BUFSIZE = 256;
|
2010-01-11 16:10:21 +01:00
|
|
|
union
|
|
|
|
{
|
|
|
|
BYTE b[BUFSIZE];
|
|
|
|
char s[BUFSIZE];
|
2011-04-19 10:39:38 +02:00
|
|
|
WCHAR w[BUFSIZE / sizeof (WCHAR)];
|
2010-01-11 16:10:21 +01:00
|
|
|
DWORD d;
|
2014-08-11 14:03:18 +02:00
|
|
|
uint32_t m[13];
|
2010-01-11 16:10:21 +01:00
|
|
|
} in_buf;
|
2009-01-20 18:22:11 +01:00
|
|
|
tmp_pathbuf tp;
|
2003-03-09 21:10:25 +01:00
|
|
|
|
2009-01-20 18:22:11 +01:00
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
2003-03-09 21:10:25 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
DWORD lpi_size = NT_MAX_PATH;
|
|
|
|
//WORD num_cpu_groups = 1; /* Pre Windows 7, only one group... */
|
|
|
|
WORD num_cpu_per_group = 64; /* ...and a max of 64 CPUs. */
|
|
|
|
|
|
|
|
if (wincap.has_processor_groups ())
|
|
|
|
{
|
|
|
|
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX lpi =
|
|
|
|
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) tp.c_get ();
|
|
|
|
lpi_size = NT_MAX_PATH;
|
2015-08-26 18:39:53 +02:00
|
|
|
if (!GetLogicalProcessorInformationEx (RelationGroup, lpi, &lpi_size))
|
2015-08-13 17:59:47 +02:00
|
|
|
lpi = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX plpi = lpi;
|
|
|
|
for (DWORD size = lpi_size; size > 0;
|
|
|
|
size -= plpi->Size, add_size (plpi, plpi->Size))
|
|
|
|
if (plpi->Relationship == RelationGroup)
|
|
|
|
{
|
|
|
|
//num_cpu_groups = plpi->Group.MaximumGroupCount;
|
|
|
|
num_cpu_per_group
|
|
|
|
= plpi->Group.GroupInfo[0].MaximumProcessorCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_num_p = wcpcpy (cpu_key, L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION"
|
|
|
|
"\\System\\CentralProcessor\\");
|
2005-10-02 02:13:41 +02:00
|
|
|
for (cpu_number = 0; ; cpu_number++)
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2015-08-13 17:59:47 +02:00
|
|
|
__small_swprintf (cpu_num_p, L"%d", cpu_number);
|
2011-04-19 10:39:38 +02:00
|
|
|
if (!NT_SUCCESS (RtlCheckRegistryKey (RTL_REGISTRY_ABSOLUTE, cpu_key)))
|
|
|
|
break;
|
2007-03-07 15:03:29 +01:00
|
|
|
if (cpu_number)
|
2007-07-07 18:46:35 +02:00
|
|
|
print ("\n");
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
WORD cpu_group = cpu_number / num_cpu_per_group;
|
|
|
|
KAFFINITY cpu_mask = 1L << (cpu_number % num_cpu_per_group);
|
|
|
|
|
|
|
|
if (wincap.has_processor_groups ())
|
|
|
|
{
|
|
|
|
GROUP_AFFINITY affinity = {
|
|
|
|
.Mask = cpu_mask,
|
|
|
|
.Group = cpu_group,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!SetThreadGroupAffinity (GetCurrentThread (), &affinity,
|
|
|
|
&orig_group_affinity))
|
|
|
|
system_printf ("SetThreadGroupAffinity(%x,%d (%x/%d)) failed %E", cpu_mask, cpu_group, cpu_number, cpu_number);
|
|
|
|
orig_affinity_mask = 1; /* Just mark success. */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
orig_affinity_mask = SetThreadAffinityMask (GetCurrentThread (),
|
|
|
|
1 << cpu_number);
|
|
|
|
if (orig_affinity_mask == 0)
|
|
|
|
debug_printf ("SetThreadAffinityMask failed %E");
|
|
|
|
}
|
2011-04-19 10:39:38 +02:00
|
|
|
/* I'm not sure whether the thread changes processor immediately
|
|
|
|
and I'm not sure whether this function will cause the thread
|
|
|
|
to be rescheduled */
|
2010-03-13 00:13:48 +01:00
|
|
|
yield ();
|
2003-03-09 21:10:25 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
DWORD cpu_mhz = 0;
|
|
|
|
RTL_QUERY_REGISTRY_TABLE tab[2] = {
|
|
|
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
|
|
|
|
L"~Mhz", &cpu_mhz, REG_NONE, NULL, 0 },
|
|
|
|
{ NULL, 0, NULL, NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
RtlQueryRegistryValues (RTL_REGISTRY_ABSOLUTE, cpu_key, tab,
|
|
|
|
NULL, NULL);
|
|
|
|
bufptr += __small_sprintf (bufptr, "processor\t: %d\n", cpu_number);
|
|
|
|
uint32_t maxf, vendor_id[4], unused;
|
|
|
|
|
|
|
|
cpuid (&maxf, &vendor_id[0], &vendor_id[2], &vendor_id[1], 0x00000000);
|
|
|
|
maxf &= 0xffff;
|
|
|
|
vendor_id[3] = 0;
|
|
|
|
|
|
|
|
/* Vendor identification. */
|
|
|
|
bool is_amd = false, is_intel = false;
|
|
|
|
if (!strcmp ((char*)vendor_id, "AuthenticAMD"))
|
|
|
|
is_amd = true;
|
|
|
|
else if (!strcmp ((char*)vendor_id, "GenuineIntel"))
|
|
|
|
is_intel = true;
|
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr, "vendor_id\t: %s\n",
|
|
|
|
(char *)vendor_id);
|
|
|
|
|
|
|
|
uint32_t features1, features2, extra_info, cpuid_sig;
|
|
|
|
cpuid (&cpuid_sig, &extra_info, &features2, &features1, 0x00000001);
|
|
|
|
uint32_t family = (cpuid_sig & 0x00000f00) >> 8,
|
|
|
|
model = (cpuid_sig & 0x000000f0) >> 4,
|
|
|
|
stepping = cpuid_sig & 0x0000000f,
|
|
|
|
apic_id = (extra_info & 0xff000000) >> 24;
|
|
|
|
if (family == 15)
|
|
|
|
family += (cpuid_sig >> 20) & 0xff;
|
|
|
|
if (family >= 6)
|
|
|
|
model += ((cpuid_sig >> 16) & 0x0f) << 4;
|
|
|
|
|
|
|
|
uint32_t maxe = 0;
|
|
|
|
cpuid (&maxe, &unused, &unused, &unused, 0x80000000);
|
|
|
|
if (maxe >= 0x80000004)
|
|
|
|
{
|
|
|
|
cpuid (&in_buf.m[0], &in_buf.m[1], &in_buf.m[2],
|
|
|
|
&in_buf.m[3], 0x80000002);
|
|
|
|
cpuid (&in_buf.m[4], &in_buf.m[5], &in_buf.m[6],
|
|
|
|
&in_buf.m[7], 0x80000003);
|
|
|
|
cpuid (&in_buf.m[8], &in_buf.m[9], &in_buf.m[10],
|
|
|
|
&in_buf.m[11], 0x80000004);
|
|
|
|
in_buf.m[12] = 0;
|
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
else
|
|
|
|
{
|
2015-08-13 17:59:47 +02:00
|
|
|
/* Could implement a lookup table here if someone needs it. */
|
|
|
|
strcpy (in_buf.s, "unknown");
|
|
|
|
}
|
|
|
|
int cache_size = -1,
|
|
|
|
clflush = 64,
|
|
|
|
cache_alignment = 64;
|
|
|
|
if (features1 & (1 << 19)) /* CLFSH */
|
|
|
|
clflush = ((extra_info >> 8) & 0xff) << 3;
|
|
|
|
if (is_intel && family == 15)
|
|
|
|
cache_alignment = clflush * 2;
|
|
|
|
if (is_intel)
|
|
|
|
{
|
2015-08-29 09:16:47 +02:00
|
|
|
extern long get_cpu_cache_intel (int sysc, uint32_t maxf);
|
|
|
|
long cs;
|
2015-08-13 17:59:47 +02:00
|
|
|
|
2015-08-29 09:16:47 +02:00
|
|
|
/* As on Linux, don't check for L3 cache. */
|
|
|
|
cs = get_cpu_cache_intel (_SC_LEVEL2_CACHE_SIZE, maxf);
|
|
|
|
if (cs == -1)
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2015-08-29 09:16:47 +02:00
|
|
|
cs = get_cpu_cache_intel (_SC_LEVEL1_ICACHE_SIZE, maxf);
|
|
|
|
if (cs != -1)
|
|
|
|
cache_size = cs;
|
|
|
|
cs = get_cpu_cache_intel (_SC_LEVEL1_DCACHE_SIZE, maxf);
|
|
|
|
if (cs != -1)
|
|
|
|
cache_size += cs;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2015-08-29 09:16:47 +02:00
|
|
|
else
|
|
|
|
cache_size = cs;
|
2015-08-13 17:59:47 +02:00
|
|
|
if (cache_size != -1)
|
|
|
|
cache_size >>= 10;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2015-08-29 09:16:47 +02:00
|
|
|
else if (is_amd)
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2015-08-29 09:16:47 +02:00
|
|
|
extern long get_cpu_cache_amd (int sysc, uint32_t maxe);
|
|
|
|
long cs;
|
2011-04-19 10:39:38 +02:00
|
|
|
|
2015-08-29 09:16:47 +02:00
|
|
|
cs = get_cpu_cache_amd (_SC_LEVEL3_CACHE_SIZE, maxe);
|
|
|
|
if (cs == -1)
|
|
|
|
cs = get_cpu_cache_amd (_SC_LEVEL2_CACHE_SIZE, maxe);
|
|
|
|
if (cs == -1)
|
|
|
|
{
|
|
|
|
cs = get_cpu_cache_amd (_SC_LEVEL1_ICACHE_SIZE, maxe);
|
|
|
|
if (cs != -1)
|
|
|
|
cache_size = cs;
|
|
|
|
cs = get_cpu_cache_amd (_SC_LEVEL1_DCACHE_SIZE, maxe);
|
|
|
|
if (cs != -1)
|
|
|
|
cache_size += cs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cache_size = cs;
|
|
|
|
if (cache_size != -1)
|
|
|
|
cache_size >>= 10;
|
2003-07-26 06:53:59 +02:00
|
|
|
}
|
2015-08-13 17:59:47 +02:00
|
|
|
bufptr += __small_sprintf (bufptr, "cpu family\t: %d\n"
|
|
|
|
"model\t\t: %d\n"
|
|
|
|
"model name\t: %s\n"
|
|
|
|
"stepping\t: %d\n"
|
|
|
|
"cpu MHz\t\t: %d.000\n",
|
|
|
|
family,
|
|
|
|
model,
|
|
|
|
in_buf.s + strspn (in_buf.s, " "),
|
|
|
|
stepping,
|
|
|
|
cpu_mhz);
|
|
|
|
|
|
|
|
if (cache_size >= 0)
|
|
|
|
bufptr += __small_sprintf (bufptr, "cache size\t: %d KB\n",
|
|
|
|
cache_size);
|
|
|
|
|
|
|
|
/* Recognize multi-core CPUs. */
|
|
|
|
if (features1 & (1 << 28)) /* HTT */
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2015-08-13 17:59:47 +02:00
|
|
|
uint32_t siblings = 0;
|
|
|
|
uint32_t cpu_cores = 0;
|
|
|
|
uint32_t phys_id = 0;
|
|
|
|
uint32_t core_id = 0;
|
|
|
|
uint32_t initial_apic_id = apic_id;
|
|
|
|
|
|
|
|
uint32_t logical_bits = 0; /* # of logical core bits in apicid. */
|
|
|
|
uint32_t ht_bits = 0; /* # of thread bits in apic_id. */
|
2011-04-19 10:39:38 +02:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
if (is_intel)
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2015-08-13 17:59:47 +02:00
|
|
|
bool valid = false;
|
|
|
|
if (maxf >= 0x0000000b) /* topoext supported? */
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2015-08-13 17:59:47 +02:00
|
|
|
uint32_t bits, logical, level, unused;
|
|
|
|
|
|
|
|
/* Threads */
|
|
|
|
cpuid (&bits, &logical, &level, &unused,
|
|
|
|
0x0000000b, 0x00);
|
|
|
|
/* Even if topoext is supposedly supported, it can return
|
|
|
|
"invalid". */
|
|
|
|
if (bits != 0 && ((level >> 8) & 0xff) == 1)
|
|
|
|
{
|
|
|
|
valid = true;
|
|
|
|
ht_bits = (bits & 0x1f);
|
|
|
|
siblings = (logical & 0xffff);
|
|
|
|
cpu_cores = siblings;
|
|
|
|
for (uint32_t idx = 1; ; ++idx)
|
|
|
|
{
|
|
|
|
cpuid (&bits, &logical, &level, &initial_apic_id,
|
|
|
|
0x0000000b, idx);
|
|
|
|
|
|
|
|
uint32_t level_type = ((level >> 8) & 0xff);
|
|
|
|
if (level_type == 0) /* Invalid */
|
|
|
|
break;
|
|
|
|
if (level_type == 2) /* Core */
|
|
|
|
{
|
|
|
|
logical_bits = (bits & 0x1f);
|
|
|
|
siblings = (logical & 0xffff);
|
|
|
|
cpu_cores = siblings >> ht_bits;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2015-08-13 17:59:47 +02:00
|
|
|
if (!valid && maxf >= 0x00000004)
|
2007-07-07 18:46:35 +02:00
|
|
|
{
|
2015-08-13 17:59:47 +02:00
|
|
|
uint32_t apic_reserved;
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
cpuid (&apic_reserved, &unused, &unused, &unused,
|
|
|
|
0x00000004, 0x00);
|
|
|
|
if (apic_reserved & 0x1f)
|
|
|
|
{
|
|
|
|
valid = true;
|
|
|
|
cpu_cores = ((apic_reserved >> 26) & 0x3f) + 1;
|
|
|
|
siblings = (extra_info >> 16) & 0xff;
|
|
|
|
if (siblings <= 1) /* HT could be fused out */
|
|
|
|
{
|
|
|
|
logical_bits = mask_bits (cpu_cores);
|
|
|
|
ht_bits = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logical_bits = mask_bits (siblings);
|
|
|
|
ht_bits = mask_bits (siblings / cpu_cores);
|
|
|
|
}
|
|
|
|
}
|
2007-03-07 15:03:29 +01:00
|
|
|
}
|
2015-08-13 17:59:47 +02:00
|
|
|
if (!valid) /* single core, multi thread */
|
2007-07-07 18:46:35 +02:00
|
|
|
{
|
2015-08-13 17:59:47 +02:00
|
|
|
cpu_cores = 1;
|
|
|
|
siblings = (extra_info >> 16) & 0xff;
|
|
|
|
logical_bits = mask_bits (siblings);
|
|
|
|
ht_bits = logical_bits;
|
2007-03-07 15:03:29 +01:00
|
|
|
}
|
2015-08-13 17:59:47 +02:00
|
|
|
}
|
|
|
|
else if (is_amd)
|
|
|
|
{
|
2015-08-17 16:35:41 +02:00
|
|
|
if (maxe >= 0x8000001e)
|
|
|
|
{
|
|
|
|
uint32_t cus, core_info;
|
|
|
|
|
|
|
|
cpuid (&unused, &unused, &core_info, &unused, 0x80000008);
|
|
|
|
cpuid (&unused, &cus, &unused, &unused, 0x8000001e);
|
|
|
|
siblings = (core_info & 0xff) + 1;
|
|
|
|
logical_bits = (core_info >> 12) & 0xf;
|
|
|
|
cus = ((cus >> 8) & 0x3) + 1;
|
|
|
|
ht_bits = mask_bits (cus);
|
|
|
|
cpu_cores = siblings >> ht_bits;
|
|
|
|
}
|
|
|
|
else if (maxe >= 0x80000008)
|
2007-07-07 18:46:35 +02:00
|
|
|
{
|
2014-08-11 14:03:18 +02:00
|
|
|
uint32_t core_info;
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
cpuid (&unused, &unused, &core_info, &unused, 0x80000008);
|
2015-08-17 16:35:41 +02:00
|
|
|
siblings = (core_info & 0xff) + 1;
|
|
|
|
cpu_cores = siblings;
|
|
|
|
logical_bits = (core_info >> 12) & 0xf;
|
|
|
|
if (!logical_bits)
|
|
|
|
logical_bits = mask_bits (siblings);
|
|
|
|
ht_bits = 0;
|
2007-03-07 15:03:29 +01:00
|
|
|
}
|
2015-08-13 17:59:47 +02:00
|
|
|
else
|
2007-07-07 18:46:35 +02:00
|
|
|
{
|
2015-08-17 16:35:41 +02:00
|
|
|
siblings = (extra_info >> 16) & 0xff;
|
|
|
|
cpu_cores = siblings;
|
|
|
|
logical_bits = mask_bits (siblings);
|
|
|
|
ht_bits = 0;
|
2007-03-07 15:03:29 +01:00
|
|
|
}
|
2015-08-13 17:59:47 +02:00
|
|
|
}
|
|
|
|
phys_id = initial_apic_id >> logical_bits;
|
|
|
|
core_id = (initial_apic_id & ((1 << logical_bits) - 1)) >> ht_bits;
|
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr, "physical id\t: %d\n", phys_id);
|
|
|
|
if (siblings > 0)
|
|
|
|
bufptr += __small_sprintf (bufptr, "siblings\t: %u\n", siblings);
|
|
|
|
bufptr += __small_sprintf (bufptr, "core id\t\t: %d\n"
|
|
|
|
"cpu cores\t: %d\n",
|
|
|
|
core_id, cpu_cores);
|
|
|
|
if (features1 & (1 << 9)) /* apic */
|
|
|
|
bufptr += __small_sprintf (bufptr, "apicid\t\t: %d\n"
|
|
|
|
"initial apicid\t: %d\n",
|
|
|
|
apic_id, initial_apic_id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr, "fpu\t\t: %s\n"
|
|
|
|
"fpu_exception\t: %s\n"
|
|
|
|
"cpuid level\t: %d\n"
|
|
|
|
"wp\t\t: yes\n",
|
|
|
|
(features1 & (1 << 0)) ? "yes" : "no",
|
|
|
|
(features1 & (1 << 0)) ? "yes" : "no",
|
|
|
|
maxf);
|
|
|
|
print ("flags\t\t:");
|
|
|
|
if (features1 & (1 << 0))
|
|
|
|
print (" fpu");
|
|
|
|
if (features1 & (1 << 1))
|
|
|
|
print (" vme");
|
|
|
|
if (features1 & (1 << 2))
|
|
|
|
print (" de");
|
|
|
|
if (features1 & (1 << 3))
|
|
|
|
print (" pse");
|
|
|
|
if (features1 & (1 << 4))
|
|
|
|
print (" tsc");
|
|
|
|
if (features1 & (1 << 5))
|
|
|
|
print (" msr");
|
|
|
|
if (features1 & (1 << 6))
|
|
|
|
print (" pae");
|
|
|
|
if (features1 & (1 << 7))
|
|
|
|
print (" mce");
|
|
|
|
if (features1 & (1 << 8))
|
|
|
|
print (" cx8");
|
|
|
|
if (features1 & (1 << 9))
|
|
|
|
print (" apic");
|
|
|
|
if (features1 & (1 << 11))
|
|
|
|
print (" sep");
|
|
|
|
if (features1 & (1 << 12))
|
|
|
|
print (" mtrr");
|
|
|
|
if (features1 & (1 << 13))
|
|
|
|
print (" pge");
|
|
|
|
if (features1 & (1 << 14))
|
|
|
|
print (" mca");
|
|
|
|
if (features1 & (1 << 15))
|
|
|
|
print (" cmov");
|
|
|
|
if (features1 & (1 << 16))
|
|
|
|
print (" pat");
|
|
|
|
if (features1 & (1 << 17))
|
|
|
|
print (" pse36");
|
|
|
|
if (features1 & (1 << 18))
|
|
|
|
print (" pn");
|
|
|
|
if (features1 & (1 << 19))
|
|
|
|
print (" clflush");
|
|
|
|
if (is_intel && features1 & (1 << 21))
|
|
|
|
print (" dts");
|
|
|
|
if (is_intel && features1 & (1 << 22))
|
|
|
|
print (" acpi");
|
|
|
|
if (features1 & (1 << 23))
|
|
|
|
print (" mmx");
|
|
|
|
if (features1 & (1 << 24))
|
|
|
|
print (" fxsr");
|
|
|
|
if (features1 & (1 << 25))
|
|
|
|
print (" sse");
|
|
|
|
if (features1 & (1 << 26))
|
|
|
|
print (" sse2");
|
|
|
|
if (is_intel && (features1 & (1 << 27)))
|
|
|
|
print (" ss");
|
|
|
|
if (features1 & (1 << 28))
|
|
|
|
print (" ht");
|
|
|
|
if (is_intel)
|
|
|
|
{
|
|
|
|
if (features1 & (1 << 29))
|
|
|
|
print (" tm");
|
|
|
|
if (features1 & (1 << 30))
|
|
|
|
print (" ia64");
|
|
|
|
if (features1 & (1 << 31))
|
|
|
|
print (" pbe");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_amd && maxe >= 0x80000001)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x80000001);
|
|
|
|
|
|
|
|
if (features1 & (1 << 11))
|
|
|
|
print (" syscall");
|
|
|
|
if (features1 & (1 << 19)) /* Huh? Not in AMD64 specs. */
|
|
|
|
print (" mp");
|
|
|
|
if (features1 & (1 << 20))
|
|
|
|
print (" nx");
|
|
|
|
if (features1 & (1 << 22))
|
|
|
|
print (" mmxext");
|
|
|
|
if (features1 & (1 << 25))
|
|
|
|
print (" fxsr_opt");
|
|
|
|
if (features1 & (1 << 26))
|
|
|
|
print (" pdpe1gb");
|
|
|
|
if (features1 & (1 << 27))
|
|
|
|
print (" rdtscp");
|
|
|
|
if (features1 & (1 << 29))
|
|
|
|
print (" lm");
|
|
|
|
if (features1 & (1 << 30)) /* 31th bit is on. */
|
|
|
|
print (" 3dnowext");
|
|
|
|
if (features1 & (1 << 31)) /* 32th bit (highest) is on. */
|
|
|
|
print (" 3dnow");
|
|
|
|
}
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
if (features2 & (1 << 0))
|
|
|
|
print (" pni");
|
|
|
|
if (is_intel)
|
|
|
|
{
|
|
|
|
if (features2 & (1 << 2))
|
|
|
|
print (" dtes64");
|
|
|
|
if (features2 & (1 << 3))
|
|
|
|
print (" monitor");
|
|
|
|
if (features2 & (1 << 4))
|
|
|
|
print (" ds_cpl");
|
|
|
|
if (features2 & (1 << 5))
|
|
|
|
print (" vmx");
|
|
|
|
if (features2 & (1 << 6))
|
|
|
|
print (" smx");
|
|
|
|
if (features2 & (1 << 7))
|
|
|
|
print (" est");
|
|
|
|
if (features2 & (1 << 8))
|
|
|
|
print (" tm2");
|
|
|
|
if (features2 & (1 << 9))
|
|
|
|
print (" ssse3");
|
|
|
|
if (features2 & (1 << 10))
|
|
|
|
print (" cid");
|
|
|
|
if (features2 & (1 << 12))
|
|
|
|
print (" fma");
|
|
|
|
}
|
|
|
|
if (features2 & (1 << 13))
|
|
|
|
print (" cx16");
|
|
|
|
if (is_intel)
|
|
|
|
{
|
|
|
|
if (features2 & (1 << 14))
|
|
|
|
print (" xtpr");
|
|
|
|
if (features2 & (1 << 15))
|
|
|
|
print (" pdcm");
|
|
|
|
if (features2 & (1 << 18))
|
|
|
|
print (" dca");
|
|
|
|
if (features2 & (1 << 19))
|
|
|
|
print (" sse4_1");
|
|
|
|
if (features2 & (1 << 20))
|
|
|
|
print (" sse4_2");
|
|
|
|
if (features2 & (1 << 21))
|
|
|
|
print (" x2apic");
|
|
|
|
if (features2 & (1 << 22))
|
|
|
|
print (" movbe");
|
|
|
|
if (features2 & (1 << 23))
|
|
|
|
print (" popcnt");
|
|
|
|
if (features2 & (1 << 25))
|
|
|
|
print (" aes");
|
|
|
|
if (features2 & (1 << 26))
|
|
|
|
print (" xsave");
|
|
|
|
if (features2 & (1 << 27))
|
|
|
|
print (" osxsave");
|
|
|
|
if (features2 & (1 << 28))
|
|
|
|
print (" avx");
|
|
|
|
if (features2 & (1 << 29))
|
|
|
|
print (" f16c");
|
|
|
|
if (features2 & (1 << 30))
|
|
|
|
print (" rdrand");
|
|
|
|
if (features2 & (1 << 31))
|
|
|
|
print (" hypervisor");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxe >= 0x80000001)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &features1, &unused, 0x80000001);
|
|
|
|
|
|
|
|
if (features1 & (1 << 0))
|
|
|
|
print (" lahf_lm");
|
|
|
|
if (features1 & (1 << 1))
|
|
|
|
print (" cmp_legacy");
|
|
|
|
if (is_amd)
|
|
|
|
{
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 2))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" svm");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 3))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" extapic");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 4))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" cr8_legacy");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 5))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" abm");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 6))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" sse4a");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 7))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" misalignsse");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 8))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" 3dnowprefetch");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 9))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" osvw");
|
|
|
|
}
|
|
|
|
if (features1 & (1 << 10))
|
|
|
|
print (" ibs");
|
|
|
|
if (is_amd)
|
|
|
|
{
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 11))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" sse5");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 12))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" skinit");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 13))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" wdt");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 15))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" lwp");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 16))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" fma4");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 17))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" tce");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 19))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" nodeid_msr");
|
|
|
|
if (features1 & (1 << 21))
|
|
|
|
print (" tbm");
|
|
|
|
if (features1 & (1 << 22))
|
|
|
|
print (" topoext");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 23))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" perfctr_core");
|
2003-03-09 21:10:25 +01:00
|
|
|
if (features1 & (1 << 24))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" perfctr_nb");
|
2007-03-07 15:03:29 +01:00
|
|
|
if (features1 & (1 << 28))
|
2015-08-13 17:59:47 +02:00
|
|
|
print (" perfctr_l2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_intel) /* features scattered in various CPUID levels. */
|
|
|
|
{
|
|
|
|
cpuid (&features1, &unused, &features2, &unused, 0x06);
|
|
|
|
|
|
|
|
if (features1 & (1 << 1))
|
|
|
|
print (" ida");
|
|
|
|
if (features1 & (1 << 2))
|
|
|
|
print (" arat");
|
|
|
|
if (features2 & (1 << 3))
|
|
|
|
print (" epb");
|
|
|
|
|
|
|
|
cpuid (&features2, &unused, &unused, &unused, 0x0d, 1);
|
|
|
|
if (features2 & (1 << 0))
|
|
|
|
print (" xsaveopt");
|
|
|
|
|
|
|
|
if (features1 & (1 << 4))
|
|
|
|
print (" pln");
|
|
|
|
if (features1 & (1 << 6))
|
|
|
|
print (" pts");
|
|
|
|
if (features1 & (1 << 0))
|
|
|
|
print (" dtherm");
|
|
|
|
}
|
|
|
|
if (is_intel) /* Extended feature flags */
|
|
|
|
{
|
|
|
|
cpuid (&unused, &features1, &unused, &unused, 0x07, 0);
|
|
|
|
|
|
|
|
if (features1 & (1 << 0))
|
|
|
|
print (" fsgsbase");
|
|
|
|
if (features1 & (1 << 1))
|
|
|
|
print (" tsc_adjust");
|
|
|
|
if (features1 & (1 << 3))
|
|
|
|
print (" bmi1");
|
|
|
|
if (features1 & (1 << 4))
|
|
|
|
print (" hle");
|
|
|
|
if (features1 & (1 << 5))
|
|
|
|
print (" avx2");
|
|
|
|
if (features1 & (1 << 7))
|
|
|
|
print (" smep");
|
|
|
|
if (features1 & (1 << 8))
|
|
|
|
print (" bmi2");
|
|
|
|
if (features1 & (1 << 9))
|
|
|
|
print (" erms");
|
|
|
|
if (features1 & (1 << 10))
|
|
|
|
print (" invpcid");
|
|
|
|
if (features1 & (1 << 11))
|
|
|
|
print (" rtm");
|
|
|
|
if (features1 & (1 << 14))
|
|
|
|
print (" mpx");
|
|
|
|
if (features1 & (1 << 16))
|
|
|
|
print (" avx512f");
|
|
|
|
if (features1 & (1 << 18))
|
|
|
|
print (" rdseed");
|
|
|
|
if (features1 & (1 << 19))
|
|
|
|
print (" adx");
|
|
|
|
if (features1 & (1 << 20))
|
|
|
|
print (" smap");
|
|
|
|
if (features1 & (1 << 23))
|
|
|
|
print (" clflushopt");
|
|
|
|
if (features1 & (1 << 26))
|
|
|
|
print (" avx512pf");
|
|
|
|
if (features1 & (1 << 27))
|
|
|
|
print (" avx512er");
|
|
|
|
if (features1 & (1 << 28))
|
|
|
|
print (" avx512cd");
|
|
|
|
}
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
print ("\n");
|
2004-07-26 15:19:03 +02:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
/* TODO: bogomips */
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
bufptr += __small_sprintf (bufptr, "clflush size\t: %d\n"
|
|
|
|
"cache_alignment\t: %d\n",
|
|
|
|
clflush,
|
|
|
|
cache_alignment);
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
if (maxe >= 0x80000008) /* Address size. */
|
|
|
|
{
|
|
|
|
uint32_t addr_size, phys, virt;
|
|
|
|
cpuid (&addr_size, &unused, &unused, &unused, 0x80000008);
|
|
|
|
|
|
|
|
phys = addr_size & 0xff;
|
|
|
|
virt = (addr_size >> 8) & 0xff;
|
|
|
|
/* Fix an errata on Intel CPUs */
|
|
|
|
if (is_intel && family == 15 && model == 3 && stepping == 4)
|
|
|
|
phys = 36;
|
|
|
|
bufptr += __small_sprintf (bufptr, "address sizes\t: "
|
|
|
|
"%u bits physical, "
|
|
|
|
"%u bits virtual\n",
|
|
|
|
phys, virt);
|
|
|
|
}
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
if (maxe >= 0x80000007) /* Advanced power management. */
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x80000007);
|
|
|
|
|
|
|
|
print ("power management:");
|
|
|
|
if (features1 & (1 << 0))
|
|
|
|
print (" ts");
|
|
|
|
if (features1 & (1 << 1))
|
|
|
|
print (" fid");
|
|
|
|
if (features1 & (1 << 2))
|
|
|
|
print (" vid");
|
|
|
|
if (features1 & (1 << 3))
|
|
|
|
print (" ttp");
|
|
|
|
if (features1 & (1 << 4))
|
|
|
|
print (" tm");
|
|
|
|
if (features1 & (1 << 5))
|
|
|
|
print (" stc");
|
|
|
|
if (features1 & (1 << 6))
|
|
|
|
print (" 100mhzsteps");
|
|
|
|
if (features1 & (1 << 7))
|
|
|
|
print (" hwpstate");
|
2015-08-17 10:04:33 +02:00
|
|
|
if (features1 & (1 << 9))
|
|
|
|
print (" cpb");
|
|
|
|
if (features1 & (1 << 10))
|
|
|
|
print (" eff_freq_ro");
|
2015-08-13 17:59:47 +02:00
|
|
|
}
|
2007-03-07 15:03:29 +01:00
|
|
|
|
2015-08-13 17:59:47 +02:00
|
|
|
if (orig_affinity_mask != 0)
|
|
|
|
{
|
|
|
|
if (wincap.has_processor_groups ())
|
|
|
|
SetThreadGroupAffinity (GetCurrentThread (), &orig_group_affinity,
|
|
|
|
NULL);
|
2007-02-22 11:54:47 +01:00
|
|
|
else
|
2015-08-13 17:59:47 +02:00
|
|
|
SetThreadAffinityMask (GetCurrentThread (), orig_affinity_mask);
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2011-04-19 10:39:38 +02:00
|
|
|
print ("\n");
|
|
|
|
}
|
2003-03-09 21:10:25 +01:00
|
|
|
|
2009-01-20 18:22:11 +01:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2009-01-20 18:22:11 +01:00
|
|
|
format_proc_partitions (void *, char *&destbuf)
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2006-03-09 10:01:08 +01:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
2011-01-17 14:38:06 +01:00
|
|
|
HANDLE dirhdl;
|
2009-01-20 18:22:11 +01:00
|
|
|
tmp_pathbuf tp;
|
|
|
|
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
2011-01-17 14:38:06 +01:00
|
|
|
char *ioctl_buf = tp.c_get ();
|
2014-10-16 17:35:10 +02:00
|
|
|
PWCHAR mp_buf = tp.w_get ();
|
|
|
|
WCHAR fpath[MAX_PATH];
|
|
|
|
WCHAR gpath[MAX_PATH];
|
|
|
|
DWORD len;
|
2006-03-09 10:01:08 +01:00
|
|
|
|
|
|
|
/* Open \Device object directory. */
|
2007-12-04 14:29:44 +01:00
|
|
|
wchar_t wpath[MAX_PATH] = L"\\Device";
|
2006-03-09 10:01:08 +01:00
|
|
|
UNICODE_STRING upath = {14, 16, wpath};
|
|
|
|
InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, NULL, NULL);
|
|
|
|
status = NtOpenDirectoryObject (&dirhdl, DIRECTORY_QUERY, &attr);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
debug_printf ("NtOpenDirectoryObject, status %y", status);
|
2011-01-17 14:38:06 +01:00
|
|
|
__seterrno_from_nt_status (status);
|
2009-01-20 18:22:11 +01:00
|
|
|
return 0;
|
2006-03-09 10:01:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Traverse \Device directory ... */
|
|
|
|
PDIRECTORY_BASIC_INFORMATION dbi = (PDIRECTORY_BASIC_INFORMATION)
|
|
|
|
alloca (640);
|
|
|
|
BOOLEAN restart = TRUE;
|
2011-01-17 14:38:06 +01:00
|
|
|
bool got_one = false;
|
2006-03-09 10:01:08 +01:00
|
|
|
ULONG context = 0;
|
|
|
|
while (NT_SUCCESS (NtQueryDirectoryObject (dirhdl, dbi, 640, TRUE, restart,
|
|
|
|
&context, NULL)))
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2011-01-17 14:38:06 +01:00
|
|
|
HANDLE devhdl;
|
|
|
|
PARTITION_INFORMATION_EX *pix = NULL;
|
|
|
|
PARTITION_INFORMATION *pi = NULL;
|
|
|
|
DWORD bytes_read;
|
2011-01-17 15:31:30 +01:00
|
|
|
DWORD part_cnt = 0;
|
2011-01-17 14:38:06 +01:00
|
|
|
unsigned long long size;
|
|
|
|
device dev;
|
|
|
|
|
2006-03-09 10:01:08 +01:00
|
|
|
restart = FALSE;
|
|
|
|
/* ... and check for a "Harddisk[0-9]*" entry. */
|
2011-04-02 13:32:55 +02:00
|
|
|
if (dbi->ObjectName.Length < 9 * sizeof (WCHAR)
|
2011-01-17 14:38:06 +01:00
|
|
|
|| wcsncasecmp (dbi->ObjectName.Buffer, L"Harddisk", 8) != 0
|
|
|
|
|| !iswdigit (dbi->ObjectName.Buffer[8]))
|
2006-03-09 10:01:08 +01:00
|
|
|
continue;
|
2011-01-17 14:38:06 +01:00
|
|
|
/* Got it. Now construct the path to the entire disk, which is
|
|
|
|
"\\Device\\HarddiskX\\Partition0", and open the disk with
|
2014-10-16 17:35:10 +02:00
|
|
|
minimum permissions. */
|
2011-01-17 14:38:06 +01:00
|
|
|
unsigned long drive_num = wcstoul (dbi->ObjectName.Buffer + 8, NULL, 10);
|
|
|
|
wcscpy (wpath, dbi->ObjectName.Buffer);
|
|
|
|
PWCHAR wpart = wpath + dbi->ObjectName.Length / sizeof (WCHAR);
|
2014-10-16 17:35:10 +02:00
|
|
|
wcpcpy (wpart, L"\\Partition0");
|
|
|
|
upath.Length = dbi->ObjectName.Length + 22;
|
2011-01-17 14:38:06 +01:00
|
|
|
upath.MaximumLength = upath.Length + sizeof (WCHAR);
|
|
|
|
InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE,
|
|
|
|
dirhdl, NULL);
|
2013-04-23 11:44:36 +02:00
|
|
|
status = NtOpenFile (&devhdl, READ_CONTROL, &attr, &io,
|
|
|
|
FILE_SHARE_VALID_FLAGS, 0);
|
2011-01-17 14:38:06 +01:00
|
|
|
if (!NT_SUCCESS (status))
|
2003-03-09 21:10:25 +01:00
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
debug_printf ("NtOpenFile(%S), status %y", &upath, status);
|
2011-01-17 14:38:06 +01:00
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!got_one)
|
|
|
|
{
|
2014-10-16 17:35:10 +02:00
|
|
|
print ("major minor #blocks name win-mounts\n\n");
|
2011-01-17 14:38:06 +01:00
|
|
|
got_one = true;
|
|
|
|
}
|
|
|
|
/* Fetch partition info for the entire disk to get its size. */
|
2013-04-23 11:44:36 +02:00
|
|
|
if (DeviceIoControl (devhdl, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0,
|
|
|
|
ioctl_buf, NT_MAX_PATH, &bytes_read, NULL))
|
2011-01-17 14:38:06 +01:00
|
|
|
{
|
|
|
|
pix = (PARTITION_INFORMATION_EX *) ioctl_buf;
|
|
|
|
size = pix->PartitionLength.QuadPart;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2011-01-17 14:38:06 +01:00
|
|
|
else if (DeviceIoControl (devhdl, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0,
|
|
|
|
ioctl_buf, NT_MAX_PATH, &bytes_read, NULL))
|
|
|
|
{
|
|
|
|
pi = (PARTITION_INFORMATION *) ioctl_buf;
|
|
|
|
size = pi->PartitionLength.QuadPart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug_printf ("DeviceIoControl (%S, "
|
|
|
|
"IOCTL_DISK_GET_PARTITION_INFO{_EX}) %E", &upath);
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
dev.parsedisk (drive_num, 0);
|
|
|
|
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n",
|
2011-05-28 20:17:09 +02:00
|
|
|
dev.get_major (), dev.get_minor (),
|
2011-01-17 14:38:06 +01:00
|
|
|
size >> 10, dev.name + 5);
|
|
|
|
/* Fetch drive layout info to get size of all partitions on the disk. */
|
2013-04-23 11:44:36 +02:00
|
|
|
if (DeviceIoControl (devhdl, IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
|
|
|
|
NULL, 0, ioctl_buf, NT_MAX_PATH, &bytes_read, NULL))
|
2011-01-17 14:38:06 +01:00
|
|
|
{
|
|
|
|
PDRIVE_LAYOUT_INFORMATION_EX pdlix = (PDRIVE_LAYOUT_INFORMATION_EX)
|
|
|
|
ioctl_buf;
|
|
|
|
part_cnt = pdlix->PartitionCount;
|
|
|
|
pix = pdlix->PartitionEntry;
|
|
|
|
}
|
|
|
|
else if (DeviceIoControl (devhdl, IOCTL_DISK_GET_DRIVE_LAYOUT,
|
|
|
|
NULL, 0, ioctl_buf, NT_MAX_PATH, &bytes_read, NULL))
|
|
|
|
{
|
|
|
|
PDRIVE_LAYOUT_INFORMATION pdli = (PDRIVE_LAYOUT_INFORMATION) ioctl_buf;
|
|
|
|
part_cnt = pdli->PartitionCount;
|
|
|
|
pi = pdli->PartitionEntry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
debug_printf ("DeviceIoControl(%S, "
|
|
|
|
"IOCTL_DISK_GET_DRIVE_LAYOUT{_EX}): %E", &upath);
|
|
|
|
/* Loop over partitions. */
|
|
|
|
if (pix || pi)
|
|
|
|
for (DWORD i = 0; i < part_cnt; ++i)
|
|
|
|
{
|
|
|
|
DWORD part_num;
|
|
|
|
|
|
|
|
if (pix)
|
|
|
|
{
|
|
|
|
size = pix->PartitionLength.QuadPart;
|
|
|
|
part_num = pix->PartitionNumber;
|
|
|
|
++pix;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size = pi->PartitionLength.QuadPart;
|
2013-04-23 11:44:36 +02:00
|
|
|
part_num = pi->PartitionNumber;
|
2011-01-17 14:38:06 +01:00
|
|
|
++pi;
|
|
|
|
}
|
|
|
|
/* A partition number of 0 denotes an extended partition or a
|
|
|
|
filler entry as described in fhandler_dev_floppy::lock_partition.
|
|
|
|
Just skip. */
|
|
|
|
if (part_num == 0)
|
|
|
|
continue;
|
|
|
|
dev.parsedisk (drive_num, part_num);
|
2014-10-16 17:35:10 +02:00
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s",
|
2011-05-28 20:17:09 +02:00
|
|
|
dev.get_major (), dev.get_minor (),
|
2011-01-17 14:38:06 +01:00
|
|
|
size >> 10, dev.name + 5);
|
2014-10-16 17:35:10 +02:00
|
|
|
/* Check if the partition is mounted in Windows and, if so,
|
|
|
|
print the mount point list. */
|
|
|
|
__small_swprintf (fpath,
|
|
|
|
L"\\\\?\\GLOBALROOT\\Device\\%S\\Partition%u\\",
|
|
|
|
&dbi->ObjectName, part_num);
|
|
|
|
if (GetVolumeNameForVolumeMountPointW (fpath, gpath, MAX_PATH)
|
|
|
|
&& GetVolumePathNamesForVolumeNameW (gpath, mp_buf,
|
|
|
|
NT_MAX_PATH, &len))
|
|
|
|
{
|
|
|
|
len = strlen (dev.name + 5);
|
|
|
|
while (len++ < 6)
|
|
|
|
*bufptr++ = ' ';
|
|
|
|
for (PWCHAR p = mp_buf; *p; p = wcschr (p, L'\0') + 1)
|
|
|
|
bufptr += __small_sprintf (bufptr, " %W", p);
|
|
|
|
}
|
|
|
|
|
|
|
|
*bufptr++ = '\n';
|
2011-01-17 14:38:06 +01:00
|
|
|
}
|
|
|
|
NtClose (devhdl);
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
2006-03-09 10:01:08 +01:00
|
|
|
NtClose (dirhdl);
|
|
|
|
|
2011-01-17 14:38:06 +01:00
|
|
|
if (!got_one)
|
|
|
|
return 0;
|
|
|
|
|
2009-01-20 18:22:11 +01:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
2003-03-09 21:10:25 +01:00
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2009-01-20 18:22:11 +01:00
|
|
|
format_proc_self (void *, char *&destbuf)
|
2009-01-17 11:16:42 +01:00
|
|
|
{
|
2009-01-20 18:22:11 +01:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 16);
|
2009-01-17 11:16:42 +01:00
|
|
|
return __small_sprintf (destbuf, "%d", getpid ());
|
|
|
|
}
|
|
|
|
|
2014-09-05 21:11:01 +02:00
|
|
|
static off_t
|
|
|
|
format_proc_cygdrive (void *, char *&destbuf)
|
|
|
|
{
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, mount_table->cygdrive_len + 1);
|
|
|
|
char *dend = stpcpy (destbuf, mount_table->cygdrive);
|
2014-10-24 21:08:55 +02:00
|
|
|
if (dend > destbuf + 1) /* cygdrive != "/"? */
|
|
|
|
*--dend = '\0';
|
2014-09-05 21:11:01 +02:00
|
|
|
return dend - destbuf;
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2009-02-04 17:40:04 +01:00
|
|
|
format_proc_mounts (void *, char *&destbuf)
|
|
|
|
{
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, sizeof ("self/mounts"));
|
|
|
|
return __small_sprintf (destbuf, "self/mounts");
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2010-08-09 10:18:30 +02:00
|
|
|
format_proc_filesystems (void *, char *&destbuf)
|
|
|
|
{
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
|
|
|
|
|
|
|
/* start at 1 to skip type "none" */
|
|
|
|
for (int i = 1; fs_names[i].name; i++)
|
|
|
|
bufptr += __small_sprintf(bufptr, "%s\t%s\n",
|
2011-06-06 07:02:13 +02:00
|
|
|
fs_names[i].block_device ? "" : "nodev",
|
|
|
|
fs_names[i].name);
|
2010-08-09 10:18:30 +02:00
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2011-04-11 04:09:43 +02:00
|
|
|
format_proc_swaps (void *, char *&destbuf)
|
|
|
|
{
|
2011-05-12 13:13:02 +02:00
|
|
|
unsigned long long total = 0ULL, used = 0ULL;
|
2011-04-11 04:09:43 +02:00
|
|
|
PSYSTEM_PAGEFILE_INFORMATION spi = NULL;
|
|
|
|
ULONG size = 512;
|
2011-12-22 12:02:36 +01:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
2011-04-11 04:09:43 +02:00
|
|
|
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
|
|
|
|
|
|
|
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size);
|
|
|
|
if (spi)
|
|
|
|
{
|
2011-12-22 12:02:36 +01:00
|
|
|
status = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi,
|
|
|
|
size, &size);
|
|
|
|
if (status == STATUS_INFO_LENGTH_MISMATCH)
|
2011-04-11 04:09:43 +02:00
|
|
|
{
|
|
|
|
free (spi);
|
|
|
|
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size);
|
|
|
|
if (spi)
|
2011-12-22 12:02:36 +01:00
|
|
|
status = NtQuerySystemInformation (SystemPagefileInformation,
|
|
|
|
(PVOID) spi, size, &size);
|
2011-04-11 04:09:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr,
|
2011-06-06 07:02:13 +02:00
|
|
|
"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
|
2011-04-11 04:09:43 +02:00
|
|
|
|
2011-12-22 12:02:36 +01:00
|
|
|
if (spi && NT_SUCCESS (status))
|
2011-04-11 04:09:43 +02:00
|
|
|
{
|
|
|
|
PSYSTEM_PAGEFILE_INFORMATION spp = spi;
|
2014-05-20 13:00:37 +02:00
|
|
|
char *filename = tp.c_get ();
|
2011-04-11 04:09:43 +02:00
|
|
|
do
|
|
|
|
{
|
2011-12-22 12:02:36 +01:00
|
|
|
total = (unsigned long long) spp->CurrentSize * wincap.page_size ();
|
|
|
|
used = (unsigned long long) spp->TotalUsed * wincap.page_size ();
|
|
|
|
cygwin_conv_path (CCP_WIN_W_TO_POSIX, spp->FileName.Buffer,
|
2014-05-20 13:00:37 +02:00
|
|
|
filename, NT_MAX_PATH);
|
2011-05-12 13:13:02 +02:00
|
|
|
bufptr += sprintf (bufptr, "%-40s%-16s%-8llu%-8llu%-8d\n",
|
2011-06-06 07:02:13 +02:00
|
|
|
filename, "file", total >> 10, used >> 10, 0);
|
2011-04-11 04:09:43 +02:00
|
|
|
}
|
|
|
|
while (spp->NextEntryOffset
|
|
|
|
&& (spp = (PSYSTEM_PAGEFILE_INFORMATION)
|
2011-12-22 12:02:36 +01:00
|
|
|
((char *) spp + spp->NextEntryOffset)));
|
2011-04-11 04:09:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (spi)
|
|
|
|
free (spi);
|
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2011-08-19 22:05:15 +02:00
|
|
|
format_proc_devices (void *, char *&destbuf)
|
|
|
|
{
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr,
|
|
|
|
"Character devices:\n"
|
|
|
|
"%3d mem\n"
|
|
|
|
"%3d cons\n"
|
|
|
|
"%3d /dev/tty\n"
|
|
|
|
"%3d /dev/console\n"
|
|
|
|
"%3d /dev/ptmx\n"
|
|
|
|
"%3d st\n"
|
|
|
|
"%3d misc\n"
|
|
|
|
"%3d sound\n"
|
|
|
|
"%3d ttyS\n"
|
|
|
|
"%3d tty\n"
|
|
|
|
"\n"
|
|
|
|
"Block devices:\n"
|
|
|
|
"%3d fd\n"
|
|
|
|
"%3d sd\n"
|
|
|
|
"%3d sr\n"
|
|
|
|
"%3d sd\n"
|
|
|
|
"%3d sd\n"
|
|
|
|
"%3d sd\n"
|
|
|
|
"%3d sd\n"
|
|
|
|
"%3d sd\n"
|
|
|
|
"%3d sd\n"
|
|
|
|
"%3d sd\n",
|
|
|
|
DEV_MEM_MAJOR, DEV_CONS_MAJOR, _major (FH_TTY),
|
2011-10-16 00:37:30 +02:00
|
|
|
_major (FH_CONSOLE), _major (FH_PTMX),
|
2011-08-19 22:05:15 +02:00
|
|
|
DEV_TAPE_MAJOR, DEV_MISC_MAJOR, DEV_SOUND_MAJOR,
|
2011-10-20 16:02:54 +02:00
|
|
|
DEV_SERIAL_MAJOR, DEV_PTYS_MAJOR, DEV_FLOPPY_MAJOR,
|
2011-08-19 22:05:15 +02:00
|
|
|
DEV_SD_MAJOR, DEV_CDROM_MAJOR, DEV_SD1_MAJOR,
|
|
|
|
DEV_SD2_MAJOR, DEV_SD3_MAJOR, DEV_SD4_MAJOR,
|
|
|
|
DEV_SD5_MAJOR, DEV_SD6_MAJOR, DEV_SD7_MAJOR);
|
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
|
|
|
}
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
static off_t
|
2011-08-19 22:05:15 +02:00
|
|
|
format_proc_misc (void *, char *&destbuf)
|
|
|
|
{
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr,
|
|
|
|
"%3d clipboard\n"
|
|
|
|
"%3d windows\n",
|
|
|
|
_minor (FH_CLIPBOARD), _minor (FH_WINDOWS));
|
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
|
|
|
}
|
|
|
|
|
2003-03-09 21:10:25 +01:00
|
|
|
#undef print
|