Пример #1
0
static void __init __map_memblock(phys_addr_t start, phys_addr_t end)
{
	/*
	 * Set up the executable regions using the existing section mappings
	 * for now. This will get more fine grained later once all memory
	 * is mapped
	 */
	unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
	unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);

	if (end < kernel_x_start) {
		create_mapping(start, __phys_to_virt(start),
			end - start, PAGE_KERNEL);
	} else if (start >= kernel_x_end) {
		create_mapping(start, __phys_to_virt(start),
			end - start, PAGE_KERNEL);
	} else {
		if (start < kernel_x_start)
			create_mapping(start, __phys_to_virt(start),
				kernel_x_start - start,
				PAGE_KERNEL);
		create_mapping(kernel_x_start,
				__phys_to_virt(kernel_x_start),
				kernel_x_end - kernel_x_start,
				PAGE_KERNEL_EXEC);
		if (kernel_x_end < end)
			create_mapping(kernel_x_end,
				__phys_to_virt(kernel_x_end),
				end - kernel_x_end,
				PAGE_KERNEL);
	}

}
Пример #2
0
static bool guest_physical_address_space_page_fault() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    zx_status_t status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    fbl::RefPtr<VmObject> vmo;
    status = create_vmo(PAGE_SIZE, &vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(gpas->RootVmar(), vmo, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");
    status = create_mapping(gpas->RootVmar(), vmo, PAGE_SIZE, ARCH_MMU_FLAG_PERM_READ);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");
    status = create_mapping(gpas->RootVmar(), vmo, PAGE_SIZE * 2,
                            ARCH_MMU_FLAG_PERM_READ | ARCH_MMU_FLAG_PERM_WRITE);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");
    status = create_mapping(gpas->RootVmar(), vmo, PAGE_SIZE * 3,
                            ARCH_MMU_FLAG_PERM_READ | ARCH_MMU_FLAG_PERM_EXECUTE);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Fault in each page.
    for (zx_gpaddr_t addr = 0; addr < PAGE_SIZE * 4; addr += PAGE_SIZE) {
      status = gpas->PageFault(addr);
      EXPECT_EQ(ZX_OK, status, "Failed to fault page\n");
    }

    END_TEST;
}
Пример #3
0
static bool guest_physical_address_space_map_interrupt_controller() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    zx_status_t status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    fbl::RefPtr<VmObject> vmo;
    status = create_vmo(PAGE_SIZE, &vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(gpas->RootVmar(), vmo, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Allocate a page to use as the APIC page.
    paddr_t paddr = 0;
    vm_page* vm_page;
    status = pmm_alloc_page(0, &vm_page, &paddr);
    EXPECT_EQ(ZX_OK, status, "Unable to allocate a page\n");

    // Map APIC page in an arbitrary location.
    const vaddr_t APIC_ADDRESS = 0xffff0000;
    status = gpas->MapInterruptController(APIC_ADDRESS, paddr, PAGE_SIZE);
    EXPECT_EQ(ZX_OK, status, "Failed to map APIC page\n");

    // Cleanup
    pmm_free_page(vm_page);
    END_TEST;
}
Пример #4
0
static bool guest_physical_address_space_get_page_not_present() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    zx_status_t status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    fbl::RefPtr<VmObject> vmo;
    status = create_vmo(PAGE_SIZE, &vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(gpas->RootVmar(), vmo, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Commit VMO.
    status = commit_vmo(vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to commit VMO\n");

    // Query unmapped address.
    zx_paddr_t gpas_paddr = 0;
    status = gpas->GetPage(UINTPTR_MAX, &gpas_paddr);
    EXPECT_EQ(ZX_ERR_NOT_FOUND, status,
              "GetPage returning unexpected value for unmapped address\n");

    END_TEST;
}
Пример #5
0
static bool guest_physical_address_space_unmap_range() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    zx_status_t status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    fbl::RefPtr<VmObject> vmo;
    status = create_vmo(PAGE_SIZE, &vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(gpas->RootVmar(), vmo, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Unmap page.
    status = gpas->UnmapRange(0, PAGE_SIZE);
    EXPECT_EQ(ZX_OK, status, "Failed to unmap page from GuestPhysicalAddressSpace\n");

    // Verify GetPage for unmapped address fails.
    zx_paddr_t gpas_paddr;
    status = gpas->GetPage(0, &gpas_paddr);
    EXPECT_EQ(ZX_ERR_NOT_FOUND, status,
              "GetPage returning unexpected value for unmapped address\n");

    END_TEST;
}
Пример #6
0
int memget_create_mapping(ptable_t L2_table, register_t index) {
    size_t page = find_page_type(2, page_unused);
    if(page == BOOK_END) return -1;

    create_mapping(page, L2_table, index);

    return 0;
}
Пример #7
0
// TODO: Revise to support Start & End addresses.
void insert_mapping(struct paging_state *s, lvaddr_t vaddr, lpaddr_t paddr){

    struct addr_mapping *m = create_mapping(vaddr, paddr);
    struct avl_node *n_p2v = create_node(m);
    struct avl_node *n_v2p = create_node(m);

    insert_node(s->phys_to_virt, P_TO_V, n_p2v);
    insert_node(s->virt_to_phys, V_TO_P, n_v2p);
}
Пример #8
0
static bool guest_physical_address_space_unmap_range_multiple_mappings() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    zx_status_t status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");

    fbl::RefPtr<VmObject> vmo1;
    status = create_vmo(PAGE_SIZE * 2, &vmo1);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(gpas->RootVmar(), vmo1, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    fbl::RefPtr<VmObject> vmo2;
    status = create_vmo(PAGE_SIZE * 2, &vmo2);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(gpas->RootVmar(), vmo2, PAGE_SIZE * 3);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Unmap pages.
    status = gpas->UnmapRange(PAGE_SIZE, PAGE_SIZE * 3);
    EXPECT_EQ(ZX_OK, status, "Failed to multiple unmap pages from GuestPhysicalAddressSpace\n");

    // Verify GetPage for unmapped addresses fails.
    zx_paddr_t gpas_paddr = 0;
    for (zx_gpaddr_t addr = PAGE_SIZE; addr < PAGE_SIZE * 4; addr += PAGE_SIZE) {
        status = gpas->GetPage(addr, &gpas_paddr);
        EXPECT_EQ(ZX_ERR_NOT_FOUND, status,
                  "GetPage returning unexpected value for unmapped address\n");
    }

    // Verify GetPage for mapped addresses succeeds.
    status = gpas->GetPage(0, &gpas_paddr);
    EXPECT_EQ(ZX_OK, status, "Failed to read page from GuestPhysicalAddressSpace\n");
    status = gpas->GetPage(PAGE_SIZE * 4, &gpas_paddr);
    EXPECT_EQ(ZX_OK, status, "Failed to read page from GuestPhysicalAddressSpace\n");

    END_TEST;
}
Пример #9
0
long create_mapping(LinPdeSysT & pde_system,
                    DomainType const & domain,
                    QuantityContainerT & quantities)
{
  long next_index = 0;

  for (std::size_t pde_index = 0; pde_index < pde_system.size(); ++pde_index)
  {
    next_index = create_mapping(pde_system, pde_index, domain, quantities, next_index);
  }

  return next_index;
}
Пример #10
0
int menu(int * matrix[MATRIX_SIZE][MATRIX_SIZE], STRING * name_list[MATRIX_SIZE])
{
    system("cls");
    printf("MAIN MENU\n\nPlease make a selection.\n");
    printf("0: Quit\n");
    printf("1: Modify relations\n");
    printf("2: View mapping\n");
    printf("3: View Adjacency Matrix\n");
    printf("4: New mapping\n");

    char c;
    int q=0;
    c = getch();
    c-=48;
    switch(c)
    {
    case 0:
        {
            q=1;
            break;
        }
    case 1:
        {
            break;
        }
    case 2:
        {
            view_mapping(name_list);
            getch();
            break;
        }
    case 3:
        {
            view_matrix(matrix);
            break;
        }
    case 4:
        {
            create_mapping(name_list);
            break;
        }
    default:
        {
            printf("n/a");
            break;
        }
    }
    return q;
}
Пример #11
0
static bool guest_physical_address_space_write_combining() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    fbl::RefPtr<VmObject> vmo;
    zx_status_t status = create_vmo(PAGE_SIZE, &vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = vmo->SetMappingCachePolicy(ZX_CACHE_POLICY_WRITE_COMBINING);
    EXPECT_EQ(ZX_OK, status, "Failed to set cache policy\n");

    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    status = create_mapping(gpas->RootVmar(), vmo, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    END_TEST;
}
Пример #12
0
/*******************************************************************************
 * Public function implementations
 ******************************************************************************/
struct gges_individual *gges_create_individual(struct gges_parameters *params)
{
    struct gges_individual *ind;

    ind = ALLOC(1, sizeof(struct gges_individual), false);
    ind->type = params->model;
    if (ind->type == GRAMMATICAL_EVOLUTION) {
        ind->representation.list = gges_ge_create_codon_list();
    } else if (ind->type == STRUCTURED_GRAMMATICAL_EVOLUTION) {
        ind->representation.genome = gges_sge_create_genome();
    } else {
        ind->representation.tree = NULL;
    }

    ind->mapping = create_mapping();

    ind->mapped = false;
    ind->evaluated = false;
    ind->fitness = GGES_WORST_FITNESS;

    return ind;
}
Пример #13
0
static bool guest_physical_address_space_unmap_range_outside_of_mapping() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    zx_status_t status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    fbl::RefPtr<VmObject> vmo;
    status = create_vmo(PAGE_SIZE, &vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(gpas->RootVmar(), vmo, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Unmap page.
    status = gpas->UnmapRange(PAGE_SIZE * 8, PAGE_SIZE);
    EXPECT_EQ(ZX_OK, status, "Failed to unmap page from GuestPhysicalAddressSpace\n");

    END_TEST;
}
Пример #14
0
static bool guest_physical_address_space_get_page() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    zx_status_t status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    fbl::RefPtr<VmObject> vmo;
    status = create_vmo(PAGE_SIZE, &vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(gpas->RootVmar(), vmo, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Commit VMO.
    status = commit_vmo(vmo);
    EXPECT_EQ(ZX_OK, status, "Failed to commit VMO\n");

    // Read expected physical address from the VMO.
    zx_paddr_t vmo_paddr = 0;
    status = vmo->Lookup(0, PAGE_SIZE, get_paddr, &vmo_paddr);
    EXPECT_EQ(ZX_OK, status, "Failed to lookup physical address of VMO\n");
    EXPECT_NE(0u, vmo_paddr, "Failed to lookup physical address of VMO\n");

    // Read physical address from GPAS & compare with address read from VMO.
    zx_paddr_t gpas_paddr = 0;
    status = gpas->GetPage(0, &gpas_paddr);
    EXPECT_EQ(ZX_OK, status, "Failed to read page from GuestPhysicalAddressSpace\n");
    EXPECT_EQ(vmo_paddr, gpas_paddr,
              "Incorrect physical address returned from GuestPhysicalAddressSpace::GetPage\n");

    END_TEST;
}
Пример #15
0
static void __init __map_memblock(phys_addr_t start, phys_addr_t end)
{
	create_mapping(start, __phys_to_virt(start), end - start,
			PAGE_KERNEL_EXEC);
}
Пример #16
0
static bool guest_physical_address_space_unmap_range_sub_region() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Setup.
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    zx_status_t status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    fbl::RefPtr<VmAddressRegion> root_vmar = gpas->RootVmar();
    // To test partial unmapping within sub-VMAR:
    // Sub-VMAR from [0, PAGE_SIZE * 2).
    // Map within sub-VMAR from [PAGE_SIZE, PAGE_SIZE * 2).
    fbl::RefPtr<VmAddressRegion> sub_vmar1;
    status = create_sub_vmar(root_vmar, 0, PAGE_SIZE * 2, &sub_vmar1);
    EXPECT_EQ(ZX_OK, status, "Failed to create sub-VMAR\n");
    EXPECT_TRUE(sub_vmar1->has_parent(), "Sub-VMAR does not have a parent");
    fbl::RefPtr<VmObject> vmo1;
    status = create_vmo(PAGE_SIZE, &vmo1);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(sub_vmar1, vmo1, PAGE_SIZE);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");
    // To test destroying of sub-VMAR:
    // Sub-VMAR from [PAGE_SIZE * 2, PAGE_SIZE * 3).
    // Map within sub-VMAR from [0, PAGE_SIZE).
    fbl::RefPtr<VmAddressRegion> sub_vmar2;
    status = create_sub_vmar(root_vmar, PAGE_SIZE * 2, PAGE_SIZE, &sub_vmar2);
    EXPECT_EQ(ZX_OK, status, "Failed to create sub-VMAR\n");
    EXPECT_TRUE(sub_vmar2->has_parent(), "Sub-VMAR does not have a parent");
    fbl::RefPtr<VmObject> vmo2;
    status = create_vmo(PAGE_SIZE, &vmo2);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(sub_vmar2, vmo2, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");
    // To test partial unmapping within root-VMAR:
    // Map within root-VMAR from [PAGE_SIZE * 3, PAGE_SIZE * 5).
    fbl::RefPtr<VmObject> vmo3;
    status = create_vmo(PAGE_SIZE * 2, &vmo3);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    status = create_mapping(root_vmar, vmo3, PAGE_SIZE * 3);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Unmap pages from [PAGE_SIZE, PAGE_SIZE * 4).
    status = gpas->UnmapRange(PAGE_SIZE, PAGE_SIZE * 3);
    EXPECT_EQ(ZX_OK, status, "Failed to multiple unmap pages from GuestPhysicalAddressSpace\n");

    // Verify GetPage for unmapped addresses fails.
    zx_paddr_t gpas_paddr = 0;
    for (zx_gpaddr_t addr = 0; addr < PAGE_SIZE * 4; addr += PAGE_SIZE) {
        status = gpas->GetPage(addr, &gpas_paddr);
        EXPECT_EQ(ZX_ERR_NOT_FOUND, status,
                  "GetPage returning unexpected value for unmapped address\n");
    }

    // Verify GetPage for mapped addresses succeeds.
    status = gpas->GetPage(PAGE_SIZE * 4, &gpas_paddr);
    EXPECT_EQ(ZX_OK, status, "Failed to read page from GuestPhysicalAddressSpace\n");

    // Verify that sub-VMARs still have a parent.
    EXPECT_TRUE(sub_vmar1->has_parent(), "Sub-VMAR does not have a parent");
    EXPECT_TRUE(sub_vmar2->has_parent(), "Sub-VMAR does not have a parent");

    END_TEST;
}
Пример #17
0
void
rspamd_cryptobox_test_func (void)
{
	void *map;
	guchar *begin, *end;
	rspamd_nm_t key;
	rspamd_nonce_t nonce;
	rspamd_sig_t mac;
	struct rspamd_cryptobox_segment *seg;
	double t1, t2;
	gint i, cnt, ms;

	map = create_mapping (mapping_size, &begin, &end);

	ottery_rand_bytes (key, sizeof (key));
	ottery_rand_bytes (nonce, sizeof (nonce));

	memset (mac, 0, sizeof (mac));
	seg = g_slice_alloc0 (sizeof (*seg) * max_seg * 10);

	/* Test baseline */
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encrypt_nm_inplace (begin, end - begin, nonce, key, mac);
	t2 = rspamd_get_ticks ();
	check_result (key, nonce, mac, begin, end);

	msg_info ("baseline encryption: %.6f", t2 - t1);
	/* A single chunk as vector */
	seg[0].data = begin;
	seg[0].len = end - begin;
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, 1, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("bulk encryption: %.6f", t2 - t1);

	/* Two chunks as vector */
	seg[0].data = begin;
	seg[0].len = (end - begin) / 2;
	seg[1].data = begin + seg[0].len;
	seg[1].len = (end - begin) - seg[0].len;
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("2 equal chunks encryption: %.6f", t2 - t1);

	seg[0].data = begin;
	seg[0].len = 1;
	seg[1].data = begin + seg[0].len;
	seg[1].len = (end - begin) - seg[0].len;
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("small and large chunks encryption: %.6f", t2 - t1);

	seg[0].data = begin;
	seg[0].len = (end - begin) - 3;
	seg[1].data = begin + seg[0].len;
	seg[1].len = (end - begin) - seg[0].len;
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("large and small chunks encryption: %.6f", t2 - t1);

	/* Random two chunks as vector */
	seg[0].data = begin;
	seg[0].len = ottery_rand_range (end - begin - 1) + 1;
	seg[1].data = begin + seg[0].len;
	seg[1].len = (end - begin) - seg[0].len;
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, 2, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("random 2 chunks encryption: %.6f", t2 - t1);

	/* 3 specific chunks */
	seg[0].data = begin;
	seg[0].len = 2;
	seg[1].data = begin + seg[0].len;
	seg[1].len = 2049;
	seg[2].data = begin + seg[0].len + seg[1].len;
	seg[2].len = (end - begin) - seg[0].len - seg[1].len;
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, 3, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("small, medium and large chunks encryption: %.6f", t2 - t1);

	cnt = create_random_split (seg, max_seg, begin, end);
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("random split of %d chunks encryption: %.6f", cnt, t2 - t1);

	cnt = create_realistic_split (seg, max_seg, begin, end);
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("realistic split of %d chunks encryption: %.6f", cnt, t2 - t1);

	cnt = create_constrainted_split (seg, max_seg + 1, 32, begin, end);
	t1 = rspamd_get_ticks ();
	rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
	t2 = rspamd_get_ticks ();

	check_result (key, nonce, mac, begin, end);

	msg_info ("constrainted split of %d chunks encryption: %.6f", cnt, t2 - t1);

	for (i = 0; i < random_fuzz_cnt; i ++) {
		ms = ottery_rand_range (i % max_seg * 2) + 1;
		cnt = create_random_split (seg, ms, begin, end);
		t1 = rspamd_get_ticks ();
		rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
		t2 = rspamd_get_ticks ();

		check_result (key, nonce, mac, begin, end);

		if (i % 1000 == 0) {
			msg_info ("random fuzz iterations: %d", i);
		}
	}
	for (i = 0; i < random_fuzz_cnt; i ++) {
		ms = ottery_rand_range (i % max_seg * 2) + 1;
		cnt = create_realistic_split (seg, ms, begin, end);
		t1 = rspamd_get_ticks ();
		rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
		t2 = rspamd_get_ticks ();

		check_result (key, nonce, mac, begin, end);

		if (i % 1000 == 0) {
			msg_info ("realistic fuzz iterations: %d", i);
		}
	}
	for (i = 0; i < random_fuzz_cnt; i ++) {
		ms = ottery_rand_range (i % max_seg * 10) + 1;
		cnt = create_constrainted_split (seg, ms, i, begin, end);
		t1 = rspamd_get_ticks ();
		rspamd_cryptobox_encryptv_nm_inplace (seg, cnt, nonce, key, mac);
		t2 = rspamd_get_ticks ();

		check_result (key, nonce, mac, begin, end);

		if (i % 1000 == 0) {
			msg_info ("constrainted fuzz iterations: %d", i);
		}
	}
}
Пример #18
0
      void operator()(SystemType pde_system,
                      DomainType & domain,
                      MatrixT    & system_matrix,
                      VectorT    & load_vector
                     ) const
      {
        typedef typename viennagrid::result_of::cell_tag<DomainType>::type CellTag;

        typedef typename viennagrid::result_of::point<DomainType>::type                                   PointType;
        typedef typename viennagrid::result_of::element<DomainType, CellTag>::type                        CellType;

        typedef typename viennagrid::result_of::element_range<DomainType, CellTag>::type                  CellContainer;
        typedef typename viennagrid::result_of::iterator<CellContainer>::type                             CellIterator;

        typedef typename SystemType::equation_type                  EquationType;

     #ifdef VIENNAFEM_DEBUG
        std::cout << "Strong form: " << pde_system.pde(0) << std::endl;
     #endif
        log_strong_form(pde_system);
        EquationType weak_form_general = viennafem::make_weak_form(pde_system.pde(0));
     #ifdef VIENNAFEM_DEBUG
        std::cout << "* pde_solver::operator(): Using weak form general: " << weak_form_general << std::endl;
     #endif
        std::vector<EquationType> temp(1); temp[0] = weak_form_general;
        log_weak_form(temp, pde_system);
        EquationType weak_form = viennamath::apply_coordinate_system(viennamath::cartesian< PointType::dim >(), weak_form_general);
        //EquationType weak_form = viennamath::apply_coordinate_system(viennamath::cartesian<Config::coordinate_system_tag::dim>(), weak_form_general);
        temp[0] = weak_form;
        log_coordinated_weak_form(temp, pde_system);

     #ifdef VIENNAFEM_DEBUG
        std::cout << "* pde_solver::operator(): Using weak form " << weak_form << std::endl;
        std::cout << "* pde_solver::operator(): Write dt_dx coefficients" << std::endl;
     #endif

        typedef typename reference_cell_for_basis<CellTag, viennafem::lagrange_tag<1> >::type    ReferenceCell;

        //
        // Create accessors for performance in the subsequent dt_dx_handler step
        //

        //viennafem::dtdx_assigner<DomainType, StorageType, ReferenceCell>::apply(domain, storage);

        viennafem::dt_dx_handler<DomainType, StorageType, ReferenceCell>  dt_dx_handler(domain, storage);

        //fill with cell quantities
        CellContainer cells = viennagrid::elements<CellType>(domain);
        for (CellIterator cell_iter = cells.begin();
            cell_iter != cells.end();
            ++cell_iter)
        {
          //cell_iter->print_short();
          //viennadata::access<example_key, double>()(*cell_iter) = i;
          //viennafem::dt_dx_handler<ReferenceCell>::apply(storage, *cell_iter);
          dt_dx_handler(*cell_iter);
        }

     #ifdef VIENNAFEM_DEBUG
        std::cout << "* pde_solver::operator(): Create Mapping:" << std::endl;
     #endif
        std::size_t map_index = create_mapping(storage, pde_system, domain);

     #ifdef VIENNAFEM_DEBUG
        std::cout << "* pde_solver::operator(): Assigned degrees of freedom in domain so far: " << map_index << std::endl;
     #endif
        // resize global system matrix and load vector if needed:
        // TODO: This can be a performance bottleneck for large numbers of segments! (lots of resize operations...)
        if (map_index > system_matrix.size1())
        {
          MatrixT temp = system_matrix;
          ////std::cout << "Resizing system matrix..." << std::endl;
          system_matrix.resize(map_index, map_index, false);
          system_matrix.clear();
          system_matrix.resize(map_index, map_index, false);
          for (typename MatrixT::iterator1 row_it = temp.begin1();
               row_it != temp.end1();
               ++row_it)
          {
            for (typename MatrixT::iterator2 col_it = row_it.begin();
                 col_it != row_it.end();
                 ++col_it)
                 system_matrix(col_it.index1(), col_it.index2()) = *col_it;
          }
        }
        if (map_index > load_vector.size())
        {
          VectorT temp = load_vector;
       #ifdef VIENNAFEM_DEBUG
          std::cout << "Resizing load vector..." << std::endl;
       #endif
          load_vector.resize(map_index, false);
          load_vector.clear();
          load_vector.resize(map_index, false);
          for (std::size_t i=0; i<temp.size(); ++i)
            load_vector(i) = temp(i);
        }

     #ifdef VIENNAFEM_DEBUG
        std::cout << "* pde_solver::operator(): Transform to reference element" << std::endl;
     #endif
        EquationType transformed_weak_form = viennafem::transform_to_reference_cell<CellType>(storage, weak_form, pde_system);
        temp[0] = transformed_weak_form;
        log_transformed_weak_form<CellType, StorageType>(temp, pde_system);

        std::cout << "* pde_solver::operator(): Transformed weak form:" << std::endl;
        std::cout << transformed_weak_form << std::endl;
        //std::cout << std::endl;

     #ifdef VIENNAFEM_DEBUG
        std::cout << "* pde_solver::operator(): Assemble system" << std::endl;
     #endif

        typedef detail::equation_wrapper<MatrixT, VectorT>    wrapper_type;
        wrapper_type wrapper(system_matrix, load_vector);

        detail::pde_assembler_internal()(storage, transformed_weak_form, pde_system, domain, wrapper);
//        pde_assembler_internal()(transformed_weak_form, pde_system, domain, system_matrix, load_vector);

      }
Пример #19
0
static bool guest_physical_address_space_get_page_complex() {
    BEGIN_TEST;

    if (!hypervisor_supported()) {
        return true;
    }

    // Test GetPage with a less trivial VMAR configuration.
    //
    //                  0 -->+--------+
    //                       |  Root  |
    //                       |  VMO   |
    //      ROOT_VMO_SIZE -->---------+ +--------+
    //                       |        | | Second |
    // ROOT_VMO_SIZE +       |        | | VMO    |
    //    SECOND_VMO_SIZE -->---------+ +--------+
    //                       |  Root  | | Shadow |
    //                       |  VMAR  | | VMAR   |
    //                        ~~~~~~~~   ~~~~~~~~
    //
    // The 'Root VMO/VMAR' is the default configuration when initializing
    // GuestPhysicalAddressSpace with a VMO size of 'PAGE_SIZE'. This test
    // allocates a second VMAR and VMO and attaches them both into the 'Root
    // VMAR' to ensure we correctly locate addresses in these structures.
    const uint ROOT_VMO_SIZE = PAGE_SIZE;
    const uint SECOND_VMO_SIZE = PAGE_SIZE;

    // Setup.
    fbl::RefPtr<VmObject> vmo1;
    zx_status_t status = create_vmo(ROOT_VMO_SIZE, &vmo1);
    EXPECT_EQ(ZX_OK, status, "Failed to create VMO\n");
    ktl::unique_ptr<hypervisor::GuestPhysicalAddressSpace> gpas;
    status = create_gpas(&gpas);
    EXPECT_EQ(ZX_OK, status, "Failed to create GuestPhysicalAddressSpace\n");
    fbl::RefPtr<VmAddressRegion> root_vmar = gpas->RootVmar();
    status = create_mapping(root_vmar, vmo1, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to create mapping\n");

    // Commit first VMO.
    status = commit_vmo(vmo1);
    EXPECT_EQ(ZX_OK, status, "Failed to commit VMO\n");

    // Allocate second VMAR, offset one page into the root.
    fbl::RefPtr<VmAddressRegion> shadow_vmar;
    status = create_sub_vmar(root_vmar, ROOT_VMO_SIZE, root_vmar->size() - ROOT_VMO_SIZE,
                             &shadow_vmar);
    EXPECT_EQ(ZX_OK, status, "Failed to create shadow VMAR\n");

    // Allocate second VMO; we'll map the original VMO on top of this one.
    fbl::RefPtr<VmObject> vmo2;
    status = create_vmo(SECOND_VMO_SIZE, &vmo2);
    EXPECT_EQ(ZX_OK, status, "Failed allocate second VMO\n");

    // Commit second VMO.
    status = commit_vmo(vmo2);
    EXPECT_EQ(ZX_OK, status, "Failed to commit second VMO\n");

    // Map second VMO into second VMAR.
    status = create_mapping(shadow_vmar, vmo2, 0);
    EXPECT_EQ(ZX_OK, status, "Failed to map vmo into shadow vmar\n");

    // Read expected physical address from the VMO.
    zx_paddr_t vmo_paddr = 0;
    status = vmo2->Lookup(0, PAGE_SIZE, get_paddr, &vmo_paddr);
    EXPECT_EQ(ZX_OK, status, "Failed to lookup physical address of VMO\n");
    EXPECT_NE(0u, vmo_paddr, "Failed to lookup physical address of VMO\n");

    // Read physical address from GPAS.
    zx_paddr_t gpas_paddr = 0;
    status = gpas->GetPage(ROOT_VMO_SIZE, &gpas_paddr);
    EXPECT_EQ(ZX_OK, status, "Failed to read page from GuestPhysicalAddressSpace\n");
    EXPECT_EQ(vmo_paddr, gpas_paddr,
              "Incorrect physical address returned from GuestPhysicalAddressSpace::GetPage\n");
    END_TEST;
}