Beispiel #1
0
/* 
 * Requires:
 *   None.
 *
 * Effects:
 *   Perform a minimal check of the heap for consistency. 
 */
void
checkheap(bool verbose) 
{
  void *bp;

  if (verbose)
    printf("Heap (%p):\n", heap_listp);

  if (GET_SIZE(HDRP(heap_listp)) != DSIZE ||
      !GET_ALLOC(HDRP(heap_listp)))
    printf("Bad prologue header\n");
  checkblock(heap_listp);

  for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = (void *)NEXT_BLKP(bp)) {
    if (verbose)
      printblock(bp);
    checkblock(bp);
  }

  if (verbose)
    printblock(bp);
  if (GET_SIZE(HDRP(bp)) != 0 || !GET_ALLOC(HDRP(bp)))
    printf("Bad epilogue header\n");

in_heap(bp);
check_coalescing();
check_free_list();
check_free_blocks();
}
//check heap
static int check_my_heap(int verbose){
	if (!verbose){
		return 0;
	}
	else {
		printf("Heap (%p):\n", heap_listp);
		void *bp;
		if ((GET_SIZE(HDRP(heap_listp)) != DSIZE) || !GET_ALLOC(HDRP(heap_listp))){
			printf("Bad prologue header\n");
			return 1;
		}
		if (checkblock(heap_listp)){
			return 1;
		}

		for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
			printblock(bp);
			if (checkblock(bp)){
				return 1;
			}
		}

		if (verbose)
			printblock(bp);
		if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp)))){
			printf("Bad epilogue header\n");
			return 1;
		}
	}
	return 0;
}
Beispiel #3
0
/*
 * checkheap - functions with multiple checks
 */
int mm_checkheap(int verbose)
{

	char *bp = heap_list_head;

	if (verbose)
	{
		printf("Heap (%p):\n", heap_list_head);
		//printf("Free List (%p):\n", free_list_head);
	}

	if ((GET_SIZE(HDRP(heap_header)) != HEADER_SIZE)
			|| !GET_ALLOC(HDRP(heap_header)))
	{
		//printf("Bad prologue header\n");
		//return 1;
	}
	checkblock(heap_list_head);
	for (bp = heap_list_head; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp))
	{
		if (verbose)
			printblock(bp);
		checkblock(bp);
	}
	if (verbose)
		printblock(bp);
	if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp))))
	{
		printf("Bad epilogue header\n");
		//return 1;
	}

	return 0;
}
Beispiel #4
0
/* 
 * Requires:
 *   None.
 *
 * Effects:
 *   Perform a minimal check of the heap for consistency. 
 */
void
checkheap(bool verbose) 
{
	void *bp;

	if (verbose)
		printf("Heap (%p):\n", heap_listp);

	if (GET_SIZE(HDRP(heap_listp)) != DSIZE)
		printf("Bad prologue header: size\n");
	if (!GET_ALLOC(HDRP(heap_listp)))
		printf("Bad prologue header: alloc\n");
	checkblock(heap_listp);

	for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
		if (verbose)
			printblock(bp);
		checkblock(bp);
	}

	if (verbose)
		printblock(bp);
	if (GET_SIZE(HDRP(bp)) != 0)
		printf("Bad epilogue header: size\n");
	if (!GET_ALLOC(HDRP(bp)))
		printf("Bad epilogue header: alloc\n");
}
Beispiel #5
0
/*
 * Requires:
 *   None.
 *
 * Effects:
 *   Perform a minimal check of the heap for consistency.
 */
void
checkheap(bool verbose)
{
    void *bp;

    if (verbose)
        printf("Heap (%p):\n", heap_listp);

    if (GET_SIZE(HDRP(heap_listp)) != DSIZE ||
        !GET_ALLOC(HDRP(heap_listp)))
        printf("Bad prologue header\n");
    checkblock(heap_listp);

    for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
        if (verbose)
            printblock(bp);
        checkblock(bp);
    }

    if (verbose)
        printblock(bp);
    if (GET_SIZE(HDRP(bp)) != 0 || !GET_ALLOC(HDRP(bp)))
        printf("Bad epilogue header\n");

	 check_is_next_ptr_pointing_to_free(bp);
	 
	 check_contigous(bp);

     check_freelist_freeblock(bp);
}
Beispiel #6
0
/*
 * mm_checkheap - Check the heap for consistency
 */
