Example #1
0
void test_priv_free(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    Priv_mem new_mem = style_to_priv((Memory) mem);
    mem->alloc((Memory) mem, 1 Kb);
    void *temp = mem->alloc((Memory) mem, 2 Kb);
    mem->alloc((Memory) mem, 1 Kb);
    CU_ASSERT(memory_start(search_memory(temp, new_mem->lists->alloclist, FALSE)) == temp);
    CU_ASSERT(priv_free((Memory) mem, temp) == 2 Kb);
    CU_ASSERT(memory_start(search_memory(temp, new_mem->lists->alloclist, FALSE)) == NULL);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Example #2
0
int main(void)
{
	memory_start();

	output_string("This is the user mode version.\n");
	output_string("The VM Engine works but we don't really have what to do with it.\n");
	output_string("You should know that the user mode version is just for testing, AND IS NOT THREAD SAFE!\n");

	memory_stop();

	return 0;
}
Example #3
0
/* the module init function */
static int __init kplugs_init(void)
{
	int err = 0;
	struct device *device = NULL;

	memory_start();

	err = context_create(&GLOBAL_CONTEXT);
	if (err < 0) {
		output_string("Couldn't create the global context.\n");
		ERROR_CLEAN(create_error(NULL, err));
	}

	err = alloc_chrdev_region(&kplugs_devno , 0, 1, DEVICE_NAME);
	if (err < 0) {
		output_string("Couldn't allocate a region.\n");
		ERROR_CLEAN(create_error(NULL, err));
	}

	kplugs_class = class_create(THIS_MODULE, DEVICE_NAME);
	if (NULL == kplugs_class) {
		output_string("Couldn't create class.\n");
		ERROR_CLEAN(-ENOMEM);
	}
	
	kplugs_cdev = cdev_alloc();
	if (NULL == kplugs_cdev) {
		output_string("Couldn't allocate a cdev.\n");
		ERROR_CLEAN(-ENOMEM);
	}

	cdev_init(kplugs_cdev, &kplugs_ops);

	err = cdev_add(kplugs_cdev, kplugs_devno, 1);
	if (err < 0) {
		output_string("Couldn't add the cdev.\n");
		ERROR_CLEAN(create_error(NULL, err));
	}

	device = device_create(kplugs_class, NULL, kplugs_devno, NULL, DEVICE_NAME);
	if (device == NULL) {
		output_string("Couldn't create the device.\n");
		ERROR_CLEAN(-ENOMEM);
	}

	return 0;

clean:
	if (NULL != kplugs_cdev) {
		cdev_del(kplugs_cdev);
	}
	if (NULL != kplugs_class) {
		class_destroy(kplugs_class);
	}
	if (kplugs_devno) {
		unregister_chrdev_region(kplugs_devno, 1);
	}
	if (NULL != GLOBAL_CONTEXT) {
		context_free(GLOBAL_CONTEXT);
	}
	memory_stop();
	return err;
}