From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20073 invoked by alias); 17 Jun 2004 14:30:45 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 20044 invoked from network); 17 Jun 2004 14:30:41 -0000 Received: from unknown (HELO mail.broadpark.no) (217.13.4.2) by sourceware.org with SMTP; 17 Jun 2004 14:30:41 -0000 Received: from famine (217-13-20-38.dd.nextgentel.com [217.13.20.38]) by mail.broadpark.no (Postfix) with ESMTP id 363EC36D9; Thu, 17 Jun 2004 16:31:04 +0200 (MEST) From: =?ISO-8859-1?Q?=D8yvind?= Harboe To: Andrew Lunn Cc: ecos-discuss@sources.redhat.com In-Reply-To: <20040617121021.GB20791@lunn.ch> References: <1087469710.31564.11.camel@famine> <20040617121021.GB20791@lunn.ch> Content-Type: multipart/mixed; boundary="=-jUSQU55QzIUsjZGI2Cfe" Organization: Zylin AS Message-Id: <1087482637.31564.28.camel@famine> Mime-Version: 1.0 Date: Thu, 17 Jun 2004 14:30:00 -0000 Subject: Re: [ECOS] New memory allocation debug feature X-SW-Source: 2004-06/txt/msg00170.txt.bz2 --=-jUSQU55QzIUsjZGI2Cfe Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-length: 1047 On Thu, 2004-06-17 at 14:10, Andrew Lunn wrote: > On Thu, Jun 17, 2004 at 12:55:11PM +0200, ?yvind Harboe wrote: > > Comments? > > I would prefer the function to use the cyg_ prefix so it does not > polute the namespace. Should be OK now. > You also need to provide an implementation in libtarget.a for when the > application does not have such a function. eg all the test programs > will not provide this function, so will fail to link when your new > option is enabled. So please add a week function which does nothing, > or maybe throws an CYG_FAIL(). Hmmm... Can this be done without adding a new source file? > It would also be nice if you used to same coding style for the patch > as for the rest of the file, ie { on the same line as the if etc. Should be OK now. My dream is that CVS would automatically enforce all such formatting rules transparently, and that text editors would present the source code in the preferred coloring and formatting of the programmer. :-) > > Andrew -- Øyvind Harboe http://www.zylin.com --=-jUSQU55QzIUsjZGI2Cfe Content-Disposition: attachment; filename=memdebug.txt Content-Type: text/plain; name=memdebug.txt; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Content-length: 8321 ? memdebug.txt Index: common/current/include/common.hxx =================================================================== RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/common.hxx,v retrieving revision 1.3 diff -u -w -r1.3 common.hxx --- common/current/include/common.hxx 23 May 2002 23:08:43 -0000 1.3 +++ common/current/include/common.hxx 17 Jun 2004 14:25:44 -0000 @@ -131,5 +131,14 @@ typedef cyg_uint16 cyg_mempool_status_flag_t; +#if CYGSEM_MEMALLOC_INVOKE_OUTOFMEMORY +// breakpoint site for out of memory conditions +__externC void cyg_memalloc_alloc_fail(); +#else +// this will compile away to nothing with optimisations turned on. +inline void cyg_memalloc_alloc_fail() { +} +#endif + #endif /* ifndef CYGONCE_MEMALLOC_COMMON_HXX */ /* EOF common.hxx */ Index: common/current/include/memjoin.inl =================================================================== RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/memjoin.inl,v retrieving revision 1.6 diff -u -w -r1.6 memjoin.inl --- common/current/include/memjoin.inl 5 Feb 2003 01:10:12 -0000 1.6 +++ common/current/include/memjoin.inl 17 Jun 2004 14:25:45 -0000 @@ -178,6 +178,10 @@ } CYG_REPORT_RETVAL( ptr ); + + if (ptr==NULL) { + cyg_memalloc_alloc_fail(); + } return ptr; } // Cyg_Mempool_Joined::try_alloc() @@ -214,6 +218,7 @@ ret = pool->resize_alloc( alloc_ptr, newsize, oldsize ); CYG_REPORT_RETVAL( ret ); + return ret; } // Cyg_Mempool_Joined::resize_alloc() Index: common/current/include/mempolt2.inl =================================================================== RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/mempolt2.inl,v retrieving revision 1.3 diff -u -w -r1.3 mempolt2.inl --- common/current/include/mempolt2.inl 23 May 2002 23:08:43 -0000 1.3 +++ common/current/include/mempolt2.inl 17 Jun 2004 14:25:45 -0000 @@ -116,6 +116,8 @@ Mempolt2WaitInfo waitinfo( size ); + cyg_memalloc_alloc_fail(); + self->set_wait_info( (CYG_ADDRWORD)&waitinfo ); self->set_sleep_reason( Cyg_Thread::WAIT ); self->sleep(); @@ -187,6 +189,9 @@ // straight to unlock. if( Cyg_Thread::NONE == self->get_wake_reason() ) { + + cyg_memalloc_alloc_fail(); + self->set_wait_info( (CYG_ADDRWORD)&waitinfo ); self->sleep(); queue.enqueue( self ); @@ -251,6 +256,11 @@ // Unlock the scheduler and maybe switch threads Cyg_Scheduler::unlock(); + + if (ret==NULL) { + cyg_memalloc_alloc_fail(); + } + return ret; } @@ -283,6 +293,11 @@ // Unlock the scheduler and maybe switch threads Cyg_Scheduler::unlock(); + + if (ret==NULL) { + cyg_memalloc_alloc_fail(); + } + return ret; } Index: common/current/include/mempoolt.inl =================================================================== RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/mempoolt.inl,v retrieving revision 1.3 diff -u -w -r1.3 mempoolt.inl --- common/current/include/mempoolt.inl 23 May 2002 23:08:43 -0000 1.3 +++ common/current/include/mempoolt.inl 17 Jun 2004 14:25:45 -0000 @@ -111,6 +111,9 @@ cyg_uint8 *ret; cyg_bool result = true; while( result && (NULL == (ret = pool.alloc( size ))) ) { + + cyg_memalloc_alloc_fail(); + self->set_sleep_reason( Cyg_Thread::WAIT ); self->sleep(); queue.enqueue( self ); @@ -182,6 +185,8 @@ result = false; while( result && (NULL == (ret = pool.alloc( size ))) ) { + cyg_memalloc_alloc_fail(); + self->set_sleep_reason( Cyg_Thread::TIMEOUT ); self->sleep(); queue.enqueue( self ); @@ -248,6 +253,10 @@ // Unlock the scheduler and maybe switch threads Cyg_Scheduler::unlock(); CYG_REPORT_RETVAL( ret ); + + if (ret==NULL) { + cyg_memalloc_alloc_fail(); + } return ret; } Index: common/current/include/mfiximpl.inl =================================================================== RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/mfiximpl.inl,v retrieving revision 1.3 diff -u -w -r1.3 mfiximpl.inl --- common/current/include/mfiximpl.inl 23 May 2002 23:08:44 -0000 1.3 +++ common/current/include/mfiximpl.inl 17 Jun 2004 14:25:46 -0000 @@ -122,8 +122,10 @@ { // size parameter is not used CYG_UNUSED_PARAM( cyg_int32, size ); - if ( 0 >= freeblocks ) + if ( 0 >= freeblocks ) { + cyg_memalloc_alloc_fail(); return NULL; + } cyg_int32 i = firstfree; cyg_uint8 *p = NULL; do { @@ -172,8 +174,10 @@ if (newsize == blocksize) return alloc_ptr; - else + else { + cyg_memalloc_alloc_fail(); return NULL; + } } // resize_alloc() Index: common/current/include/mvarimpl.inl =================================================================== RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/mvarimpl.inl,v retrieving revision 1.5 diff -u -w -r1.5 mvarimpl.inl --- common/current/include/mvarimpl.inl 23 May 2002 23:08:44 -0000 1.5 +++ common/current/include/mvarimpl.inl 17 Jun 2004 14:25:46 -0000 @@ -275,6 +275,9 @@ cyg_uint8 *ptr = memdq2alloc( dq ); CYG_ASSERT( ((CYG_ADDRESS)ptr & (alignment-1)) == 0, "returned memory not aligned" ); + if (ptr==NULL) { + cyg_memalloc_alloc_fail(); + } return ptr; } @@ -358,6 +361,9 @@ ret = alloc_ptr; } + if (ret==NULL) { + cyg_memalloc_alloc_fail(); + } return ret; } // resize_alloc() Index: common/current/include/sepmetaimpl.inl =================================================================== RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/include/sepmetaimpl.inl,v retrieving revision 1.4 diff -u -w -r1.4 sepmetaimpl.inl --- common/current/include/sepmetaimpl.inl 23 May 2002 23:08:44 -0000 1.4 +++ common/current/include/sepmetaimpl.inl 17 Jun 2004 14:25:47 -0000 @@ -374,8 +374,10 @@ size = (size + alignment - 1) & -alignment; struct memdq *dq = find_free_dq( size ); - if (NULL == dq) + if (NULL == dq) { + cyg_memalloc_alloc_fail(); return NULL; + } cyg_int32 dqsize = dq->memnext->mem - dq->mem; @@ -399,8 +401,11 @@ // first get a memdq - if ( NULL == freemetahead ) // out of metadata. + if ( NULL == freemetahead ) { + // out of metadata. + cyg_memalloc_alloc_fail(); return NULL; + } // FIXME: since we don't search all the way for an exact fit // first we may be able to find an exact fit later and therefore @@ -496,7 +501,10 @@ prevmemsize = dq->mem - dq->memprev->mem; } if (nextmemsize + prevmemsize + currsize < newsize) + { + cyg_memalloc_alloc_fail(); return NULL; // can't fit it + } // expand forwards if ( nextmemsize != 0 ) { @@ -560,8 +568,10 @@ } else { // if its already allocated we need to create a new free list // entry - if (NULL == freemetahead) + if (NULL == freemetahead) { + cyg_memalloc_alloc_fail(); return NULL; // can't do it + } struct memdq *fdq = freemetahead; freemetahead = fdq->next; Index: common/current/src/dlmalloc.cxx =================================================================== RCS file: /cvs/ecos/ecos/packages/services/memalloc/common/current/src/dlmalloc.cxx,v retrieving revision 1.8 diff -u -w -r1.8 dlmalloc.cxx --- common/current/src/dlmalloc.cxx 6 Oct 2003 18:25:57 -0000 1.8 +++ common/current/src/dlmalloc.cxx 17 Jun 2004 14:25:48 -0000 @@ -217,6 +217,8 @@ #include //#include + + /* Debugging: @@ -1273,6 +1275,7 @@ //diag_printf("chunksize(top)=%ld, nb=%d, remainder=%ld\n", chunksize(top), // nb, remainder_size); MALLOC_UNLOCK; + cyg_memalloc_alloc_fail(); return NULL; /* propagate failure */ } @@ -1558,6 +1561,7 @@ // couldn't resize the allocation any direction, so return failure MALLOC_UNLOCK; + cyg_memalloc_alloc_fail(); return NULL; } --=-jUSQU55QzIUsjZGI2Cfe Content-Type: text/plain; charset=us-ascii Content-length: 148 -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss --=-jUSQU55QzIUsjZGI2Cfe--