You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2018/02/26 10:22:47 UTC

[mynewt-core] 02/17: Fixing memory management implementation.

This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit b7f73a4f91709b8a2f0093cc27c103f511104791
Author: Markus Lampert <ma...@bibi.ca>
AuthorDate: Mon Jan 15 20:47:05 2018 -0800

    Fixing memory management implementation.
---
 hw/bsp/nucleo-f303k8/nucleo-f303k8_download.sh |  1 -
 hw/bsp/nucleo-f303k8/src/sbrk.c                | 27 +++++++++++++++-----------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/hw/bsp/nucleo-f303k8/nucleo-f303k8_download.sh b/hw/bsp/nucleo-f303k8/nucleo-f303k8_download.sh
index 0e1d687..7c90c15 100755
--- a/hw/bsp/nucleo-f303k8/nucleo-f303k8_download.sh
+++ b/hw/bsp/nucleo-f303k8/nucleo-f303k8_download.sh
@@ -52,7 +52,6 @@ else
 fi
 
 echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET
-echo "Downloading" $FILE_NAME "to" $FLASH_OFFSET > /tmp/newt.log
 
 openocd -f board/st_nucleo_f3.cfg -c init -c "reset halt" -c "flash write_image erase $FILE_NAME $FLASH_OFFSET" -c "reset run" -c shutdown
 
diff --git a/hw/bsp/nucleo-f303k8/src/sbrk.c b/hw/bsp/nucleo-f303k8/src/sbrk.c
index 669f72d..34edf72 100644
--- a/hw/bsp/nucleo-f303k8/src/sbrk.c
+++ b/hw/bsp/nucleo-f303k8/src/sbrk.c
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -6,7 +6,7 @@
  * to you 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,
@@ -17,25 +17,30 @@
  * under the License.
  */
 
-#include <hal/hal_bsp.h>
-
-extern char _heap;
-extern char _eheap;
-static char *_brk = &_heap;
+extern char __HeapBase;
+extern char __HeapLimit;
 
 void *
 _sbrk(int incr)
 {
+    static char *brk = &__HeapBase;
+
     void *prev_brk;
 
     if (incr < 0) {
         /* Returning memory to the heap. */
-        prev_brk = (void *)-1;
+        incr = -incr;
+        if (brk - incr < &__HeapBase) {
+            prev_brk = (void *)-1;
+        } else {
+            prev_brk = brk;
+            brk -= incr;
+        }
     } else {
         /* Allocating memory from the heap. */
-        if (&_eheap - _brk >= incr) {
-            prev_brk = _brk;
-            _brk += incr;
+        if (&__HeapLimit - brk >= incr) {
+            prev_brk = brk;
+            brk += incr;
         } else {
             prev_brk = (void *)-1;
         }

-- 
To stop receiving notification emails like this one, please contact
utzig@apache.org.