|
iPXE
|
Dynamic memory allocation. More...
#include <stdint.h>#include <stdlib.h>#include <ipxe/list.h>#include <ipxe/tables.h>#include <valgrind/memcheck.h>Go to the source code of this file.
Data Structures | |
| struct | heap |
| A heap. More... | |
| struct | cache_discarder |
| A cache discarder. More... | |
Macros | |
| #define | NOWHERE ( ( void * ) ~( ( intptr_t ) 0 ) ) |
| Address for zero-length memory blocks. More... | |
| #define | CACHE_DISCARDERS __table ( struct cache_discarder, "cache_discarders" ) |
| Cache discarder table. More... | |
| #define | __cache_discarder(cost) __table_entry ( CACHE_DISCARDERS, cost ) |
| Declare a cache discarder. More... | |
| #define | CACHE_CHEAP 01 |
| Items with a low replacement cost. More... | |
| #define | CACHE_NORMAL 02 |
| Items with a normal replacement cost. More... | |
| #define | CACHE_EXPENSIVE 03 |
| Items with a high replacement cost. More... | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| void * | heap_realloc (struct heap *heap, void *old_ptr, size_t new_size) |
| Reallocate memory. More... | |
| void | heap_dump (struct heap *heap) |
| Dump free block list (for debugging) More... | |
| void | heap_populate (struct heap *heap, void *start, size_t len) |
| Add memory to allocation pool. More... | |
| void *__malloc | malloc_phys_offset (size_t size, size_t phys_align, size_t offset) |
| Allocate memory with specified physical alignment and offset. More... | |
| void *__malloc | malloc_phys (size_t size, size_t phys_align) |
| Allocate memory with specified physical alignment. More... | |
| void | free_phys (void *ptr, size_t size) |
| Free memory allocated with malloc_phys() More... | |
Variables | |
| struct heap | __attribute__ |
Dynamic memory allocation.
Definition in file malloc.h.
| #define NOWHERE ( ( void * ) ~( ( intptr_t ) 0 ) ) |
Address for zero-length memory blocks.
malloc(0) or realloc(ptr,0) will return the special value NOWHERE. Calling free(NOWHERE) will have no effect.
This is consistent with the ANSI C standards, which state that "either NULL or a pointer suitable to be passed to free()" must be returned in these cases. Using a special non-NULL value means that the caller can take a NULL return value to indicate failure, without first having to check for a requested size of zero.
Code outside of the memory allocators themselves does not ever need to refer to the actual value of NOWHERE; this is an internal definition.
| #define CACHE_DISCARDERS __table ( struct cache_discarder, "cache_discarders" ) |
| #define __cache_discarder | ( | cost | ) | __table_entry ( CACHE_DISCARDERS, cost ) |
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
Reallocate memory.
| heap | Heap |
| old_ptr | Memory previously allocated by heap_realloc(), or NULL |
| new_size | Requested size |
| new_ptr | Allocated memory, or NULL |
Allocates memory with no particular alignment requirement. new_ptr will be aligned to at least a multiple of sizeof(void*). If old_ptr is non-NULL, then the contents of the newly allocated memory will be the same as the contents of the previously allocated memory, up to the minimum of the old and new sizes. The old memory will be freed.
If allocation fails the previously allocated block is left untouched and NULL is returned.
Calling heap_realloc() with a new size of zero is a valid way to free a memory block.
Definition at line 536 of file malloc.c.
References assert(), ASSERTED, container_of, data, autosized_block::data, DBGC, heap_alloc_block(), heap_free_block(), memcpy(), NOWHERE, NULL, offset, offsetof, heap::ptr_align, autosized_block::size, VALGRIND_FREELIKE_BLOCK, VALGRIND_MAKE_MEM_DEFINED, VALGRIND_MAKE_MEM_NOACCESS, and VALGRIND_MALLOCLIKE_BLOCK.
Referenced by realloc(), and uheap_realloc().
| void heap_dump | ( | struct heap * | heap | ) |
Dump free block list (for debugging)
Definition at line 792 of file malloc.c.
References block, heap::blocks, dbg_printf(), memory_block::list, and list_for_each_entry.
Add memory to allocation pool.
| heap | Heap |
| start | Start address |
| len | Length of memory |
Adds a block of memory to the allocation pool. The memory must be aligned to the heap's required free memory block alignment.
Definition at line 738 of file malloc.c.
References heap::align, assert(), heap_free_block(), len, start, and heap::usedmem.
Referenced by init_heap(), and uheap_grow().
Allocate memory with specified physical alignment and offset.
| size | Requested size |
| align | Physical alignment |
| offset | Offset from physical alignment |
| ptr | Memory, or NULL |
align must be a power of two. size may not be zero.
Definition at line 684 of file malloc.c.
References assert(), heap_alloc_block(), offset, size, and VALGRIND_MALLOCLIKE_BLOCK.
Referenced by alloc_iob_raw(), and malloc_phys().
Allocate memory with specified physical alignment.
| size | Requested size |
| align | Physical alignment |
| ptr | Memory, or NULL |
align must be a power of two. size may not be zero.
Definition at line 706 of file malloc.c.
References malloc_phys_offset(), and size.
Referenced by __vxge_hw_fifo_create(), __vxge_hw_ring_create(), a3c90x_setup_rx_ring(), a3c90x_setup_tx_ring(), arbel_alloc(), arbel_alloc_icm(), arbel_create_cq(), arbel_create_eq(), arbel_create_recv_wq(), arbel_create_send_wq(), ath5k_desc_alloc(), ath_descdma_setup(), atl1e_setup_ring_resources(), b44_init_rx_ring(), b44_init_tx_ring(), efx_hunt_alloc_special_buffer(), ehci_bus_open(), ehci_ring_alloc(), ena_create_admin(), ena_create_async(), ena_create_cq(), ena_create_sq(), ena_probe(), exanic_probe(), falcon_alloc_special_buffer(), golan_cmd_init(), golan_create_cq(), golan_create_eq(), golan_create_qp_aux(), hermon_alloc(), hermon_create_cq(), hermon_create_eq(), hermon_create_qp(), hv_alloc_message(), hv_alloc_pages(), hvm_map_hypercall(), icplus_create_ring(), ifec_net_open(), ifec_tx_setup(), igbvf_setup_rx_resources(), igbvf_setup_tx_resources(), jme_alloc_rx_resources(), jme_alloc_tx_resources(), legacy_probe(), linda_create_recv_wq(), linda_init_send(), mlx_memory_alloc_dma_priv(), myri10ge_net_open(), myson_create_ring(), natsemi_create_ring(), netfront_create_ring(), nv_init_rings(), pcnet32_setup_rx_resources(), pcnet32_setup_tx_resources(), phantom_create_rx_ctx(), phantom_create_tx_ctx(), phantom_open(), qib7322_create_recv_wq(), qib7322_init_send(), rhine_create_ring(), rtl818x_init_rx_ring(), rtl818x_init_tx_ring(), sis190_open(), skge_up(), sky2_probe(), sky2_up(), tg3_alloc_consistent(), tg3_test_dma(), uhci_bus_open(), uhci_enqueue(), uhci_ring_alloc(), velocity_alloc_rings(), vmbus_open(), and vmxnet3_open().
| void free_phys | ( | void * | ptr, |
| size_t | size | ||
| ) |
Free memory allocated with malloc_phys()
| ptr | Memory allocated by malloc_phys(), or NULL |
| size | Size of memory, as passed to malloc_phys() |
Memory allocated with malloc_phys() can only be freed with free_phys(); it cannot be freed with the standard free().
If ptr is NULL, no action is taken.
Definition at line 722 of file malloc.c.
References heap_free_block(), size, and VALGRIND_FREELIKE_BLOCK.
Referenced by __vxge_hw_fifo_delete(), __vxge_hw_ring_delete(), a3c90x_free_rx_ring(), a3c90x_free_tx_ring(), alloc_iob_raw(), arbel_alloc(), arbel_alloc_icm(), arbel_create_cq(), arbel_create_eq(), arbel_create_qp(), arbel_create_recv_wq(), arbel_destroy_cq(), arbel_destroy_eq(), arbel_destroy_qp(), arbel_free(), arbel_free_icm(), ath5k_desc_alloc(), ath5k_desc_free(), ath_descdma_cleanup(), ath_descdma_setup(), atl1e_free_ring_resources(), b44_free_rx_ring(), b44_free_tx_ring(), b44_init_rx_ring(), b44_init_tx_ring(), efx_hunt_free_special_buffer(), ehci_bus_close(), ehci_bus_open(), ehci_ring_alloc(), ehci_ring_free(), ena_create_admin(), ena_create_async(), ena_create_cq(), ena_create_sq(), ena_destroy_admin(), ena_destroy_async(), ena_destroy_cq(), ena_destroy_sq(), ena_probe(), ena_remove(), exanic_probe(), exanic_remove(), falcon_free_special_buffer(), free_iob(), golan_cmd_init(), golan_cmd_uninit(), golan_create_cq(), golan_create_eq(), golan_create_qp_aux(), golan_destory_eq(), golan_destroy_cq(), golan_destroy_qp(), hermon_alloc(), hermon_create_cq(), hermon_create_eq(), hermon_create_qp(), hermon_destroy_cq(), hermon_destroy_eq(), hermon_destroy_qp(), hermon_free(), hv_alloc_pages(), hv_free_message(), hv_free_pages(), hvm_unmap_hypercall(), icplus_create_ring(), icplus_destroy_ring(), ifec_free(), ifec_net_open(), igbvf_free_rx_resources(), igbvf_free_tx_resources(), jme_free_rx_resources(), jme_free_tx_resources(), legacy_probe(), legacy_remove(), linda_create_recv_wq(), linda_destroy_recv_wq(), linda_fini_send(), linda_init_send(), mlx_memory_free_dma_priv(), myri10ge_net_close(), myri10ge_net_open(), myson_create_ring(), myson_destroy_ring(), natsemi_create_ring(), natsemi_destroy_ring(), netfront_create_ring(), netfront_destroy_ring(), nv_free_rxtx_resources(), pcnet32_free_rx_resources(), pcnet32_free_tx_resources(), phantom_close(), phantom_create_rx_ctx(), phantom_create_tx_ctx(), phantom_open(), qib7322_create_recv_wq(), qib7322_destroy_recv_wq(), qib7322_fini_send(), qib7322_init_send(), rhine_destroy_ring(), rtl818x_free_rx_ring(), rtl818x_free_tx_ring(), sis190_free(), skge_free(), sky2_free_rings(), sky2_probe(), sky2_remove(), tg3_free_consistent(), tg3_rx_prodring_fini(), tg3_test_dma(), uhci_bus_close(), uhci_bus_open(), uhci_dequeue(), uhci_enqueue(), uhci_ring_alloc(), uhci_ring_free(), velocity_alloc_rings(), velocity_close(), vmbus_close(), vmbus_open(), vmxnet3_close(), and vmxnet3_open().
| struct heap __attribute__ |
1.8.15