void mm_checkheap(int verbose)
{
    char *bp = heap_listp;

    if (verbose) {
        printf("Heap (%p):\n", heap_listp);
        printf("Root (%p):\n", tree_root);
    }

    if ((GET_SIZE(HDRP(heap_listp)) != DSIZE) || !GET_ALLOC(HDRP(heap_listp)))
        printf("Bad prologue header\n");

    checkblock(heap_listp);

    for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
        if (verbose)
            printblock(bp);

        checkblock(bp);
    }

    if (verbose)
        printblock(bp);

    if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp))))
        printf("Bad epilogue header\n");
}
//
// mm_checkheap - Check the heap for consistency 
//
void mm_checkheap(int verbose) 
{
  //
  // This provided implementation assumes you're using the structure
  // of the sample solution in the text. If not, omit this code
  // and provide your own mm_checkheap
  //
  void *bp = heap_listp;
  
  if (verbose) {
    printf("Heap (%p):\n", heap_listp);
  }

  if ((GET_SIZE(HDRP(heap_listp)) != DSIZE) || !GET_ALLOC(HDRP(heap_listp))) {
	printf("Bad prologue header\n");
  }
  checkblock(heap_listp);

  for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
    if (verbose)  {
      printblock(bp);
    }
    checkblock(bp);
  }
     
  if (verbose) {
    printblock(bp);
  }

  if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp)))) {
    printf("Bad epilogue header\n");
  }
}
Beispiel #8
0
// Returns 0 if no errors were found, otherwise returns the error
int mm_checkheap(int verbose) {
  // char *bp = heap_listp;

  if (verbose)
    printf("Heap (%p):\n", heap_listp);

  if ((GET_SIZE(HDRP(heap_listp)) != DSIZE) || !GET_ALLOC(HDRP(heap_listp)))
    printf("Bad prologue header\n");
  checkblock(heap_listp);

  void* list;
  int count_free_in_list = 0;
  int count_free_in_heap = 0;
  for (int i =0; i < 9; i++)
    {
      for (list = (void*)(*(long*)GET_BUCKET(root,i)); list != NULL;
           list =  get_succ(list)  ) {
        if (verbose)
          printblock(list);
        checkblock(list);
        if ( get_succ(list) != NULL && get_pred(list) !=NULL)
          check_succ_pred(list);
        check_address(list);
        count_free_in_list++;
        check_in_correct_bucket(list, i);
      }
    }

  char *bp;

  for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
    if (verbose)
      {
        if (GET_ALLOC(HDRP(bp)) == 0)
          count_free_in_heap ++;
        printblock(bp);
        checkblock(bp);
        check_coalescing( (void*)bp);
      }
  }

  if (count_free_in_heap != count_free_in_list)
    printf ("Number of free block not consistent in heap and list list \n");

  if (verbose)
    printblock(bp);
    if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp))))
      {
        printf("Bad epilogue header\n");
        if (GET_SIZE(HDRP(bp)) != 0)
          printf ("size is not 0\n");
        if (!(GET_ALLOC(HDRP(bp))) )
           printf ("not allocated properly\n");
     }
    return 0;
}
Beispiel #9
0
/*
 * checkheap - Check the heap for consistency
 * (iterates all the blocks starting from prologue to epilogue) 
 * 
 */
void _checkheap(void)
{
	char *bp = heap_listp;
	size_t prev_alloc, curr_alloc;
	

	dbg1("\n[CHECK HEAP]\n");
	dbg1("\n[verbose=%d]\n", verbose);

	if (verbose) {
		printf("Heap (starting address:%p):\n", heap_listp);
		printf("-prologue-");
		printblock(bp);
	}

	/* checking prologue block (size, allocate bit) */
	if ((GET_SIZE(HDRP(heap_listp)) != DSIZE) || !GET_ALLOC(HDRP(heap_listp))) {
		printf("Bad prologue header\n");
		printf("-prologue-");
		printblock(bp);
	}
	checkblock(heap_listp);             /* alignment, header/footer */
	prev_alloc = GET_ALLOC(HDRP(bp));
	
	/* checking allocated/free blocks */
	for (bp = NEXT_BLKP(heap_listp); GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
		curr_alloc = GET_PREV_ALLOC(HDRP(bp));
		if (verbose)
			printblock(bp);
		if (!prev_alloc != !curr_alloc) {
			/* previous block's allocate bit should match current block's prev allocate bit */
			printf("prev allocate bit mismatch\n");
			printblock(bp);
			exit(0);
		}
		prev_alloc = GET_ALLOC(HDRP(bp));
		checkblock(bp);
	}
	printf("done\n");

	/* checking epilouge block */
	if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp)))){
		printf("Bad epilogue header\n");
		printf("-epilogue-");
		printblock(bp);
	}

	checklist();
	
	dbg1("[CHECK DONE]\n\n");
}
Beispiel #10
0
/*
 * mm_checkheap - Check the heap for consistency
 */
