Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | */ |
| 5 | |
| 6 | #ifndef MEMORY_ALLOC_H |
| 7 | #define MEMORY_ALLOC_H |
| 8 | |
| 9 | #include <stddef.h> |
| 10 | |
| 11 | struct _memory_header; |
| 12 | typedef struct memory_header_s memory_header_t; |
| 13 | |
| 14 | /* |
| 15 | * Number of pages per REC to be allocated. MbedTLS needs 8K of heap |
| 16 | * for attestation usecases. |
| 17 | */ |
| 18 | #define REC_HEAP_PAGES 2 |
| 19 | |
| 20 | struct buffer_alloc_ctx { |
| 21 | unsigned char *buf; |
| 22 | size_t len; |
| 23 | memory_header_t *first; |
| 24 | memory_header_t *first_free; |
| 25 | int verify; |
| 26 | }; |
| 27 | |
| 28 | struct memory_header_s { |
| 29 | size_t magic1; |
| 30 | size_t size; |
| 31 | size_t alloc; |
| 32 | memory_header_t *prev; |
| 33 | memory_header_t *next; |
| 34 | memory_header_t *prev_free; |
| 35 | memory_header_t *next_free; |
| 36 | size_t magic2; |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | /* |
| 41 | * Function to assign a heap context to the current CPU for |
| 42 | * use by the MbedCrypto. In case the heap needs to be isolated |
| 43 | * to the CPU executing a realm , this function must to be |
| 44 | * called before entering a Realm. This will ensure that any |
| 45 | * crypto operations triggered via RSI will used the assigned |
| 46 | * heap. |
| 47 | * Arguments: |
| 48 | * ctx - Pointer to a valid context for the memory allocator. |
| 49 | * Returns: |
| 50 | * 0 on success or a POSIX error code or error. |
| 51 | */ |
| 52 | int buffer_alloc_ctx_assign(struct buffer_alloc_ctx *ctx); |
| 53 | |
| 54 | /* |
| 55 | * Function to unasign a heap context from the current CPU. |
| 56 | * In case the heap was isolated to the CPU executing a realm, |
| 57 | * this function must to be called after exiting a Realm. |
| 58 | */ |
| 59 | void buffer_alloc_ctx_unassign(void); |
| 60 | |
| 61 | #endif /* MEMORY_ALLOC_H */ |