How to get memory information

Hi Friends,
I try to get memory information :

  1. size of available mem, something like GlobalMemoryStatus() but for kernel mode .

2 . size of installed mem in machine (in user mode) where some of mem is hide by boot.ini switch /MAXMEM=xxx.
if I use GlobalMemoryStatus() , I get only xxx .
for example If I have 4 Gb installed in machine and in file boot.ini
I have /MAXMEM=1024, then I can’t know the real size installed in machine or additional hide mem.

thank you

You can try using MmGetPhysicalMemoryRanges.

It’ll definitely work but it wont be a WHQL favouring way since its a undocumented routine.

This routine is just going to return you physical memory ranges which OS can use and baiscally this info comes from HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System Resources\Physical Memory.Translated
registry key.

Also google out this function. You will get example code snippets of how to use the output of this function to calculate the memory size.

You need to do some circus after calling this function to get the actual memory size.

Good luck.
Regards,
Dhirendra
----- Original Message ----
From: “xxxxx@orbotech.com
To: Windows System Software Devs Interest List
Sent: Wednesday, 28 March, 2007 8:07:31 PM
Subject: [ntdev] How to get memory information

Hi Friends,
I try to get memory information :

1. size of available mem, something like GlobalMemoryStatus() but for kernel mode .

2 . size of installed mem in machine (in user mode) where some of mem is hide by boot.ini switch /MAXMEM=xxx.
if I use GlobalMemoryStatus() , I get only xxx .
for example If I have 4 Gb installed in machine and in file boot.ini
I have /MAXMEM=1024, then I can’t know the real size installed in machine or additional hide mem.

thank you


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

__________________________________________________________
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/

Yes well fine but I don’t think that is going to solve his problem as the memory he hid with /MAXMEM is still hidden and as far as I know will not be present in HKLM*\Physical Memory.

The OP should consider a two step install process. Step one install driver and service with normal memory configuration. Service uses documented apis to discover memory configuration of the system. Service sets up boot.ini parameters for /maxmem, stores information for the driver in the service registry key for the driver, and reboots the system. On reboot the driver picks up the registry information.

The maxmem hack is in general not a good idea for a real product.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of dhirendra pratap
Sent: Wednesday, March 28, 2007 11:04 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to get memory information

You can try using MmGetPhysicalMemoryRanges.

It’ll definitely work but it wont be a WHQL favouring way since its a undocumented routine.

This routine is just going to return you physical memory ranges which OS can use and baiscally this info comes from HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System Resources\Physical Memory.Translated registry key.

Also google out this function. You will get example code snippets of how to use the output of this function to calculate the memory size.

You need to do some circus after calling this function to get the actual memory size.

Good luck.
Regards,
Dhirendra

----- Original Message ----
From: “xxxxx@orbotech.com
To: Windows System Software Devs Interest List
Sent: Wednesday, 28 March, 2007 8:07:31 PM
Subject: [ntdev] How to get memory information

Hi Friends,
I try to get memory information :

1. size of available mem, something like GlobalMemoryStatus() but for kernel mode .

2 . size of installed mem in machine (in user mode) where some of mem is hide by boot.ini switch /MAXMEM=xxx.
if I use GlobalMemoryStatus() , I get only xxx .
for example If I have 4 Gb installed in machine and in file boot.ini
I have /MAXMEM=1024, then I can’t know the real size installed in machine or additional hide mem.

thank you


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

________________________________

Here?s a new way to find what you’re looking for - Yahoo! Answers http:</http:>

Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

What i know is that /Maxmem is just a switch which is used by control the RAM used by OS.
But the ranges in “HKEY_LOCAL_MACHINE.…\Physical Memory.Translated” are the memory ranges given by BIOS to OS for OS use.

Bios is not going to care about some /Maxmem switch or how much memory OS is going to use. So i think this should work.
But not 100% sure on this.

Thanks,
Dhirendra

