/* mm.h - prototypes and declarations for memory manager */ /* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2002,2007 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #ifndef VAS_EBOOT_MM_H #define VAS_EBOOT_MM_H 1 #include #include #include #include #ifndef NULL # define NULL ((void *) 0) #endif #define VAS_EBOOT_MM_ADD_REGION_NONE 0 #define VAS_EBOOT_MM_ADD_REGION_CONSECUTIVE (1 << 0) /* * Function used to request memory regions of `VasEBoot_size_t` bytes. The second * parameter is a bitfield of `VAS_EBOOT_MM_ADD_REGION` flags. */ typedef VasEBoot_err_t (*VasEBoot_mm_add_region_func_t) (VasEBoot_size_t, unsigned int); /* * Set this function pointer to enable adding memory-regions at runtime in case * a memory allocation cannot be satisfied with existing regions. */ #ifndef VAS_EBOOT_MACHINE_EMU extern VasEBoot_mm_add_region_func_t EXPORT_VAR(VasEBoot_mm_add_region_fn); #endif void VasEBoot_mm_init_region (void *addr, VasEBoot_size_t size); void *EXPORT_FUNC(VasEBoot_calloc) (VasEBoot_size_t nmemb, VasEBoot_size_t size); void *EXPORT_FUNC(VasEBoot_malloc) (VasEBoot_size_t size); void *EXPORT_FUNC(VasEBoot_zalloc) (VasEBoot_size_t size); void EXPORT_FUNC(VasEBoot_free) (void *ptr); void *EXPORT_FUNC(VasEBoot_realloc) (void *ptr, VasEBoot_size_t size); #ifndef VAS_EBOOT_MACHINE_EMU void *EXPORT_FUNC(VasEBoot_memalign) (VasEBoot_size_t align, VasEBoot_size_t size); #endif typedef VasEBoot_uint64_t VasEBoot_mem_attr_t; #define VAS_EBOOT_MEM_ATTR_R ((VasEBoot_mem_attr_t) 0x0000000000000004) #define VAS_EBOOT_MEM_ATTR_W ((VasEBoot_mem_attr_t) 0x0000000000000002) #define VAS_EBOOT_MEM_ATTR_X ((VasEBoot_mem_attr_t) 0x0000000000000001) #ifdef VAS_EBOOT_MACHINE_EFI VasEBoot_err_t EXPORT_FUNC(VasEBoot_get_mem_attrs) (VasEBoot_addr_t addr, VasEBoot_size_t size, VasEBoot_mem_attr_t *attrs); VasEBoot_err_t EXPORT_FUNC(VasEBoot_update_mem_attrs) (VasEBoot_addr_t addr, VasEBoot_size_t size, VasEBoot_mem_attr_t set_attrs, VasEBoot_mem_attr_t clear_attrs); #else /* !VAS_EBOOT_MACHINE_EFI */ static inline VasEBoot_err_t VasEBoot_get_mem_attrs (VasEBoot_addr_t addr __attribute__((__unused__)), VasEBoot_size_t size __attribute__((__unused__)), VasEBoot_mem_attr_t *attrs) { *attrs = VAS_EBOOT_MEM_ATTR_R | VAS_EBOOT_MEM_ATTR_W | VAS_EBOOT_MEM_ATTR_X; return VAS_EBOOT_ERR_NONE; } static inline VasEBoot_err_t VasEBoot_update_mem_attrs (VasEBoot_addr_t addr __attribute__((__unused__)), VasEBoot_size_t size __attribute__((__unused__)), VasEBoot_mem_attr_t set_attrs __attribute__((__unused__)), VasEBoot_mem_attr_t clear_attrs __attribute__((__unused__))) { return VAS_EBOOT_ERR_NONE; } #endif /* VAS_EBOOT_MACHINE_EFI */ void VasEBoot_mm_check_real (const char *file, int line); #define VasEBoot_mm_check() VasEBoot_mm_check_real (VAS_EBOOT_FILE, __LINE__); /* For debugging. */ #if defined(MM_DEBUG) && !defined(VAS_EBOOT_UTIL) && !defined (VAS_EBOOT_MACHINE_EMU) /* Set this variable to 1 when you want to trace all memory function calls. */ extern int EXPORT_VAR(VasEBoot_mm_debug); void EXPORT_FUNC(VasEBoot_mm_dump_free) (void); void EXPORT_FUNC(VasEBoot_mm_dump) (unsigned lineno); void EXPORT_FUNC(VasEBoot_mm_dump_regions) (void); #define VasEBoot_calloc(nmemb, size) \ VasEBoot_debug_calloc (VAS_EBOOT_FILE, __LINE__, nmemb, size) #define VasEBoot_malloc(size) \ VasEBoot_debug_malloc (VAS_EBOOT_FILE, __LINE__, size) #define VasEBoot_zalloc(size) \ VasEBoot_debug_zalloc (VAS_EBOOT_FILE, __LINE__, size) #define VasEBoot_realloc(ptr,size) \ VasEBoot_debug_realloc (VAS_EBOOT_FILE, __LINE__, ptr, size) #define VasEBoot_memalign(align,size) \ VasEBoot_debug_memalign (VAS_EBOOT_FILE, __LINE__, align, size) #define VasEBoot_free(ptr) \ VasEBoot_debug_free (VAS_EBOOT_FILE, __LINE__, ptr) void *EXPORT_FUNC(VasEBoot_debug_calloc) (const char *file, int line, VasEBoot_size_t nmemb, VasEBoot_size_t size); void *EXPORT_FUNC(VasEBoot_debug_malloc) (const char *file, int line, VasEBoot_size_t size); void *EXPORT_FUNC(VasEBoot_debug_zalloc) (const char *file, int line, VasEBoot_size_t size); void EXPORT_FUNC(VasEBoot_debug_free) (const char *file, int line, void *ptr); void *EXPORT_FUNC(VasEBoot_debug_realloc) (const char *file, int line, void *ptr, VasEBoot_size_t size); void *EXPORT_FUNC(VasEBoot_debug_memalign) (const char *file, int line, VasEBoot_size_t align, VasEBoot_size_t size); #endif /* MM_DEBUG && ! VAS_EBOOT_UTIL */ #endif /* ! VAS_EBOOT_MM_H */