init
Embed:
(wiki syntax)
Show/hide line numbers
nsdynmemLIB_stub.c
00001 /* 00002 * Copyright (c) 2014-2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include "nsdynmemLIB_stub.h" 00018 #include <stdint.h> 00019 #include <string.h> 00020 #include <nsdynmemLIB.h> 00021 #include "platform/arm_hal_interrupt.h" 00022 #include <stdlib.h> 00023 00024 nsdynmemlib_stub_data_t nsdynmemlib_stub; 00025 00026 #if NSDYNMEMLIB_API_VERSION < 2 00027 typedef int16_t ns_mem_block_size_t; 00028 typedef int16_t ns_mem_heap_size_t; 00029 void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr) 00030 { 00031 } 00032 #else 00033 void ns_dyn_mem_init(void *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr) 00034 { 00035 } 00036 #endif 00037 00038 void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size) 00039 { 00040 if (nsdynmemlib_stub.returnCounter > 0) 00041 { 00042 nsdynmemlib_stub.returnCounter--; 00043 return malloc(alloc_size); 00044 } 00045 else 00046 { 00047 return(nsdynmemlib_stub.expectedPointer); 00048 } 00049 } 00050 00051 void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size) 00052 { 00053 if (nsdynmemlib_stub.returnCounter > 0) 00054 { 00055 nsdynmemlib_stub.returnCounter--; 00056 return malloc(alloc_size); 00057 } 00058 else 00059 { 00060 return(nsdynmemlib_stub.expectedPointer); 00061 } 00062 } 00063 00064 void ns_dyn_mem_free(void *block) 00065 { 00066 free(block); 00067 }
Generated on Tue Jul 12 2022 13:25:01 by
1.7.2