github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/memory_allocator.h (about) 1 /* 2 * Copyright (c) 2013 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 #ifndef _MEMORY_ALLOCATOR_H 16 #define _MEMORY_ALLOCATOR_H 17 18 #include "vmm_defs.h" 19 #include "heap.h" 20 21 22 // FUNCTION : vmm_memory_allocate() 23 // PURPOSE : Allocates contiguous buffer of given size, filled with zeroes 24 // ARGUMENTS: IN UINT32 size - size of the buffer in bytes 25 // RETURNS : void* address of allocted buffer if OK, NULL if failed 26 void* vmm_mem_allocate( char *file_name, INT32 line_number, IN UINT32 size); 27 28 // FUNCTION : vmm_memory_free() 29 // PURPOSE : Release previously allocated buffer 30 // ARGUMENTS: IN void *p_buffer - buffer to be released 31 // RETURNS : void 32 void vmm_mem_free( char *file_name, INT32 line_number, 33 IN void *buff); 34 35 void* vmm_mem_allocate_aligned( char *file_name, 36 INT32 line_number, IN UINT32 size, IN UINT32 alignment); 37 38 // FUNCTION : vmm_mem_buff_size() 39 // PURPOSE : Get size of buff 40 // ARGUMENTS: IN void *p_buffer - the buffer 41 // RETURNS : UINT32 - size 42 UINT32 vmm_mem_buff_size( char *file_name, 43 INT32 line_number, IN void *buff); 44 45 // FUNCTION : vmm_mem_pool_size() 46 // PURPOSE : Get the size of pool that will be needed to alloc a buff of given size 47 // ARGUMENTS: IN UINT32 size - size 48 // RETURNS : UINT32 - pool size 49 UINT32 vmm_mem_pool_size( char *file_name, 50 INT32 line_number, IN UINT32 size); 51 52 #if defined DEBUG || defined ENABLE_RELEASE_VMM_LOG 53 // This is done to remove out the file name and line number (present in strings) 54 // from the release build 55 #define vmm_malloc(__size) \ 56 vmm_mem_allocate(__FILE__, __LINE__, __size) 57 58 #define vmm_malloc_aligned(__size, __alignment) \ 59 vmm_mem_allocate_aligned(__FILE__, __LINE__, __size, __alignment) 60 61 #define vmm_mfree(__buff) \ 62 vmm_mem_free(__FILE__, __LINE__, __buff) 63 64 #define vmm_mem_alloc_size(__size) \ 65 vmm_mem_pool_size(__FILE__, __LINE__, __size) 66 67 #define vmm_mem_free_size(__buff) \ 68 vmm_mem_buff_size(__FILE__, __LINE__, __buff) 69 #else 70 #define vmm_malloc(__size) \ 71 vmm_mem_allocate(NULL, 0, __size) 72 73 #define vmm_malloc_aligned(__size, __alignment) \ 74 vmm_mem_allocate_aligned(NULL, 0, __size, __alignment) 75 76 #define vmm_mfree(__buff) \ 77 vmm_mem_free(NULL, 0, __buff) 78 79 #define vmm_mem_alloc_size(__size) \ 80 vmm_mem_pool_size(NULL, 0, __size) 81 82 #define vmm_mem_free_size(__buff) \ 83 vmm_mem_buff_size(NULL, 0, __buff) 84 #endif 85 86 void memory_allocator_print(void); 87 88 #endif