delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/06/14:56:57

Date: Wed, 6 Oct 1999 15:53:16 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Prashant TR <prashant_news AT yahoo DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Finding physical memory size
In-Reply-To: <19991005060345.20262.rocketmail@web1405.mail.yahoo.com>
Message-ID: <Pine.SUN.3.91.991006155304.13916B-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, 4 Oct 1999, Prashant TR wrote:

>  base[0x2000000] = base[0x2000000];  // This works. (32MB)
> 
>  // Debugging this with FSDB shows that reading the
>  // memory causes the exception.
>  base[__djgpp_base_address] = base[__djgpp_base_address]; // Causes SIGSEGV.

The last line causes SIGSEGV because you are accessing the null page
(base points to physical address zero, so base[__djgpp_base_address]
is offset zero from the DS base of the DJGPP program), and the startup
code decommits that page.  Under CWSDPMI, the page is actually
unmapped from the address space, and that's why you get a Page Fault.

To prevent that, set the _CRT0_FLAG_NULLOK bit in the
_crt0_startup_flags variable.  Then the startup code won't decommit
the null page, and your program will work.  It did for me.

> > Work-around for what?  If you did everything
> > correctly, you should be 
> > able to access the program's code without a SIGSEGV.
> > 
>
> I mentioned this because in the previous mail you told
> me that you can access all physical memory _except_
> the portion in use by the code and the DPMI host.

Well, I never imagined you'd want to scribble over the code of your
program, which is exactly what you are doing above.  In other words,
``except the portion in use'' doesn't necessarily mean that something
will crash your program, just that it spells trouble.

Of course, if that's precisely what you want to do, and if you know
what you are doing, then you *can* do even that, since the code
section is not write-protected in the DJGPP environment.  Just disable
the null page protection and you are free to do whatever damage you
like ;-).

Also note that __djgpp_map_physical_memory will crash/freeze/reboot
your machine if you call it like that under some memory manager or
Windows, because it unmaps the pages previously mapped into the
address space, including any pages that are in use by the memory
manager.  So this code is only suitable for running without any memory
manager.  In other words, CHILDREN, DON'T TRY THIS AT HOME!!

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019