* fhandler.h (fhandler_dev_mem): Erase member `init_phase' and
member function `init'. * fhandler_mem.cc: Add typedefs for NT internal data types `SYSTEM_INFORMATION_CLASS' and `SYSTEM_BASIC_INFORMATION'. Add prototype for `NtQuerySystemInformation' function. (fhandler_dev_mem::fhandler_dev_mem): Takes over initialization task from `init'. Use `NtQuerySystemInformation' function to evaluate the size of physical memory instead of interval search. (fhandler_dev_mem::init): Eliminated. (fhandler_dev_mem::open): Don't call `init'. (fhandler_dev_mem::read): Eliminate check for `init_phase'. (dummy_autoload): Add load statement for `NtQuerySystemInformation'.
This commit is contained in:
parent
b9e7a2b666
commit
42f1b6c544
@ -1,3 +1,18 @@
|
|||||||
|
Mon Oct 9 15:11:00 2000 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* fhandler.h (fhandler_dev_mem): Erase member `init_phase' and
|
||||||
|
member function `init'.
|
||||||
|
* fhandler_mem.cc: Add typedefs for NT internal data types
|
||||||
|
`SYSTEM_INFORMATION_CLASS' and `SYSTEM_BASIC_INFORMATION'.
|
||||||
|
Add prototype for `NtQuerySystemInformation' function.
|
||||||
|
(fhandler_dev_mem::fhandler_dev_mem): Takes over initialization task
|
||||||
|
from `init'. Use `NtQuerySystemInformation' function to evaluate the
|
||||||
|
size of physical memory instead of interval search.
|
||||||
|
(fhandler_dev_mem::init): Eliminated.
|
||||||
|
(fhandler_dev_mem::open): Don't call `init'.
|
||||||
|
(fhandler_dev_mem::read): Eliminate check for `init_phase'.
|
||||||
|
(dummy_autoload): Add load statement for `NtQuerySystemInformation'.
|
||||||
|
|
||||||
Sun Oct 8 22:38:40 2000 Christopher Faylor <cgf@cygnus.com>
|
Sun Oct 8 22:38:40 2000 Christopher Faylor <cgf@cygnus.com>
|
||||||
|
|
||||||
* dtable.cc (set_std_handle): Use std_consts array to control
|
* dtable.cc (set_std_handle): Use std_consts array to control
|
||||||
|
@ -776,9 +776,6 @@ protected:
|
|||||||
int unit;
|
int unit;
|
||||||
DWORD mem_size;
|
DWORD mem_size;
|
||||||
DWORD pos;
|
DWORD pos;
|
||||||
bool init_phase;
|
|
||||||
|
|
||||||
void init (void);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
fhandler_dev_mem (const char *name, int unit);
|
fhandler_dev_mem (const char *name, int unit);
|
||||||
|
@ -22,10 +22,36 @@
|
|||||||
#include "fhandler.h"
|
#include "fhandler.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following both data structures aren't defined anywhere in the Microsoft
|
||||||
|
* header files. Taken from the book "Windows NT/2000 Native API Reference"
|
||||||
|
* by Gary Nebbett.
|
||||||
|
*/
|
||||||
|
typedef enum _SYSTEM_INFORMATION_CLASS {
|
||||||
|
SystemBasicInformation = 0
|
||||||
|
/* Dropped each other since not used here. */
|
||||||
|
} SYSTEM_INFORMATION_CLASS;
|
||||||
|
|
||||||
|
typedef struct _SYSTEM_BASIC_INFORMATION {
|
||||||
|
ULONG Unknown;
|
||||||
|
ULONG MaximumIncrement;
|
||||||
|
ULONG PhysicalPageSize;
|
||||||
|
ULONG NumberOfPhysicalPages;
|
||||||
|
ULONG LowestPhysicalPage;
|
||||||
|
ULONG HighestPhysicalPage;
|
||||||
|
ULONG AllocationGranularity;
|
||||||
|
ULONG LowestUserAddress;
|
||||||
|
ULONG HighestUserAddress;
|
||||||
|
ULONG ActiveProcessors;
|
||||||
|
ULONG NumberProcessors;
|
||||||
|
} SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
NTSTATUS NTAPI NtMapViewOfSection(HANDLE,HANDLE,PVOID*,ULONG,ULONG,
|
NTSTATUS NTAPI NtMapViewOfSection(HANDLE,HANDLE,PVOID*,ULONG,ULONG,
|
||||||
PLARGE_INTEGER,PULONG,SECTION_INHERIT,
|
PLARGE_INTEGER,PULONG,SECTION_INHERIT,
|
||||||
ULONG,ULONG);
|
ULONG,ULONG);
|
||||||
|
NTSTATUS NTAPI NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS,
|
||||||
|
PVOID,ULONG,PULONG);
|
||||||
NTSTATUS NTAPI NtOpenSection(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES);
|
NTSTATUS NTAPI NtOpenSection(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES);
|
||||||
NTSTATUS NTAPI NtUnmapViewOfSection(HANDLE,PVOID);
|
NTSTATUS NTAPI NtUnmapViewOfSection(HANDLE,PVOID);
|
||||||
VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING,PCWSTR);
|
VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING,PCWSTR);
|
||||||
@ -37,37 +63,22 @@ ULONG NTAPI RtlNtStatusToDosError(NTSTATUS);
|
|||||||
|
|
||||||
fhandler_dev_mem::fhandler_dev_mem (const char *name, int nunit)
|
fhandler_dev_mem::fhandler_dev_mem (const char *name, int nunit)
|
||||||
: fhandler_base (FH_MEM, name),
|
: fhandler_base (FH_MEM, name),
|
||||||
unit (nunit),
|
unit (nunit)
|
||||||
init_phase (false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
fhandler_dev_mem::~fhandler_dev_mem (void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
fhandler_dev_mem::init ()
|
|
||||||
{
|
{
|
||||||
if (unit == 1) /* /dev/mem */
|
if (unit == 1) /* /dev/mem */
|
||||||
{
|
{
|
||||||
long page_size = getpagesize ();
|
NTSTATUS ret;
|
||||||
char buf[1];
|
SYSTEM_BASIC_INFORMATION sbi;
|
||||||
|
if ((ret = NtQuerySystemInformation (SystemBasicInformation, (PVOID) &sbi,
|
||||||
init_phase = true;
|
sizeof sbi, NULL)) != STATUS_SUCCESS)
|
||||||
mem_size = pos = 1 << 30;
|
|
||||||
for (off_t afct = 1 << 29; afct >= page_size; afct >>= 1)
|
|
||||||
{
|
{
|
||||||
if (read (buf, 1) > 0)
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
||||||
pos += afct;
|
debug_printf("NtQuerySystemInformation: ret = %d, Dos(ret) = %d",
|
||||||
|
ret, RtlNtStatusToDosError (ret));
|
||||||
|
mem_size = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
mem_size = sbi.PhysicalPageSize * sbi.NumberOfPhysicalPages;
|
||||||
if (pos < mem_size)
|
|
||||||
mem_size = pos;
|
|
||||||
pos -= afct;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pos = 0;
|
|
||||||
debug_printf ("MemSize: %d MB", mem_size >>= 20);
|
debug_printf ("MemSize: %d MB", mem_size >>= 20);
|
||||||
}
|
}
|
||||||
else if (unit == 2) /* /dev/kmem - Not yet supported */
|
else if (unit == 2) /* /dev/kmem - Not yet supported */
|
||||||
@ -82,9 +93,13 @@ fhandler_dev_mem::init ()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug_printf ("Illegal unit!!!");
|
mem_size = 0;
|
||||||
|
debug_printf ("Illegal minor number!!!");
|
||||||
}
|
}
|
||||||
init_phase = false;
|
}
|
||||||
|
|
||||||
|
fhandler_dev_mem::~fhandler_dev_mem (void)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -140,7 +155,6 @@ fhandler_dev_mem::open (const char *, int flags, mode_t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_io_handle (mem);
|
set_io_handle (mem);
|
||||||
init ();
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +238,6 @@ fhandler_dev_mem::read (void *ptr, size_t ulen)
|
|||||||
0,
|
0,
|
||||||
PAGE_READONLY)) != STATUS_SUCCESS)
|
PAGE_READONLY)) != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
if (!init_phase) /* Don't want to flood debug output with init crap. */
|
|
||||||
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -453,6 +466,7 @@ dummy_autoload (void)
|
|||||||
LoadDLLinit (ntdll)
|
LoadDLLinit (ntdll)
|
||||||
LoadDLLfuncEx (NtMapViewOfSection, 40, ntdll, 1)
|
LoadDLLfuncEx (NtMapViewOfSection, 40, ntdll, 1)
|
||||||
LoadDLLfuncEx (NtOpenSection, 12, ntdll, 1)
|
LoadDLLfuncEx (NtOpenSection, 12, ntdll, 1)
|
||||||
|
LoadDLLfuncEx (NtQuerySystemInformation, 16, ntdll, 1)
|
||||||
LoadDLLfuncEx (NtUnmapViewOfSection, 8, ntdll, 1)
|
LoadDLLfuncEx (NtUnmapViewOfSection, 8, ntdll, 1)
|
||||||
LoadDLLfuncEx (RtlInitUnicodeString, 8, ntdll, 1)
|
LoadDLLfuncEx (RtlInitUnicodeString, 8, ntdll, 1)
|
||||||
LoadDLLfuncEx (RtlNtStatusToDosError, 4, ntdll, 1)
|
LoadDLLfuncEx (RtlNtStatusToDosError, 4, ntdll, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user