void mm_checkheap(int verbose)
{
    if (verbose)
        printf("Check heap: \n");
    char *bp = heap_listp;
    int free_block_flag = 0;
    int free_block_count = 0;
    
    if (verbose)
        printf("Heap (%p):\n", heap_listp);
    
    // check prologue block
    if ((GET_SIZE(HDRP(heap_listp)) != OVERHEAD) || !GET_ALLOC(HDRP(heap_listp)))
        printf("Bad prologue header\n");
    checkblock(heap_listp);
    
    for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
        if (verbose)
            printblock(bp);
        checkblock(bp);
        
        // check coalescing
        if (!GET_ALLOC(HDRP(bp))) {
            if (free_block_flag == 1) {
                printf("Error: consecutive free blocks %p | %p in the heap.\n", PREV_BLKP(bp),bp);
            }
            free_block_flag = 1;
            free_block_count++;
        } else {
            free_block_flag = 0;
        }
        
    }
    
    if (verbose)
        printblock(bp);
    
    // check epilogue block
    if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp))))
        printf("Bad epilogue header\n");
    
    // print heap boundaries
    check_heapboundaries(heap_listp-DSIZE, bp-1);

    if (verbose) {
        printfreelist();
    }
    checkfreelist(free_block_count);
}
Beispiel #11
0
/**
 * print_all - Prints every block in the heap structure
 */
void print_all()
{
    void *bp;
    for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
           printblock(bp);
    }
}
Beispiel #12
0
/*
 * place - Place block of asize bytes at start of free block bp
 *		 and split if remainder would be at least minimum block size
 */
static void place(block_ptr bp, size_t asize)
{
	size_t csize = GET_SIZE(HDRP(bp)), delta = csize - asize;

	if (delta >= (2 * DSIZE))
	{
		PUT(HDRP(bp), PACK(asize, 1));
		PUT(FTRP(bp), PACK(asize, 1));
		SET_ALLOC(bp);
		bp = NEXT_BLKP(bp);
		PUT(HDRP(bp), PACK(delta, 0));
		PUT(FTRP(bp), PACK(delta, 0));
		SET_UNALLOC(bp);
		reset_block(bp);
		insert_free_block(bp, delta);
#ifdef DEBUG
		{
			printf("Block with size %zu remains a block:\n", asize);
			printblock(bp);
		}
#endif
	}
	else
	{
		PUT(HDRP(bp), PACK(csize, 1));
		PUT(FTRP(bp), PACK(csize, 1));
		SET_ALLOC(bp);
	}
}
Beispiel #13
0
/*
 * Initialize: return -1 on error, 0 on success.
 */
int mm_init(void)
{
	/* Create the initial empty heap */
	if ((bins = mem_sbrk(
		ALIGN(fixed_bin_count * sizeof(block_ptr)) +
		4 * WSIZE)) == (block_ptr)-1)
		return -1;
	memset(bins, 0, fixed_bin_count * sizeof(block_ptr));
	heap_listp = (char *)ALIGN((unsigned long)(bins + fixed_bin_count));
	larger_bin_root = NULL;
	PUTTRUNC(heap_listp, 0);							/* Alignment padding */
	PUTTRUNC(heap_listp + (1 * WSIZE), PACK(DSIZE, 1)); /* Prologue header */
	PUTTRUNC(heap_listp + (2 * WSIZE), PACK(DSIZE, 1)); /* Prologue footer */
	PUTTRUNC(heap_listp + (3 * WSIZE), PACK(0, 1));		/* Epilogue header */
	heap_listp += (2 * WSIZE);
	SET_ALLOC(heap_listp);
#ifdef DEBUG
	{
		printblock(heap_listp);
		checkblock(heap_listp);
	}
	operid = 0;
#endif
	return 0;
}
Beispiel #14
0
/* dump out a Paragraph in the desired manner
 */
static Paragraph*
display(Paragraph *p, MMIOT *f)
{
    if ( !p ) return 0;
    
    switch ( p->typ ) {
    case STYLE:
    case WHITESPACE:
	break;

    case HTML:
	printhtml(p->text, f);
	break;
	
    case CODE:
	printcode(p->text, f);
	break;
	
    case QUOTE:
	htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f);
	break;
	
    case UL:
    case OL:
    case AL:
	listdisplay(p->typ, p->down, f);
	break;

#if DL_TAG_EXTENSION
    case DL:
	definitionlist(p->down, f);
	break;
#endif

    case HR:
	Qstring("<hr />", f);
	break;

    case HDR:
	printheader(p, f);
	break;

    case TABLE:
	printtable(p, f);
	break;

    case SOURCE:
	htmlify(p->down, 0, 0, f);
	break;
	
    default:
	printblock(p, f);
	break;
    }
    return p->next;
}
Beispiel #15
0
void printlist(int i) {

		void *bp = GET_FREE_LISTP(i);
		
		printf("[freelist(%d)] printing...\n", i);
		for(;bp != NULL; bp = NEXT_FREE_BLKP(bp))
			printblock(bp);
		printf("[freelist(%d)] end of list\n", i);

}
Beispiel #16
0
/* 
 * mm_checkheap - Check the heap for consistency 
 */