xxxxx@orbotech.com wrote:

Hi Friends,
I try to get memory information :

  1. size of available mem, something like GlobalMemoryStatus() but for kernel mode .

2 . size of installed mem in machine (in user mode) where some of mem is hide by boot.ini switch /MAXMEM=xxx.
if I use GlobalMemoryStatus() , I get only xxx .
for example If I have 4 Gb installed in machine and in file boot.ini
I have /MAXMEM=1024, then I can’t know the real size installed in machine or additional hide mem.

What good will this do you? I don’t want to start yet another tirade
about the “kernel police” telling people what they should and shouldn’t
do, but it’s a fact that, in most cases, folks who think they need to
know the actual size of physical memory are doing something the wrong
way. If the user specified /MAXMEM=1024, then he wants you to think the
machine has 1GB RAM. Who are you to call him a liar?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Sometimes what you know and what is are two different things.
The memory map in the registry is a reflection of the os view of memory,
not the bios view.

You made me go out to the lab and actually confirm reality:

Contents of HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System
Resources\Physical Memory

Boot with 2gb: (using maxmem)

630,784 9a000
14,680,064 E00000
2,130,378,752 7efb0000


2,145,689,600 7FE4A000

Boot with 4gb:

630,784 9a000
14,680,064 e00000
2,130,378,752 7efb0000
2,147,483,648 80000000


4,293,173,248 FFE4A000

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.co.in
Sent: Wednesday, March 28, 2007 11:47 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to get memory information

What i know is that /Maxmem is just a switch which is used by control
the RAM used by OS.
But the ranges in “HKEY_LOCAL_MACHINE.…\Physical Memory.Translated”
are the memory ranges given by BIOS to OS for OS use.

Bios is not going to care about some /Maxmem switch or how much memory
OS is going to use. So i think this should work.
But not 100% sure on this.

Thanks,
Dhirendra


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> 2 . size of installed mem in machine (in user mode) where some of mem is hide

by boot.ini switch /MAXMEM=xxx.

I don’t think it is possible.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

In the kernel mode, I used to retrieve the size of available memory with NtQuerySystemInformation(SystemBasicInformation,…).

// ntddk.h
NTSTATUS
NtQuerySystemInformation (
IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
OUT PVOID SystemInformation,
IN ULONG SystemInformationLength,
OUT PULONG ReturnLength OPTIONAL
);

// Per Gary Nebbett
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;
UCHAR NumberProcessors;
} SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;

The 64-bit version of SYSTEM_BASIC_INFORMATION is a bit different because some of the fields, such as NumberOfPhysicalPages, a defined as ULONGLONG. Reverse-engineering the structure is easy:

for (i = 1; i < 1024; i++) {
if ( NtQuerySystemInformation(SystemBasicInformation, SystemInformation, i, NULL) == STATUS_SUCCESS)
break;
}
// Dump i bytes from address SystemInformation, yada, yada, yada

A similar function exist in the user-mode, but I have never tried it.

Regards,
Alex Goykhman

P.S. The above is mostly based on my recollection as I no longer have access to the code, so take it with a grain of salt:

First of all, read Tim’s post carefully - he said something that makes a perfect sense (i.e. if the OS
believes that the amount of memory on the machine is X, why should you be bothered about the fact that the actual amount of memory is not X but Y). However, if you are just desperate to find out the actual amount of memory, you can get this info from BIOS. BIOS resides in the physical range 0xf0000 - 0xfffff. Map it to the virtual memory , locate SMBIOS table, get to the Structure Table (offsets to the Structure table’s size and physical address are respectively 0x16 and 0x18 from the beginning of SMBIOS table), and then find structures that describe the sought info. I believe
Type 16 ( Physical Memory Array) and especially Type 19 ( Memory Array Mapped Address) must be of interest. Please check SMBIOS specifications for more info.

