This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Have _sbrk() for ARM fail gracefully if too much memory is requested.


Hi Guys,

  I am applying the patch below to change the simple implementation of
  _sbrk() for the ARM so that if too much memory is requested it fails
  gracefully, by setting errno to ENOMEM and returning -1.  Its
  current behaviour is to issue an error message and then call abort,
  but there are some tests in the libstdc++-v3 testsuite that are
  looking for this ENOMEM result and which fail if it is not
  encountered.

Cheers
        Nick

2002-01-17  Nick Clifton  <nickc@cambridge.redhat.com>

	* libc/sys/arm/syscalls.c (_sbrk): Return -1 rather than aborting
	if too much memory is requested.

Index: newlib/libc/sys/arm/syscalls.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/arm/syscalls.c,v
retrieving revision 1.3
diff -c -3 -p -w -r1.3 syscalls.c
*** syscalls.c	2000/03/24 18:17:17	1.3
--- syscalls.c	2002/01/17 16:34:26
*************** _getpid (int n)
*** 470,477 ****
    n = n;
  }
  
- extern void abort (void);
- 
  caddr_t
  _sbrk (int incr)
  {
--- 470,475 ----
*************** _sbrk (int incr)
*** 486,493 ****
--- 484,501 ----
    
    if (heap_end + incr > stack_ptr)
      {
+       /* Some of the libstdc++-v3 tests rely upon detecting
+ 	 out of memory errors, so do not abort here.  */
+ #if 0
+       extern void abort (void);
+ 
        _write (1, "_sbrk: Heap and stack collision\n", 32);
+       
        abort ();
+ #else
+       errno = ENOMEM;
+       return -1;
+ #endif
      }
    
    heap_end += incr;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]