void mm_checkheap(int verbose) 
{
	//printf("************ CHECK BEGIN ***************\n");
    char *bp = heap_listp;
	char *checkAll = heap_listp;
	int countblocks = -1;

    if (verbose) {
        printf("Heap: (%p)\n", heap_listp);
    }

    if ((GET_SIZE(HDRP(heap_listp)) != OVERHEAD) || !GET_ALLOC(HDRP(heap_listp))) {
        printf("Bad prologue header\n");
    }
    checkblock(heap_listp);
	
	
	 while(GET(SUCC(bp)) != 0){
		if(verbose == 1)
		 	printblock(bp);
		checkblock(bp);
		//countblocks++;
		bp = (char*)GET(SUCC(bp));
	}
	 if(verbose == 1)
		 printblock(bp);

    for (checkAll = heap_listp; GET_SIZE(HDRP(checkAll)) > 0; checkAll = NEXT_BLKP(checkAll)) {
		if(!GET_ALLOC(HDRP(checkAll)) && !block_in_free_list(checkAll)){
			printf("Block is marked free but not in free list\n");		
		}
        checkblock(checkAll);
		countblocks++;
    }

	//printf("Number of free blocks: %d\n", freeblockcount);
	//printf("Total number of blocks: %d\n", countblocks);
    
    if ((GET_SIZE(HDRP(checkAll)) != 0) || !(GET_ALLOC(HDRP(checkAll)))) {
        printf("Bad epilogue header\n");
    }
	//printf("****************** CHECK END ********************\n");
}
Beispiel #17
0
/*
     * checkheap
     * Check the consistency of the memory heap
     * Return nonzero if the heap is consistant.
     */
 void checkheap(bool verbose){

        int i;
        void *bp;  

        for(i = 0; i < TOTAL_LISTS; i++) {
            bp = free_listp[i];       
  
            while (bp) {                       
                      //Checking for a allocated block in free list

                if (GET_ALLOC(HDRP(bp)) == 1 || GET_ALLOC(FTRP(bp)) == 1){
                        printf("Found a allocated block in %dth freelist\n",i);

                        return;
                }     
                bp  = getNext(bp);
            }
        }

            if (verbose)
	            printf("Heap (%p):\n", heaplistp);

            if (GET_SIZE(HDRP(heaplistp)) != DSIZE ||!GET_ALLOC(HDRP(heaplistp)))
                    printf("Bad prologue header\n");

            checkblock(heaplistp);

            for (bp = heaplistp; GET_SIZE(HDRP(bp)) > 0; bp = (void *)NEXT_BLKP(bp)) {

	        if (verbose)
          	      printblock(bp);

                checkblock(bp);
        }
            if (verbose)
		printblock(bp);

            if (GET_SIZE(HDRP(bp)) != 0 || !GET_ALLOC(HDRP(bp)))
           	printf("Bad epilogue header\n");
    }
Beispiel #18
0
/*This is to check if there are any free blocks that missed the coalescing and end up in the free list as two different blocks */
static void
check_coalescing(){

void *bp;
void *temp;

  for (bp = list_head; bp != NULL; bp = GET_NEXTP(bp) ){
  	for (temp = list_head; temp != NULL; temp = GET_NEXTP(temp))
  	{
  		/* code */
  		if(NEXT_BLKP(bp) == temp)
  		{
  			printf("ERROR: A block missed during Coalescing.");
  			printblock(bp);
  			printblock(temp);
  		}
  	}
  }


}
Beispiel #19
0
/**
 * print_free - Prints all segregated free lists
 */
void print_free()
{
    void *bp;
    for(int i=0; i<NO_OF_LISTS;i++) {
        dbg_printf("List No: %d",i);
        bp = GET_SEGI(seg_list,i);
        while(bp != NULL && GET_SIZE(HDRP(bp)) > 0) {       
            printblock(bp);
            bp = GET_NEXTP(bp);
        }
    }
}
Beispiel #20
0
/* This is to check if there are any allocated blocks in the free blocks! */
static void
check_free_list(){

  void *bp;
  for (bp = list_head; bp != NULL; bp = GET_NEXTP(bp) ){
    if (GET_ALLOC(bp)) {
      printf("ERROR: allocated block in free list!\n");
      printblock(bp);
    }
  }

}
Beispiel #21
0
/*=========================================
 * check_keys -- Validate keys of index or block
 * Created: 2003/09/05, Perry Rapp
 *=======================================*/
