From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin1!goblin.stu.neva.ru!news.albasani.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 15 Aug 2013 10:59:27 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: GNAT Allocation of a very large record References: <9de9c3bf-c4c5-466f-a8cd-fca992daecbe@googlegroups.com> In-Reply-To: <9de9c3bf-c4c5-466f-a8cd-fca992daecbe@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <520c9870$0$6553$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 15 Aug 2013 10:59:28 CEST NNTP-Posting-Host: 0c0d08bd.newsspool4.arcor-online.net X-Trace: DXC=Tk:k53hLId?nBOkdL^Lo7>4IUK:Lh>_cHTX3j=7CnNJk[XaH9 X-Complaints-To: usenet-abuse@arcor.de X-Original-Bytes: 4514 Xref: number.nntp.dca.giganews.com comp.lang.ada:183031 Date: 2013-08-15T10:59:28+02:00 List-Id: On 14.08.13 05:50, hyunghwan.chung@gmail.com wrote: > Hi, > > The program at the bottom of this message, when compiled with GNAT 4.6 on Ubuntu12/x86_64, seems to corrupt memory, ending up with a malloc error message. > > $ ./x1 > 1. Kind: POINTER_OBJECT Size: 10 > x1: malloc.c:2451: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed. > ^C > > On some other platforms (i.e. debian/armv5tel, gcc/gnat 4.4.5), just segmentation fault. > > I expect an output like this, meaning that the second call to 'new' should raise an exception like storage_error. > > $ ./x1 > 1. Kind: POINTER_OBJECT Size: 10 > 2. Allocation Failed > For the record only, On Mac OS X, using both GNAT GPL 2012 and GCC 4.8.1 I get $ ./x1 1. Kind: POINTER_OBJECT Size: 10 x1(3471) malloc: *** mmap(size=576460752303427584) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug 2. Allocation Failed Or, with some tracing statements inserted, some in a local copy of s-memory.adb, $ ./x1 Size: 10 Alloc: Size as S.CRTL.size_t 104, Size 104, Actual_Size 104 1. Kind: POINTER_OBJECT Size: 10 Size: 72057594037927935 Alloc: Size as S.CRTL.size_t 576460752303423504, Size 576460752303423504, Actual_Size 576460752303423504 x1(13497) malloc: *** mmap(size=576460752303427584) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug Alloc: Size as S.CRTL.size_t 656, Size 656, Actual_Size 656 Exception name: STORAGE_ERROR Message: heap exhausted 2. Allocation Failed Doing as the ***-lines suggest, in the debugger, the stack frames said that System.Memory.Alloc had been called (line 92 of s-memory.adb), Result := c_malloc (System.CRTL.size_t (Actual_Size)); After learning about libgmalloc, I tried $ DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib ./x1 GuardMalloc[x1-6126]: Allocations will be placed on 16 byte boundaries. GuardMalloc[x1-6126]: - Some buffer overruns may not be noticed. GuardMalloc[x1-6126]: - Applications using vector instructions (e.g., SSE) should work. GuardMalloc[x1-6126]: version 25 1. Kind: POINTER_OBJECT Size: 10 GuardMalloc[x1-6126]: Attempting excessively large memory allocation: 576460752303423504 bytes GuardMalloc[x1-6126]: If you really wanted to allocate so much memory, launch your executable with the environment variable MALLOC_PERMIT_INSANE_REQUESTS set to any value to circumvent this check. GuardMalloc[x1-6126]: If you run under the debugger, it will automatically break here. ^C The following little C program triggers the same message from the mallocs: #include #include int main() { size_t what = 576460752303423504; /* 0x800000000000010 */ void *bytes; fprintf(stdout, "d %ld u %lu x %lx\n", what, what, what); bytes = malloc(what); return 0; } The C program starts working properly on this (4GB, OS X 10.7) machine at what = 576460752303423504 /(1<<13).