Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
unsupported_malloc.c
00001 /* 00002 * Copyright (c) 2015-2016, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * 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, WITHOUT 00013 * 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 "uvisor-lib/uvisor-lib.h" 00018 00019 #if !(defined(UVISOR_PRESENT) && (UVISOR_PRESENT == 1)) 00020 00021 #include <string.h> /* for memset */ 00022 00023 /* Forward declaration of the page allocator API. */ 00024 extern void page_allocator_init(void * const heap_start, void * const heap_end, const uint32_t * const page_size); 00025 00026 extern uint32_t __end__[]; /* __heap_start */ 00027 extern uint32_t __HeapLimit[]; /* __heap_end */ 00028 00029 extern uint32_t __StackLimit[]; /* bottom of stack */ 00030 00031 /* There is only one box index for box 0. */ 00032 RtxBoxIndex * __uvisor_ps UVISOR_ALIGN(4); 00033 00034 static void box_index_init(void *box_bss, uint32_t heap_size) 00035 { 00036 const uint32_t index_size = sizeof(RtxBoxIndex); 00037 /* Adjust size for overhead of box index */ 00038 heap_size -= index_size; 00039 00040 /* The box index is at the beginning of the bss section */ 00041 RtxBoxIndex *const indexOS = box_bss; 00042 /* Zero the _entire_ index, so that we know to initialize the mutex on 00043 * first use! */ 00044 memset(box_bss, 0, index_size); 00045 /* Initialize user context */ 00046 indexOS->index.ctx = NULL; 00047 /* Initialize box heap */ 00048 indexOS->index.box_heap = box_bss + index_size; 00049 indexOS->index.box_heap_size = heap_size; 00050 /* Active heap pointer is NULL */ 00051 indexOS->index.active_heap = NULL; 00052 00053 /* There is no box config for unsupported! */ 00054 indexOS->index.config = NULL; 00055 00056 /* Set the index */ 00057 __uvisor_ps = indexOS; 00058 } 00059 00060 void secure_malloc_init(void) 00061 { 00062 /* get the public heap size from the linker script */ 00063 uint32_t heap_size = ((uint32_t) __HeapLimit - 00064 (uint32_t) __end__); 00065 /* Public heap size is aligned to page boundaries n*UVISOR_PAGE_SIZE */ 00066 uint32_t heap_start = (uint32_t) __StackLimit - heap_size; 00067 /* align the start address of the public heap to a page boundary */ 00068 heap_start &= ~(UVISOR_PAGE_SIZE - 1); 00069 /* adjust the heap size to the new heap start address */ 00070 heap_size = (uint32_t) __StackLimit - heap_start; 00071 00072 /* page heap now extends from the previous public heap start address 00073 * to the new public heap start address */ 00074 extern uint32_t __uvisor_page_size; 00075 page_allocator_init(__end__, (void *) heap_start, &__uvisor_page_size); 00076 box_index_init((void *) heap_start, heap_size); 00077 } 00078 00079 #endif
Generated on Sun Jul 17 2022 08:25:32 by 1.7.2