Align libgloss/arm and libc/sys/arm sources: HeapInfo and __heap_limit

Applied changes from commit 8d98f95:

	* arm/crt0.S: Initialise __heap_limit when ARM_RDI_MONITOR is defined.
	* arm/syscalls.c: define __heap_limit global symbol.
	* arm/syscalls.c (_sbrk): Honour __heap_limit.

Applied changes from commit 8d98f95:
	Fixed semihosting for ARM when heapinfo not provided by debugger
This commit is contained in:
Alexander Fedotov 2019-08-02 07:33:44 -05:00 committed by Ken Brown
parent ecf2fbe4f3
commit e538b63421
3 changed files with 20 additions and 8 deletions

View File

@ -707,15 +707,15 @@ uint __heap_limit = 0xcafedead;
void * __attribute__((weak)) void * __attribute__((weak))
_sbrk (ptrdiff_t incr) _sbrk (ptrdiff_t incr)
{ {
extern char end asm ("end"); /* Defined by the linker. */ extern char end asm ("end"); /* Defined by the linker. */
static char * heap_end; static char * heap_end;
char * prev_heap_end; char * prev_heap_end;
if (heap_end == NULL) if (heap_end == NULL)
heap_end = & end; heap_end = & end;
prev_heap_end = heap_end; prev_heap_end = heap_end;
if ((heap_end + incr > stack_ptr) if ((heap_end + incr > stack_ptr)
/* Honour heap limit if it's valid. */ /* Honour heap limit if it's valid. */
|| (__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit)) || (__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit))
@ -726,14 +726,14 @@ _sbrk (ptrdiff_t incr)
extern void abort (void); extern void abort (void);
_write (1, "_sbrk: Heap and stack collision\n", 32); _write (1, "_sbrk: Heap and stack collision\n", 32);
abort (); abort ();
#else #else
errno = ENOMEM; errno = ENOMEM;
return (void *) -1; return (void *) -1;
#endif #endif
} }
heap_end += incr; heap_end += incr;
return (void *) prev_heap_end; return (void *) prev_heap_end;

View File

@ -282,6 +282,13 @@
#endif #endif
ldr r0, .LC0 /* Point at values read. */ ldr r0, .LC0 /* Point at values read. */
/* Set __heap_limit. */
ldr r1, [r0, #4]
cmp r1, #0
beq .LC33
ldr r2, =__heap_limit
str r1, [r2]
.LC33:
ldr r1, [r0, #0] ldr r1, [r0, #0]
cmp r1, #0 cmp r1, #0
bne .LC32 bne .LC32

View File

@ -487,10 +487,13 @@ _getpid (void)
return (pid_t)1; return (pid_t)1;
} }
/* Heap limit returned from SYS_HEAPINFO Angel semihost call. */
uint __heap_limit = 0xcafedead;
void * __attribute__((weak)) void * __attribute__((weak))
_sbrk (ptrdiff_t incr) _sbrk (ptrdiff_t incr)
{ {
extern char end asm ("end"); /* Defined by the linker. */ extern char end asm ("end"); /* Defined by the linker. */
static char * heap_end; static char * heap_end;
char * prev_heap_end; char * prev_heap_end;
@ -499,7 +502,9 @@ _sbrk (ptrdiff_t incr)
prev_heap_end = heap_end; prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr) if ((heap_end + incr > stack_ptr)
/* Honour heap limit if it's valid. */
|| (__heap_limit != 0xcafedead && heap_end + incr > (char *)__heap_limit))
{ {
/* Some of the libstdc++-v3 tests rely upon detecting /* Some of the libstdc++-v3 tests rely upon detecting
out of memory errors, so do not abort here. */ out of memory errors, so do not abort here. */