1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /*
- * Copyright 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.
- *
- */
- /**
- * @file realloc.c
- * @author Ioannis Koutras (joko@microlab.ntua.gr)
- * @date September 2012
- *
- * @brief Implementation of realloc() call.
- */
- #include "dmmlib/dmmlib.h"
- #include <stdbool.h>
- #ifdef BITMAP_RB_ONLY
- #include "bitmap/bitmap.h"
- #include "bitmap/bitmap_rb.h"
- #endif /* BITMAP_RB_ONLY */
- #include "release_memory.h"
- void * realloc(void *ptr, size_t size) {
- raw_block_header_t *current_raw_block;
- bool found;
- if(ptr == NULL) {
- return malloc(size);
- }
- if(size == 0) {
- free(ptr);
- #ifdef BITMAP_RB_ONLY
- return malloc(CHUNK_HDR_SIZE + 32); // FIXME 32 <- minimum size
- #endif /* BITMAP_RB_ONLY */
- #ifdef FL_RB_ONLY
- return malloc((size_t) 32); // FIXME 32 <- minimum size
- #endif /* FL_RB_ONLY */
- }
- found = false;
- current_raw_block = systemallocator.raw_block_head;
- while(current_raw_block) {
- if(((char *)ptr > (char *)current_raw_block) &&
- ((char *)ptr < (char *)(current_raw_block) +
- current_raw_block->size)) {
- found = true;
- break;
- }
- current_raw_block = current_raw_block->next_raw_block;
- }
- if(found == true) {
- #ifdef BITMAP_RB_ONLY
- bitmap_rb_t *bitmap_rb;
- bitmap_rb = (bitmap_rb_t *)((char *)current_raw_block +
- sizeof(raw_block_header_t));
- return bitmap_realloc(bitmap_rb, ptr, size);
- #endif /* BITMAP_RB_ONLY */
- #ifdef FL_RB_ONLY
- return freelist_realloc(current_raw_block, ptr, size);
- #endif /* FL_RB_ONLY */
- } else {
- return NULL; // FIXME what about big blocks?
- }
- }
|