Пример #1
0
// Starts the bitmaps setting em all to 0
static void fs_bitmaps_init() {
	bitmap_handling = 1;
	int i = 0;
	for (; i < FS_BLOCK_GROUP_COUNT; i++) {
		block_read((void *)&g_inode_bmps[i], gbdt[i].bg_inode_bitmap);
		block_read((void *)&g_block_bmps[i], gbdt[i].bg_block_bitmap);
	}
	
	
	
	bm_inodes = bitmap_init(FS_INODE_TABLE_SIZE * FS_INODES_PER_BLOCK, FS_BLOCK_SIZE * 8, g_inode_bmps);
	bm_blocks = bitmap_init(FS_DATA_TABLE_SIZE, FS_BLOCK_SIZE * 8, g_block_bmps);
	bitmap_handling = 0;
}
Пример #2
0
void b_malloc_init(unsigned long heap_nbytes)
{
  bm = bitmap_init((heap_nbytes/BITMAP_BIT_NUM_BYTES)/CHAR_BIT);

  heap_info = g_tree_new((GCompareFunc) compare_heap_entry);
  heap = malloc(heap_nbytes);
}
Пример #3
0
/**
 * Physical memory initialization. Finds out number of physical pages and
 * number of staticly reserved physical pages. Marks reserved pages
 * reserved in physmem_free_pages.
 */
void physmem_init(void *bootinfo)
{
  int num_res_pages;
  int i;

  /* We dont use this */
  bootinfo = bootinfo;

  physmem_num_pages = physmem_get_size();

  physmem_free_pages =
    (uint32_t *)stalloc(bitmap_sizeof(physmem_num_pages));
  bitmap_init(physmem_free_pages, physmem_num_pages);

  /* Note that number of reserved pages must be get after we have
     (staticly) reserved memory for bitmap. */
  num_res_pages = physmem_get_reserved_size();
  physmem_num_free_pages = physmem_num_pages - num_res_pages;
  physmem_static_end = num_res_pages;

  for (i = 0; i < num_res_pages; i++)
    bitmap_set(physmem_free_pages, i, 1);

  spinlock_reset(&physmem_slock);

  kprintf("Physmem: Found %d pages of size %d\n", physmem_num_pages,
          PAGE_SIZE);
  kprintf("Physmem: Static allocation for kernel: %d pages\n",
          num_res_pages);
}
Пример #4
0
struct file *
file_open(char *name)
{
    int result;
    struct file *f = malloc(sizeof(struct file));
    if (f == NULL) {
        goto done;
    }
    f->f_fd = open(name, O_CREAT | O_RDWR, S_IRWXU);
    if (f->f_fd == -1) {
        goto cleanup_malloc;
    }
    f->f_size = io_size(f->f_fd);
    unsigned bitmapbytes = FILE_BITMAP_PAGES * PAGESIZE;
    if (f->f_size == 0) {
        // if we are creating the file for the first time, allocate the
        // first page for the bitmap, and mark the page as taken
        f->f_page_bitmap = bitmap_create(bitmapbytes * 8);
        if (f->f_page_bitmap == NULL) {
            goto cleanup_fd;
        }
        for (unsigned i = 0; i < FILE_BITMAP_PAGES; i++) {
            bitmap_mark(f->f_page_bitmap, i);
        }
        result = file_sync_bitmap(f);
        if (result) {
            bitmap_destroy(f->f_page_bitmap);
            goto cleanup_fd;
        }
        f->f_size += bitmapbytes;
    } else {
        // if we are initing from an already existing file, read the first
        // page and init the bitmap using that page
        unsigned char buf[bitmapbytes];
        bzero(buf, bitmapbytes);
        result = io_read(f->f_fd, buf, bitmapbytes);
        if (result) {
            goto cleanup_fd;
        }
        f->f_page_bitmap = bitmap_init(bitmapbytes * 8, buf);
        if (f->f_page_bitmap == NULL) {
            goto cleanup_fd;
        }
    }
    // seek back to beginning on opening
    result = lseek(f->f_fd, 0, SEEK_SET);
    f->f_last_alloc_page = FILE_BITMAP_PAGES - 1;
    if (result) {
        goto cleanup_fd;
    }
    goto done;

  cleanup_fd:
    assert(close(f->f_fd) == 0);
  cleanup_malloc:
    free(f);
    f = NULL;
  done:
    return f;
}
Пример #5
0
void start(uint32_t* modulep, void* physbase, void* physfree)
{
	struct smap_t {
		uint64_t base, length;
		uint32_t type;
	}__attribute__((packed)) *smap;
	while(modulep[0] != 0x9001) modulep += modulep[1]+2;
	int i=0;
	bitmap_init(physfree);
	for(smap = (struct smap_t*)(modulep+2); smap < (struct smap_t*)((char*)modulep+modulep[1]+2*4); ++smap) {
		if (smap->type == 1 /* memory */ && smap->length != 0) {
//			printf("Available Physical Memory [%x-%x]\n", smap->base, smap->base + smap->length);
		        mem_track_init(smap->base, smap->length, physfree);
			i++;
		}
	}
//	printf("tarfs in [%p:%p]\n", &_binary_tarfs_start, &_binary_tarfs_end);
//	printf("Physbase and Physfree is: %p - %p\n", physbase, physfree);
	// kernel starts here
	set_kernel_video_page();
	kmalloc_bump_ptr += (uint64_t)kern_max;
	init_tarfs();
	init_process();

	printf("After init proc\n");
	printf("BACK IN MAIN\n");
	while(1);
}
Пример #6
0
TEST_END

