Subject: Re: STATUS ACCESS VIOLATION
From: [email-masked] (Patrick J. Fay)

21 Feb 1998 16:54:33 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
To: Gio <[email-masked]>
Cc: [email-masked]

Hello Giovanni,
Here's my guess not knowing more details. Either you are
running out memory or the pattern of malloc's you are doing
is fragmenting memory too much.  Or perhaps your recursive
routine is exhausting your 'stack'. The OS usually reports
the address that is causing the segmentation violation,
I don't see it in cygwin's exception message. This would
provide a clue as to whether you were exhausting your
stack or your heap. (or maybe there is just a bug in
_malloc_r but that is probably way down on the list 
of possibilities).

All malloc's use some 'rules' to figure out whether to
reuse an old free'd block or alloc a new one. Any malloc
will fail if you malloc in a certain pattern. My guess is
that _malloc_r is bombing due to out of memory. I don't
really see why it should abend.
It seems like I can exhaust my memory (even though I
actually only have malloc'd half of it) by:
     for (i=1000000;i<paging_file_size;i+=1000000)
     {
       char *ptr;
       printf("malloc %d bytes\n",i);
       ptr = (char *)malloc(i);
       if(ptr!=NULL)
       {
         printf("malloc worked. free %d bytes\n",i);
         getchar();
         free(ptr);
 
       }
       else
       {
         printf("failed to malloc %d bytes\n",i);
       }
     }
If watch NT's task manager 'VM size' column, you'll see that each
malloc gets a power of 2 block of memory and so even though
you only need a small part of it, it can't malloc a power of 2 
block and abends. 
There may also be a mallopt's routine (look in whatever include
file malloc is defined in). If so you might be able to 
tell malloc to allocate a big block and do the 1 byte mallocs
from that small block. (I hope you are just doing 1 byte
mallocs as an experiment.)

All that having been said, you are probably fragmenting your 
memory or running out stack space. Figure out how to increase
your stack space and see if it runs further before abending.
Pat

Patrick Fay, Ph.D., Intel Corp.            email:   [email-masked]
Los Alamos National Lab                    wk:         (505) 665-9141
CTI M.S. B296                              fax:        (505) 667-5921
Los Alamos NM 87545    ASCI-RED http://www.acl.lanl.gov/~pfay/teraflop
On Fri, 20 Feb 1998, Gio wrote:

> 
> 
> On Tue, 17 Feb 1998, Giovanni Denaro wrote:
> 
> > Hi,
> > 
> > I am actually porting under a Windows 95 platform a tool previously
> > developed for unix platforms, using b18 gnuwin32 g++.
> > 
> > I have solved all my compile time problems,
> > but now I get the following run-time problem:
> > 
> > during execution my process crashes with the following output:
> > 
> > -----------------------------------------
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) In
> > cygwin_exc ept_handler exc C0000005 at 1004667C sp 25CFAEC
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023)
> > Exception trapped!
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023)
> > exception C0000005 at 1004667C
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023)
> > exception: ax 0 bx 0 cx 4705E44 dx 65697266
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023)
> > exception: si 1004C2DC di 1 bp 25CFAF4 sp 25CFAEC
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023)
> > exception is: STATUS_ACCESS_VIOLATION
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) Stack
> > trace:
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 0: sp = 0x25CF904, pc = 0x10007BB2
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 1: sp = 0x25CF920, pc = 0xBFF76780
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 2: sp = 0x25CF944, pc = 0xBFF858F3
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 3: sp = 0x25CF9DC, pc = 0xFFECBAD7
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 4: sp = 0x25CFAF4, pc = 0x1000F26D
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 5: sp = 0x25CFB04, pc = 0x466DEA
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 6: sp = 0x25CFB18, pc = 0x4672FB
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 7: sp = 0x25CFB24, pc = 0x411A20
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 8: sp = 0x25CFB40, pc = 0x428F52
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 9: sp = 0x25CFBD8, pc = 0x42043A
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 10: sp= 0x25CFC68, pc = 0x41BE85
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 11: sp= 0x25D00A8, pc = 0x41DF36
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 12: sp= 0x25D10D0, pc = 0x444098
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 13: sp= 0x25D10F8, pc = 0x442610
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 14: sp= 0x25D110C, pc = 0x44B39B
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) frame
> > 15: sp= 0x25D1154, pc = 0x4036E4
> > (C:\WINDOWS\PROFILES\DENARO\DESKTOP\PORTING2\EDITOR\MTD+.EXE 1023) End of
> > stacktrace (more stack frames may be present)
> > 
> > -------------------------------------
> > 
> > I have debugged (using gdb) my program and I find that the crash happends
> > executing a "new" statement for allocation of a single character...
> > 
> > is it possible???
> > 
> > To verify this i have written a simple program that cyclically allocates
> > characters it crashes too....
> > 
> > I read mails in the mail-archives and find that this error has been
> > hilighted from other people in the past (in different and various 
> > circumstances) but i have not found a working solution for it.
> > 
> > I have already installed the Sergey's coolview and placed the new
> > cygwin.dll in the correct places (gnuwin32\b18\H-i386-cygwin32\bin and
> > gnuwin32\b18\H-i386-cygwin32\i386-cygwin32\lib).
> > I have update the libcygwin.a and bash.exe too.
> > 
> > I worked for three months without any good result.
> > 
> > May somebody help me??
> > 
> > Thank you in advance...
> > 
> > Giovanni
> > 
> >  
> 
> I am continuing to find a solution for my problem.
> 
> this is the output of a simple gdb session for the program before
> descripted:
> 
> ------------------------------------------
> 
> (gdb) Breakpoint 1 at 0x4057e3
> Starting program : C:/WINDOWS/Profiles/denaro/Desktop/porting2/editor/Mtd+.exe
> [tcsetpgrp failed in terminal_inferior: error 0]
> 7c6c0000:/WINDOWS/SYSTEM/WSOCK32.DLL
> bfec0000:/WINDOWS/SYSTEM/ADVAPI32.DLL
> bff30000:/WINDOWS/SYSTEM/GDI32.DLL
> bff60000:/WINDOWS/SYSTEM/USER32.DLL
> bff70000:/WINDOWS/SYSTEM/KERNEL32.DLL
> 10000000:/LANG/GNUWIN32/B18/H-I386-CYGWIN32/BIN/CYGWIN.DLL
> bfb60000:/WINDOWS/SYSTEM/SHLWAPI.DLL
> 70200000:/WINDOWS/SYSTEM/WININET.DLL
> 0x4057e3 in main ()
> Continuing.
> [tcsetpgrp failed in terminal_inferior: error 0]
> 
> Program received signal SIGSEV, Segmentation fault.
> 0x1004667c in _malloc_r ()
> 
> (gdb)bt
> #0  0x1004667c in _malloc_r ()
> #1  0x1000f26d in export_malloc ()
> #2  0x466dea in __builtin_new (sz=1)
> #3  0x4672fb in __builtin_vec_new (sz=1)
> #4  0x411a20 in KString::Kstring ()
> #5  0x428f52 in formatEnablings ()
> #6  0x42043a in get Enablings ()
> #7  0x41be85 in HTPLNKernel::apply_message ()
> #8  0x41df36 in HTPLNKernel::receiveMessage ()
> #9  0x444098 in Interface::sendMessage ()
> #10 0x442610 in Interface::Step ()
> #11 0x44b39b in AUMExecutor::Step ()
> #12 0x4036e4 in evaluateMessage ()
> #13 0x405711 in sendmessage ()
> #14 0x405d0e in main ()
> #15 0x100063ba in dll_crt0_1 ()
> #16 0x100063cb in dll_crt0 ()
> #17 0x46840d in cygwin_crt0 ()
> (gdb)
> 
> ------------------------------------------
> 
> 
> this seems to confirm that program crashes during a malloc!
> 
> May anybody help me???
> 
> by
> Gio
> 
> -
> For help on using this list (especially unsubscribing), send a message to
> "[email-masked]" with one line of text: "help".
> 

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".