void send_jpeg_data(rgb_ptr image_buffer, int quality) { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE * outfile; JSAMPROW row_pointer[1]; int row_stride; char filename[256]; get_tmp_file_name(filename, get_io_cfg()->tmp_path); cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); if ((outfile = fopen(filename, "wb")) == NULL ) { fprintf(stderr, "can't open %s\n", filename); return; } jpeg_stdio_dest(&cinfo, outfile); cinfo.image_width = get_cap()-> weigth; cinfo.image_height = get_cap()-> height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, true); jpeg_start_compress(&cinfo, true); row_stride = get_cap()-> weigth * 3; while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = &image_buffer[cinfo.next_scanline * row_stride]; (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_compress(&cinfo); fclose(outfile); jpeg_destroy_compress(&cinfo); FILE* f; f = fopen(filename, "r"); int c; size_t s = 0; char* buff = malloc(1024 * 30); while((c = getc(f))!=EOF){ buff[s++]=c; } fclose(f); send_data((rgb_ptr)buff, s); free(buff); }
static int test_cnode_mutate(env_t env) { int error; seL4_Word src, dest; /* A call that should succeed. */ src = get_cap(&env->vka); dest = get_free_slot(env); error = cnode_mutate(env, src, dest); test_assert(!error); test_assert(is_slot_empty(env, src)); test_assert(!is_slot_empty(env, dest)); /* Mutating to an occupied slot (should fail). */ src = get_cap(&env->vka); dest = get_cap(&env->vka); error = cnode_mutate(env, src, dest); test_assert(error == seL4_DeleteFirst); test_assert(!is_slot_empty(env, src)); test_assert(!is_slot_empty(env, dest)); /* Mutating an empty slot (should fail). */ src = get_free_slot(env); dest = get_free_slot(env); error = cnode_mutate(env, src, dest); test_assert(error == seL4_FailedLookup); test_assert(is_slot_empty(env, src)); test_assert(is_slot_empty(env, dest)); return sel4test_get_result(); }
static int test_cnode_mint(env_t env) { int error; seL4_Word src, dest; /* A call that should succeed. */ src = get_cap(&env->vka); dest = get_free_slot(env); error = cnode_mint(env, src, dest, seL4_AllRights, seL4_NilData); test_assert(!error); test_assert(!are_tcbs_distinct(src, dest)); /* Mint to an occupied slot (should fail). */ src = get_cap(&env->vka); dest = get_cap(&env->vka); error = cnode_mint(env, src, dest, seL4_AllRights, seL4_NilData); test_assert(error == seL4_DeleteFirst); test_assert(are_tcbs_distinct(src, dest)); /* Mint from an empty slot (should fail). */ src = get_free_slot(env); dest = get_free_slot(env); error = cnode_mint(env, src, dest, seL4_AllRights, seL4_NilData); test_assert(error == seL4_FailedLookup); test_assert(are_tcbs_distinct(src, dest)); return sel4test_get_result(); }
void sel4utils_unmap_pages(vspace_t *vspace, void *vaddr, size_t num_pages, size_t size_bits, vka_t *vka) { uintptr_t v = (uintptr_t) vaddr; sel4utils_alloc_data_t *data = get_alloc_data(vspace); sel4utils_res_t *reserve = find_reserve(data, v); if (!sel4_valid_size_bits(size_bits)) { ZF_LOGE("Invalid size_bits %zu", size_bits); return; } if (vka == VSPACE_FREE) { vka = data->vka; } for (int i = 0; i < num_pages; i++) { seL4_CPtr cap = get_cap(data->top_level, v); /* unmap */ if (cap != 0) { int error = seL4_ARCH_Page_Unmap(cap); if (error != seL4_NoError) { ZF_LOGE("Failed to unmap page at vaddr %p", vaddr); } } if (vka) { cspacepath_t path; vka_cspace_make_path(vka, cap, &path); vka_cnode_delete(&path); vka_cspace_free(vka, cap); if (sel4utils_get_cookie(vspace, vaddr)) { vka_utspace_free(vka, kobject_get_type(KOBJECT_FRAME, size_bits), size_bits, sel4utils_get_cookie(vspace, vaddr)); } } if (reserve == NULL) { clear_entries(vspace, v, size_bits); } else { reserve_entries(vspace, v, size_bits); } assert(get_cap(data->top_level, v) != cap); assert(get_cookie(data->top_level, v) == 0); v += (1 << size_bits); vaddr = (void *) v; } }
Obj_space_virt<SPACE>::v_delete(V_pfn virt, Order size, L4_fpage::Rights page_attribs) { (void)size; assert (size == Order(0)); Entry *c; if (Optimize_local && SPACE::mem_space(this) == Mem_space::current_mem_space(current_cpu())) { c = cap_virt(virt); if (!c) return L4_fpage::Rights(0); Capability cap = Mem_layout::read_special_safe((Capability*)c); if (!cap.valid()) return L4_fpage::Rights(0); } else c = get_cap(virt); if (c && c->valid()) { if (page_attribs & L4_fpage::Rights::R()) c->invalidate(); else c->del_rights(page_attribs & L4_fpage::Rights::CWSD()); } return L4_fpage::Rights(0); }
typename Generic_obj_space<SPACE>::Status Generic_obj_space<SPACE>::v_insert(Phys_addr phys, Addr const &virt, Size size, unsigned char page_attribs) { (void)size; assert (size.value() == 1); Entry *c = get_cap(virt.value()); if (!c && !(c = caps_alloc(virt.value()))) return Insert_err_nomem; assert (size.value() == 1); if (c->valid()) { if (c->obj() == phys) { if (EXPECT_FALSE(c->rights() == page_attribs)) return Insert_warn_exists; c->add_rights(page_attribs); return Insert_warn_attrib_upgrade; } else return Insert_err_exists; } Obj::set_entry(virt, c); c->set(phys, page_attribs); return Insert_ok; }
static void max8903_work(struct work_struct *work) { struct max8903_data *data = container_of(work, struct max8903_data, work.work); get_cap(data); schedule_delayed_work(&data->work, MAX8903_DELAY); }
unsigned long Generic_obj_space<SPACE>::v_delete(Page_number virt, Size size, unsigned long page_attribs = L4_fpage::CRWSD) { (void)size; assert (size.value() == 1); Entry *c; if (Optimize_local && mem_space() == Mem_space::current_mem_space(current_cpu())) { c = cap_virt(virt.value()); if (!c) return 0; Capability cap = Mem_layout::read_special_safe((Capability*)c); if (!cap.valid()) return 0; } else c = get_cap(virt.value()); if (c && c->valid()) { if (page_attribs & L4_fpage::R) c->invalidate(); else c->del_rights(page_attribs & L4_fpage::CWSD); } return 0; }
void Obj_space_virt<SPACE>::caps_free() { Mem_space *ms = SPACE::mem_space(this); if (EXPECT_FALSE(!ms || !ms->dir())) return; Kmem_alloc *a = Kmem_alloc::allocator(); for (Cap_index i = Cap_index(0); i < obj_map_max_address(); i += Cap_diff(Obj::Caps_per_page)) { Entry *c = get_cap(i); if (!c) continue; Address cp = Address(ms->virt_to_phys(Address(c))); assert_kdb (cp != ~0UL); void *cv = (void*)Mem_layout::phys_to_pmem(cp); Obj::remove_cap_page_dbg_info(cv); a->q_unaligned_free(SPACE::ram_quota(this), Config::PAGE_SIZE, cv); } ms->dir()->destroy(Virt_addr(Mem_layout::Caps_start), Virt_addr(Mem_layout::Caps_end-1), Pdir::Super_level, Pdir::Depth, Kmem_alloc::q_allocator(SPACE::ram_quota(this))); }
bool Generic_obj_space<SPACE>::v_lookup(Addr const &virt, Phys_addr *phys = 0, Size *size = 0, unsigned *attribs = 0) { if (size) size->set_value(1); Entry *cap; if (Optimize_local && mem_space() == Mem_space::current_mem_space(current_cpu())) cap = cap_virt(virt.value()); else cap = get_cap(virt.value()); if (EXPECT_FALSE(!cap)) { if (size) size->set_value(Caps_per_page); return false; } if (Optimize_local) { Capability c = Mem_layout::read_special_safe((Capability*)cap); if (phys) *phys = c.obj(); if (c.valid() && attribs) *attribs = c.rights(); return c.valid(); } else { Obj::set_entry(virt, cap); if (phys) *phys = cap->obj(); if (cap->valid() && attribs) *attribs = cap->rights(); return cap->valid(); } }
void Generic_obj_space<SPACE>::caps_free() { Mem_space *ms = mem_space(); if (EXPECT_FALSE(!ms || !ms->dir())) return; Mapped_allocator *a = Mapped_allocator::allocator(); for (unsigned long i = 0; i < map_max_address().value(); i += Caps_per_page) { Entry *c = get_cap(i); if (!c) continue; Address cp = Address(ms->virt_to_phys(Address(c))); assert_kdb (cp != ~0UL); void *cv = (void*)Mem_layout::phys_to_pmem(cp); remove_dbg_info(cv); a->q_unaligned_free(ram_quota(), Config::PAGE_SIZE, cv); } #if defined (CONFIG_ARM) ms->dir()->free_page_tables((void*)Mem_layout::Caps_start, (void*)Mem_layout::Caps_end); #else ms->dir()->Pdir::alloc_cast<Mem_space_q_alloc>() ->destroy(Virt_addr(Mem_layout::Caps_start), Virt_addr(Mem_layout::Caps_end), Pdir::Depth - 1, Mem_space_q_alloc(ram_quota(), Mapped_allocator::allocator())); #endif }
Obj_space_phys<SPACE>::v_insert(Phys_addr phys, V_pfn const &virt, Page_order size, Attr page_attribs) { (void)size; assert (size == Page_order(0)); Entry *c = get_cap(virt); if (!c && !(c = caps_alloc(virt))) return Obj::Insert_err_nomem; if (c->valid()) { if (c->obj() == phys) { if (EXPECT_FALSE(c->rights() == page_attribs)) return Obj::Insert_warn_exists; c->add_rights(page_attribs); return Obj::Insert_warn_attrib_upgrade; } else return Obj::Insert_err_exists; } Obj::set_entry(virt, c); c->set(phys, page_attribs); return Obj::Insert_ok; }
static int test_cnode_rotate(env_t env) { int error; seL4_Word src, pivot, dest; /* A call that should succeed. */ src = get_cap(&env->vka); pivot = get_cap(&env->vka); dest = get_free_slot(env); error = cnode_rotate(env, src, pivot, dest); test_assert(!error); test_assert(is_slot_empty(env, src)); test_assert(!is_slot_empty(env, pivot)); test_assert(!is_slot_empty(env, dest)); /* Destination occupied (should fail). */ src = get_cap(&env->vka); pivot = get_cap(&env->vka); dest = get_cap(&env->vka); error = cnode_rotate(env, src, pivot, dest); test_assert(error == seL4_DeleteFirst); test_assert(!is_slot_empty(env, src)); test_assert(!is_slot_empty(env, pivot)); test_assert(!is_slot_empty(env, dest)); /* Swapping two caps (should succeed). */ src = get_cap(&env->vka); pivot = get_cap(&env->vka); dest = src; error = cnode_rotate(env, src, pivot, dest); test_assert(!error); test_assert(!are_tcbs_distinct(src, dest)); test_assert(!is_slot_empty(env, pivot)); /* Moving a cap onto itself (should fail). */ src = get_cap(&env->vka); pivot = src; dest = get_free_slot(env); error = cnode_rotate(env, src, pivot, dest); test_assert(error == seL4_IllegalOperation); test_assert(!is_slot_empty(env, src)); test_assert(is_slot_empty(env, dest)); /* Moving empty slots (should fail). */ src = get_free_slot(env); pivot = get_free_slot(env); dest = get_free_slot(env); error = cnode_rotate(env, src, pivot, dest); test_assert(error == seL4_FailedLookup); test_assert(is_slot_empty(env, src)); test_assert(is_slot_empty(env, pivot)); test_assert(is_slot_empty(env, dest)); return sel4test_get_result(); }
void write_jpeg_file(rgb_ptr image_buffer, int quality) { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE * outfile; JSAMPROW row_pointer[1]; int row_stride; char filename[256]; get_file_name(filename, get_io_cfg()->path); cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); if ((outfile = fopen(filename, "wb")) == NULL ) { fprintf(stderr, "can't open %s\n", filename); return; } jpeg_stdio_dest(&cinfo, outfile); cinfo.image_width = get_cap()-> weigth; cinfo.image_height = get_cap()-> height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, true); jpeg_start_compress(&cinfo, true); row_stride = get_cap()-> weigth * 3; while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = &image_buffer[cinfo.next_scanline * row_stride]; (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_compress(&cinfo); fclose(outfile); jpeg_destroy_compress(&cinfo); }
typename Obj_space_phys<SPACE>::Capability __attribute__((__flatten__)) Obj_space_phys<SPACE>::lookup(Cap_index virt) { Capability *c = get_cap(virt); if (EXPECT_FALSE(!c)) return Capability(0); // void return *c; }
typename Generic_obj_space<SPACE>::Capability Generic_obj_space<SPACE>::lookup(Address virt) { Capability *c = get_cap(virt); if (EXPECT_FALSE(!c)) return Capability(0); // void return *c; }
seL4_CPtr sel4utils_get_cap(vspace_t *vspace, void *vaddr) { sel4utils_alloc_data_t *data = get_alloc_data(vspace); seL4_CPtr cap = get_cap(data->top_level, (uintptr_t) vaddr); if (cap == RESERVED) { cap = 0; } return cap; }
void* startcapture(void* dev) { can_stop = 1; capture* d = get_cap(); dev_name = d->device; wigth = d->weigth; heigth = d->height; open_device(); init_device(); start_capturing(); mainloop(d->refresh); stop_capturing(); uninit_device(); close_device(); return 0; }
typename Obj_space_virt<SPACE>::Capability __attribute__((__flatten__)) Obj_space_virt<SPACE>::lookup(Cap_index virt) { Capability *c; virt &= Cap_index(~(~0UL << Whole_space)); if (SPACE::mem_space(this) == Mem_space::current_mem_space(current_cpu())) c = reinterpret_cast<Capability*>(cap_virt(virt)); else c = get_cap(virt); if (EXPECT_FALSE(!c)) return Capability(0); // void return Mem_layout::read_special_safe(c); }
inline Kobject_iface * Generic_obj_space<SPACE>::lookup_local(Address virt, unsigned char *rights = 0) { Entry *c = get_cap(virt); if (EXPECT_FALSE(!c)) return 0; Capability cap = *c; if (rights) *rights = cap.rights(); return cap.obj(); }
typename Generic_obj_space<SPACE>::Capability Generic_obj_space<SPACE>::lookup(Address virt) { Capability *c; virt &= ~(~0UL << Whole_space); if (mem_space() == Mem_space::current_mem_space(current_cpu())) c = reinterpret_cast<Capability*>(cap_virt(virt)); else c = get_cap(virt); if (EXPECT_FALSE(!c)) return Capability(0); // void return Mem_layout::read_special_safe(c); }
inline Kobject_iface * Obj_space_phys<SPACE>::lookup_local(Cap_index virt, L4_fpage::Rights *rights) { Entry *c = get_cap(virt); if (EXPECT_FALSE(!c)) return 0; Capability cap = *c; if (rights) *rights = L4_fpage::Rights(cap.rights()); return cap.obj(); }
Obj_space_phys<SPACE>::v_delete(V_pfn virt, Page_order size, L4_fpage::Rights page_attribs = L4_fpage::Rights::FULL()) { (void)size; assert (size == Page_order(0)); Capability *c = get_cap(virt); if (c && c->valid()) { if (page_attribs & L4_fpage::Rights::R()) c->invalidate(); else c->del_rights(page_attribs); } return L4_fpage::Rights(0); }
Obj_space_virt<SPACE>::v_insert(Phys_addr phys, V_pfn const &virt, Order size, Attr page_attribs) { (void)size; assert (size == Order(0)); Entry *c; if (Optimize_local && SPACE::mem_space(this) == Mem_space::current_mem_space(current_cpu())) { c = cap_virt(virt); if (!c) return Obj::Insert_err_nomem; Capability cap; if (!Mem_layout::read_special_safe((Capability*)c, cap) && !caps_alloc(virt)) return Obj::Insert_err_nomem; } else { c = get_cap(virt); if (!c && !(c = caps_alloc(virt))) return Obj::Insert_err_nomem; Obj::set_entry(virt, c); } if (c->valid()) { if (c->obj() == phys) { if (EXPECT_FALSE(c->rights() == page_attribs)) return Obj::Insert_warn_exists; c->add_rights(page_attribs); return Obj::Insert_warn_attrib_upgrade; } else return Obj::Insert_err_exists; } c->set(phys, page_attribs); return Obj::Insert_ok; }
unsigned long Generic_obj_space<SPACE>::v_delete(Page_number virt, Size size, unsigned long page_attribs = L4_fpage::RWX) { (void)size; assert (size.value() == 1); Capability *c = get_cap(virt.value()); if (c && c->valid()) { if (page_attribs & L4_fpage::R) c->invalidate(); else c->del_rights(page_attribs & L4_fpage::WX); } return 0; }
Obj_space_phys<SPACE>::v_lookup(V_pfn const &virt, Phys_addr *phys, Page_order *size, Attr *attribs) { if (size) *size = Page_order(0); Entry *cap = get_cap(virt); if (EXPECT_FALSE(!cap)) { if (size) *size = Page_order(Obj::Caps_per_page_ld2); return false; } Capability c = *cap; Obj::set_entry(virt, cap); if (phys) *phys = c.obj(); if (c.valid() && attribs) *attribs = cap->rights(); return c.valid(); }
static int test_cnode_recycle(env_t env) { int error; seL4_Word slot; /* A call that should succeed. */ slot = get_cap(&env->vka); error = cnode_recycle(env, slot); test_assert(!error); test_assert(!is_slot_empty(env, slot)); /* Recycling an empty slot (should fail). */ slot = get_free_slot(env); error = cnode_recycle(env, slot); test_assert(error == seL4_IllegalOperation); test_assert(is_slot_empty(env, slot)); return sel4test_get_result(); }
static int test_cnode_revoke(env_t env) { int error; seL4_Word slot; /* A call that should succeed. */ slot = get_cap(&env->vka); error = cnode_revoke(env, slot); test_assert(!error); test_assert(!is_slot_empty(env, slot)); /* Revoking a null cap (should fail). */ slot = get_free_slot(env); error = cnode_revoke(env, slot); test_assert(!error); test_assert(is_slot_empty(env, slot)); return sel4test_get_result(); }
bool Generic_obj_space<SPACE>::v_lookup(Addr const &virt, Phys_addr *phys = 0, Size *size = 0, unsigned *attribs = 0) { if (size) *size = Size::create(1); Entry *cap = get_cap(virt.value()); if (EXPECT_FALSE(!cap)) { if (size) *size = Size::create(Caps_per_page); return false; } Capability c = *cap; Obj::set_entry(virt, cap); if (phys) *phys = c.obj(); if (c.valid() && attribs) *attribs = cap->rights(); return c.valid(); }
static int test_cnode_delete(env_t env) { int error; seL4_Word slot; /* A call that should succeed. */ slot = get_cap(&env->vka); error = cnode_delete(env, slot); test_assert(!error); test_assert(is_slot_empty(env, slot)); /* Deleting a free slot (should succeed). */ slot = get_free_slot(env); error = cnode_delete(env, slot); test_assert(!error); test_assert(is_slot_empty(env, slot)); return sel4test_get_result(); }