TEST_BEGIN(test_bitmap_unset)
{
	size_t i;

	for (i = 1; i <= BITMAP_MAXBITS; i++) {
		bitmap_info_t binfo;
		bitmap_info_init(&binfo, i);
		{
			size_t j;
			bitmap_t *bitmap = (bitmap_t *)malloc(
			    bitmap_size(&binfo));
			bitmap_init(bitmap, &binfo);

			for (j = 0; j < i; j++)
				bitmap_set(bitmap, &binfo, j);
			assert_true(bitmap_full(bitmap, &binfo),
			    "All bits should be set");
			for (j = 0; j < i; j++)
				bitmap_unset(bitmap, &binfo, j);
			for (j = 0; j < i; j++)
				bitmap_set(bitmap, &binfo, j);
			assert_true(bitmap_full(bitmap, &binfo),
			    "All bits should be set");
			free(bitmap);
		}
	}
}
Пример #7
0
static void
test_bitmap_unset(void)
{
    size_t i;

    for (i = 1; i <= MAXBITS; i++) {
        bitmap_info_t binfo;
        bitmap_info_init(&binfo, i);
        {
            size_t j;
            bitmap_t *bitmap = malloc(sizeof(bitmap_t) *
                                      bitmap_info_ngroups(&binfo));
            bitmap_init(bitmap, &binfo);

            for (j = 0; j < i; j++)
                bitmap_set(bitmap, &binfo, j);
            assert(bitmap_full(bitmap, &binfo));
            for (j = 0; j < i; j++)
                bitmap_unset(bitmap, &binfo, j);
            for (j = 0; j < i; j++)
                bitmap_set(bitmap, &binfo, j);
            assert(bitmap_full(bitmap, &binfo));
            free(bitmap);
        }
    }
}
Пример #8
0
int
e820_init(void)
{
    realmode_t *rm = NULL;
    int ret = -1;
    int count = 0;
    const int dest = 0x20000;

    rm = malloc(sizeof *rm);
    if (rm == NULL) {
	return -1;
    }

    realmode_set_default_callbacks(rm);
    bitmap_init(rm->rm_shadow_bitmap, REALMODE_PAGES, BITMAP_ALL_ONES);

    ret = realmode_create_mem_shadow(rm);
    if (ret < 0) {
	goto out;
    }

#define env (&rm->rm_x86env)

    env->x86.R_CS = 0x1000;
    env->x86.R_SS = 0x1000;
    env->x86.R_ESP = 0xFFF0;
    env->x86.R_IP = 0;
    env->x86.R_EBX = 0;
    
    do {
	env->x86.R_EAX = 0xe820;
	env->x86.R_EDX = SMAP;
	env->x86.R_ECX = sizeof(E820Entry);
	env->x86.R_DS  = dest >> 4;
	env->x86.R_ES  = dest >> 4;
	env->x86.R_DI = 0x0;
	env->x86.R_FLG |= F_CF;

	realmode_int(rm, 0x15);

	if ((env->x86.R_FLG & F_CF) ||
	    env->x86.R_EAX != SMAP ||
	    env->x86.R_ECX != sizeof(E820Entry)) {
	    goto release;
	}

	memcpy(&__e820map[count++], (void *)rm->rm_pages[dest >> VM_PAGE_SHIFT],
	       env->x86.R_ECX);
    } while (env->x86.R_EBX != 0 && count < E820MAX);

    __e820nr = count;
    ret = 0;

 release:
    realmode_release_mem_shadow(rm);
 out:
    free(rm);
    return ret;
}
Пример #9
0
my_bool test_compare(MY_BITMAP *map, uint bitsize)
{
  MY_BITMAP map2;
  uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
  uint i, test_bit;
  uint no_loops= bitsize > 128 ? 128 : bitsize;
  if (bitmap_init(&map2, map2buf, bitsize, FALSE))
  {
    diag("init error for bitsize %d", bitsize);
    return TRUE;
  }
  /* Test all 4 possible combinations of set/unset bits. */
  for (i=0; i < no_loops; i++)
  {
    test_bit=get_rand_bit(bitsize);
    bitmap_clear_bit(map, test_bit);
    bitmap_clear_bit(&map2, test_bit);
    if (!bitmap_is_subset(map, &map2))
      goto error_is_subset;
    bitmap_set_bit(map, test_bit);
    if (bitmap_is_subset(map, &map2))
      goto error_is_subset;
    bitmap_set_bit(&map2, test_bit);
    if (!bitmap_is_subset(map, &map2))
      goto error_is_subset;
    bitmap_clear_bit(map, test_bit);
    if (!bitmap_is_subset(map, &map2))
      goto error_is_subset;
    /* Note that test_bit is not cleared i map2. */
  }
  bitmap_clear_all(map);
  bitmap_clear_all(&map2);
  /* Test all 4 possible combinations of set/unset bits. */
  for (i=0; i < no_loops; i++)
  {
    test_bit=get_rand_bit(bitsize);
    if (bitmap_is_overlapping(map, &map2))
      goto error_is_overlapping;
    bitmap_set_bit(map, test_bit);
    if (bitmap_is_overlapping(map, &map2))
      goto error_is_overlapping;
    bitmap_set_bit(&map2, test_bit);
    if (!bitmap_is_overlapping(map, &map2))
      goto error_is_overlapping;
    bitmap_clear_bit(map, test_bit);
    if (bitmap_is_overlapping(map, &map2))
      goto error_is_overlapping;
    bitmap_clear_bit(&map2, test_bit);
    /* Note that test_bit is not cleared i map2. */
  }
  return FALSE;
error_is_subset:
  diag("is_subset error  bitsize = %u", bitsize);
  return TRUE;
error_is_overlapping:
  diag("is_overlapping error  bitsize = %u", bitsize);
  return TRUE;
}
Пример #10
0
TEST_END

