/* * Copyright 2011 Institute of Communication and Computer Systems (ICCS) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include "block_header.h" #include "other.h" #include "split.h" #include "dmm_config.h" void split(allocator_t *allocator, heap_t *heap, void *ptr, size_t req_size) { void *new_block; int fixed_list_id, i; size_t new_block_size; maptable_node_t *current_maptable_node; new_block = (void *) ((char *) ptr + req_size + HEADER_SIZE); new_block_size = get_size(ptr) - req_size - HEADER_SIZE; /* Resize the previous, to be used block */ set_size_and_used(ptr, req_size); set_size_and_free(new_block, new_block_size); set_previous_size_availability(new_block, get_size_availability(ptr)); #ifdef WITH_FIXED_LISTS /* FIXME code from custom_free, some refactoring maybe? * Be careful, custom_free also does coalescing, we don't need that */ /* Check if the block could be put in a fixed list */ fixed_list_id = map_size_to_list(heap, new_block_size); if(fixed_list_id != -1) { /* put it in the right fixed list */ current_maptable_node = heap->maptable_head; if(fixed_list_id != 0) { for(i = 1; i < fixed_list_id; i++) { current_maptable_node = current_maptable_node->next; } } push_block(&new_block, ¤t_maptable_node->fixed_list_head); } else { /* put it in the free list */ #endif /* WITH_FIXED_LISTS */ push_block(&new_block, &heap->free_list_head); #ifdef WITH_FIXED_LISTS } #endif /* WITH_FIXED_LISTS */ #ifdef WITH_OWNERSHIP set_owner(new_block, heap); #endif /* WITH_OWNERSHIP */ if(allocator->border_ptr == ptr) { allocator->border_ptr = new_block; } }