From 6c7fea37759d4b4feb32a8bbac3b42c33100baa5 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Mon, 17 Jan 2022 20:01:13 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15372 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/sb/user/lib/syscalls.c | 15 ++++++++------- os/sb/user/lib/syscalls.h | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 os/sb/user/lib/syscalls.h diff --git a/os/sb/user/lib/syscalls.c b/os/sb/user/lib/syscalls.c index 60066aaac..bc0cfb31d 100644 --- a/os/sb/user/lib/syscalls.c +++ b/os/sb/user/lib/syscalls.c @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + ChibiOS - Copyright (C) 2006..2022 Giovanni Di Sirio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,6 +25,9 @@ #include "errcodes.h" #include "sbuser.h" +#include "syscalls.h" + +uint8_t *__sbrk_next = &__heap_base__; __attribute__((used)) int _open_r(struct _reent *r, const char *p, int oflag, int mode) { @@ -127,19 +130,17 @@ int _isatty_r(struct _reent *r, int fd) { __attribute__((used)) caddr_t _sbrk_r(struct _reent *r, int incr) { - extern uint8_t __heap_base__; - uint8_t *p = &__heap_base__; uint8_t *prevp; - prevp = p; - if ((p + incr > __sb_parameters.heap_end) || - (p + incr < &__heap_base__)) { + prevp = __sbrk_next; + if ((prevp + incr > __sb_parameters.heap_end) || + (prevp + incr < &__heap_base__)) { __errno_r(r) = ENOMEM; return (caddr_t)-1; } (void)r; - p += incr; + __sbrk_next += incr; return (caddr_t)prevp; } diff --git a/os/sb/user/lib/syscalls.h b/os/sb/user/lib/syscalls.h new file mode 100644 index 000000000..6c375b395 --- /dev/null +++ b/os/sb/user/lib/syscalls.h @@ -0,0 +1,19 @@ +/* + ChibiOS - Copyright (C) 2006..2022 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + + +extern uint8_t __heap_base__; +extern uint8_t *__sbrk_next;