www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/03/05:11:34

Date: Mon, 3 Mar 1997 10:01:58 GMT
Message-Id: <199703031001.KAA02454@bryggen>
From: Gisle Vanem <giva AT bgnett DOT no>
To: djgpp AT delorie DOT com
Cc: giva AT bbb DOT no
Subject: Re: ERROR 0004

ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) writes:

> Eli Zaretskii (eliz AT is DOT elta DOT co DOT il) writes:
> > On Thu, 27 Feb 1997, Mark T Logan wrote:
> >
> >> I looked all over the DJGPP docs, but I couldn't find
> >> any error number listings.  My program is crashing
> >> with a page fault, and error 0004.  What is error 0004?
> >
> > Please post a complete traceback printed when the program crashes.  It
> > is very hard to answer your question otherwise.
>
>
> 0004 is general protection fault.
>
> * Array access out of bounds
> * Malloc access out of bounds
> * Null pointer usage (see below)
> * Pointer used before initialized
> * Pointer from a malloc used before checking for NULL (but NULL from
>   malloc is very rare if you have reasonable RAM and free disk, under GCC!)
>
>
> below:
>
> void main (void) {
>   int a;
>   a= *((int *)0);
> }
>
> This will cause a GPF.
> Beware dereferencing NULL!

You makes very confident statements on thing you obviously knows little about!

1) The original poster clearly stated he got a page fault. This is CPU
   exception 14. GPF is exception 13. A GPF has numerous causes (the Intel 386
   manual lists 15 causes, 486/Pentium also add some extra), some of which
   you correctly mentioned. Array access out of bounds is *not* one of them.
   Bound exception is number 5 and is only generated if the "bound" instuction
   is used. AFAIK gcc does not have that option.

2) The points you listed are not allways harmful in itself. They may cause
   an exception later on if code/data has been overwritten.
   Exception due to "Null pointer usage" depends on the DPMI host. AFAIK,
   CWSDPMI protects djgpp programs from reading/writing null-pointers.
   QDPMI does not. Don't know about Windows/OS2.

3) The error number 0004 refers to the extra parameter (in addition to EFLAGS,
   CS and EIP) pushed on the stack when the exception is generated.
   To complicate thing further, Intel choose to add this error code to
   these exceptions only:
     Double Fault (8), Invalid TSS (10), Segment Not Present (11),
     Stack Fault (12), General Protection (13) and Page Fault (14).

   There are 17 exceptions in all (djgpp also uses signal to simulate
   exceptions).

Hope this is a bit clearer. And btw, error code 0004 (bit2=1) (in the
context of a page fault) is
<intel quote>

"The access causing the fault originated when the processor was executing
in user mode"

</intel quote>

The opposite mode (bit 2=0) is supervisor mode. AFAIK, the CPU is always
in user-mode (except for when e.g. laptops/green-PC's shuts down).
Maybe the real experts out there care to comment.

Gisle V.
Gisle V.

- Raw text -


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