The funniest thing is that there is nothing “unsupported” here - the only calls that you make are
MmMapIoSpace() and MmUnmapIoSpace(), and reading memory is not “unsupported” operation either…

Anton Bassov

Thanks Mark for clarifying.

Understood now.

Regards,
Dhirendra

----- Original Message ----
From: “Roddy, Mark”
To: Windows System Software Devs Interest List
Sent: Thursday, 29 March, 2007 12:38:08 AM
Subject: RE: [ntdev] How to get memory information

Sometimes what you know and what is are two different things.
The memory map in the registry is a reflection of the os view of memory,
not the bios view.

You made me go out to the lab and actually confirm reality:

Contents of HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System
Resources\Physical Memory

Boot with 2gb: (using maxmem)

630,784 9a000
14,680,064 E00000
2,130,378,752 7efb0000

2,145,689,600 7FE4A000

Boot with 4gb:

630,784 9a000
14,680,064 e00000
2,130,378,752 7efb0000
2,147,483,648 80000000

4,293,173,248 FFE4A000

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.co.in
Sent: Wednesday, March 28, 2007 11:47 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How to get memory information

What i know is that /Maxmem is just a switch which is used by control
the RAM used by OS.
But the ranges in “HKEY_LOCAL_MACHINE.…\Physical Memory.Translated”
are the memory ranges given by BIOS to OS for OS use.

Bios is not going to care about some /Maxmem switch or how much memory
OS is going to use. So i think this should work.
But not 100% sure on this.

Thanks,
Dhirendra


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

__________________________________________________________
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/

I would agree with Tim’s observation, but I would also agree with Anton;
this works, it is documented, and don’t imagine that there is a machine
out there without SMBIOS support.

>> xxxxx@hotmail.com 2007-03-28 22:51 >>>
First of all, read Tim’s post carefully - he said something that makes
a perfect sense (i.e. if the OS
believes that the amount of memory on the machine is X, why should you
be bothered about the fact that the actual amount of memory is not X but
Y). However, if you are just desperate to find out the actual amount of
memory, you can get this info from BIOS. BIOS resides in the physical
range 0xf0000 - 0xfffff. Map it to the virtual memory , locate SMBIOS
table, get to the Structure Table (offsets to the Structure table’s size
and physical address are respectively 0x16 and 0x18 from the beginning
of SMBIOS table), and then find structures that describe the sought
info. I believe
Type 16 ( Physical Memory Array) and especially Type 19 ( Memory Array
Mapped Address) must be of interest. Please check SMBIOS specifications
for more info.

The funniest thing is that there is nothing “unsupported” here - the
only calls that you make are
MmMapIoSpace() and MmUnmapIoSpace(), and reading memory is not
“unsupported” operation either…

Anton Bassov


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

There is an article about SMBIOS access on WHDC …
http://www.microsoft.com/whdc/system/platform/firmware/SMBIOS.mspx

wrote in message news:xxxxx@ntdev…
> First of all, read Tim’s post carefully - he said something that makes a
> perfect sense (i.e. if the OS
> believes that the amount of memory on the machine is X, why should you be
> bothered about the fact that the actual amount of memory is not X but Y).
> However, if you are just desperate to find out the actual amount of
> memory, you can get this info from BIOS. BIOS resides in the physical
> range 0xf0000 - 0xfffff. Map it to the virtual memory , locate SMBIOS
> table, get to the Structure Table (offsets to the Structure table’s size
> and physical address are respectively 0x16 and 0x18 from the beginning of
> SMBIOS table), and then find structures that describe the sought info. I
> believe
> Type 16 ( Physical Memory Array) and especially Type 19 ( Memory Array
> Mapped Address) must be of interest. Please check SMBIOS specifications
> for more info.
>
> The funniest thing is that there is nothing “unsupported” here - the only
> calls that you make are
> MmMapIoSpace() and MmUnmapIoSpace(), and reading memory is not
> “unsupported” operation either…
>
> Anton Bassov
>
>
>