/* create the pages structure and allocate the default pages with default size */ mmc_GC_pages_type pages_create(size_t default_pages_size, size_t default_page_size, size_t default_number_of_pages, size_t default_free_slots_size) { mmc_GC_pages_type pages = {0, 0, 0,}; size_t sz = sizeof(mmc_GC_page_type) * default_pages_size; size_t i = 0; pages.start = (mmc_GC_page_type*)malloc(sz); if (!pages.start) { fprintf(stderr, "not enough memory (%lu) to allocate the pages!\n", (long unsigned int)sz); fflush(NULL); assert(pages.start != 0); } /* the current index points to the start at the begining! */ pages.current = 0; /* the limit points to the end of the pages array */ pages.limit = default_pages_size; for (i = 0; i < default_number_of_pages; i++) { pages = pages_add(pages, page_create(default_page_size, default_free_slots_size)); } return pages; }
static menu_screen_error_e _animated_pack_item(Evas_Object *item, Evas_Object *scroller, Evas_Object *page, int from) { Evas_Object *item_out_page = NULL; char buf[32]; int to; int page_no; retv_if(NULL == item, MENU_SCREEN_ERROR_INVALID_PARAMETER); retv_if(NULL == scroller, MENU_SCREEN_ERROR_INVALID_PARAMETER); retv_if(NULL == page, MENU_SCREEN_ERROR_INVALID_PARAMETER); page_no = page_scroller_get_page_no(scroller, page); do { to = page_find_empty_near(page, from); if (to < 0) { int page_max_app; page_max_app = (int) evas_object_data_get(page, "page_max_app"); to = page_max_app - 1; item_out_page = page_unpack_item_at(page, to); } for (to --; to >= from; to --) { Evas_Object *item_in_page; item_in_page = page_unpack_item_at(page, to); page_pack_item(page, to + 1, item_in_page); snprintf(buf, 32, "menu%d", to + 1); edje_object_signal_emit(_EDJ(page), STR_MOVE_PREV, buf); edje_object_signal_emit(_EDJ(page), STR_ANI_RETURN, buf); } page_pack_item(page, from, item); if (!item_out_page) break; page_no ++; page = page_scroller_get_page_at(scroller, page_no); if (!page) { int rotate; rotate = (int) evas_object_data_get(scroller, "rotate"); page = page_create(scroller, page_no, rotate); retv_if(NULL == page, MENU_SCREEN_ERROR_FAIL); mapbuf_enable(page, 0); } from = 0; item = item_out_page; item_out_page = NULL; } while (page && item); return MENU_SCREEN_ERROR_OK; }
int op_page_next(cmd_t *cmd, boolean_t smpl) { /* * Create a new page and append it after the current page in page * list. The new page is showed in page_next_execute(). */ if (page_create(cmd) != NULL) { if (page_next_execute(smpl)) { return (0); } } return (-1); }
VALUE doc_page_at(VALUE doc, VALUE pg){ VALUE page; int page_number; Document *document; Data_Get_Struct( doc, Document, document); page_number = FIX2INT(pg); if ( page_number < 0 || page_number > fz_count_pages(document->fz_document) ){ rb_raise(rb_eArgError, "Page Number must be between 0..%d",page_number); } page = document->pages[page_number]; if ( ! page ){ page = page_create(document, page_number); rb_gc_mark(page); document->pages[page_number] = page; } printf("Doc page_at: %016" PRIxPTR " %lu\n", (uintptr_t)document, page); return page; }
/* Fault handling function called by trap code */ int vm_fault(int faulttype, vaddr_t faultaddress) { struct addrspace* as = proc_getas(); if (as == NULL) { //kprintf("AS was null\n"); return EFAULT; } struct region* reg = findRegionForFaultAddress(as, faultaddress); if (reg == NULL) { //kprintf("Region not found\n"); return EFAULT; } // TODO Check if it is a permission issue and return an error code in that case. // get page struct page* pg = findPageForFaultAddress(as, faultaddress); if (pg == NULL) { struct page* newpage = page_create(as, faultaddress); pg = newpage; } if (pg == NULL) { //kprintf("Failed to create a page\n"); return EFAULT; } if (pg->pt_state == PT_STATE_SWAPPED) { //kprintf("Trying swap out from %x\n",pg->pt_pagebase); //kprintf("Swap out page Vaddr = %x\n",pg->pt_virtbase); swapout(as, pg); //kprintf("after swap out paddr = %x\n",pg->pt_pagebase); //kprintf("after Swap out Vaddr = %x\n", pg->pt_virtbase); //kprintf("after Swap out state = %d\n",pg->pt_state); } // load page address to tlb int spl = splhigh(); tlb_random(pg->pt_virtbase * PAGE_SIZE, (pg->pt_pagebase * PAGE_SIZE) | TLBLO_DIRTY | TLBLO_VALID); splx(spl); (void) faulttype; return 0; }
void renderer_init() { SYS_VERIFY( shader_create( &s_renderer.paperShader, &s_shader_paper, 1u, 1u, 0u ) ); SYS_VERIFY( shader_create( &s_renderer.penShader, &s_shader_pen, 0u, 2u, 0u ) ); SYS_VERIFY( shader_create( &s_renderer.pageShader, &s_shader_page, 0u, 0u, 3u ) ); SYS_VERIFY( shader_create( &s_renderer.pageFlipShader, &s_shader_pageflip, 1u, 0u, 2u ) ); SYS_VERIFY( shader_create( &s_renderer.burnHoleShader, &s_shader_burnhole, 0u, 2u, 1u ) ); SYS_VERIFY( shader_create( &s_renderer.noiseShader, &s_shader_noise, 0u, 0u, 0u ) ); #ifndef SYS_BUILD_MASTER SYS_VERIFY( shader_create( &s_renderer.debugPenShader, &s_shader_debugpen, 1u, 0u, 0u ) ); #endif SYS_VERIFY( rendertarget_create( &s_renderer.noiseTarget, 512u, 512u, PixelFormat_R8G8B8A8 ) ); graphics_setBlendMode( BlendMode_Disabled ); // fill noise map: graphics_setRenderTarget( &s_renderer.noiseTarget ); graphics_setShader( &s_renderer.noiseShader ); graphics_drawFullscreenQuad(); const int width = sys_getScreenWidth(); const int height = sys_getScreenHeight(); // create page: for( uint i = 0u; i < SYS_COUNTOF( s_renderer.pages ); ++i ) { page_create( &s_renderer.pages[ i ], width, height ); } s_renderer.currentPage = 0u; s_renderer.lastPage = 1u; s_renderer.currentCommand = 0u; s_renderer.pageNumber = 0u; s_renderer.pageState = PageState_Done; s_renderer.stateTime = 0.0f; clearStrokeBuffer( &s_renderer.strokeBuffer ); float3 color; color.x = 0.2f; color.y = 0.2f; color.z = 0.2f; createPen( &s_renderer.pens[ Pen_Default ], 2.0f, 1.0f, &color ); createPen( &s_renderer.pens[ Pen_Font ], 2.0f, 1.0f, &color ); createPen( &s_renderer.pens[ Pen_Fat ], 3.0f, 1.0f, &color ); createPen( &s_renderer.pens[ Pen_DebugRed ], 2.0f, 1.0f, float3_set( &color, 1.0f, 0.0f, 0.0f ) ); createPen( &s_renderer.pens[ Pen_DebugGreen ], 2.0f, 1.0f, float3_set( &color, 0.0f, 1.0f, 0.0f ) ); createPen( &s_renderer.pens[ Pen_PageNumber ], 2.0f, 1.0f, float3_set( &color, 0.0f, 0.0f, 0.0f ) ); // create page flip mesh: createPageFlipMesh( &s_renderer.pageFlipMesh, 64u, 36u ); s_renderer.flipTime = -1.0f; for( uint i = 0u; i < SYS_COUNTOF(s_renderer.burnHoles); ++i ) { s_renderer.burnHoles[i].size = -1.0f; } renderer_setDrawSpeed( 0.5f ); renderer_setPen( Pen_Default ); renderer_setTransform( 0 ); }
void* frame_evict (void* uaddr) { /* 1. Choose a frame to evict, using your page replacement algorithm. The "accessed" and "dirty" bits in the page table, described below, will come in handy. */ struct frame_table_entry *fte = NULL; switch (PAGE_EVICTION_ALGORITHM) { /* First in first out */ case PAGE_EVICTION_FIFO: fte = frame_evict_choose_fifo (); break; /* Second chance */ case PAGE_EVICTION_SECONDCHANCE: fte = frame_evict_choose_secondchance (); break; default: PANIC ("Invalid eviction algorithm choice."); } ASSERT (fte != NULL); /* 2. Remove references to the frame from any page table that refers to it. Unless you have implemented sharing, only a single page should refer to a frame at any given time. */ pagedir_clear_page (fte->owner->pagedir, pg_round_down (fte->uaddr)); /* 3. If necessary, write the page to the file system or to swap. The evicted frame may then be used to store a different page. */ struct page *p_evict = page_lookup (fte->owner->pages, pg_round_down (fte->uaddr)); if (p_evict == NULL) PANIC ("Failed to get supp page for existing page."); /* Page to be evicted is in swap */ if (p_evict->page_location_option == FILESYS) { if (p_evict->writable) { file_write_at (p_evict->file, fte->kaddr, p_evict->page_read_bytes, p_evict->ofs); } } else if (p_evict->page_location_option == ALLZERO) { // All zero, so can just be overwritten } else { // From stack int index = swap_to_disk (pg_round_down (fte->uaddr)); /* Creates a supp page and insert it into pages. */ struct page *p = page_create (); if (p == NULL) PANIC ("Failed to get supp page for swap slot."); p->addr = fte->uaddr; p->page_location_option = SWAPSLOT; p->swap_index = index; page_insert (fte->owner->pages, &p->hash_elem); } /* Replace virtual address with new virtual address */ fte->owner = thread_current (); fte->uaddr = uaddr; /* Reinsert the frame table entry into the frame table */ lock_acquire (&frame_table_lock); list_remove (&fte->elem); list_push_front (&frame_table, &fte->elem); lock_release (&frame_table_lock); return fte->kaddr; }