File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -425,3 +425,30 @@ extern "C" void __iar_argc_argv() {
425
425
mbed_main ();
426
426
}
427
427
#endif
428
+
429
+ // Provide implementation of _sbrk (low-level dynamic memory allocation
430
+ // routine) for GCC_ARM which compares new heap pointer with MSP instead of
431
+ // SP. This make it compatible with RTX RTOS thread stacks.
432
+ #if defined(TOOLCHAIN_GCC_ARM)
433
+ // Linker defined symbol used by _sbrk to indicate where heap should start.
434
+ extern " C" int __end__;
435
+
436
+ // Turn off the errno macro and use actual global variable instead.
437
+ #undef errno
438
+ extern " C" int errno;
439
+
440
+ // Dynamic memory allocation related syscall.
441
+ extern " C" caddr_t _sbrk (int incr) {
442
+ static unsigned char * heap = (unsigned char *)&__end__;
443
+ unsigned char * prev_heap = heap;
444
+ unsigned char * new_heap = heap + incr;
445
+
446
+ if (new_heap >= (unsigned char *)__get_MSP ()) {
447
+ errno = ENOMEM;
448
+ return (caddr_t )-1 ;
449
+ }
450
+
451
+ heap = new_heap;
452
+ return (caddr_t ) prev_heap;
453
+ }
454
+ #endif
You can’t perform that action at this time.
0 commit comments