* Resize allocated memory on specified heap. */
| 162 | * Resize allocated memory on specified heap. |
| 163 | */ |
| 164 | void * |
| 165 | rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket) |
| 166 | { |
| 167 | size_t user_size; |
| 168 | |
| 169 | if (ptr == NULL) |
| 170 | return rte_malloc_socket(NULL, size, align, socket); |
| 171 | |
| 172 | struct malloc_elem *elem = malloc_elem_from_data(ptr); |
| 173 | if (elem == NULL) { |
| 174 | RTE_LOG(ERR, EAL, "Error: memory corruption detected\n"); |
| 175 | return NULL; |
| 176 | } |
| 177 | |
| 178 | user_size = size; |
| 179 | |
| 180 | size = RTE_CACHE_LINE_ROUNDUP(size), align = RTE_CACHE_LINE_ROUNDUP(align); |
| 181 | |
| 182 | /* check requested socket id and alignment matches first, and if ok, |
| 183 | * see if we can resize block |
| 184 | */ |
| 185 | if ((socket == SOCKET_ID_ANY || |
| 186 | (unsigned int)socket == elem->heap->socket_id) && |
| 187 | RTE_PTR_ALIGN(ptr, align) == ptr && |
| 188 | malloc_heap_resize(elem, size) == 0) { |
| 189 | rte_eal_trace_mem_realloc(size, align, socket, ptr); |
| 190 | |
| 191 | asan_set_redzone(elem, user_size); |
| 192 | |
| 193 | return ptr; |
| 194 | } |
| 195 | |
| 196 | /* either requested socket id doesn't match, alignment is off |
| 197 | * or we have no room to expand, |
| 198 | * so move the data. |
| 199 | */ |
| 200 | void *new_ptr = rte_malloc_socket(NULL, size, align, socket); |
| 201 | if (new_ptr == NULL) |
| 202 | return NULL; |
| 203 | /* elem: |pad|data_elem|data|trailer| */ |
| 204 | const size_t old_size = old_malloc_size(elem); |
| 205 | rte_memcpy(new_ptr, ptr, old_size < size ? old_size : size); |
| 206 | rte_free(ptr); |
| 207 | |
| 208 | rte_eal_trace_mem_realloc(size, align, socket, new_ptr); |
| 209 | return new_ptr; |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * Resize allocated memory. |