1 /****************************************************************************** 2 * 3 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 4 * Analog Devices, Inc.), 5 * Copyright (C) 2023-2024 Analog Devices, Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 ******************************************************************************/ 20 21 #include <stdint.h> 22 #include <sys/errno.h> 23 #include <unistd.h> 24 25 /* 26 sbrk 27 Increase program data space. 28 Malloc and related functions depend on this 29 */ 30 static char *heap_end = 0; 31 extern unsigned int __HeapBase; 32 extern unsigned int __HeapLimit; _sbrk(int incr)33caddr_t _sbrk(int incr) 34 { 35 char *prev_heap_end; 36 37 if (heap_end == 0) { 38 heap_end = (caddr_t)&__HeapBase; 39 } 40 prev_heap_end = heap_end; 41 42 if ((unsigned int)(heap_end + incr) > (unsigned int)&__HeapLimit) { 43 errno = ENOMEM; 44 return (caddr_t)-1; 45 } 46 47 heap_end += incr; 48 49 return (caddr_t)prev_heap_end; 50 } 51