2002-05-02 12:26:05 +08: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-08 00:15:45 +08:00
|
|
|
#include "miscfuncs.h"
|
2002-05-02 12:26:05 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
2011-04-11 10:09:43 +08:00
|
|
|
#include <stdio.h>
|
2002-05-02 12:26:05 +08:00
|
|
|
#include "cygerrno.h"
|
|
|
|
#include "security.h"
|
|
|
|
#include "path.h"
|
2014-09-06 03:11:01 +08: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 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2009-01-21 01:22:11 +08:00
|
|
|
#include "fhandler_virtual.h"
|
2002-05-02 12:26:05 +08:00
|
|
|
#include "pinfo.h"
|
2002-05-04 11:24:35 +08:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2009-01-21 01:22:11 +08:00
|
|
|
#include "tls_pbuf.h"
|
2002-05-02 12:26:05 +08:00
|
|
|
#include <sys/utsname.h>
|
2002-09-01 00:37:51 +08:00
|
|
|
#include <sys/param.h>
|
2011-05-12 19:13:02 +08:00
|
|
|
#include <sys/sysinfo.h>
|
2002-05-12 09:37:48 +08:00
|
|
|
#include "ntdll.h"
|
2003-03-10 04:10:25 +08:00
|
|
|
#include <winioctl.h>
|
2006-03-09 17:01:08 +08:00
|
|
|
#include <wchar.h>
|
2011-01-17 21:38:06 +08:00
|
|
|
#include <wctype.h>
|
2003-04-16 11:03:45 +08:00
|
|
|
#include "cpuid.h"
|
2010-08-09 16:18:30 +08:00
|
|
|
#include "mount.h"
|
2017-04-08 20:39:44 +08:00
|
|
|
#include <math.h>
|
2002-05-02 12:26:05 +08:00
|
|
|
|
|
|
|
#define _COMPILING_NEWLIB
|
|
|
|
#include <dirent.h>
|
|
|
|
|
2013-04-23 17:44:36 +08: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-06 03:11:01 +08:00
|
|
|
static off_t format_proc_cygdrive (void *, char *&);
|
2013-04-23 17:44:36 +08: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 12:26:05 +08:00
|
|
|
|
|
|
|
/* names of objects in /proc */
|
2009-01-21 01:22:11 +08:00
|
|
|
static const virt_tab_t proc_tab[] = {
|
2010-09-06 17:47:01 +08:00
|
|
|
{ _VN ("."), FH_PROC, virt_directory, NULL },
|
|
|
|
{ _VN (".."), FH_PROC, virt_directory, NULL },
|
|
|
|
{ _VN ("cpuinfo"), FH_PROC, virt_file, format_proc_cpuinfo },
|
2014-09-06 03:11:01 +08:00
|
|
|
{ _VN ("cygdrive"), FH_PROC, virt_symlink, format_proc_cygdrive },
|
2011-08-20 04:05:15 +08:00
|
|
|
{ _VN ("devices"), FH_PROC, virt_file, format_proc_devices },
|
2010-09-06 17:47:01 +08: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-20 04:05:15 +08:00
|
|
|
{ _VN ("misc"), FH_PROC, virt_file, format_proc_misc },
|
2010-09-06 17:47:01 +08: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 10:09:43 +08:00
|
|
|
{ _VN ("swaps"), FH_PROC, virt_file, format_proc_swaps },
|
2010-09-06 17:47:01 +08:00
|
|
|
{ _VN ("sys"), FH_PROCSYS, virt_directory, NULL },
|
2011-04-02 03:48:19 +08:00
|
|
|
{ _VN ("sysvipc"), FH_PROCSYSVIPC, virt_directory, NULL },
|
2010-09-06 17:47:01 +08:00
|
|
|
{ _VN ("uptime"), FH_PROC, virt_file, format_proc_uptime },
|
|
|
|
{ _VN ("version"), FH_PROC, virt_file, format_proc_version },
|
2020-03-11 20:23:55 +08:00
|
|
|
{ NULL, 0, FH_NADA, virt_none, NULL }
|
2002-05-02 12:26:05 +08:00
|
|
|
};
|
|
|
|
|
2007-07-27 01:30:54 +08:00
|
|
|
#define PROC_DIR_COUNT 4
|
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
static const int PROC_LINK_COUNT = (sizeof (proc_tab) / sizeof (virt_tab_t)) - 1;
|
2002-05-02 12:26:05 +08:00
|
|
|
|
|
|
|
/* name of the /proc filesystem */
|
|
|
|
const char proc[] = "/proc";
|
2010-09-06 17:47:01 +08:00
|
|
|
const size_t proc_len = sizeof (proc) - 1;
|
2002-05-02 12:26:05 +08:00
|
|
|
|
2010-09-06 17:47:01 +08: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 21:38:06 +08:00
|
|
|
/* Helper function to perform a binary search of the incoming pathname
|
2010-09-06 17:47:01 +08: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-13 04:15:26 +08:00
|
|
|
virt_tab_t key = { path, 0, FH_NADA, virt_none, NULL };
|
2010-09-06 17:47:01 +08: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-29 02:17:09 +08:00
|
|
|
fh_devices
|
2002-05-02 12:26:05 +08: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-10 04:10:25 +08:00
|
|
|
it being normalised and therefore the path may have runs of slashes
|
|
|
|
in it. */
|
2003-01-09 16:22:05 +08:00
|
|
|
while (isdirsep (*path))
|
2002-05-02 12:26:05 +08:00
|
|
|
path++;
|
|
|
|
|
|
|
|
/* Check if this is the root of the virtual filesystem (i.e. /proc). */
|
|
|
|
if (*path == 0)
|
|
|
|
return FH_PROC;
|
|
|
|
|
2010-09-06 17:47:01 +08:00
|
|
|
virt_tab_t *entry = virt_tab_search (path, true, proc_tab,
|
|
|
|
PROC_LINK_COUNT);
|
|
|
|
if (entry)
|
|
|
|
return entry->fhandler;
|
2002-05-02 12:26:05 +08:00
|
|
|
|
2019-01-06 04:36:34 +08:00
|
|
|
char *e;
|
|
|
|
pid_t pid = strtoul (path, &e, 10);
|
|
|
|
if (*e != '/' && *e != '\0')
|
|
|
|
return FH_NADA;
|
2011-08-12 00:43:26 +08:00
|
|
|
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)
|
2019-01-06 04:36:34 +08:00
|
|
|
{
|
|
|
|
/* Check for entry in fd subdir */
|
|
|
|
if (!strncmp (++e, "fd/", 3) && e[3] != '\0')
|
|
|
|
return FH_PROCESSFD;
|
|
|
|
return FH_PROCESS;
|
|
|
|
}
|
2002-05-04 11:24:35 +08:00
|
|
|
|
2002-06-02 14:07:01 +08:00
|
|
|
bool has_subdir = false;
|
|
|
|
while (*path)
|
2003-01-09 16:22:05 +08:00
|
|
|
if (isdirsep (*path++))
|
2002-06-02 14:07:01 +08:00
|
|
|
{
|
|
|
|
has_subdir = true;
|
|
|
|
break;
|
|
|
|
}
|
2002-05-04 11:24:35 +08:00
|
|
|
|
2002-06-02 14:07:01 +08:00
|
|
|
if (has_subdir)
|
|
|
|
/* The user is trying to access a non-existent subdirectory of /proc. */
|
2011-06-13 04:15:26 +08:00
|
|
|
return FH_NADA;
|
2002-06-02 14:07:01 +08:00
|
|
|
else
|
2007-03-07 22:03:29 +08:00
|
|
|
/* Return FH_PROC so that we can return EROFS if the user is trying to
|
|
|
|
create a file. */
|
2002-06-02 14:07:01 +08:00
|
|
|
return FH_PROC;
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
|
|
|
|
2010-09-06 17:47:01 +08:00
|
|
|
virtual_ftype_t
|
2002-05-23 06:09:58 +08:00
|
|
|
fhandler_proc::exists ()
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2002-05-23 06:09:58 +08:00
|
|
|
const char *path = get_name ();
|
2002-05-02 12:26:05 +08:00
|
|
|
debug_printf ("exists (%s)", path);
|
|
|
|
path += proc_len;
|
|
|
|
if (*path == 0)
|
2009-01-21 01:22:11 +08:00
|
|
|
return virt_rootdir;
|
2010-09-06 17:47:01 +08: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-21 01:22:11 +08:00
|
|
|
return virt_none;
|
2002-05-02 12:26:05 +08: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 08:37:18 +08:00
|
|
|
fhandler_virtual ()
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
int __reg2
|
2013-04-23 17:44:36 +08:00
|
|
|
fhandler_proc::fstat (struct stat *buf)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
|
|
|
const char *path = get_name ();
|
2002-06-02 11:13:22 +08:00
|
|
|
debug_printf ("fstat (%s)", path);
|
|
|
|
|
2002-05-02 12:26:05 +08:00
|
|
|
path += proc_len;
|
2005-07-07 04:05:03 +08:00
|
|
|
fhandler_base::fstat (buf);
|
2002-05-02 12:26:05 +08:00
|
|
|
|
|
|
|
buf->st_mode &= ~_IFMT & NO_W;
|
|
|
|
|
|
|
|
if (!*path)
|
|
|
|
{
|
2007-07-27 01:30:54 +08:00
|
|
|
winpids pids ((DWORD) 0);
|
|
|
|
buf->st_ino = 2;
|
2002-05-02 12:26:05 +08:00
|
|
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
2007-07-27 01:30:54 +08:00
|
|
|
buf->st_nlink = PROC_DIR_COUNT + 2 + pids.npids;
|
2002-05-02 12:26:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-06 17:47:01 +08: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 12:26:05 +08:00
|
|
|
}
|
|
|
|
set_errno (ENOENT);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-08-12 20:31:08 +08: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 20:35:37 +08:00
|
|
|
delete (winpids *) dir->__handle;
|
2011-08-12 20:31:08 +08:00
|
|
|
return fhandler_virtual::closedir (dir);
|
|
|
|
}
|
|
|
|
|
2005-08-20 14:19:55 +08:00
|
|
|
int
|
|
|
|
fhandler_proc::readdir (DIR *dir, dirent *de)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2005-08-20 14:19:55 +08:00
|
|
|
int res;
|
|
|
|
if (dir->__d_position < PROC_LINK_COUNT)
|
|
|
|
{
|
2014-10-09 21:24:37 +08: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-28 05:50:42 +08:00
|
|
|
dir->__flags |= dirent_saw_dot | dirent_saw_dot_dot;
|
2005-08-20 14:19:55 +08:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2011-08-12 20:31:08 +08:00
|
|
|
winpids &pids = *(winpids *) dir->__handle;
|
2002-05-02 12:26:05 +08:00
|
|
|
int found = 0;
|
2005-08-20 14:19:55 +08:00
|
|
|
res = ENMFILE;
|
2002-05-02 12:26:05 +08:00
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
2002-06-02 14:07:01 +08:00
|
|
|
if (found++ == dir->__d_position - PROC_LINK_COUNT)
|
|
|
|
{
|
2005-08-20 14:19:55 +08:00
|
|
|
__small_sprintf (de->d_name, "%d", pids[i]->pid);
|
2014-10-09 21:24:37 +08:00
|
|
|
de->d_type = DT_DIR;
|
2002-06-02 14:07:01 +08:00
|
|
|
dir->__d_position++;
|
2005-08-20 14:19:55 +08:00
|
|
|
res = 0;
|
|
|
|
break;
|
2002-06-02 14:07:01 +08:00
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
|
|
|
|
2011-12-04 05:43:27 +08:00
|
|
|
syscall_printf ("%d = readdir(%p, %p) (%s)", res, dir, de, de->d_name);
|
2005-08-20 14:19:55 +08:00
|
|
|
return res;
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_proc::open (int flags, mode_t mode)
|
2002-05-02 12:26:05 +08: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 08:37:18 +08:00
|
|
|
int res = fhandler_virtual::open (flags, mode);
|
2002-05-02 12:26:05 +08:00
|
|
|
if (!res)
|
|
|
|
goto out;
|
|
|
|
|
2004-04-10 21:45:10 +08:00
|
|
|
nohandle (true);
|
2002-07-02 09:36:15 +08:00
|
|
|
|
2002-05-02 12:26:05 +08:00
|
|
|
const char *path;
|
|
|
|
|
2002-05-03 10:43:45 +08:00
|
|
|
path = get_name () + proc_len;
|
2002-05-02 12:26:05 +08:00
|
|
|
|
|
|
|
if (!*path)
|
|
|
|
{
|
2002-05-04 11:24:35 +08:00
|
|
|
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
set_errno (EEXIST);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-04 11:24:35 +08:00
|
|
|
else if (flags & O_WRONLY)
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
set_errno (EISDIR);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
else
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
2020-09-08 04:45:38 +08:00
|
|
|
diropen = true;
|
2002-05-28 09:55:40 +08:00
|
|
|
goto success;
|
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
proc_file_no = -1;
|
2009-01-17 18:16:42 +08: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-17 04:20:45 +08:00
|
|
|
false))
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2002-05-28 09:55:40 +08:00
|
|
|
proc_file_no = i;
|
2009-01-17 18:16:42 +08:00
|
|
|
if (proc_tab[i].fhandler != FH_PROC)
|
2002-05-28 09:55:40 +08: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
|
|
|
|
{
|
2020-09-08 04:45:38 +08:00
|
|
|
diropen = true;
|
2002-05-28 09:55:40 +08:00
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proc_file_no == -1)
|
|
|
|
{
|
2002-05-04 11:24:35 +08:00
|
|
|
if (flags & O_CREAT)
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
else
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
|
|
|
set_errno (ENOENT);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
2002-05-04 11:24:35 +08:00
|
|
|
if (flags & O_WRONLY)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
|
|
|
set_errno (EROFS);
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-12 09:37:48 +08:00
|
|
|
|
|
|
|
fileid = proc_file_no;
|
2002-07-02 09:36:15 +08:00
|
|
|
if (!fill_filebuf ())
|
|
|
|
{
|
|
|
|
res = 0;
|
|
|
|
goto out;
|
2009-01-17 18:16:42 +08:00
|
|
|
}
|
2002-05-12 09:37:48 +08:00
|
|
|
|
|
|
|
if (flags & O_APPEND)
|
|
|
|
position = filesize;
|
|
|
|
else
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
success:
|
|
|
|
res = 1;
|
2002-07-02 03:03:26 +08:00
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
2002-05-12 09:37:48 +08:00
|
|
|
set_open_status ();
|
|
|
|
out:
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("%d = fhandler_proc::open(%y, 0%o)", res, flags, mode);
|
2002-05-12 09:37:48 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-07-02 09:36:15 +08:00
|
|
|
bool
|
2002-05-12 09:37:48 +08:00
|
|
|
fhandler_proc::fill_filebuf ()
|
|
|
|
{
|
2009-01-17 18:16:42 +08:00
|
|
|
if (fileid < PROC_LINK_COUNT && proc_tab[fileid].format_func)
|
2002-05-02 12:26:05 +08:00
|
|
|
{
|
2009-01-21 01:22:11 +08:00
|
|
|
filesize = proc_tab[fileid].format_func (NULL, filebuf);
|
2011-01-17 21:38:06 +08:00
|
|
|
if (filesize > 0)
|
|
|
|
return true;
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
2009-01-17 18:16:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:34:00 +08:00
|
|
|
extern "C" int uname_x (struct utsname *);
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_proc_version (void *, char *&destbuf)
|
2009-01-17 18:16:42 +08:00
|
|
|
{
|
2011-04-04 19:12:48 +08:00
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
2009-01-17 18:16:42 +08:00
|
|
|
struct utsname uts_name;
|
|
|
|
|
2019-03-18 18:34:00 +08:00
|
|
|
uname_x (&uts_name);
|
2011-04-04 19:12:48 +08: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 18:16:42 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_proc_loadavg (void *, char *&destbuf)
|
2009-01-17 18:16:42 +08:00
|
|
|
{
|
2011-04-01 17:00:21 +08:00
|
|
|
extern int get_process_state (DWORD dwProcessId);
|
2017-03-22 03:17:42 +08:00
|
|
|
unsigned int running = 0;
|
2011-04-01 17:00:21 +08:00
|
|
|
winpids pids ((DWORD) 0);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
|
|
|
switch (get_process_state (i)) {
|
|
|
|
case 'O':
|
|
|
|
case 'R':
|
2011-06-06 13:02:13 +08:00
|
|
|
running++;
|
|
|
|
break;
|
2011-04-01 17:00:21 +08:00
|
|
|
}
|
|
|
|
|
2017-03-22 03:17:42 +08:00
|
|
|
double loadavg[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
getloadavg (loadavg, 3);
|
|
|
|
|
2017-04-08 20:39:44 +08:00
|
|
|
#define HUNDRETHS(l) (int)((l - floor(l))*100)
|
|
|
|
|
2013-04-04 03:54:58 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 48);
|
2017-04-08 20:39:44 +08:00
|
|
|
return __small_sprintf (destbuf, "%u.%02u %u.%02u %u.%02u %u/%u\n",
|
|
|
|
(int)loadavg[0], HUNDRETHS(loadavg[0]),
|
|
|
|
(int)loadavg[1], HUNDRETHS(loadavg[1]),
|
|
|
|
(int)loadavg[2], HUNDRETHS(loadavg[2]),
|
|
|
|
running, (unsigned int)pids.npids);
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
2002-05-02 12:26:05 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_proc_meminfo (void *, char *&destbuf)
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2011-05-12 19:13:02 +08: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-21 01:22:11 +08:00
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 512);
|
2011-05-12 19:13:02 +08: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 09:37:48 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_proc_uptime (void *, char *&destbuf)
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
|
|
|
unsigned long long uptime = 0ULL, idle_time = 0ULL;
|
2011-12-22 19:02:36 +08:00
|
|
|
NTSTATUS status;
|
2013-04-23 17:44:36 +08:00
|
|
|
SYSTEM_TIMEOFDAY_INFORMATION stodi;
|
2009-06-09 17:45:29 +08: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 18:54:47 +08:00
|
|
|
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtQuerySystemInformation (SystemTimeOfDayInformation, &stodi,
|
|
|
|
sizeof stodi, NULL);
|
|
|
|
if (NT_SUCCESS (status))
|
2007-03-07 22:03:29 +08:00
|
|
|
uptime = (stodi.CurrentTime.QuadPart - stodi.BootTime.QuadPart) / 100000ULL;
|
2009-06-09 04:04:37 +08:00
|
|
|
else
|
|
|
|
debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
|
2013-04-23 17:44:36 +08:00
|
|
|
"status %y", status);
|
2009-06-09 04:04:37 +08:00
|
|
|
|
2009-06-09 17:45:29 +08:00
|
|
|
if (NT_SUCCESS (NtQuerySystemInformation (SystemPerformanceInformation,
|
|
|
|
spi, sizeof_spi, NULL)))
|
2011-05-10 23:39:02 +08:00
|
|
|
idle_time = (spi->IdleTime.QuadPart / wincap.cpu_count ())
|
2009-06-09 17:45:29 +08:00
|
|
|
/ 100000ULL;
|
2002-05-02 12:26:05 +08:00
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 80);
|
2002-05-12 09:37:48 +08:00
|
|
|
return __small_sprintf (destbuf, "%U.%02u %U.%02u\n",
|
2002-05-28 09:55:40 +08:00
|
|
|
uptime / 100, long (uptime % 100),
|
|
|
|
idle_time / 100, long (idle_time % 100));
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_proc_stat (void *, char *&destbuf)
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
|
|
|
unsigned long pages_in = 0UL, pages_out = 0UL, interrupt_count = 0UL,
|
2002-05-28 09:55:40 +08:00
|
|
|
context_switches = 0UL, swap_in = 0UL, swap_out = 0UL;
|
2002-05-12 09:37:48 +08:00
|
|
|
time_t boot_time = 0;
|
2011-12-22 19:02:36 +08:00
|
|
|
NTSTATUS status;
|
2009-06-09 17:45:29 +08: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 17:44:36 +08:00
|
|
|
SYSTEM_TIMEOFDAY_INFORMATION stodi;
|
2009-01-21 01:22:11 +08:00
|
|
|
tmp_pathbuf tp;
|
|
|
|
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *eobuf = buf;
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION spt[wincap.cpu_count ()];
|
|
|
|
status = NtQuerySystemInformation (SystemProcessorPerformanceInformation,
|
|
|
|
(PVOID) spt,
|
2011-12-22 19:02:36 +08:00
|
|
|
sizeof spt[0] * wincap.cpu_count (), NULL);
|
|
|
|
if (!NT_SUCCESS (status))
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("NtQuerySystemInformation(SystemProcessorPerformanceInformation), "
|
|
|
|
"status %y", status);
|
2009-06-09 04:04:37 +08:00
|
|
|
else
|
2002-05-12 09:37:48 +08:00
|
|
|
{
|
2007-02-22 18:54:47 +08:00
|
|
|
unsigned long long user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
|
2011-05-10 23:39:02 +08:00
|
|
|
for (unsigned long i = 0; i < wincap.cpu_count (); i++)
|
2003-07-10 09:09:24 +08:00
|
|
|
{
|
2007-02-22 18:54:47 +08:00
|
|
|
kernel_time += (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart)
|
2018-02-13 05:08:42 +08:00
|
|
|
* CLOCKS_PER_SEC / NS100PERSEC;
|
|
|
|
user_time += spt[i].UserTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
|
|
|
|
idle_time += spt[i].IdleTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
|
2003-07-10 09:09:24 +08:00
|
|
|
}
|
|
|
|
|
2007-02-22 18:54:47 +08: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 23:39:02 +08:00
|
|
|
for (unsigned long i = 0; i < wincap.cpu_count (); i++)
|
2003-07-10 09:09:24 +08:00
|
|
|
{
|
2007-02-22 18:54:47 +08:00
|
|
|
interrupt_count += spt[i].InterruptCount;
|
2018-02-13 05:08:42 +08:00
|
|
|
kernel_time = (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart)
|
|
|
|
* CLOCKS_PER_SEC / NS100PERSEC;
|
|
|
|
user_time = spt[i].UserTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
|
|
|
|
idle_time = spt[i].IdleTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
|
2007-02-22 18:54:47 +08:00
|
|
|
eobuf += __small_sprintf (eobuf, "cpu%d %U %U %U %U\n", i,
|
2003-07-10 09:09:24 +08:00
|
|
|
user_time, 0ULL, kernel_time, idle_time);
|
2002-05-28 09:55:40 +08:00
|
|
|
}
|
2007-02-22 18:54:47 +08:00
|
|
|
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtQuerySystemInformation (SystemPerformanceInformation,
|
|
|
|
(PVOID) spi, sizeof_spi, NULL);
|
|
|
|
if (!NT_SUCCESS (status))
|
2009-06-09 04:04:37 +08:00
|
|
|
{
|
|
|
|
debug_printf ("NtQuerySystemInformation(SystemPerformanceInformation)"
|
2013-04-23 17:44:36 +08:00
|
|
|
", status %y", status);
|
2009-06-09 17:45:29 +08:00
|
|
|
memset (spi, 0, sizeof_spi);
|
2009-06-09 04:04:37 +08:00
|
|
|
}
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtQuerySystemInformation (SystemTimeOfDayInformation,
|
|
|
|
(PVOID) &stodi, sizeof stodi, NULL);
|
|
|
|
if (!NT_SUCCESS (status))
|
2009-06-09 04:04:37 +08:00
|
|
|
debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
|
2013-04-23 17:44:36 +08:00
|
|
|
"status %y", status);
|
2002-05-12 09:37:48 +08:00
|
|
|
}
|
2011-12-22 19:02:36 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
2011-01-17 21:38:06 +08:00
|
|
|
{
|
2011-12-22 19:02:36 +08:00
|
|
|
__seterrno_from_nt_status (status);
|
2011-01-17 21:38:06 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-06-09 04:04:37 +08:00
|
|
|
|
2009-06-09 17:45:29 +08:00
|
|
|
pages_in = spi->PagesRead;
|
|
|
|
pages_out = spi->PagefilePagesWritten + spi->MappedFilePagesWritten;
|
2011-12-22 19:02:36 +08: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 17:45:29 +08:00
|
|
|
swap_in = spi->PagesRead;
|
|
|
|
swap_out = spi->PagefilePagesWritten;
|
|
|
|
context_switches = spi->ContextSwitches;
|
2013-06-14 17:09:41 +08:00
|
|
|
boot_time = to_time_t (&stodi.BootTime);
|
2007-02-22 18:54:47 +08:00
|
|
|
|
2003-07-10 09:09:24 +08:00
|
|
|
eobuf += __small_sprintf (eobuf, "page %u %u\n"
|
2002-05-28 09:55:40 +08:00
|
|
|
"swap %u %u\n"
|
|
|
|
"intr %u\n"
|
|
|
|
"ctxt %u\n"
|
|
|
|
"btime %u\n",
|
2003-07-10 09:09:24 +08:00
|
|
|
pages_in, pages_out,
|
|
|
|
swap_in, swap_out,
|
|
|
|
interrupt_count,
|
|
|
|
context_switches,
|
|
|
|
boot_time);
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, eobuf - buf);
|
|
|
|
memcpy (destbuf, buf, eobuf - buf);
|
|
|
|
return eobuf - buf;
|
2002-05-02 12:26:05 +08:00
|
|
|
}
|
2003-03-10 04:10:25 +08:00
|
|
|
|
2011-04-19 16:39:38 +08:00
|
|
|
#define print(x) { bufptr = stpcpy (bufptr, (x)); }
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* feature test unconditional print */
|
|
|
|
#define ftuprint(msg) print (" " msg)
|
2019-10-08 00:23:04 +08:00
|
|
|
/* feature test bit position (0-32) and conditional print */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
#define ftcprint(feat,bitno,msg) if ((feat) & (1 << (bitno))) { ftuprint (msg); }
|
2003-03-10 04:10:25 +08:00
|
|
|
|
2015-08-13 23:59:47 +08: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 17:44:36 +08:00
|
|
|
static off_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_proc_cpuinfo (void *, char *&destbuf)
|
2003-03-10 04:10:25 +08:00
|
|
|
{
|
2015-08-13 23:59:47 +08:00
|
|
|
WCHAR cpu_key[128], *cpu_num_p;
|
|
|
|
DWORD orig_affinity_mask = 0;
|
|
|
|
GROUP_AFFINITY orig_group_affinity;
|
2003-03-10 04:10:25 +08:00
|
|
|
int cpu_number;
|
|
|
|
const int BUFSIZE = 256;
|
2010-01-11 23:10:21 +08:00
|
|
|
union
|
|
|
|
{
|
|
|
|
BYTE b[BUFSIZE];
|
|
|
|
char s[BUFSIZE];
|
2011-04-19 16:39:38 +08:00
|
|
|
WCHAR w[BUFSIZE / sizeof (WCHAR)];
|
2010-01-11 23:10:21 +08:00
|
|
|
DWORD d;
|
2014-08-11 20:03:18 +08:00
|
|
|
uint32_t m[13];
|
2010-01-11 23:10:21 +08:00
|
|
|
} in_buf;
|
2009-01-21 01:22:11 +08:00
|
|
|
tmp_pathbuf tp;
|
2003-03-10 04:10:25 +08:00
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
2003-03-10 04:10:25 +08:00
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
//WORD num_cpu_groups = 1; /* Pre Windows 7, only one group... */
|
2018-08-07 20:51:10 +08:00
|
|
|
WORD num_cpu_per_group = __get_cpus_per_group ();
|
2018-04-11 18:45:57 +08:00
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
cpu_num_p = wcpcpy (cpu_key, L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION"
|
|
|
|
"\\System\\CentralProcessor\\");
|
2005-10-02 08:13:41 +08:00
|
|
|
for (cpu_number = 0; ; cpu_number++)
|
2003-03-10 04:10:25 +08:00
|
|
|
{
|
2015-08-13 23:59:47 +08:00
|
|
|
__small_swprintf (cpu_num_p, L"%d", cpu_number);
|
2011-04-19 16:39:38 +08:00
|
|
|
if (!NT_SUCCESS (RtlCheckRegistryKey (RTL_REGISTRY_ABSOLUTE, cpu_key)))
|
|
|
|
break;
|
2007-03-07 22:03:29 +08:00
|
|
|
if (cpu_number)
|
2007-07-08 00:46:35 +08:00
|
|
|
print ("\n");
|
2007-03-07 22:03:29 +08:00
|
|
|
|
2015-08-13 23:59:47 +08: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 16:39:38 +08: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 07:13:48 +08:00
|
|
|
yield ();
|
2003-03-10 04:10:25 +08:00
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
DWORD cpu_mhz = 0;
|
2019-10-08 00:23:03 +08:00
|
|
|
union
|
|
|
|
{
|
|
|
|
LONG uc_len; /* -max size of buffer before call */
|
2020-07-08 03:00:36 +08:00
|
|
|
char uc_microcode[16]; /* at least 8 bytes */
|
|
|
|
} uc[4]; /* microcode values changed historically */
|
2019-10-08 00:23:03 +08:00
|
|
|
|
2020-07-08 03:00:36 +08:00
|
|
|
RTL_QUERY_REGISTRY_TABLE tab[6] =
|
2019-10-08 00:23:03 +08:00
|
|
|
{
|
|
|
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
|
2020-07-08 03:00:36 +08:00
|
|
|
L"~Mhz", &cpu_mhz, REG_NONE, NULL, 0 },
|
2019-10-08 00:23:03 +08:00
|
|
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
|
2020-07-08 03:00:36 +08:00
|
|
|
L"Update Revision", &uc[0], REG_NONE, NULL, 0 },
|
|
|
|
/* latest MSR */
|
|
|
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
|
|
|
|
L"Update Signature", &uc[1], REG_NONE, NULL, 0 },
|
|
|
|
/* previous MSR */
|
|
|
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
|
|
|
|
L"CurrentPatchLevel", &uc[2], REG_NONE, NULL, 0 },
|
|
|
|
/* earlier MSR */
|
|
|
|
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
|
|
|
|
L"Platform Specific Field1", &uc[3], REG_NONE, NULL, 0 },
|
|
|
|
/* alternative */
|
2019-10-08 00:23:03 +08:00
|
|
|
{ NULL, 0, NULL, NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2020-07-08 03:00:36 +08:00
|
|
|
for (size_t uci = 0; uci < sizeof (uc)/sizeof (*uc); ++uci)
|
|
|
|
{
|
|
|
|
memset (&uc[uci], 0, sizeof (uc[uci]));
|
|
|
|
uc[uci].uc_len = -(LONG)sizeof (uc[0].uc_microcode);
|
|
|
|
/* neg buffer size */
|
|
|
|
}
|
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
RtlQueryRegistryValues (RTL_REGISTRY_ABSOLUTE, cpu_key, tab,
|
|
|
|
NULL, NULL);
|
2019-10-08 00:23:01 +08:00
|
|
|
cpu_mhz = ((cpu_mhz - 1) / 10 + 1) * 10; /* round up to multiple of 10 */
|
2019-10-08 00:23:02 +08:00
|
|
|
DWORD bogomips = cpu_mhz * 2; /* bogomips is double cpu MHz since MMX */
|
2020-07-08 03:00:36 +08:00
|
|
|
|
|
|
|
unsigned long long microcode = 0; /* needs 8 bytes */
|
|
|
|
for (size_t uci = 0; uci < sizeof (uc)/sizeof (*uc) && !microcode; ++uci)
|
|
|
|
{
|
|
|
|
/* still neg buffer size => no data */
|
|
|
|
if (-(LONG)sizeof (uc[uci].uc_microcode) != uc[uci].uc_len)
|
|
|
|
{
|
|
|
|
memcpy (µcode, uc[uci].uc_microcode, sizeof (microcode));
|
|
|
|
|
|
|
|
if (!(microcode & 0xFFFFFFFFLL)) /* some values in high bits */
|
2020-07-08 03:00:37 +08:00
|
|
|
microcode >>= 32; /* shift them down */
|
2020-07-08 03:00:36 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-08 00:23:03 +08:00
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
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;
|
2019-05-17 11:29:11 +08:00
|
|
|
if (!strcmp ((char*)vendor_id, "AuthenticAMD")
|
|
|
|
|| !strcmp((char*)vendor_id, "HygonGenuine"))
|
2015-08-13 23:59:47 +08:00
|
|
|
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)
|
2019-10-08 00:23:07 +08:00
|
|
|
model |= ((cpuid_sig >> 16) & 0x0f) << 4; /* ext model << 4 | model */
|
2015-08-13 23:59:47 +08:00
|
|
|
|
|
|
|
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-10 04:10:25 +08:00
|
|
|
else
|
|
|
|
{
|
2015-08-13 23:59:47 +08: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;
|
2019-10-08 00:22:58 +08:00
|
|
|
long (*get_cpu_cache) (int, uint32_t) = NULL;
|
|
|
|
uint32_t max;
|
2015-08-13 23:59:47 +08:00
|
|
|
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 15:16:47 +08:00
|
|
|
extern long get_cpu_cache_intel (int sysc, uint32_t maxf);
|
2019-10-08 00:22:58 +08:00
|
|
|
get_cpu_cache = get_cpu_cache_intel;
|
|
|
|
max = maxf; /* Intel uses normal cpuid levels */
|
2003-03-10 04:10:25 +08:00
|
|
|
}
|
2015-08-29 15:16:47 +08:00
|
|
|
else if (is_amd)
|
2003-03-10 04:10:25 +08:00
|
|
|
{
|
2015-08-29 15:16:47 +08:00
|
|
|
extern long get_cpu_cache_amd (int sysc, uint32_t maxe);
|
2019-10-08 00:22:58 +08:00
|
|
|
get_cpu_cache = get_cpu_cache_amd;
|
|
|
|
max = maxe; /* AMD uses extended cpuid levels */
|
|
|
|
}
|
|
|
|
if (get_cpu_cache)
|
|
|
|
{
|
2015-08-29 15:16:47 +08:00
|
|
|
long cs;
|
2011-04-19 16:39:38 +08:00
|
|
|
|
2019-10-08 00:22:58 +08:00
|
|
|
cs = get_cpu_cache (_SC_LEVEL3_CACHE_SIZE, max);
|
|
|
|
if (cs <= 0)
|
|
|
|
cs = get_cpu_cache (_SC_LEVEL2_CACHE_SIZE, max);
|
|
|
|
if (cs <= 0)
|
2015-08-29 15:16:47 +08:00
|
|
|
{
|
2019-10-08 00:22:58 +08:00
|
|
|
cs = get_cpu_cache (_SC_LEVEL1_ICACHE_SIZE, max);
|
|
|
|
if (cs > 0)
|
2015-08-29 15:16:47 +08:00
|
|
|
cache_size = cs;
|
2019-10-08 00:22:58 +08:00
|
|
|
cs = get_cpu_cache (_SC_LEVEL1_DCACHE_SIZE, max);
|
|
|
|
if (cs > 0)
|
2015-08-29 15:16:47 +08:00
|
|
|
cache_size += cs;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cache_size = cs;
|
2019-10-08 00:22:58 +08:00
|
|
|
if (cache_size > 0)
|
2015-08-29 15:16:47 +08:00
|
|
|
cache_size >>= 10;
|
2003-07-26 12:53:59 +08:00
|
|
|
}
|
2015-08-13 23:59:47 +08:00
|
|
|
bufptr += __small_sprintf (bufptr, "cpu family\t: %d\n"
|
|
|
|
"model\t\t: %d\n"
|
|
|
|
"model name\t: %s\n"
|
|
|
|
"stepping\t: %d\n"
|
2020-08-04 14:51:56 +08:00
|
|
|
"microcode\t: 0x%X\n"
|
2015-08-13 23:59:47 +08:00
|
|
|
"cpu MHz\t\t: %d.000\n",
|
|
|
|
family,
|
|
|
|
model,
|
2020-03-11 20:44:05 +08:00
|
|
|
in_buf.s + strspn (in_buf.s, " \t"),
|
2015-08-13 23:59:47 +08:00
|
|
|
stepping,
|
2019-10-08 00:23:03 +08:00
|
|
|
microcode,
|
2015-08-13 23:59:47 +08:00
|
|
|
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-10 04:10:25 +08:00
|
|
|
{
|
2015-08-13 23:59:47 +08: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 16:39:38 +08:00
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
if (is_intel)
|
2003-03-10 04:10:25 +08:00
|
|
|
{
|
2015-08-13 23:59:47 +08:00
|
|
|
bool valid = false;
|
|
|
|
if (maxf >= 0x0000000b) /* topoext supported? */
|
2003-03-10 04:10:25 +08:00
|
|
|
{
|
2015-08-13 23:59:47 +08: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-10 04:10:25 +08:00
|
|
|
}
|
2015-08-13 23:59:47 +08:00
|
|
|
if (!valid && maxf >= 0x00000004)
|
2007-07-08 00:46:35 +08:00
|
|
|
{
|
2015-08-13 23:59:47 +08:00
|
|
|
uint32_t apic_reserved;
|
2007-03-07 22:03:29 +08:00
|
|
|
|
2015-08-13 23:59:47 +08: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 22:03:29 +08:00
|
|
|
}
|
2015-08-13 23:59:47 +08:00
|
|
|
if (!valid) /* single core, multi thread */
|
2007-07-08 00:46:35 +08:00
|
|
|
{
|
2015-08-13 23:59:47 +08:00
|
|
|
cpu_cores = 1;
|
|
|
|
siblings = (extra_info >> 16) & 0xff;
|
|
|
|
logical_bits = mask_bits (siblings);
|
|
|
|
ht_bits = logical_bits;
|
2007-03-07 22:03:29 +08:00
|
|
|
}
|
2015-08-13 23:59:47 +08:00
|
|
|
}
|
|
|
|
else if (is_amd)
|
|
|
|
{
|
2015-08-17 22:35:41 +08:00
|
|
|
if (maxe >= 0x8000001e)
|
|
|
|
{
|
|
|
|
uint32_t cus, core_info;
|
|
|
|
|
|
|
|
cpuid (&unused, &unused, &core_info, &unused, 0x80000008);
|
|
|
|
cpuid (&unused, &cus, &unused, &unused, 0x8000001e);
|
2019-10-08 00:23:00 +08:00
|
|
|
siblings = cpu_cores = (core_info & 0xff) + 1;
|
2015-08-17 22:35:41 +08:00
|
|
|
logical_bits = (core_info >> 12) & 0xf;
|
|
|
|
cus = ((cus >> 8) & 0x3) + 1;
|
|
|
|
ht_bits = mask_bits (cus);
|
|
|
|
}
|
|
|
|
else if (maxe >= 0x80000008)
|
2007-07-08 00:46:35 +08:00
|
|
|
{
|
2014-08-11 20:03:18 +08:00
|
|
|
uint32_t core_info;
|
2007-03-07 22:03:29 +08:00
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
cpuid (&unused, &unused, &core_info, &unused, 0x80000008);
|
2015-08-17 22:35:41 +08: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 22:03:29 +08:00
|
|
|
}
|
2015-08-13 23:59:47 +08:00
|
|
|
else
|
2007-07-08 00:46:35 +08:00
|
|
|
{
|
2015-08-17 22:35:41 +08:00
|
|
|
siblings = (extra_info >> 16) & 0xff;
|
|
|
|
cpu_cores = siblings;
|
|
|
|
logical_bits = mask_bits (siblings);
|
|
|
|
ht_bits = 0;
|
2007-03-07 22:03:29 +08:00
|
|
|
}
|
2015-08-13 23:59:47 +08: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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-08 00:22:59 +08:00
|
|
|
/* level is number of non-zero leafs exc. sub-leafs */
|
|
|
|
int level = maxf + 1 + (maxe & 0x7fffffff) + 1;
|
|
|
|
|
|
|
|
for (uint32_t l = maxe; 0x80000001 < l; --l)
|
|
|
|
{
|
|
|
|
uint32_t a, b, c, d;
|
|
|
|
cpuid (&a, &b, &c, &d, l);
|
|
|
|
if (!(a | b | c | d)) --level;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t l = maxf; 1 < l; --l)
|
|
|
|
{
|
|
|
|
uint32_t a, b, c, d;
|
|
|
|
cpuid (&a, &b, &c, &d, l);
|
|
|
|
if (!(a | b | c | d)) --level;
|
|
|
|
}
|
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
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",
|
2019-10-08 00:22:59 +08:00
|
|
|
level);
|
2015-08-13 23:59:47 +08:00
|
|
|
print ("flags\t\t:");
|
2019-10-08 00:23:04 +08:00
|
|
|
/* cpuid 0x00000001 edx */
|
|
|
|
ftcprint (features1, 0, "fpu"); /* x87 floating point */
|
|
|
|
ftcprint (features1, 1, "vme"); /* VM enhancements */
|
|
|
|
ftcprint (features1, 2, "de"); /* debugging extensions */
|
|
|
|
ftcprint (features1, 3, "pse"); /* page size extensions */
|
|
|
|
ftcprint (features1, 4, "tsc"); /* rdtsc/p */
|
|
|
|
ftcprint (features1, 5, "msr"); /* rd/wrmsr */
|
|
|
|
ftcprint (features1, 6, "pae"); /* phy addr extensions */
|
|
|
|
ftcprint (features1, 7, "mce"); /* Machine check exception */
|
|
|
|
ftcprint (features1, 8, "cx8"); /* cmpxchg8b */
|
|
|
|
ftcprint (features1, 9, "apic"); /* APIC enabled */
|
|
|
|
ftcprint (features1, 11, "sep"); /* sysenter/sysexit */
|
|
|
|
ftcprint (features1, 12, "mtrr"); /* memory type range registers */
|
|
|
|
ftcprint (features1, 13, "pge"); /* page global extension */
|
|
|
|
ftcprint (features1, 14, "mca"); /* machine check architecture */
|
|
|
|
ftcprint (features1, 15, "cmov"); /* conditional move */
|
|
|
|
ftcprint (features1, 16, "pat"); /* page attribute table */
|
|
|
|
ftcprint (features1, 17, "pse36");/* 36 bit page size extensions */
|
|
|
|
ftcprint (features1, 18, "pn"); /* processor serial number */
|
|
|
|
ftcprint (features1, 19, "clflush"); /* clflush instruction */
|
|
|
|
ftcprint (features1, 21, "dts"); /* debug store */
|
|
|
|
ftcprint (features1, 22, "acpi"); /* ACPI via MSR */
|
|
|
|
ftcprint (features1, 23, "mmx"); /* multimedia extensions */
|
|
|
|
ftcprint (features1, 24, "fxsr"); /* fxsave/fxrstor */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
ftcprint (features1, 25, "sse"); /* xmm sse */
|
|
|
|
ftcprint (features1, 26, "sse2"); /* xmm2 sse2 */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 27, "ss"); /* CPU self snoop */
|
|
|
|
ftcprint (features1, 28, "ht"); /* hyper threading */
|
|
|
|
ftcprint (features1, 29, "tm"); /* acc automatic clock control */
|
|
|
|
ftcprint (features1, 30, "ia64"); /* IA 64 processor */
|
|
|
|
ftcprint (features1, 31, "pbe"); /* pending break enable */
|
|
|
|
|
|
|
|
/* AMD cpuid 0x80000001 edx */
|
2015-08-13 23:59:47 +08:00
|
|
|
if (is_amd && maxe >= 0x80000001)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x80000001);
|
|
|
|
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 11, "syscall"); /* syscall/sysret */
|
|
|
|
ftcprint (features1, 19, "mp"); /* MP capable */
|
|
|
|
ftcprint (features1, 20, "nx"); /* no-execute protection */
|
|
|
|
ftcprint (features1, 22, "mmxext"); /* MMX extensions */
|
|
|
|
ftcprint (features1, 25, "fxsr_opt"); /* fxsave/fxrstor optims */
|
|
|
|
ftcprint (features1, 26, "pdpe1gb"); /* GB large pages */
|
|
|
|
ftcprint (features1, 27, "rdtscp"); /* rdtscp */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
ftcprint (features1, 29, "lm"); /* long mode (x86-64 amd64) */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 30, "3dnowext"); /* 3DNow extensions */
|
|
|
|
ftcprint (features1, 31, "3dnow"); /* 3DNow */
|
2015-08-13 23:59:47 +08:00
|
|
|
}
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
|
|
|
|
/* cpuid 0x80000007 edx */
|
|
|
|
if (maxe >= 0x80000007)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x80000007);
|
|
|
|
|
|
|
|
ftcprint (features1, 8, "constant_tsc"); /* TSC ticks at a constant rate */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ftcprint (features2, 9, "up"); *//* SMP kernel running on UP N/A */
|
|
|
|
|
|
|
|
/* cpuid 0x00000007 ebx */
|
|
|
|
if (maxf >= 0x00000007)
|
|
|
|
cpuid (&unused, &features1, &unused, &unused, 0x00000007, 0);
|
|
|
|
else
|
|
|
|
features1 = 0;
|
|
|
|
/* cpuid 0x80000007 edx */
|
|
|
|
if (maxe >= 0x80000007)
|
|
|
|
cpuid (&unused, &unused, &unused, &features2, 0x80000007);
|
|
|
|
else
|
|
|
|
features2 = 0;
|
|
|
|
uint32_t cr_den, cr_num, Hz;
|
|
|
|
/* cpuid 0x00000015 eax ebx ecx clock ratios optional Hz */
|
|
|
|
if (is_intel && maxf >= 0x00000015)
|
|
|
|
cpuid (&cr_den, &cr_num, &Hz, &unused, 0x00000015);
|
|
|
|
else
|
|
|
|
cr_den = 0;
|
|
|
|
/* TSC requires adjustment, nonstop, and clock ratio divider min */
|
|
|
|
if ((features1 & (1 << 1)) && /* TSC adjustment MSR 0x3B */
|
|
|
|
(features2 & (1 << 8)) && /* nonstop C states */
|
|
|
|
(cr_den > 1)) /* clock ratio denominator > min */
|
|
|
|
ftuprint ("art"); /* Always running timer (ART) */
|
|
|
|
|
|
|
|
/* Intel cpuid 0x0000000a eax Arch Perf Mon */
|
|
|
|
if (is_intel && maxf >= 0x0000000a)
|
|
|
|
{
|
|
|
|
cpuid (&features2, &unused, &unused, &unused, 0x0000000a);
|
|
|
|
|
|
|
|
/* rev > 0 and # counters/cpu > 1 */
|
|
|
|
if ((features2 & 0xff) > 0 && (((features2 >> 8) & 0xff) > 1))
|
|
|
|
ftuprint ("arch_perfmon"); /* Intel Arch Perf Mon */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ftcprint (features2, 12, "pebs");*//* MSR_IA32_MISC_ENABLE 12 Precise-Event Based Sampling */
|
|
|
|
/* ftcprint (features2, 13, "bts"); *//* MSR_IA32_MISC_ENABLE 11 Branch Trace Store */
|
|
|
|
|
|
|
|
/* AMD cpuid 0x00000001 eax */
|
|
|
|
if (is_amd && maxf >= 0x00000001)
|
|
|
|
cpuid(&features2, &unused, &unused, &unused, 0x00000001);
|
|
|
|
else
|
|
|
|
features2 = 0;
|
|
|
|
|
|
|
|
/* Intel family 6 or AMD family >= x10 or ... */
|
|
|
|
/* ... or AMD cpuid 0x00000001 eax in [0x0f58,) or [0x0f48,0x0f50) */
|
|
|
|
if ((is_intel && family == 6) ||
|
|
|
|
(is_amd && (family >= 0x10 ||
|
|
|
|
(features2 >= 0x0f58 ||
|
|
|
|
(features2 >= 0x0f48 && features2 < 0x0f50)))))
|
|
|
|
ftuprint ("rep_good"); /* REP microcode works well */
|
|
|
|
|
|
|
|
/* cpuid 0x80000007 edx Advanced power management */
|
|
|
|
if (maxe >= 0x80000007)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features2, 0x80000007);
|
|
|
|
|
|
|
|
ftcprint (features2, 12, "acc_power"); /* accum power */
|
|
|
|
}
|
|
|
|
|
|
|
|
#if __x86_64__
|
|
|
|
ftuprint ("nopl"); /* NOPL (0F 1F) instructions */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* cpuid 0x0000000b ecx[8:15] type */
|
|
|
|
#define BAD_TYPE 0
|
|
|
|
#define SMT_TYPE 1
|
|
|
|
#define CORE_TYPE 2
|
|
|
|
/* cpuid 0x0000000b ebx ecx */
|
|
|
|
if (maxf >= 0x0000000b)
|
|
|
|
{
|
|
|
|
cpuid(&unused, &features1, &features2, &unused, 0x0000000b);
|
|
|
|
|
|
|
|
/* check if SMT implemented */
|
|
|
|
if (features1 != 0 && (((features2 >> 8) & 0xff) == SMT_TYPE))
|
|
|
|
ftuprint ("xtopology"); /* CPU topology enum extensions */
|
|
|
|
}
|
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
/* AMD cpuid 0x80000007 edx */
|
|
|
|
if (is_amd && maxe >= 0x80000007)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x80000007);
|
|
|
|
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
ftcprint (features1, 8, "tsc_reliable"); /* TSC constant rate */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 8, "nonstop_tsc"); /* nonstop C states */
|
|
|
|
}
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
|
|
|
|
if (is_amd || is_intel)
|
|
|
|
ftuprint ("cpuid"); /* CPU has CPUID instruction */
|
|
|
|
|
|
|
|
if (is_amd && family > 0x16)
|
|
|
|
ftuprint ("extd_apicid"); /* Extended APICID (8 bits) */
|
|
|
|
|
|
|
|
/* AMD cpuid 0x8000001e ecx */
|
|
|
|
if (is_amd && maxe >= 0x8000001e)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &features1, &unused, 0x8000001e);
|
|
|
|
|
|
|
|
if (((features1 >> 8) & 7) + 1 > 1) /* nodes/socket */
|
|
|
|
ftuprint ("amd_dcm"); /* AMD multi-node processor */
|
|
|
|
}
|
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
/* cpuid 0x00000006 ecx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x00000006)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &features1, &unused, 0x00000006);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
|
|
|
ftcprint (features1, 0, "aperfmperf"); /* P state hw coord fb */
|
|
|
|
}
|
2015-08-13 23:59:47 +08:00
|
|
|
|
2021-06-30 01:09:24 +08:00
|
|
|
/* cpuid 0x80000007 edx Advanced power management */
|
|
|
|
if (maxe >= 0x80000007)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features2, 0x80000007);
|
|
|
|
|
|
|
|
ftcprint (features2, 14, "rapl"); /* runtime avg power limit */
|
|
|
|
}
|
|
|
|
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* Penwell, Cloverview, ... TSC doesn't sleep on S3 */
|
|
|
|
if (is_intel && family == 6)
|
|
|
|
switch (model)
|
|
|
|
{
|
|
|
|
case 0x27: /* Atom Saltwell Mid Penwell */
|
|
|
|
case 0x35: /* Atom Saltwell Tablet Cloverview */
|
|
|
|
case 0x4a: /* Atom Silvermont Mid Merriefield */
|
|
|
|
case 0x75: /* Atom Airmont NP Lightning Mountain */
|
|
|
|
ftuprint ("nonstop_tsc_s3"); /* TSC doesn't stop in S3 state */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cpuid 0x00000015 eax ebx ecx clock ratios optional Hz */
|
|
|
|
if (is_intel && maxf >= 0x00000015)
|
|
|
|
{
|
|
|
|
uint32_t cr_den, cr_num, Hz, kHz;
|
|
|
|
cpuid (&cr_den, &cr_num, &Hz, &unused, 0x00000015);
|
|
|
|
if (cr_num != 0 && cr_den != 0)
|
|
|
|
{
|
|
|
|
kHz = Hz / 1000;
|
|
|
|
/* Denverton don't report hz nor support cpuid 0x16 so set 25MHz */
|
|
|
|
if (kHz == 0 && model == 0x5F) /* Atom Goldmont D Denverton */
|
|
|
|
kHz = 25000;
|
|
|
|
|
|
|
|
/* cpuid TSC frequency is known */
|
|
|
|
if (kHz != 0)
|
|
|
|
ftuprint ("tsc_known_freq"); /* TSC has known frequency */
|
|
|
|
#if 0 /* keep for future and doc */
|
|
|
|
else /* kHz == 0 */
|
|
|
|
/* Skylake and Kabylake don't report clock so use CPU speed and ratio */
|
|
|
|
if (maxf >= 0x00000016)
|
|
|
|
{
|
|
|
|
uint32_t mHz;
|
|
|
|
cpuid(&mHz, &unused, &unused, &unused, 0x00000016);
|
|
|
|
kHz = mHz * 1000 * cr_num / cr_den;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 00:23:04 +08:00
|
|
|
/* cpuid 0x00000001 ecx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &features2, &unused, 0x00000001);
|
|
|
|
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features2, 0, "pni"); /* xmm3 sse3 */
|
|
|
|
ftcprint (features2, 1, "pclmuldq"); /* pclmulqdq instruction */
|
|
|
|
ftcprint (features2, 2, "dtes64"); /* 64-bit debug store */
|
|
|
|
ftcprint (features2, 3, "monitor"); /* monitor/mwait support */
|
|
|
|
ftcprint (features2, 4, "ds_cpl"); /* CPL-qual debug store */
|
|
|
|
ftcprint (features2, 5, "vmx"); /* hardware virtualization */
|
|
|
|
ftcprint (features2, 6, "smx"); /* safer mode extensions */
|
|
|
|
ftcprint (features2, 7, "est"); /* enhanced speedstep */
|
|
|
|
ftcprint (features2, 8, "tm2"); /* thermal monitor 2 */
|
|
|
|
ftcprint (features2, 9, "ssse3"); /* supplemental sse3 */
|
|
|
|
ftcprint (features2, 10, "cid"); /* context id */
|
|
|
|
ftcprint (features2, 11, "sdbg"); /* silicon debug */
|
|
|
|
ftcprint (features2, 12, "fma"); /* fused multiply add */
|
|
|
|
ftcprint (features2, 13, "cx16"); /* cmpxchg16b instruction */
|
|
|
|
ftcprint (features2, 14, "xtpr"); /* send task priority messages */
|
|
|
|
ftcprint (features2, 15, "pdcm"); /* perf/debug capabilities MSR */
|
|
|
|
ftcprint (features2, 17, "pcid"); /* process context identifiers */
|
|
|
|
ftcprint (features2, 18, "dca"); /* direct cache access */
|
|
|
|
ftcprint (features2, 19, "sse4_1"); /* xmm 4_1 sse 4.1 */
|
|
|
|
ftcprint (features2, 20, "sse4_2"); /* xmm 4_2 sse 4.2 */
|
|
|
|
ftcprint (features2, 21, "x2apic"); /* x2 APIC */
|
|
|
|
ftcprint (features2, 22, "movbe"); /* movbe instruction */
|
|
|
|
ftcprint (features2, 23, "popcnt"); /* popcnt instruction */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features2, 24, "tsc_deadline_timer"); /* TSC deadline timer */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features2, 25, "aes"); /* AES instructions */
|
|
|
|
ftcprint (features2, 26, "xsave"); /* xsave/xrstor/xsetbv/xgetbv */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* ftcprint (features2, 27, "osxsave");*//* "" XSAVE supported in OS */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features2, 28, "avx"); /* advanced vector extensions */
|
|
|
|
ftcprint (features2, 29, "f16c"); /* 16 bit FP conversions */
|
|
|
|
ftcprint (features2, 30, "rdrand"); /* RNG rdrand instruction */
|
|
|
|
ftcprint (features2, 31, "hypervisor"); /* hypervisor guest */
|
|
|
|
|
|
|
|
/* cpuid 0x80000001 ecx */
|
2015-08-13 23:59:47 +08:00
|
|
|
if (maxe >= 0x80000001)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &features1, &unused, 0x80000001);
|
|
|
|
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 0, "lahf_lm"); /* l/sahf long mode */
|
|
|
|
ftcprint (features1, 1, "cmp_legacy"); /* HT not valid */
|
2015-08-13 23:59:47 +08:00
|
|
|
if (is_amd)
|
|
|
|
{
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 2, "svm"); /* secure VM */
|
|
|
|
ftcprint (features1, 3, "extapic"); /* ext APIC space */
|
|
|
|
ftcprint (features1, 4, "cr8_legacy"); /* CR8 32 bit mode */
|
|
|
|
ftcprint (features1, 5, "abm"); /* adv bit manip lzcnt */
|
|
|
|
ftcprint (features1, 6, "sse4a"); /* sse 4a */
|
|
|
|
ftcprint (features1, 7, "misalignsse"); /* misaligned SSE ok */
|
|
|
|
ftcprint (features1, 8, "3dnowprefetch"); /* 3DNow prefetch */
|
|
|
|
ftcprint (features1, 9, "osvw"); /* OS vis workaround */
|
2015-08-13 23:59:47 +08:00
|
|
|
}
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 10, "ibs"); /* instr based sampling */
|
2015-08-13 23:59:47 +08:00
|
|
|
if (is_amd)
|
|
|
|
{
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 11, "xop"); /* sse 5 extended AVX */
|
|
|
|
ftcprint (features1, 12, "skinit"); /* skinit/stgi */
|
|
|
|
ftcprint (features1, 13, "wdt"); /* watchdog timer */
|
|
|
|
ftcprint (features1, 15, "lwp"); /* light weight prof */
|
|
|
|
ftcprint (features1, 16, "fma4"); /* 4 operand MAC */
|
|
|
|
ftcprint (features1, 17, "tce"); /* translat cache ext */
|
|
|
|
ftcprint (features1, 19, "nodeid_msr"); /* nodeid MSR */
|
|
|
|
ftcprint (features1, 21, "tbm"); /* trailing bit manip */
|
|
|
|
ftcprint (features1, 22, "topoext"); /* topology ext */
|
|
|
|
ftcprint (features1, 23, "perfctr_core"); /* core perf ctr ext */
|
|
|
|
ftcprint (features1, 24, "perfctr_nb"); /* NB perf ctr ext */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 26, "bpext"); /* data brkpt ext */
|
|
|
|
ftcprint (features1, 27, "ptsc"); /* perf timestamp ctr */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 28, "perfctr_llc"); /* ll cache perf ctr */
|
|
|
|
ftcprint (features1, 29, "mwaitx"); /* monitor/mwaitx ext */
|
2015-08-13 23:59:47 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-08 00:23:04 +08:00
|
|
|
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* ring 3 monitor/mwait */
|
|
|
|
if (is_intel && family == 6)
|
|
|
|
switch (model)
|
|
|
|
{
|
|
|
|
case 0x57: /* Xeon Phi Knights Landing */
|
|
|
|
case 0x85: /* Xeon Phi Knights Mill */
|
|
|
|
ftuprint ("ring3mwait"); /* Ring 3 MONITOR/MWAIT instructions */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ftcprint (features1, 1, "cpuid_fault");*//* MSR_PLATFORM_INFO Intel CPUID faulting */
|
|
|
|
|
|
|
|
/* features scattered in various CPUID levels. */
|
2019-10-08 00:23:05 +08:00
|
|
|
/* cpuid 0x80000007 edx */
|
2021-02-18 00:28:35 +08:00
|
|
|
if (maxe >= 0x80000007)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x80000007);
|
|
|
|
|
|
|
|
ftcprint (features1, 9, "cpb"); /* core performance boost */
|
|
|
|
}
|
|
|
|
/* cpuid 0x00000006 ecx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x00000006)
|
2015-08-13 23:59:47 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &features1, &unused, 0x00000006);
|
2015-08-13 23:59:47 +08:00
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 3, "epb"); /* energy perf bias */
|
|
|
|
}
|
|
|
|
/* cpuid 0x00000010 ebx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x00000010)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &features1, &unused, &unused, 0x00000010);
|
2019-10-08 00:23:04 +08:00
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 1, "cat_l3"); /* cache alloc tech l3 */
|
|
|
|
ftcprint (features1, 2, "cat_l2"); /* cache alloc tech l2 */
|
|
|
|
|
|
|
|
/* cpuid 0x00000010:1 ecx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &features1, &unused, 0x00000010, 1);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
|
|
|
ftcprint (features1, 2, "cdp_l3"); /* code data prior l3 */
|
|
|
|
}
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
|
|
|
|
/* ftcprint (features1, 7, "invpcid_single");*//* INVPCID && CR4.PCIDE=1 */
|
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
/* cpuid 0x80000007 edx */
|
|
|
|
if (maxe >= 0x80000007)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x80000007);
|
|
|
|
|
|
|
|
ftcprint (features1, 7, "hw_pstate"); /* hw P state */
|
|
|
|
ftcprint (features1, 11, "proc_feedback"); /* proc feedback interf */
|
|
|
|
}
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
|
|
|
|
/* ftcprint (features1, 11, "pti");*//* Page Table Isolation reqd with Meltdown */
|
|
|
|
|
|
|
|
/* ftcprint (features1, 14, "intel_ppin");*//* MSR_PPIN_CTL Prot Proc Id No */
|
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
/* cpuid 0x00000010:2 ecx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x00000010)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &features2, &unused, 0x00000010, 2);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
ftcprint (features2, 2, "cdp_l2"); /* code data prior l2 */
|
|
|
|
}
|
|
|
|
/* cpuid 0x80000008 ebx */
|
|
|
|
if (maxe >= 0x80000008)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &features1, &unused, &unused, 0x80000008, 0);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
ftcprint (features1, 24, "ssbd"); /* spec store byp dis */
|
|
|
|
}
|
|
|
|
/* cpuid 0x00000010 ebx */
|
|
|
|
if (maxf >= 0x00000010)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &features2, &unused, &unused, 0x00000010);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
ftcprint (features2, 3, "mba"); /* memory bandwidth alloc */
|
2019-10-08 00:23:05 +08:00
|
|
|
}
|
|
|
|
/* cpuid 0x80000008 ebx */
|
|
|
|
if (maxe >= 0x80000008)
|
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* cpuid (&unused, &features1, &unused, &unused, 0x80000008, 0); */
|
|
|
|
/* from above */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 6, "mba"); /* memory bandwidth alloc */
|
2015-08-13 23:59:47 +08:00
|
|
|
}
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* cpuid 0x80000008 ebx */
|
|
|
|
if (maxe >= 0x80000008)
|
|
|
|
{
|
|
|
|
/* cpuid (&unused, &features1, &unused, &unused, 0x80000008, 0); */
|
|
|
|
/* from above */
|
|
|
|
/* ftcprint (features1, 0, "clzero"); *//* clzero instruction */
|
|
|
|
/* ftcprint (features1, 1, "irperf"); *//* instr retired count */
|
|
|
|
/* ftcprint (features1, 2, "xsaveerptr");*//* save/rest FP err ptrs */
|
|
|
|
/* ftcprint (features1, 4, "rdpru"); *//* user level rd proc reg */
|
|
|
|
/* ftcprint (features1, 6, "mba"); *//* memory BW alloc */
|
|
|
|
/* ftcprint (features1, 9, "wbnoinvd"); *//* wbnoinvd instruction */
|
|
|
|
ftcprint (features1, 14, "ibrs"); /* ind br restricted spec */
|
|
|
|
ftcprint (features1, 12, "ibpb"); /* ind br pred barrier */
|
|
|
|
ftcprint (features1, 15, "stibp"); /* 1 thread ind br pred */
|
|
|
|
ftcprint (features1, 16, "ibrs_enhanced"); /* IBRS_ALL enhanced IBRS always on */
|
|
|
|
/* ftcprint (features1, 17, "stibp_always_on"); */ /* stibp always on */
|
|
|
|
/* ftcprint (features1, 18, "ibrs_pref");*//* IBRS_PREF IBRS preferred */
|
|
|
|
/* ftcprint (features1, 23, "amd_ppin"); *//* protected proc id no */
|
|
|
|
/* ftcprint (features1, 24, "ssbd"); *//* spec store byp dis */
|
|
|
|
/* ftcprint (features1, 25, "virt_ssbd");*//* vir spec store byp dis */
|
|
|
|
/* ftcprint (features1, 26, "ssb_no"); *//* ssb fixed in hardware */
|
|
|
|
}
|
2019-10-08 00:23:05 +08:00
|
|
|
|
2019-10-08 00:23:04 +08:00
|
|
|
/* cpuid 0x00000007 ebx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x00000007)
|
2015-08-13 23:59:47 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &features1, &unused, &unused, 0x00000007, 0);
|
2015-08-13 23:59:47 +08:00
|
|
|
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 0, "fsgsbase"); /* rd/wr fs/gs base */
|
|
|
|
ftcprint (features1, 1, "tsc_adjust"); /* TSC adjustment MSR 0x3B */
|
2020-12-17 15:11:28 +08:00
|
|
|
ftcprint (features1, 2, "sgx"); /* software guard extensions */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 3, "bmi1"); /* bit manip ext group 1 */
|
|
|
|
ftcprint (features1, 4, "hle"); /* hardware lock elision */
|
|
|
|
ftcprint (features1, 5, "avx2"); /* AVX ext instructions */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* ftcprint (features1, 6, "fpdx"); */ /* "" FP data ptr upd on exc */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 7, "smep"); /* super mode exec prot */
|
|
|
|
ftcprint (features1, 8, "bmi2"); /* bit manip ext group 2 */
|
|
|
|
ftcprint (features1, 9, "erms"); /* enh rep movsb/stosb */
|
|
|
|
ftcprint (features1, 10, "invpcid"); /* inv proc context id */
|
|
|
|
ftcprint (features1, 11, "rtm"); /* restricted txnal mem */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 12, "cqm"); /* cache QoS monitoring */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* ftcprint (features1, 13, "fpcsdsz"); */ /* "" zero FP cs/ds */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 14, "mpx"); /* mem prot ext */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 15, "rdt_a"); /* rsrc dir tech alloc */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 16, "avx512f"); /* vec foundation */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 17, "avx512dq"); /* vec dq granular */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 18, "rdseed"); /* RNG rdseed instruction */
|
|
|
|
ftcprint (features1, 19, "adx"); /* adcx/adox */
|
|
|
|
ftcprint (features1, 20, "smap"); /* sec mode access prev */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 21, "avx512ifma"); /* vec int FMA */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 23, "clflushopt"); /* cache line flush opt */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 24, "clwb"); /* cache line write back */
|
|
|
|
ftcprint (features1, 25, "intel_pt"); /* intel processor trace */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 26, "avx512pf"); /* vec prefetch */
|
|
|
|
ftcprint (features1, 27, "avx512er"); /* vec exp/recip aprx */
|
|
|
|
ftcprint (features1, 28, "avx512cd"); /* vec conflict detect */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 29, "sha_ni"); /* SHA extensions */
|
|
|
|
ftcprint (features1, 30, "avx512bw"); /* vec byte/word gran */
|
|
|
|
ftcprint (features1, 31, "avx512vl"); /* vec vec len ext */
|
2019-10-08 00:23:04 +08:00
|
|
|
}
|
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
/* more random feature flags */
|
|
|
|
/* cpuid 0x0000000d:1 eax */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x0000000d)
|
2019-10-08 00:23:04 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&features1, &unused, &unused, &unused, 0x0000000d, 1);
|
2019-10-08 00:23:04 +08:00
|
|
|
|
|
|
|
ftcprint (features1, 0, "xsaveopt"); /* xsaveopt instruction */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 1, "xsavec"); /* xsavec instruction */
|
|
|
|
ftcprint (features1, 2, "xgetbv1"); /* xgetbv ecx 1 */
|
|
|
|
ftcprint (features1, 3, "xsaves"); /* xsaves/xrstors */
|
|
|
|
}
|
|
|
|
/* cpuid 0x0000000f edx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x0000000f)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x0000000f);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
|
|
|
ftcprint (features1, 1, "cqm_llc"); /* llc QoS */
|
|
|
|
|
|
|
|
/* cpuid 0x0000000f:1 edx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x0000000f, 1);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
|
|
|
ftcprint (features1, 0, "cqm_occup_llc"); /* llc occup monitor */
|
|
|
|
ftcprint (features1, 1, "cqm_mbm_total"); /* llc total MBM mon */
|
|
|
|
ftcprint (features1, 2, "cqm_mbm_local"); /* llc local MBM mon */
|
|
|
|
}
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
|
|
|
|
/* ftcprint (features1, 6, "split_lock_detect");*//* MSR_TEST_CTRL split lock */
|
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
/* cpuid 0x00000007:1 eax */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x00000007)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&features1, &unused, &unused, &unused, 0x00000007, 1);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
2021-02-18 00:28:36 +08:00
|
|
|
ftcprint (features1, 4, "avx_vnni"); /* vex enc NN vec */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 5, "avx512_bf16"); /* vec bfloat16 short */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AMD cpuid 0x80000008 ebx */
|
|
|
|
if (is_amd && maxe >= 0x80000008)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &features1, &unused, &unused, 0x80000008, 0);
|
|
|
|
|
|
|
|
ftcprint (features1, 0, "clzero"); /* clzero instruction */
|
|
|
|
ftcprint (features1, 1, "irperf"); /* instr retired count */
|
|
|
|
ftcprint (features1, 2, "xsaveerptr"); /* save/rest FP err ptrs */
|
2020-01-23 17:06:27 +08:00
|
|
|
ftcprint (features1, 4, "rdpru"); /* user level rd proc reg */
|
2019-10-08 00:23:06 +08:00
|
|
|
/* ftcprint (features1, 6, "mba"); */ /* memory BW alloc */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 9, "wbnoinvd"); /* wbnoinvd instruction */
|
2019-10-08 00:23:06 +08:00
|
|
|
/* ftcprint (features1, 12, "ibpb" ); */ /* ind br pred barrier */
|
|
|
|
/* ftcprint (features1, 14, "ibrs" ); */ /* ind br restricted spec */
|
|
|
|
/* ftcprint (features1, 15, "stibp"); */ /* 1 thread ind br pred */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* ftcprint (features1, 16, "ibrs_enhanced");*//* IBRS_ALL enhanced IBRS always on */
|
2019-10-08 00:23:06 +08:00
|
|
|
/* ftcprint (features1, 17, "stibp_always_on"); */ /* stibp always on */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* ftcprint (features1, 18, "ibrs_pref");*//* IBRS_PREF IBRS preferred */
|
2020-04-11 12:35:28 +08:00
|
|
|
ftcprint (features1, 23, "amd_ppin"); /* protected proc id no */
|
2019-10-08 00:23:06 +08:00
|
|
|
/* ftcprint (features1, 24, "ssbd"); */ /* spec store byp dis */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 25, "virt_ssbd"); /* vir spec store byp dis */
|
2019-10-08 00:23:06 +08:00
|
|
|
/* ftcprint (features1, 26, "ssb_no"); */ /* ssb fixed in hardware */
|
2019-10-08 00:23:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* thermal & power cpuid 0x00000006 eax */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (maxf >= 0x00000006)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&features1, &unused, &features2, &unused, 0x00000006);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
|
|
|
ftcprint (features1, 0, "dtherm"); /* digital thermal sensor */
|
|
|
|
ftcprint (features1, 1, "ida"); /* Intel dynamic acceleration */
|
|
|
|
ftcprint (features1, 2, "arat"); /* always running APIC timer */
|
|
|
|
ftcprint (features1, 4, "pln"); /* power limit notification */
|
|
|
|
ftcprint (features1, 6, "pts"); /* package thermal status */
|
|
|
|
ftcprint (features1, 7, "hwp"); /* hardware P states */
|
|
|
|
ftcprint (features1, 8, "hwp_notify"); /* HWP notification */
|
|
|
|
ftcprint (features1, 9, "hwp_act_window"); /* HWP activity window */
|
|
|
|
ftcprint (features1, 10, "hwp_epp"); /* HWP energy perf pref */
|
|
|
|
ftcprint (features1, 11, "hwp_pkg_req"); /* HWP package level req */
|
2015-08-13 23:59:47 +08:00
|
|
|
}
|
2007-03-07 22:03:29 +08:00
|
|
|
|
2019-10-08 00:23:05 +08:00
|
|
|
/* AMD SVM cpuid 0x8000000a edx */
|
|
|
|
if (is_amd && maxe >= 0x8000000a)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x8000000a, 0);
|
|
|
|
|
|
|
|
ftcprint (features1, 0, "npt"); /* nested paging */
|
|
|
|
ftcprint (features1, 1, "lbrv"); /* lbr virtualization */
|
|
|
|
ftcprint (features1, 2, "svm_lock"); /* SVM locking MSR */
|
|
|
|
ftcprint (features1, 3, "nrip_save"); /* SVM next rip save */
|
|
|
|
ftcprint (features1, 4, "tsc_scale"); /* TSC rate control */
|
|
|
|
ftcprint (features1, 5, "vmcb_clean"); /* VMCB clean bits */
|
|
|
|
ftcprint (features1, 6, "flushbyasid"); /* flush by ASID */
|
|
|
|
ftcprint (features1, 7, "decode_assists"); /* decode assists */
|
|
|
|
ftcprint (features1, 10, "pausefilter"); /* filt pause intrcpt */
|
|
|
|
ftcprint (features1, 12, "pfthreshold"); /* pause filt thresh */
|
|
|
|
ftcprint (features1, 13, "avic"); /* virt int control */
|
|
|
|
ftcprint (features1, 15, "v_vmsave_vmload"); /* virt vmsave vmload */
|
|
|
|
ftcprint (features1, 16, "vgif"); /* virt glb int flag */
|
2021-04-28 07:28:52 +08:00
|
|
|
ftcprint (features1, 20, "v_spec_ctrl"); /* virt spec ctrl support */
|
2021-02-18 00:28:36 +08:00
|
|
|
/* ftcprint (features1, 28, "svme_addr_chk"); *//* secure vmexit addr check */
|
2019-10-08 00:23:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Intel cpuid 0x00000007 ecx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (is_intel && maxf >= 0x00000007)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &features1, &unused, 0x00000007, 0);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
|
|
|
ftcprint (features1, 1, "avx512vbmi"); /* vec bit manip */
|
|
|
|
ftcprint (features1, 2, "umip"); /* user mode ins prot */
|
|
|
|
ftcprint (features1, 3, "pku"); /* prot key userspace */
|
|
|
|
ftcprint (features1, 4, "ospke"); /* OS prot keys en */
|
|
|
|
ftcprint (features1, 5, "waitpkg"); /* umon/umwait/tpause */
|
|
|
|
ftcprint (features1, 6, "avx512_vbmi2"); /* vec bit manip 2 */
|
|
|
|
ftcprint (features1, 8, "gfni"); /* Galois field instr */
|
|
|
|
ftcprint (features1, 9, "vaes"); /* vector AES */
|
|
|
|
ftcprint (features1, 10, "vpclmulqdq"); /* nc mul dbl quad */
|
|
|
|
ftcprint (features1, 11, "avx512_vnni"); /* vec neural net */
|
|
|
|
ftcprint (features1, 12, "avx512_bitalg"); /* vpopcnt/b/w vpshuf */
|
|
|
|
ftcprint (features1, 13, "tme"); /* total mem encrypt */
|
|
|
|
ftcprint (features1, 14, "avx512_vpopcntdq"); /* vec popcnt dw/qw */
|
|
|
|
ftcprint (features1, 16, "la57"); /* 5 level paging */
|
|
|
|
ftcprint (features1, 22, "rdpid"); /* rdpid instruction */
|
2021-04-28 07:28:52 +08:00
|
|
|
ftcprint (features1, 24, "bus_lock_detect"); /* bus lock detect dbg excptn */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 25, "cldemote"); /* cldemote instr */
|
|
|
|
ftcprint (features1, 27, "movdiri"); /* movdiri instr */
|
|
|
|
ftcprint (features1, 28, "movdir64b"); /* movdir64b instr */
|
2020-10-13 23:11:08 +08:00
|
|
|
ftcprint (features1, 29, "enqcmd"); /* enqcmd/s instructions*/
|
2020-12-17 15:11:28 +08:00
|
|
|
ftcprint (features1, 30, "sgx_lc"); /* sgx launch control */
|
2019-10-08 00:23:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* AMD MCA cpuid 0x80000007 ebx */
|
|
|
|
if (is_amd && maxe >= 0x80000007)
|
|
|
|
{
|
|
|
|
cpuid (&unused, &features1, &unused, &unused, 0x80000007, 0);
|
|
|
|
|
|
|
|
ftcprint (features1, 0, "overflow_recov"); /* MCA oflow recovery */
|
|
|
|
ftcprint (features1, 1, "succor"); /* uncor err recovery */
|
|
|
|
ftcprint (features1, 3, "smca"); /* scalable MCA */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Intel cpuid 0x00000007 edx */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
if (is_intel && maxf >= 0x00000007)
|
2019-10-08 00:23:05 +08:00
|
|
|
{
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x00000007, 0);
|
2019-10-08 00:23:05 +08:00
|
|
|
|
|
|
|
ftcprint (features1, 2, "avx512_4vnniw"); /* vec dot prod dw */
|
|
|
|
ftcprint (features1, 3, "avx512_4fmaps"); /* vec 4 FMA single */
|
2020-02-22 05:28:08 +08:00
|
|
|
ftcprint (features1, 4, "fsrm"); /* fast short REP MOVSB */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 8, "avx512_vp2intersect"); /* vec intcpt d/q */
|
|
|
|
ftcprint (features1, 10, "md_clear"); /* verw clear buf */
|
2020-08-04 00:22:46 +08:00
|
|
|
ftcprint (features1, 14, "serialize"); /* SERIALIZE instruction */
|
2020-09-18 02:51:25 +08:00
|
|
|
ftcprint (features1, 16, "tsxldtrk"); /* TSX Susp Ld Addr Track */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 18, "pconfig"); /* platform config */
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
ftcprint (features1, 19, "arch_lbr"); /* last branch records */
|
2021-02-18 00:28:36 +08:00
|
|
|
ftcprint (features1, 23, "avx512_fp16"); /* avx512 fp16 */
|
2019-10-08 00:23:05 +08:00
|
|
|
ftcprint (features1, 28, "flush_l1d"); /* flush l1d cache */
|
|
|
|
ftcprint (features1, 29, "arch_capabilities"); /* arch cap MSR */
|
|
|
|
}
|
|
|
|
|
2021-02-18 00:28:36 +08:00
|
|
|
/* cpuid x8000001f eax */
|
|
|
|
if (is_amd && maxe >= 0x8000001f)
|
|
|
|
{
|
|
|
|
cpuid (&features2, &unused, &unused, &unused, 0x8000001f);
|
|
|
|
|
|
|
|
ftcprint (features2, 0, "sme"); /* secure memory encryption */
|
|
|
|
ftcprint (features2, 1, "sev"); /* AMD secure encrypted virt */
|
|
|
|
/* ftcprint (features2, 2, "vm_page_flush");*/ /* VM page flush MSR */
|
|
|
|
ftcprint (features2, 3, "sev_es"); /* AMD SEV encrypted state */
|
|
|
|
/* ftcprint (features2, 4, "sev_snp");*//* AMD SEV secure nested paging */
|
|
|
|
/* ftcprint (features2, 5, "vmpl"); *//* VM permission levels support */
|
|
|
|
/* ftcprint (features2, 10, "sme_coherent"); *//* SME h/w cache coherent */
|
|
|
|
/* ftcprint (features2, 11, "sev_64b");*//* SEV 64 bit host guest only */
|
|
|
|
/* ftcprint (features2, 12, "sev_rest_inj"); *//* SEV restricted injection */
|
|
|
|
/* ftcprint (features2, 13, "sev_alt_inj"); *//* SEV alternate injection */
|
|
|
|
/* ftcprint (features2, 14, "sev_es_dbg_swap");*//* SEV-ES debug state swap */
|
|
|
|
/* ftcprint (features2, 15, "no_host_ibs"); *//* host IBS unsupported */
|
|
|
|
/* ftcprint (features2, 16, "vte"); *//* virtual transparent encryption */
|
|
|
|
}
|
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
print ("\n");
|
2004-07-26 21:19:03 +08:00
|
|
|
|
2019-10-08 00:23:02 +08:00
|
|
|
bufptr += __small_sprintf (bufptr, "bogomips\t: %d.00\n",
|
|
|
|
bogomips);
|
2007-03-07 22:03:29 +08:00
|
|
|
|
fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-23 03:22:54 +08:00
|
|
|
/* cpuid 0x80000006 ebx TLB size */
|
|
|
|
if (maxe >= 0x80000006)
|
|
|
|
{
|
|
|
|
cpuid( &unused, &features1, &unused, &unused, 0x80000006, 0);
|
|
|
|
uint32_t tlbsize = ((features1 >> 16) & 0xfff) + (features1 & 0xfff);
|
|
|
|
if (tlbsize > 0)
|
|
|
|
bufptr += __small_sprintf (bufptr, "TLB size\t: %d 4K pages\n",
|
|
|
|
tlbsize);
|
|
|
|
}
|
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
bufptr += __small_sprintf (bufptr, "clflush size\t: %d\n"
|
|
|
|
"cache_alignment\t: %d\n",
|
|
|
|
clflush,
|
|
|
|
cache_alignment);
|
2007-03-07 22:03:29 +08:00
|
|
|
|
2015-08-13 23:59:47 +08: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 22:03:29 +08:00
|
|
|
|
2019-10-08 00:23:04 +08:00
|
|
|
/* cpuid 0x80000007 edx */
|
2015-08-13 23:59:47 +08:00
|
|
|
if (maxe >= 0x80000007) /* Advanced power management. */
|
|
|
|
{
|
|
|
|
cpuid (&unused, &unused, &unused, &features1, 0x80000007);
|
|
|
|
|
|
|
|
print ("power management:");
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 0, "ts"); /* temperature sensor */
|
|
|
|
ftcprint (features1, 1, "fid"); /* frequency id control */
|
|
|
|
ftcprint (features1, 2, "vid"); /* voltage id control */
|
|
|
|
ftcprint (features1, 3, "ttp"); /* thermal trip */
|
|
|
|
ftcprint (features1, 4, "tm"); /* hw thermal control */
|
|
|
|
ftcprint (features1, 5, "stc"); /* sw thermal control */
|
|
|
|
ftcprint (features1, 6, "100mhzsteps"); /* 100 MHz mult control */
|
|
|
|
ftcprint (features1, 7, "hwpstate"); /* hw P state control */
|
2019-10-08 00:23:06 +08:00
|
|
|
/* ftcprint (features1, 8, "invariant_tsc"); */ /* TSC invariant */
|
2019-10-08 00:23:04 +08:00
|
|
|
ftcprint (features1, 9, "cpb"); /* core performance boost */
|
|
|
|
ftcprint (features1, 10, "eff_freq_ro"); /* ro eff freq interface */
|
2020-02-26 07:44:16 +08:00
|
|
|
ftcprint (features1, 11, "proc_feedback");/* proc feedback if */
|
|
|
|
ftcprint (features1, 12, "acc_power"); /* core power reporting */
|
2019-10-08 00:23:06 +08:00
|
|
|
/* ftcprint (features1, 13, "connstby"); */ /* connected standby */
|
|
|
|
/* ftcprint (features1, 14, "rapl"); */ /* running average power limit */
|
2015-08-13 23:59:47 +08:00
|
|
|
}
|
2007-03-07 22:03:29 +08:00
|
|
|
|
2015-08-13 23:59:47 +08:00
|
|
|
if (orig_affinity_mask != 0)
|
|
|
|
{
|
|
|
|
if (wincap.has_processor_groups ())
|
|
|
|
SetThreadGroupAffinity (GetCurrentThread (), &orig_group_affinity,
|
|
|
|
NULL);
|
2007-02-22 18:54:47 +08:00
|
|
|
else
|
2015-08-13 23:59:47 +08:00
|
|
|
SetThreadAffinityMask (GetCurrentThread (), orig_affinity_mask);
|
2003-03-10 04:10:25 +08:00
|
|
|
}
|
2011-04-19 16:39:38 +08:00
|
|
|
print ("\n");
|
|
|
|
}
|
2003-03-10 04:10:25 +08:00
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
2003-03-10 04:10:25 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_proc_partitions (void *, char *&destbuf)
|
2003-03-10 04:10:25 +08:00
|
|
|
{
|
2006-03-09 17:01:08 +08:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
NTSTATUS status;
|
2011-01-17 21:38:06 +08:00
|
|
|
HANDLE dirhdl;
|
2009-01-21 01:22:11 +08:00
|
|
|
tmp_pathbuf tp;
|
|
|
|
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
2011-01-17 21:38:06 +08:00
|
|
|
char *ioctl_buf = tp.c_get ();
|
2014-10-16 23:35:10 +08:00
|
|
|
PWCHAR mp_buf = tp.w_get ();
|
|
|
|
WCHAR fpath[MAX_PATH];
|
|
|
|
WCHAR gpath[MAX_PATH];
|
|
|
|
DWORD len;
|
2006-03-09 17:01:08 +08:00
|
|
|
|
|
|
|
/* Open \Device object directory. */
|
2007-12-04 21:29:44 +08:00
|
|
|
wchar_t wpath[MAX_PATH] = L"\\Device";
|
2006-03-09 17:01:08 +08: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 17:44:36 +08:00
|
|
|
debug_printf ("NtOpenDirectoryObject, status %y", status);
|
2011-01-17 21:38:06 +08:00
|
|
|
__seterrno_from_nt_status (status);
|
2009-01-21 01:22:11 +08:00
|
|
|
return 0;
|
2006-03-09 17:01:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Traverse \Device directory ... */
|
|
|
|
PDIRECTORY_BASIC_INFORMATION dbi = (PDIRECTORY_BASIC_INFORMATION)
|
|
|
|
alloca (640);
|
|
|
|
BOOLEAN restart = TRUE;
|
2011-01-17 21:38:06 +08:00
|
|
|
bool got_one = false;
|
2006-03-09 17:01:08 +08:00
|
|
|
ULONG context = 0;
|
|
|
|
while (NT_SUCCESS (NtQueryDirectoryObject (dirhdl, dbi, 640, TRUE, restart,
|
|
|
|
&context, NULL)))
|
2003-03-10 04:10:25 +08:00
|
|
|
{
|
2011-01-17 21:38:06 +08:00
|
|
|
HANDLE devhdl;
|
|
|
|
PARTITION_INFORMATION_EX *pix = NULL;
|
|
|
|
PARTITION_INFORMATION *pi = NULL;
|
|
|
|
DWORD bytes_read;
|
2011-01-17 22:31:30 +08:00
|
|
|
DWORD part_cnt = 0;
|
2011-01-17 21:38:06 +08:00
|
|
|
unsigned long long size;
|
|
|
|
|
2006-03-09 17:01:08 +08:00
|
|
|
restart = FALSE;
|
|
|
|
/* ... and check for a "Harddisk[0-9]*" entry. */
|
2011-04-02 19:32:55 +08:00
|
|
|
if (dbi->ObjectName.Length < 9 * sizeof (WCHAR)
|
2011-01-17 21:38:06 +08:00
|
|
|
|| wcsncasecmp (dbi->ObjectName.Buffer, L"Harddisk", 8) != 0
|
|
|
|
|| !iswdigit (dbi->ObjectName.Buffer[8]))
|
2006-03-09 17:01:08 +08:00
|
|
|
continue;
|
2011-01-17 21:38:06 +08:00
|
|
|
/* Got it. Now construct the path to the entire disk, which is
|
|
|
|
"\\Device\\HarddiskX\\Partition0", and open the disk with
|
2014-10-16 23:35:10 +08:00
|
|
|
minimum permissions. */
|
2011-01-17 21:38:06 +08: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 23:35:10 +08:00
|
|
|
wcpcpy (wpart, L"\\Partition0");
|
|
|
|
upath.Length = dbi->ObjectName.Length + 22;
|
2011-01-17 21:38:06 +08:00
|
|
|
upath.MaximumLength = upath.Length + sizeof (WCHAR);
|
|
|
|
InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE,
|
|
|
|
dirhdl, NULL);
|
2013-04-23 17:44:36 +08:00
|
|
|
status = NtOpenFile (&devhdl, READ_CONTROL, &attr, &io,
|
|
|
|
FILE_SHARE_VALID_FLAGS, 0);
|
2011-01-17 21:38:06 +08:00
|
|
|
if (!NT_SUCCESS (status))
|
2003-03-10 04:10:25 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
debug_printf ("NtOpenFile(%S), status %y", &upath, status);
|
2011-01-17 21:38:06 +08:00
|
|
|
__seterrno_from_nt_status (status);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!got_one)
|
|
|
|
{
|
2014-10-16 23:35:10 +08:00
|
|
|
print ("major minor #blocks name win-mounts\n\n");
|
2011-01-17 21:38:06 +08:00
|
|
|
got_one = true;
|
|
|
|
}
|
|
|
|
/* Fetch partition info for the entire disk to get its size. */
|
2013-04-23 17:44:36 +08:00
|
|
|
if (DeviceIoControl (devhdl, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0,
|
|
|
|
ioctl_buf, NT_MAX_PATH, &bytes_read, NULL))
|
2011-01-17 21:38:06 +08:00
|
|
|
{
|
|
|
|
pix = (PARTITION_INFORMATION_EX *) ioctl_buf;
|
|
|
|
size = pix->PartitionLength.QuadPart;
|
2003-03-10 04:10:25 +08:00
|
|
|
}
|
2011-01-17 21:38:06 +08: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;
|
|
|
|
}
|
2016-06-23 22:56:41 +08:00
|
|
|
device dev (drive_num, 0);
|
2011-01-17 21:38:06 +08:00
|
|
|
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n",
|
2011-05-29 02:17:09 +08:00
|
|
|
dev.get_major (), dev.get_minor (),
|
2016-06-23 22:56:41 +08:00
|
|
|
size >> 10, dev.name () + 5);
|
2011-01-17 21:38:06 +08:00
|
|
|
/* Fetch drive layout info to get size of all partitions on the disk. */
|
2013-04-23 17:44:36 +08:00
|
|
|
if (DeviceIoControl (devhdl, IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
|
|
|
|
NULL, 0, ioctl_buf, NT_MAX_PATH, &bytes_read, NULL))
|
2011-01-17 21:38:06 +08: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)
|
2016-06-23 22:56:41 +08:00
|
|
|
for (DWORD i = 0; i < part_cnt && i < 64; ++i)
|
2011-01-17 21:38:06 +08:00
|
|
|
{
|
|
|
|
DWORD part_num;
|
|
|
|
|
|
|
|
if (pix)
|
|
|
|
{
|
|
|
|
size = pix->PartitionLength.QuadPart;
|
|
|
|
part_num = pix->PartitionNumber;
|
|
|
|
++pix;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size = pi->PartitionLength.QuadPart;
|
2013-04-23 17:44:36 +08:00
|
|
|
part_num = pi->PartitionNumber;
|
2011-01-17 21:38:06 +08: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;
|
2016-06-23 22:56:41 +08:00
|
|
|
device dev (drive_num, part_num);
|
2014-10-16 23:35:10 +08:00
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s",
|
2011-05-29 02:17:09 +08:00
|
|
|
dev.get_major (), dev.get_minor (),
|
2016-06-23 22:56:41 +08:00
|
|
|
size >> 10, dev.name () + 5);
|
2014-10-16 23:35:10 +08: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))
|
|
|
|
{
|
2016-06-23 22:56:41 +08:00
|
|
|
len = strlen (dev.name () + 5);
|
2014-10-16 23:35:10 +08:00
|
|
|
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 21:38:06 +08:00
|
|
|
}
|
|
|
|
NtClose (devhdl);
|
2003-03-10 04:10:25 +08:00
|
|
|
}
|
2006-03-09 17:01:08 +08:00
|
|
|
NtClose (dirhdl);
|
|
|
|
|
2011-01-17 21:38:06 +08:00
|
|
|
if (!got_one)
|
|
|
|
return 0;
|
|
|
|
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
2003-03-10 04:10:25 +08:00
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2009-01-21 01:22:11 +08:00
|
|
|
format_proc_self (void *, char *&destbuf)
|
2009-01-17 18:16:42 +08:00
|
|
|
{
|
2009-01-21 01:22:11 +08:00
|
|
|
destbuf = (char *) crealloc_abort (destbuf, 16);
|
2009-01-17 18:16:42 +08:00
|
|
|
return __small_sprintf (destbuf, "%d", getpid ());
|
|
|
|
}
|
|
|
|
|
2014-09-06 03:11:01 +08: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-25 03:08:55 +08:00
|
|
|
if (dend > destbuf + 1) /* cygdrive != "/"? */
|
|
|
|
*--dend = '\0';
|
2014-09-06 03:11:01 +08:00
|
|
|
return dend - destbuf;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2009-02-05 00:40:04 +08:00
|
|
|
format_proc_mounts (void *, char *&destbuf)
|
|
|
|
{
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, sizeof ("self/mounts"));
|
|
|
|
return __small_sprintf (destbuf, "self/mounts");
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2010-08-09 16:18:30 +08: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 13:02:13 +08:00
|
|
|
fs_names[i].block_device ? "" : "nodev",
|
|
|
|
fs_names[i].name);
|
2010-08-09 16:18:30 +08:00
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2011-04-11 10:09:43 +08:00
|
|
|
format_proc_swaps (void *, char *&destbuf)
|
|
|
|
{
|
2011-05-12 19:13:02 +08:00
|
|
|
unsigned long long total = 0ULL, used = 0ULL;
|
2011-04-11 10:09:43 +08:00
|
|
|
PSYSTEM_PAGEFILE_INFORMATION spi = NULL;
|
|
|
|
ULONG size = 512;
|
2011-12-22 19:02:36 +08:00
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
2011-04-11 10:09:43 +08:00
|
|
|
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *buf = tp.c_get ();
|
|
|
|
char *bufptr = buf;
|
|
|
|
|
|
|
|
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size);
|
|
|
|
if (spi)
|
|
|
|
{
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi,
|
|
|
|
size, &size);
|
|
|
|
if (status == STATUS_INFO_LENGTH_MISMATCH)
|
2011-04-11 10:09:43 +08:00
|
|
|
{
|
|
|
|
free (spi);
|
|
|
|
spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (size);
|
|
|
|
if (spi)
|
2011-12-22 19:02:36 +08:00
|
|
|
status = NtQuerySystemInformation (SystemPagefileInformation,
|
|
|
|
(PVOID) spi, size, &size);
|
2011-04-11 10:09:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bufptr += __small_sprintf (bufptr,
|
2021-04-30 21:19:20 +08:00
|
|
|
"Filename\t\t\t\tType\t\tSize\t\tUsed\t\tPriority\n");
|
2011-04-11 10:09:43 +08:00
|
|
|
|
2011-12-22 19:02:36 +08:00
|
|
|
if (spi && NT_SUCCESS (status))
|
2011-04-11 10:09:43 +08:00
|
|
|
{
|
|
|
|
PSYSTEM_PAGEFILE_INFORMATION spp = spi;
|
2014-05-20 19:00:37 +08:00
|
|
|
char *filename = tp.c_get ();
|
2011-04-11 10:09:43 +08:00
|
|
|
do
|
|
|
|
{
|
2011-12-22 19:02:36 +08: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 19:00:37 +08:00
|
|
|
filename, NT_MAX_PATH);
|
2021-04-30 21:19:20 +08:00
|
|
|
/* ensure space between fields for clarity */
|
|
|
|
size_t tabo = strlen (filename) / 8; /* offset tabs to space name */
|
|
|
|
bufptr += sprintf (bufptr, "%s%s%s\t\t%llu%s\t%llu%s\t%d\n",
|
|
|
|
filename,
|
|
|
|
tabo < 5 ? "\t\t\t\t\t" + tabo : " ",
|
|
|
|
"file",
|
|
|
|
total >> 10,
|
|
|
|
total < 10000000000 ? "\t" : "",
|
|
|
|
used >> 10,
|
|
|
|
used < 10000000000 ? "\t" : "",
|
|
|
|
0);
|
2011-04-11 10:09:43 +08:00
|
|
|
}
|
|
|
|
while (spp->NextEntryOffset
|
|
|
|
&& (spp = (PSYSTEM_PAGEFILE_INFORMATION)
|
2011-12-22 19:02:36 +08:00
|
|
|
((char *) spp + spp->NextEntryOffset)));
|
2011-04-11 10:09:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (spi)
|
|
|
|
free (spi);
|
|
|
|
|
|
|
|
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
|
|
|
|
memcpy (destbuf, buf, bufptr - buf);
|
|
|
|
return bufptr - buf;
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static off_t
|
2011-08-20 04:05:15 +08: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 06:37:30 +08:00
|
|
|
_major (FH_CONSOLE), _major (FH_PTMX),
|
2011-08-20 04:05:15 +08:00
|
|
|
DEV_TAPE_MAJOR, DEV_MISC_MAJOR, DEV_SOUND_MAJOR,
|
2011-10-20 22:02:54 +08:00
|
|
|
DEV_SERIAL_MAJOR, DEV_PTYS_MAJOR, DEV_FLOPPY_MAJOR,
|
2011-08-20 04:05:15 +08: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 17:44:36 +08:00
|
|
|
static off_t
|
2011-08-20 04:05:15 +08: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-10 04:10:25 +08:00
|
|
|
#undef print
|