TEST_BEGIN(test_bitmap_sfu)
{
	size_t i;

	for (i = 1; i <= BITMAP_MAXBITS; i++) {
		bitmap_info_t binfo;
		bitmap_info_init(&binfo, i);
		{
			size_t j;
			bitmap_t *bitmap = (bitmap_t *)malloc(
			    bitmap_size(&binfo));
			bitmap_init(bitmap, &binfo);

			/* Iteratively set bits starting at the beginning. */
			for (j = 0; j < i; j++) {
				assert_zd_eq(bitmap_sfu(bitmap, &binfo), j,
				    "First unset bit should be just after "
				    "previous first unset bit");
			}
			assert_true(bitmap_full(bitmap, &binfo),
			    "All bits should be set");

			/*
			 * Iteratively unset bits starting at the end, and
			 * verify that bitmap_sfu() reaches the unset bits.
			 */
			for (j = i - 1; j < i; j--) { /* (i..0] */
				bitmap_unset(bitmap, &binfo, j);
				assert_zd_eq(bitmap_sfu(bitmap, &binfo), j,
				    "First unset bit should the bit previously "
				    "unset");
				bitmap_unset(bitmap, &binfo, j);
			}
			assert_false(bitmap_get(bitmap, &binfo, 0),
			    "Bit should be unset");

			/*
			 * Iteratively set bits starting at the beginning, and
			 * verify that bitmap_sfu() looks past them.
			 */
			for (j = 1; j < i; j++) {
				bitmap_set(bitmap, &binfo, j - 1);
				assert_zd_eq(bitmap_sfu(bitmap, &binfo), j,
				    "First unset bit should be just after the "
				    "bit previously set");
				bitmap_unset(bitmap, &binfo, j);
			}
			assert_zd_eq(bitmap_sfu(bitmap, &binfo), i - 1,
			    "First unset bit should be the last bit");
			assert_true(bitmap_full(bitmap, &binfo),
			    "All bits should be set");
			free(bitmap);
		}
	}
}
Пример #11
0
void
bitmap_load(Bitmap *bitmap, const char *path)
{
    // TODO: Treat path as relative to executable, not the CWD!
    int width, height, comp;
    Color *pixels = (Color *)stbi_load(path, &width, &height, &comp, STBI_rgb_alpha);
    ASSERT(pixels);
    ASSERT(comp == 4);

    bitmap_init(bitmap, (i32)width, (i32)height, pixels, BITMAP_32);
    free(pixels);
}
Пример #12
0
my_bool test_intersect(MY_BITMAP *map, uint bitsize)
{
  uint bitsize2 = 1 + get_rand_bit(MAX_TESTED_BITMAP_SIZE - 1);
  MY_BITMAP map2;
  uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
  uint i, test_bit1, test_bit2, test_bit3;
  if (bitmap_init(&map2, map2buf, bitsize2, FALSE))
  {
    diag("init error for bitsize %d", bitsize2);
    return TRUE;
  }
  test_bit1= get_rand_bit(bitsize);
  test_bit2= get_rand_bit(bitsize);
  bitmap_set_bit(map, test_bit1);
  bitmap_set_bit(map, test_bit2);
  test_bit3= get_rand_bit(bitsize2);
  bitmap_set_bit(&map2, test_bit3);
  if (test_bit2 < bitsize2)
    bitmap_set_bit(&map2, test_bit2);

  bitmap_intersect(map, &map2);
  if (test_bit2 < bitsize2)
  {
    if (!bitmap_is_set(map, test_bit2))
      goto error;
    bitmap_clear_bit(map, test_bit2);
  }
  if (test_bit1 == test_bit3)
  {
    if (!bitmap_is_set(map, test_bit1))
      goto error;
    bitmap_clear_bit(map, test_bit1);
  }
  if (!bitmap_is_clear_all(map))
    goto error;

  bitmap_set_all(map);
  bitmap_set_all(&map2);
  for (i=0; i < bitsize2; i++)
    bitmap_clear_bit(&map2, i);
  bitmap_intersect(map, &map2);
  if (!bitmap_is_clear_all(map))
    goto error;
  return FALSE;
error:
  diag("intersect error  bitsize = %u, bit1 = %u, bit2 = %u, bit3 = %u",
       bitsize, test_bit1, test_bit2, test_bit3);
  return TRUE;
}
Пример #13
0
TEST_END