static BOOLEAN
check_keys (BLOCK block, RKEY * lo, RKEY * hi)
{
    INT n = nkeys(block);
    INT i = 0;
    INT start = 0;
    BOOLEAN ok = TRUE;
    if (ixtype(block) == BTINDEXTYPE)
        ++start; /* keys are 1..n for index */
    else
        --n; /* keys are 0..n-1 for block */
    for (i=start ; i <= n; i++) {
        if (i==start && lo) {
            INT rel = cmpkeys(lo, &rkeys(block, i));
            if (rel < 0) {
                printf(_("First key in block below parent's limit\n"));
                printblock(block);
                ok = FALSE;
            }
        }
        if (i==n && hi) {
            INT rel = cmpkeys(&rkeys(block, i), hi);
            if (rel > 0) {
                printf(_("Last key in block above parent's limit\n"));
                printblock(block);
                ok = FALSE;
            }
        }
        if (i<n) {
            INT rel = cmpkeys(&rkeys(block, i), &rkeys(block, i+1));
            if (rel >= 0) {
                printf(_("Key not below next key"));
                printf(": %ld\n", i);
                printblock(block);
                ok = FALSE;
            }
        }
    }
    return ok;
}
Beispiel #22
0
void unpack_block(FILE *f, scan_desc_t *scan_desc, uint32_t index, 
		  int32_t T[_BSIZE])
{
	printdecod("Start unpack_block #%u (index = %u)\n",calls_count,index);
	assert(feof(f) == 0);
	huff_table_t *DC = scan_desc->table[0][index];
	huff_table_t *AC = scan_desc->table[1][index];
	if (DC == NULL || AC == NULL) {
		printf("\n** ERREUR: Table de Huffman absente **\n");
	}
	assert(DC != NULL);
	assert(AC != NULL);
	/* decodage du coefficient DC */
	uint8_t magnitude = read_symbol(f,scan_desc,DC);
	int32_t offset = read_value(f,scan_desc,magnitude);
	T[0] = scan_desc->pred[index] + offset;
	scan_desc->pred[index] = T[0];
	/* decodage des coefficients AC */
	uint8_t symbol;
	uint8_t nb_zero;
	uint32_t i = 1;
	while (i < 64) {
		symbol = read_symbol(f,scan_desc,AC);
		if (symbol == 0xf0) {        /* ZRL */
			for (uint32_t j = 0; j < 16; j++) {
				T[i] = 0;
				i++;
			}	
		} else if (symbol == 0x00) { /* EOB */
			while (i < 64) {
				T[i] = 0;
				i++;
			}
		} else {                     /* symbole normal */
			magnitude = symbol % 16;
			nb_zero = symbol >> 4;
			printdecod("=> sym: %u   mag: %u  nb_zero: %u\n",symbol,
			   magnitude,nb_zero);
			for (uint32_t j = 0; j < nb_zero; j++) {
				T[i] = 0;
				i++;
			}
			T[i] = read_value(f,scan_desc,magnitude);
			i++;
		}
	}
	printdecod("\n");
	printblock(T);
	calls_count++;
}
Beispiel #23
0
/*
 * malloc
 */
block_ptr malloc(size_t size)
{
	size_t asize;      /* Adjusted block size */
	size_t extendsize; /* Amount to extend heap if no fit */
	char *bp;

	if (heap_listp == 0)
	{
		mm_init();
	}

	/* Ignore spurious requests */
	if (size == 0)
		return NULL;


	/* Adjust block size to include overhead and alignment reqs. */
	if (size <= DSIZE)
		asize = 2 * DSIZE;
	else
		asize = DSIZE * ((size + (WSIZE) + (DSIZE - 1)) / DSIZE);

#ifdef DEBUG
	printf("\nMalloc request: size = %zu, rounded to %zu \033[41;37m[ID:%d]\033[0m\n", size, asize, operid++);
#endif

	/* Search the free list for a fit */
	if ((bp = find_fit(asize)) != NULL)
	{
#ifdef DEBUG
		{
			puts("Found fit!");
			checkblock(bp);
			printblock(bp);
		}
#endif
		place(bp, asize);
		return bp;
	}

	/* No fit found. Get more memory and place the block */
	extendsize = MAX(asize, BLOCKSIZE);
	if ((bp = extend_heap(extendsize / WSIZE)) == NULL)
		return NULL;
	place(bp, asize);
	return bp;
}
Beispiel #24
0
/*
 * mm_checkheap - Checks the invariants of the heap
 * This function checks the invariants of the heap such as header-footer match,
 * absence of contiguous blocks of free memory and confirmation that the
 * block pointers are within the heaps boundaries.
 */
