[comp.os.msdos.programmer] Memory allocation error

fisher@sc2a.unige.ch (05/23/91)

In article <1991May20.055124.24741@ariel.unm.edu>, rrubio@triton.unm.edu (Dent L'Dir) writes:
> Memory allocation error
> Cannot load COMMAND.COM
> SYSTEM HALTED
> 
> is the wonderful error Im am beginning to get on my machine.  (The error doesnt
> look exactly like that, but the idea is the same).
> [...]

I probaly don't need to tell you that COMMAND.COM has a resident portion,
loaded low, and a much larger portion, loaded high, which can be overwritten
by memory allocation requests of child processes (i.e. programs that are run).
Whenever you exit a program, the resident portion checks whether the high
portion has been overwritten, and loads it again from disk if needed.

If your program trashes the COMSPEC variable, if the disk containing
COMMAND.COM gets rerouted (by a SUBST or Novell's MAP), or if COMMAND.COM
itself is deleted or renamed, you'll get a similar message, with the indication
`COMMAND.COM not found'.

This is not the case here, so the reason is probaly that the offending program
(i.e. the one you run *before* the crash) doesn't release the memory it has
requested upon exit.  Some otherwise very serious programs (I know of one
accounting program), have (or had) this bug.  Also, some early c compilers
(don't remember which one in particular) didn't automagically release the
memory arena in case the programmer had forgotten to do it cleanly.

Now this is a *very serious* bug, which no sane user should tolerate.  Find the
offending program, make extensive tests to be shure of your facts, and ask for
a free upgrade or a refund.

Hope this is of some use,

Markus G. Fischer, Dept of Anthropolgy, Geneva CH       fisher@sc2a.unige.ch

naga@wet.UUCP (Peter Davidson) (05/24/91)

-From: rrubio@triton.unm.edu (Dent L'Dir)
-Subject: Memory allocation error
-
-Memory allocation error
-Cannot load COMMAND.COM
-SYSTEM HALTED
-
-is the wonderful error Im am beginning to get on my machine.  (The error
-doesnt look exactly like that, but the idea is the same).
-
-Ive got a 386sx/16 by Packard Bell that ran very smoothly up until 2 months ago
-when this started to happen.  It seems to happen when I terminate one program
-and then run another.  ...
-    ...  I have no clue here.  Anyone know whats going on?
-
-rrubio@triton.unm.edu

Dolphin Software's Far Memory Manager & Diagnostic C Library is designed
to (among other things) track down just such memory allocation errors.
The company's address is 48 Shattuck Square #147, Berkeley, CA 94704.

Peter.Davidson@sunbrk.FidoNet.Org (Peter Davidson) (05/24/91)

-From: rrubio@triton.unm.edu (Dent L'Dir)
-Subject: Memory allocation error
-
-Memory allocation error
-Cannot load COMMAND.COM
-SYSTEM HALTED
-
-is the wonderful error Im am beginning to get on my machine.  (The error
-doesnt look exactly like that, but the idea is the same).
-
-Ive got a 386sx/16 by Packard Bell that ran very smoothly up until 2 months ago
-when this started to happen.  It seems to happen when I terminate one program
-and then run another.  ...
-    ...  I have no clue here.  Anyone know whats going on?
-
-rrubio@triton.unm.edu

Dolphin Software's Far Memory Manager & Diagnostic C Library is designed
to (among other things) track down just such memory allocation errors.
The company's address is 48 Shattuck Square #147, Berkeley, CA 94704.

 * Origin: Seaeast - Fidonet<->Usenet Gateway - sunbrk (1:343/15.0)

joe@proto.com (Joe Huffman) (05/25/91)

fisher@sc2a.unige.ch writes:

>I probaly don't need to tell you that COMMAND.COM has a resident portion,
>loaded low, and a much larger portion, loaded high, which can be overwritten
>by memory allocation requests of child processes (i.e. programs that are run).
>Whenever you exit a program, the resident portion checks whether the high
>portion has been overwritten, and loads it again from disk if needed.

>[...stuff about applications that cause crashes related to resident 
portion...]

My brother discovered that the check for the overwrite is faulty.  It is
quite easy to overwrite part of the resident portion and not have it 
detected.

--------- high memory -------\
			      \
                               ---      Resident portion
      --magic position--      /
----- not so high memory ----/

You can trash from 'magic position' to 'high memory' that has been given to 
you by a valid memory allocation call, free it, exit your program and get a
nasty message telling you to reboot.  If you were to trash all of it then
it is detected and everything is fine.

It's a bug in DOS 4.01 (and probably others).
-- 
joe@proto.com

Ralf.Brown@B.GP.CS.CMU.EDU (05/25/91)

In article <1991May24.235640.17077@proto.com>, joe@proto.com (Joe Huffman) wrote:
}
}You can trash from 'magic position' to 'high memory' that has been given to 
}you by a valid memory allocation call, free it, exit your program and get a
}nasty message telling you to reboot.  If you were to trash all of it then
}it is detected and everything is fine.
}
}It's a bug in DOS 4.01 (and probably others).

Actually, it's COMMAND.COM's overwrite check which is too simplistic.  All it
does is add up all the bytes of the transient portion's memory (modulo 64K)
and compare that to the checksum made when it first loaded.  So any random
trashing has a one-in-64K chance of being undetected; any form of scrambling
which only rearranges the bytes will never be detected.


-- 
{backbone}!cs.cmu.edu!ralf  ARPA: RALF@CS.CMU.EDU   FIDO: Ralf Brown 1:129/53
BITnet: RALF%CS.CMU.EDU@CARNEGIE   AT&Tnet: (412)268-3053 (school)   FAX: ask
DISCLAIMER?  Did  | It isn't what we don't know that gives us trouble, it's
I claim something?| what we know that ain't so.  --Will Rogers

theall@rm105serve.sas.upenn.edu (George A. Theall) (05/26/91)

In article <1991May24.235640.17077@proto.com> joe@proto.com (Joe Huffman) writes:
>--------- high memory -------\
>			      \
>                               ---      Resident portion
>      --magic position--      /
>----- not so high memory ----/

   How does one determine where this portion begins in high memory?

George
--- 
theall@rm105serve.sas.upenn.edu			Dept. of Economics
theall@ssctemp.sas.upenn.edu			Univ. of Pennsylvania
gtheall@penndrls.upenn.edu			Philadelphia, PA 19104

joe@proto.com (Joe Huffman) (05/29/91)

theall@rm105serve.sas.upenn.edu (George A. Theall) writes:

>In article <1991May24.235640.17077@proto.com> joe@proto.com (Joe Huffman) writes:
>>--------- high memory -------\
>>			   	\
>>                               ---      Resident portion
>>      --magic position--      /
>>----- not so high memory ----/

>   How does one determine where this portion begins in high memory?

Rough outline:

long unsigned int mask = 1L << 20;
long unsigned int M;

do	/* A binary search. */
{
  mask >>= 1;
  M |= mask;
  Allocate all of DOS memory.
  if(M < bytes_allocated)
  {
    Set the top 'M' bytes to 0.
    Free all allocated DOS memory.
    Exit program.
    if(no_crash)
      M ^= mask;
  }
  else
    M ^= mask;
} while(mask != 0);

Answer = 'Magic position' is M bytes from top of memory.
-- 
joe@proto.com