static void
test_bitmap_set_body(const bitmap_info_t *binfo, size_t nbits)
{
	size_t i;
	bitmap_t *bitmap = (bitmap_t *)malloc(bitmap_size(binfo));
	assert_ptr_not_null(bitmap, "Unexpected malloc() failure");
	bitmap_init(bitmap, binfo);

	for (i = 0; i < nbits; i++)
		bitmap_set(bitmap, binfo, i);
	assert_true(bitmap_full(bitmap, binfo), "All bits should be set");
	free(bitmap);
}
Пример #14
0
int buddy_init(buddy_t *bd, uint8_t *overhead_storage,
               range_t r, int start_freed) {
  bd->start = r.start;
  bd->size  = r.extent;

  for (unsigned i = 0; i < NUM_BUDDY_BUCKETS; ++i) {
    unsigned nbits = bd->size >> (MIN_BUDDY_SZ_LOG2 + i);
    bitmap_init(&bd->orders[i], overhead_storage, nbits);
    overhead_storage += nbits / 8 + 1;
  }

  if (start_freed != 0)
    buddy_free_range(bd, r);

  return 0;
}
Пример #15
0
TEST_END

static void
test_bitmap_init_body(const bitmap_info_t *binfo, size_t nbits)
{
	size_t i;
	bitmap_t *bitmap = (bitmap_t *)malloc(bitmap_size(binfo));
	assert_ptr_not_null(bitmap, "Unexpected malloc() failure");
	bitmap_init(bitmap, binfo);

	for (i = 0; i < nbits; i++) {
		assert_false(bitmap_get(bitmap, binfo, i),
		    "Bit should be unset");
	}
	free(bitmap);
}
Пример #16
0
static
void
check_sb(void)
{
	struct sfs_super sp;
	uint32_t i;
	int schanged=0;

	diskread(&sp, SFS_SB_LOCATION);
	swapsb(&sp);
	if (sp.sp_magic != SFS_MAGIC) {
		errx(EXIT_UNRECOV, "Not an sfs filesystem");
	}

	assert(nblocks==0);
	assert(bitblocks==0);
	nblocks = sp.sp_nblocks;
	bitblocks = SFS_BITBLOCKS(nblocks);
	assert(nblocks>0);
	assert(bitblocks>0);

	bitmap_init(bitblocks);
	for (i=nblocks; i<bitblocks*SFS_BLOCKBITS; i++) {
		bitmap_mark(i, B_PASTEND, 0);
	}

	if (checknullstring(sp.sp_volname, sizeof(sp.sp_volname))) {
		warnx("Volume name not null-terminated (fixed)");
		setbadness(EXIT_RECOV);
		schanged = 1;
	}
	if (checkbadstring(sp.sp_volname)) {
		warnx("Volume name contains illegal characters (fixed)");
		setbadness(EXIT_RECOV);
		schanged = 1;
	}

	if (schanged) {
		swapsb(&sp);
		diskwrite(&sp, SFS_SB_LOCATION);
	}

	bitmap_mark(SFS_SB_LOCATION, B_SUPERBLOCK, 0);
	for (i=0; i<bitblocks; i++) {
		bitmap_mark(SFS_MAP_LOCATION+i, B_BITBLOCK, i);
	}
}
Пример #17
0
TEST_END