void mm_checkheap(int verbose)
{
  void *bp = heap_listp; //Points to the first block in the heap
  verbose = verbose;

  /* If first block's header's size or allocation bit is wrong,
   * the prologue header is incorrect. */

  if ((GET_SIZE(HDRP(heap_listp)) != MINBLOCKSIZE) ||
      !GET_ALLOC(HDRP(heap_listp)))
    printf("Bad prologue header\n");
  checkblock(bp);

  for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp))
    {
      if (verbose)
	printblock(bp);
      if(GET_SIZE(HDRP(bp)) == 0)
	printf("Error: block has zero size\n");
      checkblock(bp);

      /* Checking to see if free block in the free list */
      if(!GET_ALLOC(HDRP(bp)))
	checkInFreeList(bp);

    }

  /* If last block's header's size or allocation bit is wrong,
   * the epilogue's header is wrong. We also check the specific location
   * of the epilogue header with respect to the last byte of the heap.
   * mem_heap_hi() and bp(at this point) both point to the same word,
   * but mem_heap_hi() points to the last byte and hence we must add 3 to
   * the address of the header of bp to check this condition.
   */
  if (GET_SIZE(HDRP(bp)) != 0 || (GET_ALLOC(HDRP(bp)) != 1)
      || (HDRP(bp) + WSIZE - 1) != mem_heap_hi())
    printf("Bad epilogue header\n");

  for(bp = free_listp; GET_ALLOC(HDRP(bp)) == 0; bp = NEXT_FREE(bp))
    checkFreeNodes(bp);

}
Beispiel #25
0
/*=========================================
 * check_index -- Validate one index node of btree
 * Created: 2003/09/05, Perry Rapp
 *=======================================*/
static BOOLEAN
check_index (BTREE btr, INDEX index, TABLE fkeytab, RKEY * lo, RKEY * hi)
{
    INT n = nkeys(index);
    INT i;
    if (!check_keys((BLOCK)index, lo, hi))
        return FALSE;
    for (i = 0; i <= n; i++) {
        INDEX newix=0;
        char scratch[200];
        FKEY fkey = fkeys(index, i);
        RKEY *lox, *hix;

        get_index_file(scratch, btr, fkey);
        if (in_table(fkeytab, scratch)) {
            printf(_("Cycle in indexes, file %s found again!\n"), scratch);
            return FALSE;
        } else {
            insert_table_int(fkeytab, scratch, 1);
        }
        newix = readindex(btr, fkey, TRUE);
        if (!newix) {
            printf(_("Error loading index at key"));
            printf("%ld\n", i);
            printblock((BLOCK)index);
        }
        /* figure upper & lower bounds of what keys should be in the child */
        lox = (i==0 ? lo : &rkeys(index, i));
        hix = (i==n ? hi : &rkeys(index, i+1));
        if (ixtype(newix) == BTINDEXTYPE) {
            if (!check_index(btr, newix, fkeytab, lox, hix))
                return FALSE;
        } else {
            if (!check_block((BLOCK)newix, lox, hix))
                return FALSE;
        }
    }
    /* TODO: use fkeytab */
    return TRUE;
}
Beispiel #26
0
/*
 * free
 */
