Beispiel #1
0
/**
 * Returns the next unused frame, based on the PROT_READ flag,
 * or NO_UNUSED_FRAMES if none are available.
 */
int next_unused_frame(struct page_table *pt) {
    int i;

    for (i = 0; i < page_table_get_nframes(pt); ++i)
        if (ft[i] == -1) return i;

    return NO_UNUSED_FRAMES;
}
void page_fault_handler( struct page_table *pt, int page )
{
    printf("page_rep_choice=%i\n",page_rep_choice);
    int frame,nframes,npages,retframe,bits;
    // get max number of pages and frames
    nframes = page_table_get_nframes(pt);
    npages = page_table_get_npages(pt);

    // check if frame number should be page number
    if (nframes>=npages){
	    printf("page fault on page #%d\n",page);
        frame = page;
    }
    // FIFO
    else if (nframes<npages){
	    printf("page fault on page #%d\n",page);
	    if (page_rep_choice==0){
	        // RAND
	        frame = page;
        }
        else if (page_rep_choice==1){
	        // FIFO
	        frame = page % nframes;
        }
        else if (page_rep_choice==2){
            // CUSTOM
            frame = page;
        }
    }

    // check permissions
    //  - no permissions -> read
    //  - read permissions -> write
    //  - write permissions -> all
    if (bits==0){
        page_table_set_entry(pt,page,frame,PROT_READ);
    }
    else if(bits==1){
        page_table_set_entry(pt,page,frame,PROT_WRITE);
    }
    else{
        page_table_set_entry(pt,page,frame,PROT_READ|PROT_WRITE|PROT_EXEC);
    }

    page_table_get_entry(pt,page,&retframe,&bits);
    printf("frame=%i\tbits=%i\n",retframe,bits);
    
//	exit(1);
}
Beispiel #3
0
void custom_handler(struct page_table *pt, int page) {
    int i, frame, bits,
        nframes = page_table_get_nframes(pt),
        rand_count = MAX(1, nframes * CUST_RAND_PCT / 100),
        rand_frames[rand_count];

    for (i = 0; i < rand_count; ++i) {
        rand_frames[i] = lrand48() % nframes;
    }

    for (i = 0; i < rand_count; ++i) {
        page_table_get_entry(pt, ft[rand_frames[i]], &frame, &bits);
        if (!has_write(bits)) {
            swap_page(pt, page, frame);
            return;
        }
    }

    swap_page(pt, page, frame);
}
Beispiel #4
0
void fifo_handler(struct page_table *pt, int page) {
    swap_page(pt, page, fi++ % page_table_get_nframes(pt));
}
Beispiel #5
0
void rand_handler(struct page_table *pt, int page) {
    // Get page of random frame from ft
    int frame = lrand48() % page_table_get_nframes(pt);
    swap_page(pt, page, frame);
}