static void
test_bitmap_sfu_body(const bitmap_info_t *binfo, size_t nbits)
{
	size_t i;
	bitmap_t *bitmap = (bitmap_t *)malloc(bitmap_size(binfo));
	assert_ptr_not_null(bitmap, "Unexpected malloc() failure");
	bitmap_init(bitmap, binfo);

	/* Iteratively set bits starting at the beginning. */
	for (i = 0; i < nbits; i++) {
		assert_zd_eq(bitmap_sfu(bitmap, binfo), i,
		    "First unset bit should be just after previous first unset "
		    "bit");
	}
	assert_true(bitmap_full(bitmap, binfo), "All bits should be set");

	/*
	 * Iteratively unset bits starting at the end, and verify that
	 * bitmap_sfu() reaches the unset bits.
	 */
	for (i = nbits - 1; i < nbits; i--) { /* (nbits..0] */
		bitmap_unset(bitmap, binfo, i);
		assert_zd_eq(bitmap_sfu(bitmap, binfo), i,
		    "First unset bit should the bit previously unset");
		bitmap_unset(bitmap, binfo, i);
	}
	assert_false(bitmap_get(bitmap, binfo, 0), "Bit should be unset");

	/*
	 * Iteratively set bits starting at the beginning, and verify that
	 * bitmap_sfu() looks past them.
	 */
	for (i = 1; i < nbits; i++) {
		bitmap_set(bitmap, binfo, i - 1);
		assert_zd_eq(bitmap_sfu(bitmap, binfo), i,
		    "First unset bit should be just after the bit previously "
		    "set");
		bitmap_unset(bitmap, binfo, i);
	}
	assert_zd_eq(bitmap_sfu(bitmap, binfo), nbits - 1,
	    "First unset bit should be the last bit");
	assert_true(bitmap_full(bitmap, binfo), "All bits should be set");
	free(bitmap);
}
Пример #18
0
Bitmap *loadFromPath(std::string const &path)
{
    bitmap_init();
    Bitmap *ret = NULL;
    IxRead *ir = IxRead::readFromFile(path.c_str());
    try
    {
        ret = loadFromData(ir->dataSegment(0, ir->size()), ir->size(), fileext(path));
    }
    catch (...)
    {
        delete ir;
        throw;
    }
    delete ir;
    return ret;
}
Пример #19
0
static void
test_bitmap_sfu(void)
{
    size_t i;

    for (i = 1; i <= MAXBITS; i++) {
        bitmap_info_t binfo;
        bitmap_info_init(&binfo, i);
        {
            ssize_t j;
            bitmap_t *bitmap = malloc(sizeof(bitmap_t) *
                                      bitmap_info_ngroups(&binfo));
            bitmap_init(bitmap, &binfo);

            /* Iteratively set bits starting at the beginning. */
            for (j = 0; j < i; j++)
                assert(bitmap_sfu(bitmap, &binfo) == j);
            assert(bitmap_full(bitmap, &binfo));

            /*
             * Iteratively unset bits starting at the end, and
             * verify that bitmap_sfu() reaches the unset bits.
             */
            for (j = i - 1; j >= 0; j--) {
                bitmap_unset(bitmap, &binfo, j);
                assert(bitmap_sfu(bitmap, &binfo) == j);
                bitmap_unset(bitmap, &binfo, j);
            }
            assert(bitmap_get(bitmap, &binfo, 0) == false);

            /*
             * Iteratively set bits starting at the beginning, and
             * verify that bitmap_sfu() looks past them.
             */
            for (j = 1; j < i; j++) {
                bitmap_set(bitmap, &binfo, j - 1);
                assert(bitmap_sfu(bitmap, &binfo) == j);
                bitmap_unset(bitmap, &binfo, j);
            }
            assert(bitmap_sfu(bitmap, &binfo) == i - 1);
            assert(bitmap_full(bitmap, &binfo));
            free(bitmap);
        }
    }
}
Пример #20
0
void
bitmap_load_resource(Bitmap *bitmap, const char *resource_name)
{
    int width, height, comp;
    isize size;
    void *ptr;
    Color *pixels;

    ptr = resource_get(resource_name, &size);

    ASSERT(ptr);
    pixels = (Color *)stbi_load_from_memory((u8 *)ptr, (int)size, &width, &height, &comp, STBI_rgb_alpha);
    ASSERT(pixels);
    ASSERT(comp == 4);

    bitmap_init(bitmap, (i32)width, (i32)height, pixels, BITMAP_32);
    free(pixels);
}
Пример #21
0
static void
test_bitmap_set(void)
{
	size_t i;

	for (i = 1; i <= MAXBITS; i++) {
		bitmap_info_t binfo;
		bitmap_info_init(&binfo, i);
		{
			size_t j;
			bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
			bitmap_init(bitmap, &binfo);

			for (j = 0; j < i; j++)
				bitmap_set(bitmap, &binfo, j);
			assert(bitmap_full(bitmap, &binfo));
		}
	}
}
Пример #22
0
/**
   Creates a new bitmap.
   @param size size of bitmap
   @return pointer to bitmap
*/
bitmap_t *
bitmap_new (unsigned size)
{
  bitmap_t * bm;
  
  if (size == 0)
    abort ();
  
  bm = malloc (sizeof (bitmap_t));
  if (! bm)
    return NULL;
  if (! bitmap_init (bm, size))
    {
      free (bm);
      return NULL;
    }
  else
    return bm;
}
Пример #23
0
my_bool do_test(uint bitsize)
{
  MY_BITMAP map;
  uint32 buf[MAX_TESTED_BITMAP_SIZE];
  if (bitmap_init(&map, buf, bitsize, FALSE))
  {
    diag("init error for bitsize %d", bitsize);
    goto error;
  }
  if (test_set_get_clear_bit(&map,bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_flip_bit(&map,bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_get_all_bits(&map, bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_compare_operators(&map,bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_count_bits_set(&map,bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_get_first_bit(&map,bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_get_next_bit(&map,bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_prefix(&map,bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_compare(&map,bitsize))
    goto error;
  bitmap_clear_all(&map);
  if (test_intersect(&map,bitsize))
    goto error;
  return FALSE;
error:
  return TRUE;
}
Пример #24
0
int main(int argc, char *argv[]) {
    // TODO: currently must run from cmd-line: no way to set working dir in cmake?
    printf("converting addresses to indexes\n");
    system("python ../cunit/addr2index.py < ../cunit/ANSIC_MALLOC_FREE_TRACE.txt > /tmp/trace.txt");
    printf("simulating...\n");

    cunit_setup = setup;
    cunit_teardown = teardown;

    bitmap_init(HEAP_SIZE);
    {
        time_t start = time(NULL);
        test(replay_ansic_grammar_with_dparser);
        time_t stop = time(NULL);

        fprintf(stderr, "simulation took %ldms\n", (stop-start));
    }

    return 0;
}
Пример #25
0
static int video_init()
{
    /* If we are running under X, get a connection to the X server and create
       an empty window of size (1, 1). It makes a couple of init functions a
       lot easier. */
	if(vstat.scaling<1)
		vstat.scaling=1;
    if(init_window())
		return(-1);

	bitmap_init(x11_drawrect, x11_flush);

    /* Initialize mode 3 (text, 80x25, 16 colors) */
    if(init_mode(3)) {
		return(-1);
	}

	sem_wait(&mode_set);

    return(0);
}
Пример #26
0
si_t engine_draw_bitmap(si_t graphics_device_handle, char* path, si_t align)
{
	struct bitmap bm;
    struct rectangle area;
    struct graphics_device * gd;

    gd = (struct graphics_device *)graphics_device_handle;
    area = gd->rectangle;

	bm.path = path;

	if(bitmap_init(&bm) == -1)
        return -1;

    bitmap_align(&bm, &area, align);

	show_bitmap(&bm, gd, &area);

	bitmap_exit(&bm);

    return 0;
}
Пример #27
0
TEST_END

TEST_BEGIN(test_bitmap_init)
{
	size_t i;

	for (i = 1; i <= BITMAP_MAXBITS; i++) {
		bitmap_info_t binfo;
		bitmap_info_init(&binfo, i);
		{
			size_t j;
			bitmap_t *bitmap = (bitmap_t *)malloc(
			    bitmap_size(&binfo));
			bitmap_init(bitmap, &binfo);

			for (j = 0; j < i; j++) {
				assert_false(bitmap_get(bitmap, &binfo, j),
				    "Bit should be unset");
			}
			free(bitmap);
		}
	}
}
Пример #28
0
Bitmap *loadFromData(void const *data, size_t size, std::string const &fmt)
{
    ilGetError();
    ILenum ilFormat = IL_RAW;
    ilFormat = get_bitmap_ext_fmt(fmt);
    bitmap_init();
    int img = ilGenImage();
    ilBindImage(img);
    ilEnable(IL_ORIGIN_SET);
    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
    ilEnable(IL_CONV_PAL);
    ilLoadL(ilFormat, data, size);
    int err = ilGetError();
    if (err != IL_NO_ERROR)
    {
        ilDeleteImage(img);
        char errStr[256];
        _snprintf_s(errStr, 256, "Error 0x%x", err);
        errStr[255] = 0;
        throw std::runtime_error(std::string("Error loading image format: ") + fmt
            + "\n" + errStr);
    }
    return new ILBitmap(img);
}
Пример #29
0
static void setup()		{
    bitmap_init(HEAP_SIZE);
}
Пример #30
0
my_bool test_compare_operators(MY_BITMAP *map, uint bitsize)
{
  uint i, j, test_bit1, test_bit2, test_bit3,test_bit4;
  uint no_loops= bitsize > 128 ? 128 : bitsize;
  MY_BITMAP map2_obj, map3_obj;
  MY_BITMAP *map2= &map2_obj, *map3= &map3_obj;
  uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
  uint32 map3buf[MAX_TESTED_BITMAP_SIZE];
  bitmap_init(&map2_obj, map2buf, bitsize, FALSE);
  bitmap_init(&map3_obj, map3buf, bitsize, FALSE);
  bitmap_clear_all(map2);
  bitmap_clear_all(map3);
  for (i=0; i < no_loops; i++)
  {
    test_bit1=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    test_bit2=get_rand_bit(bitsize);
    bitmap_set_prefix(map2, test_bit2);
    bitmap_intersect(map, map2);
    test_bit3= test_bit2 < test_bit1 ? test_bit2 : test_bit1;
    bitmap_set_prefix(map3, test_bit3);
    if (!bitmap_cmp(map, map3))
      goto error1;
    bitmap_clear_all(map);
    bitmap_clear_all(map2);
    bitmap_clear_all(map3);
    test_bit1=get_rand_bit(bitsize);
    test_bit2=get_rand_bit(bitsize);
    test_bit3=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    bitmap_set_prefix(map2, test_bit2);
    test_bit3= test_bit2 > test_bit1 ? test_bit2 : test_bit1;
    bitmap_set_prefix(map3, test_bit3);
    bitmap_union(map, map2);
    if (!bitmap_cmp(map, map3))
      goto error2;
    bitmap_clear_all(map);
    bitmap_clear_all(map2);
    bitmap_clear_all(map3);
    test_bit1=get_rand_bit(bitsize);
    test_bit2=get_rand_bit(bitsize);
    test_bit3=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    bitmap_set_prefix(map2, test_bit2);
    bitmap_xor(map, map2);
    test_bit3= test_bit2 > test_bit1 ? test_bit2 : test_bit1;
    test_bit4= test_bit2 < test_bit1 ? test_bit2 : test_bit1;
    bitmap_set_prefix(map3, test_bit3);
    for (j=0; j < test_bit4; j++)
      bitmap_clear_bit(map3, j);
    if (!bitmap_cmp(map, map3))
      goto error3;
    bitmap_clear_all(map);
    bitmap_clear_all(map2);
    bitmap_clear_all(map3);
    test_bit1=get_rand_bit(bitsize);
    test_bit2=get_rand_bit(bitsize);
    test_bit3=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    bitmap_set_prefix(map2, test_bit2);
    bitmap_subtract(map, map2);
    if (test_bit2 < test_bit1)
    {
      bitmap_set_prefix(map3, test_bit1);
      for (j=0; j < test_bit2; j++)
        bitmap_clear_bit(map3, j);
    }
    if (!bitmap_cmp(map, map3))
      goto error4;
    bitmap_clear_all(map);
    bitmap_clear_all(map2);
    bitmap_clear_all(map3);
    test_bit1=get_rand_bit(bitsize);
    bitmap_set_prefix(map, test_bit1);
    bitmap_invert(map);
    bitmap_set_all(map3);
    for (j=0; j < test_bit1; j++)
      bitmap_clear_bit(map3, j);
    if (!bitmap_cmp(map, map3))
      goto error5;
    bitmap_clear_all(map);
    bitmap_clear_all(map3);
  }
  return FALSE;
error1:
  diag("intersect error  bitsize=%u,size1=%u,size2=%u", bitsize,
  test_bit1,test_bit2);
  return TRUE;
error2:
  diag("union error  bitsize=%u,size1=%u,size2=%u", bitsize,
  test_bit1,test_bit2);
  return TRUE;
error3:
  diag("xor error  bitsize=%u,size1=%u,size2=%u", bitsize,
  test_bit1,test_bit2);
  return TRUE;
error4:
  diag("subtract error  bitsize=%u,size1=%u,size2=%u", bitsize,
  test_bit1,test_bit2);
  return TRUE;
error5:
  diag("invert error  bitsize=%u,size=%u", bitsize,
  test_bit1);
  return TRUE;
}