void free(block_ptr ptr)
{
	block_ptr tmp;
	size_t size;
	if (!ptr || !in_heap(ptr) || !aligned(ptr))
		return;

#ifdef DEBUG
	{
		printf("\nFree request: ptr = %p \033[41;37m[ID:%d]\033[0m\n", ptr, operid++);
		printblock(ptr);
	}
#endif

	size = GET_SIZE(HDRP(ptr));
	PUT(HDRP(ptr), PACK(size, 0));
	PUT(FTRP(ptr), PACK(size, 0));
	SET_UNALLOC(ptr);
	reset_block(ptr);
	tmp = coalesce(ptr);
	insert_free_block(tmp, GET_SIZE(HDRP(tmp)));
}
Beispiel #27
0
void loop() {
	// get block
	block blck = getRdm();

	// update the grid and print
	// for (int i = 0; i < 4; ++i){
	// 	grid[blck.row[i]][blck.col[i]] = 1;
	// }
	block old_blck = blck;

	printblock(blck);

	while(down(&blck)) {
		// blck is has been moved down.

		// remove old_blck
		removeblock(old_blck);

		// update old_blck
		old_blck = blck;

		// check "turn" button
		if (digitalRead(turnPin) == HIGH) {
			// turn us
			turnblock(&blck);
		}

		// check "left block"
		if (digitalRead(leftPin) == HIGH) {
			// go left if possible - arguments are blockr and blockc
			left(&blck);
		}

		// check "right block"
		if (digitalRead(rightPin) == HIGH) {
			// go right if possible  - arguments are blockr and blockc
			right(&blck);
		}

		// remove old_blck
		removeblock(old_blck);

		// update old_blck
		old_blck = blck;

		// print new blck
		printblock(blck);
		
		// difficulty
		// change how fast the block falls based on score
		if (score < 5) {
			Serial.println(1);
			delay(250);
		}
		if (score >= 5 && score < 10) {
			Serial.println(2);
			delay(200);
		}
		if (score >= 10 && score < 20) {
			Serial.println(3);
			delay(150);
		}
		if (score >= 20) {
			Serial.println(4);
			delay(100);
		}

		// gridprinter();
	}

	// check grid for and full rows or endgame.
	checkrow();
}
Beispiel #28
0
// Prints the map graphics in the bottom right of the screen
void printsitemap(int x, int y, int z) {
    int xscreen, xsite;
    int yscreen, ysite;

    // Build the frame
    set_color(COLOR_WHITE, COLOR_BLACK, 0);

    for(xscreen = 53; xscreen < 80; xscreen++) {
        move(24, xscreen);
        addch('-');
    }

    for(yscreen = 9; yscreen < 24; yscreen++) {
        move(yscreen, 53);
        addstr("|                         |");
    }

    // Display the map
    for(xsite = x - 2, xscreen = 79 - 5 * 5; xsite < x + 3; xscreen += 5, xsite++) {
        for(ysite = y - 2, yscreen = 24 - 3 * 5; ysite < y + 3; yscreen += 3, ysite++)
            printblock(xsite, ysite, z, xscreen, yscreen);
    }

    //PRINT SPECIAL
    char str[200];

    switch(levelmap[locx][locy][locz].special) {
    case SPECIAL_LAB_COSMETICS_CAGEDANIMALS:
        strcpy(str, "Caged Animals");
        break;

    case SPECIAL_NUCLEAR_ONOFF:
        strcpy(str, "Reactor Control Room");
        break;

    case SPECIAL_LAB_GENETIC_CAGEDANIMALS:
        strcpy(str, "Caged \"Animals\"");
        break;

    case SPECIAL_POLICESTATION_LOCKUP:
        strcpy(str, "Police Detention Room");
        break;

    case SPECIAL_COURTHOUSE_LOCKUP:
        strcpy(str, "Courthouse Jail");
        break;

    case SPECIAL_COURTHOUSE_JURYROOM:
        strcpy(str, "Jury Room");
        break;

    case SPECIAL_PRISON_CONTROL:
    case SPECIAL_PRISON_CONTROL_LOW:
    case SPECIAL_PRISON_CONTROL_MEDIUM:
    case SPECIAL_PRISON_CONTROL_HIGH:
        strcpy(str, "Prison Control Room");
        break;

    case SPECIAL_INTEL_SUPERCOMPUTER:
        strcpy(str, "Supercomputer");
        break;

    case SPECIAL_SWEATSHOP_EQUIPMENT:
        strcpy(str, "Textile Equipment");
        break;

    case SPECIAL_POLLUTER_EQUIPMENT:
        strcpy(str, "Factory Equipment");
        break;

    case SPECIAL_HOUSE_PHOTOS:
        strcpy(str, "Safe");
        break;

    case SPECIAL_ARMORY:
        strcpy(str, "Armory");
        break;

    case SPECIAL_HOUSE_CEO:
        strcpy(str, "CEO's Study");
        break;

    case SPECIAL_CORPORATE_FILES:
        strcpy(str, "Safe");
        break;

    case SPECIAL_RADIO_BROADCASTSTUDIO:
        strcpy(str, "Radio Broadcast Room");
        break;

    case SPECIAL_NEWS_BROADCASTSTUDIO:
        strcpy(str, "News Broadcast Studio");
        break;

    case SPECIAL_APARTMENT_LANDLORD:
        strcpy(str, "Landlord's Office");
        break;

    case SPECIAL_SIGN_ONE:
        strcpy(str, "Sign");
        break;

    case SPECIAL_SIGN_TWO:
        strcpy(str, "Sign");
        break;

    case SPECIAL_SIGN_THREE:
        strcpy(str, "Sign");
        break;

    case SPECIAL_DISPLAY_CASE:
        strcpy(str, "Display Case");
        break;

    case SPECIAL_STAIRS_UP:
        strcpy(str, "Stairs Up");
        break;

    case SPECIAL_STAIRS_DOWN:
        strcpy(str, "Stairs Down");
        break;

    case SPECIAL_RESTAURANT_TABLE:
        strcpy(str, "Table");
        break;

    case SPECIAL_CAFE_COMPUTER:
        strcpy(str, "Computer");
        break;

    case SPECIAL_PARK_BENCH:
        strcpy(str, "Bench");
        break;

    case SPECIAL_BANK_VAULT:
        strcpy(str, "Bank Vault");
        break;

    case SPECIAL_BANK_TELLER:
        strcpy(str, "Bank Teller");
        break;

    case SPECIAL_BANK_MONEY:
        strcpy(str, "Oh Wow So Much Money");
        break;

    case SPECIAL_CCS_BOSS:
        strcpy(str, "CCS Boss");
        break;

    case SPECIAL_OVAL_OFFICE_NW:
    case SPECIAL_OVAL_OFFICE_NE:
    case SPECIAL_OVAL_OFFICE_SW:
    case SPECIAL_OVAL_OFFICE_SE:
        strcpy(str, "The Office of the President");
        break;

    default:
        strcpy(str, "");
        break;
    }

    if(levelmap[locx][locy][locz].special != -1) {
        set_color(COLOR_WHITE, COLOR_BLACK, 1);
        move(24, 67 - (strlen(str) >> 1));
        addstr(str);
    }
Beispiel #29
0
/* dump out a Paragraph in the desired manner
 */
static Paragraph*
display(Paragraph *p, MMIOT *f, int easyNewLine)
{
    if ( !p ) return 0;

    switch ( p->typ ) {
    case STYLE:
    case WHITESPACE:
	break;

    case HTML:
	printhtml(p->text, f);
	break;
	
    case CODE:
	printcode(p->text, f);
	break;
	
    case QUOTE:
    if (p->down) {
        p->down->easyNewline = p->easyNewline;
    }
	htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f);
	break;
	
    case UL:
    case OL:
    case AL:
	listdisplay(p->typ, p->down, f);
	break;

    case DL:
	definitionlist(p->down, f);
	break;

    case HR:
	Qstring("<hr />", f);
	break;

    case HDR:
	printheader(p, f);
	break;

    case TABLE:
	printtable(p, f);
	break;

    case SOURCE:
    if (p->down) {
        p->down->easyNewline = p->easyNewline;
    }
	htmlify(p->down, 0, 0, f);
	break;
	
    default:
	printblock(p, f, easyNewLine);
	break;
    }
    // MK HACK, copy easyNewLine
    Paragraph *pNext = p->next;
    if (pNext) {
        pNext->easyNewline = p->easyNewline;
    }
    return pNext;
}
Beispiel #30
0
/**
 * checkheap - Function to check the consistency of the heap
 * @param verbose How much information to be printed on the screen
 */
void checkheap(int verbose) 
{
    /* Checks:
     * 1. Check each block for
     *     a. Alignment
     *     b. Header and Footer :
     *         i. Size Match
     *         ii. Header Footer Match Each other
     *     c. In Heap
     * 2. Get next block in free list.
     * 3. Check for no extra block in heap, from the seg lists
     * 4. Check for the cycle in the list.
     * 5. Check Epilogue Block
     * 6. Check Prologue Block
     * 7. Check proper coalescing - no previous and next free blocks
     */
    
    char *bp = heap_listp;
    

    /**
     * run checkheap with verbose =9 to avoid compiler from giving error, 
     * and also making sure that checkheap doesnot run
     */
    if(verbose == 9) {
        return;
    }
    /**
     * Following condition never will be true. 
     * A place function to avoid compiler compalaining
     */
    if(verbose ==10) {
        print_free_block(GET_SEGI(seg_list,0));

    }
    if (verbose){
        dbg_printf("Heap (%p):\n", heap_listp);        
    }

    /*Check for epilogue*/
    if ((GET_SIZE(HDRP(heap_listp)) != DSIZE) || !GET_ALLOC(HDRP(heap_listp))){
        printf("ERROR: Bad prologue header\n");
    }
    
    /*Check header block for issues*/
    checkblock(heap_listp);
    /*Now check the complete heap*/
    for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
        if (verbose) {
            printblock(bp);/*If Verbose , Print the heap*/
        }
        checkblock(bp);
    }

    if (verbose)
        printblock(bp);
    /*Check for Epilogue*/
    if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp)))) {
        printf("ERROR: Bad epilogue header for block \n");
        printblock(bp);
    }

    /**
     * Checks with respect to seg list
     */
    
    /*Check if all the pointers in all the free lists are aligned*/
    check_seg_pointers();


    /* Check for count of free blocks, iterating over blocks and by 
     * going through next pointers*/
    check_count_free_list();

    /*Check for cycle in the free list*/
    check_cycle();
}