void proc1_test1(char *msg ) { char *addr; int i; get_bs(TEST1_BS, 100); if (xmmap(PROC1_VPNO, TEST1_BS, 100) == SYSERR) { kprintf("xmmap call failed\n"); sleep(3); return; } addr = (char*) PROC1_VADDR; for (i = 0; i < 26; i++) { register char a; *(addr + i * NBPG) = a = 'A' + i; kprintf("%s Writing 0x%x: %c a=%c\n", msg, (addr + i * NBPG), *(addr + i * NBPG),a); } sleep(1); for (i = 25; i >=0; i--) { kprintf("%s 0x%08x: %c\n",msg, addr + i * NBPG, *(addr + i * NBPG)); } xmunmap(PROC1_VPNO); sleep(10); release_bs(TEST1_BS); return; }
proc_share_fifo1() { char *addr = (char*) 0x80050000; bsd_t bs = 6; int i = ((unsigned long) addr) >> 12; get_bs(bs, 256); kprintf("\nPROC A: got bs"); if (xmmap(i, bs, 256) == SYSERR) { kprintf("xmmap call failed\n"); return 0; } else { kprintf("\nPROC A: xmmap success"); } for (i = 0; i < 256; i++) { //kprintf("\nPROC A: in for loop count %d",i); *addr = 'A'; //kprintf("\n\n in for %s",*addr); addr += NBPG; //increment by one page each time } sleep(10); //accessing the first shared frame addr = (char*) 0x80050000; kprintf("\nAccessing the first vpaddr %lu, data %c\n",(unsigned long)addr, *addr); xmunmap(0x80050000 >> 12); }
int procB() { char *addr = (char*) 0x60000000; //1G int i = ((unsigned long) addr) >> 12; // the ith page int result; kprintf("procB lives\n"); bsd_t bs = 1; result = get_bs(bs, 100); if(result == SYSERR){ kprintf("procB get_bs call failed\n"); return 0; } else kprintf("procB get_bs call result %d\n", result); if (xmmap(i, bs, 100) == SYSERR) { kprintf("procB xmmap call failed\n"); return 0; } addr = (char*) 0x60000000; //1G for (i = 0; i < 10; i++) { kprintf("procB 0x%08x: %c\n", addr, *addr); addr += 4096; //increment by one page each time } return 0; }
void test_aging(char *name, char *arg) { kprintf("executing %s, this is tested with 25 frames only. change NFRAMES to 25\n", name); kprintf("setting aging policy\n"); srpolicy(AGING); char *addr = (char*) 0x40000000; //1G bsd_t bs = 1; int i = ((unsigned long) addr) >> 12; // the ith page get_bs(bs, 200); if (xmmap(i, bs, 200) == SYSERR) { kprintf("xmmap call failed\n"); return; } i = 0; kprintf("*******************generating first page fault\n"); *addr = 'A' + (i++); addr += NBPG; //increment by one page each time kprintf("************filling all the pages\n"); while (!is_free_frm_list_empty()) { *addr = 'A' + (i++); addr += NBPG; //increment by one page each time } kprintf("*************all pages filled\n"); kprintf("access first page again\n"); addr = (char*) 0x40000000; //1G *addr = 'A'; kprintf("************generating aging page fault\n"); addr += ((++i) * NBPG); //increment by one page each time *addr = 'Z'; kprintf("setting back fifo policy\n"); srpolicy(FIFO); }
void procA(void) { int rc = EMPTY; int vpage = 6000; int npages = 100; int bs_id = 5; char *x; char temp; rc = get_bs(bs_id, npages); kprintf("get_bs in %s.. %d\n", __func__, rc); rc = xmmap(vpage, bs_id, npages); kprintf("xmmap in %s.. %d\n", rc); x = (char *) (vpage * NBPG); kprintf("%s trying to access vaddr 0x%08x\n", __func__, x); *x = 'Y'; temp = *x; kprintf("value of temp in %s.. %c\n", __func__, temp); sleep(10); rc = xmunmap(vpage); kprintf("xmunmap in %s.. %d\n", __func__, rc); rc = release_bs(bs_id); kprintf("release_bs in %s.. %d\n", __func__, rc); return; }
proc1(char c) { bsd_t bs = get_free_bs(); get_bs(bs, 250); char *addr = (char*) 0x20000000; int i = ((unsigned long) addr) >> 12; if (xmmap(i, bs, 250) == SYSERR) { kprintf("xmmap call failed\n"); return 0; } else { } for (i = 0; i < 250; i++) { *addr = 500 + i; addr += NBPG; //increment by one page each time } sleep(5); xmunmap(0x20000000 >> 12); release_bs(bs); kill(currpid); }
////////////////////////////////////////////////////////////////////////// // basic_test ( given code from initial main.c ) ////////////////////////////////////////////////////////////////////////// void basic_test() { char *addr = (char*) 0x40000000; //1G bsd_t bs = 1; int i = ((unsigned long) addr) >> 12; // the ith page kprintf("\n\nHello World, Xinu lives\n\n"); get_bs(bs, 200); if (xmmap(i, bs, 200) == SYSERR) { kprintf("xmmap call failed\n"); return 0; } for (i = 0; i < 16; i++) { *addr = 'A' + i; addr += NBPG; //increment by one page each time } addr = (char*) 0x40000000; //1G for (i = 0; i < 16; i++) { kprintf("0x%08x: %c\n", addr, *addr); addr += 4096; //increment by one page each time } xmunmap(0x40000000 >> 12); }
void procA(void) { int vpage = 9000; int npages = 100; bsd_t bs = 1; char *addr; int i = 0; addr = (char *) (vpage * NBPG); get_bs(bs, npages); if (xmmap(vpage, bs, npages) == SYSERR) { kprintf("xmmap call failed\n"); return; } kprintf("data in %s..\n", __func__); addr = (char *) (vpage * NBPG) + NBPG; for (i = 0; i < 26; ++i) { kprintf("0x%08x: %c\n", addr, *addr); addr += NBPG; } xmunmap(vpage); return; }
void proc1_test4(int* ret) { char *addr; int i; get_bs(MYBS1, 100); if (xmmap(MYVPNO1, MYBS1, 100) == SYSERR) { kprintf("xmmap call failed\n"); *ret = TFAILED; sleep(3); return; } addr = (char*) MYVADDR1; for (i = 0; i < 26; i++) { *(addr + i * NBPG) = 'A' + i; } sleep(6); /*Shoud see what proc 2 updated*/ for (i = 0; i < 26; i++) { /*expected output is abcde.....*/ if (*(addr + i * NBPG) != 'a'+i){ *ret = TFAILED; break; } } xmunmap(MYVPNO1); release_bs(MYBS1); return; }
void test_xmmap(char *name, char *arg){ char *addr = (char*) 0x40000000; //1G bsd_t bs = 1; int i = ((unsigned long) addr) >> 12; // the ith page get_bs(bs, 200); if (xmmap(i, bs, 200) == SYSERR) { kprintf("xmmap call failed\n"); return; } for (i = 0; i < 16; i++) { kprintf("Write Operation\n==================\n"); *addr = 'A' + i; addr += NBPG; //increment by one page each time } addr = (char*) 0x40000000; //1G for (i = 0; i < 16; i++) { kprintf("\nRead Operation\n==================\n"); kprintf("0x%08x: %c\n", addr, *addr); addr += 4096; //increment by one page each time } xmunmap(0x40000000 >> 12); }
void test_default() { char *addr = (char*) 0x40000000; //1G bsd_t bs = get_free_bs(); int i = ((unsigned long) addr) >> 12; // the ith page kprintf("\n\nHello World, Xinu lives %d\n\n", i); get_bs(bs, 200); if (xmmap(i, bs, 200) == SYSERR) { kprintf("xmmap call failed\n"); return 0; } else { } for (i = 0; i < 16; i++) { *addr = 'A' + i; addr += NBPG; //increment by one page each time } addr = (char*) 0x40000000; //1G for (i = 0; i < 16; i++) { kprintf("0x%08x: %c\n", addr, *addr); addr += 4096; //increment by one page each time } xmunmap(0x40003000 >> 12); release_bs(bs); //resume(create(main,INITSTK,INITPRIO,INITNAME,INITARGS)); }
proc_new_share3(char c) { char *addr = (char*) 0x60050000; bsd_t bs = 6; int i = ((unsigned long) addr) >> 12; get_bs(bs, 200); kprintf("\nPROC C: got bs"); if (xmmap(i, bs, 200) == SYSERR) { kprintf("xmmap call failed\n"); return 0; } else { kprintf("\nPROC C: xmmap success"); } for (i = 0; i < 10; i++) { kprintf("\nPROC C: in for loop count %d",i); *addr = 'X' + i; //kprintf("\n\n in for %s",*addr); addr += NBPG; //increment by one page each time } sleep(5); xmunmap(0x60050000 >> 12); }
void test_getbs_A(void) { int bs_id = 5; int npages = 120; int rc = -1; rc = get_bs(bs_id, npages); kprintf("%d %s> asked %d, got %d\n", currpid, __func__, npages, rc); #ifdef DBG_ON print_bs_details(bs_id, TRUE); #endif sleep(2); rc = release_bs(bs_id); kprintf("%d %s: release_bs() returned %d\n", currpid, __func__, rc); sleep(2); npages = 50; rc = get_bs(bs_id, npages); kprintf("%d %s> asked %d, got %d\n", currpid, __func__, npages, rc); #ifdef DBG_ON print_bs_details(bs_id, TRUE); #endif rc = xmmap(4095, 5, 50); kprintf("%d %s> xmmap asked %d, got %d\n", currpid, __func__, npages, rc); sleep(2); return; }
void proc1_test1(char *msg, int lck) { char *addr; int i; get_bs(TEST1_BS, 200); if (xmmap(PROC1_VPNO, TEST1_BS, 200) == SYSERR) { kprintf("xmmap call failed\n"); sleep(3); return; } addr = (char*) PROC1_VADDR; for (i = 0; i < 26; i++) { *(addr + i * NBPG) = 'A' + i; } sleep(6); for (i = 0; i < 26; i++) { kprintf("0x%08x: %c\n", addr + i * NBPG, *(addr + i * NBPG)); } xmunmap(PROC1_VPNO); return; }
void proc2_test4(int *ret) { char *addr; int i; get_bs(MYBS1, 100); if (xmmap(MYVPNO2, MYBS1, 100) == SYSERR) { kprintf("xmmap call failed\n"); *ret = TFAILED; sleep(3); return; } addr = (char*) MYVADDR2; /*Shoud see what proc 1 updated*/ for (i = 0; i < 26; i++) { /*expected output is ABCDEF.....*/ if (*(addr + i * NBPG) != 'A'+i){ *ret = TFAILED; break; } } /*Update the content, proc1 should see it*/ for (i = 0; i < 26; i++) { *(addr + i * NBPG) = 'a' + i; } xmunmap(MYVPNO2); release_bs(MYBS1); return; }
void test1() { kprintf("\nTest 1: Testing xmmap.\n"); char *addr1 = (char*)0x40000000; int i = ((unsigned long)addr1) >> 12; get_bs(MYBS1, 100); if (xmmap(i, MYBS1, 100) == SYSERR) { kprintf("xmmap call failed\n"); kprintf("\tFAILED!\n"); return; } for (i = 0; i < 26; i++) { *addr1 = 'A'+i; //trigger page fault for every iteration addr1 += NBPG; //increment by one page each time } addr1 = (char*)0x40000000; for (i = 0; i < 26; i++) { if (*addr1 != 'A'+i) { kprintf("\tFAILED!\n"); return; } addr1 += NBPG; //increment by one page each time } xmunmap(0x40000000>>12); release_bs(MYBS1); kprintf("\tPASSED!\n"); return; }
void kill_task2(int sem) { int i,j; int rc; char * x; char *addr = (char*) 0x50000000; bsd_t bsid = 5; int npages = 5; kprintf("kill_task2... start consuming.\n"); get_bs(bsid, npages); rc = xmmap(VA2VPNO(addr), bsid, npages); if (rc == SYSERR) { kprintf("xmmap call failed\n"); return 0; } kprintf("kill_task2.. sleeping 5\n"); sleep(5); // Read back all of the values from memory and print them out x = addr; kprintf("kill_task2 end: "); for (i = 0; i < npages; i++) { for (j = 0; j < 5; j++) { kprintf("%c", *(x + j)); } kprintf(" "); x += NBPG; //go to the next page } kprintf("\n"); kprintf("kill_task2.. sleeping 5\n"); sleep(5); // NOTE: This is after other task has been killed // Read back all of the values from memory and print them out x = addr; kprintf("kill_task2 end: "); for (i = 0; i < npages; i++) { for (j = 0; j < 5; j++) { kprintf("%c", *(x + j)); } kprintf(" "); x += NBPG; //go to the next page } kprintf("\n"); sleep(1); xmunmap(VA2VPNO(addr)); release_bs(bsid); }
static void *init(char *file, struct stat *s) { int fd; void *buf; fd = xopen(file, O_RDONLY); xfstat(fd, s); buf = xmmap(NULL, s->st_size, PROT_READ, MAP_PRIVATE, fd, 0); return (buf); }
proc_share2(char c) { char *x; char temp_b; xmmap(60000, 4, 100); x = (char *)(60000 * NBPG); sleep(10); kprintf("\nReading from proc 2 %c (should be Y) and no page fault should be generated\n", *x); xmunmap(60000); }
proc_share1(char c) { char *x; char temp; get_bs(4, 100); xmmap(70000, 4, 100); /* This call simply creates an entry in the backing store mapping */ x = (char *)(70000*NBPG); *x = 'Y'; /* write into virtual memory, will create a fault and system should proceed as in the prev example */ kprintf("\nReading from proc 1 %c\n", *x); /* read back and check */ sleep(5); xmunmap(70000); }
void test_xmmap_failure(char *name, char *arg){ kprintf("executing %s\n", name); char *addr = (char*) 0x40000000; //1G bsd_t bs = 0; int i = ((unsigned long) addr) >> 12; // the ith page get_bs(bs, 200); if (xmmap(i, bs, 200) == SYSERR) { kprintf("Expected:xmmap call failed\n"); return; } }
////////////////////////////////////////////////////////////////////////// // random_access (tests replacement policies) ////////////////////////////////////////////////////////////////////////// void random_access_test() { int i, x, rc; char *addr = (char*) 0x50000000; char *w; bsd_t bsid = 7; int npages = 40; pt_t * pt; virt_addr_t * vaddr; kprintf("\nRandom access test\n"); srand(25); // some random seed rc = get_bs(bsid, npages); if (rc == SYSERR) { kprintf("get_bs call failed\n"); return 0; } rc = xmmap(VA2VPNO(addr), bsid, npages); if (rc == SYSERR) { kprintf("xmmap call failed\n"); return 0; } for (i=0; i<50; i++) { // Get a number between 0 and npages // This number will be the page offset from the // beginning of the backing store that we will access x = ((int) rand()) % npages; // Get the virtual address w = addr + x*NBPG; *w = 'F'; vaddr = &w; pt = VPNO2VA(proctab[currpid].pd[vaddr->pd_offset].pt_base); kprintf("Just accessed vaddr:0x%08x frame:%d bspage:%d\n", w, PA2FID(VPNO2VA(pt[vaddr->pt_offset].p_base)), x); } xmunmap(VA2VPNO(addr)); release_bs(bsid); }
/* * Depending on `mmap_strategy`, either mmap or read the contents of * the `packed-refs` file into the snapshot. Return 1 if the file * existed and was read, or 0 if the file was absent. Die on errors. */ static int load_contents(struct snapshot *snapshot) { int fd; struct stat st; size_t size; ssize_t bytes_read; fd = open(snapshot->refs->path, O_RDONLY); if (fd < 0) { if (errno == ENOENT) { /* * This is OK; it just means that no * "packed-refs" file has been written yet, * which is equivalent to it being empty, * which is its state when initialized with * zeros. */ return 0; } else { die_errno("couldn't read %s", snapshot->refs->path); } } stat_validity_update(&snapshot->validity, fd); if (fstat(fd, &st) < 0) die_errno("couldn't stat %s", snapshot->refs->path); size = xsize_t(st.st_size); switch (mmap_strategy) { case MMAP_NONE: snapshot->buf = xmalloc(size); bytes_read = read_in_full(fd, snapshot->buf, size); if (bytes_read < 0 || bytes_read != size) die_errno("couldn't read %s", snapshot->refs->path); snapshot->eof = snapshot->buf + size; snapshot->mmapped = 0; break; case MMAP_TEMPORARY: case MMAP_OK: snapshot->buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); snapshot->eof = snapshot->buf + size; snapshot->mmapped = 1; break; } close(fd); return 1; }
/*-------------------------------------------------------------------------------------*/ void proc1_test3(int i,int* ret) { char *addr; int bsize; int r; get_bs(i, 100); if (xmmap(MYVPNO1, i, 100) == SYSERR) { *ret = TFAILED; return 0; } sleep(4); xmunmap(MYVPNO1); release_bs(i); return; }
static void build_code(char *str) { char *args[] = {"as", "--32", SFILE_WRITE, "-o", BFILE_WRITE, NULL}; Elf32_Ehdr *aspElf_Header; Elf32_Shdr *aspElf_Shdr; Elf32_Off offset; struct stat sts; uint32_t size; int status; void *map; pid_t pid; int fd; del_files(); write_source_file(str); pid = fork(); if (pid == 0) { execvp(args[0], args); exit(EXIT_SUCCESS); } waitpid(pid, &status, 0); if (stat(BFILE_WRITE, &sts) == -1) exit(EXIT_FAILURE); fd = xopen(BFILE_WRITE, O_RDONLY, 0644); map = xmmap(0, sts.st_size, PROT_READ, MAP_SHARED, fd, 0); aspElf_Header = map; aspElf_Shdr = (Elf32_Shdr *)((char *)map + aspElf_Header->e_shoff); offset = return_info_text(0, map, aspElf_Header, aspElf_Shdr); size = return_info_text(1, map, aspElf_Header, aspElf_Shdr); asm_mode.size = size; asm_mode.opcode = xmalloc((size * sizeof(char)) + 1); asm_mode.argument = str; memcpy((char *)asm_mode.opcode, (char *)map + offset, asm_mode.size); opcode_mode.flag = 1; opcode_mode.size = asm_mode.size; opcode_mode.opcode = asm_mode.opcode; xclose(fd); del_files(); }
/*------------------------------------------------------------------------ * main -- user main program *------------------------------------------------------------------------ */ int main() { int proc_A, proc_B, process_VA; int result; kprintf("\n\nHello World, Xinu lives\n\n"); //srpolicy(FIFO); char *addr = (char*) 0x40000000; //1G bsd_t bs = 1; int i = ((unsigned long) addr) >> 12; // the ith page result = get_bs(bs, 200); if(result == SYSERR){ kprintf("get_bs call failed\n"); return 0; } else kprintf("main get_bs call result %d\n", result); if (xmmap(i, bs, 150) == SYSERR) { kprintf("xmmap call failed\n"); return 0; } for (i = 0; i < 10; i++) { *addr = 'A' + i; addr += NBPG; //increment by one page each time } addr = (char*) 0x40000000; //1G for (i = 0; i < 10; i++) { kprintf("0x%08x: %c\n", addr, *addr); addr += 4096; //increment by one page each time } proc_B = create(procB,INITSTK,INITPRIO,"procB",INITARGS); resume(proc_B); process_VA = vcreate(processVA,INITSTK,100,INITPRIO,"processVA",INITARGS); resume(process_VA); sleep(2); xmunmap(0x40000000 >> 12); release_bs(bs); kprintf("All izz well\n"); return 0; }
void error_test() { int p1; int rc; char *addr = (char*) 0x40000000; //1G int hsize = 100; // heap size in pages int npages = 20; kprintf("\nBasic error tests\n"); // Tests test case 1 rc = xmmap(VA2VPNO(addr), 5, npages); if (rc == SYSERR) { kprintf("error_test: Test 1 PASS!\n"); } else { kprintf("error_test: Test 1 FAIL!\n"); } // Create a process that is always ready to run at priority 15 p1 = vcreate(error_task, 2000, 20, hsize, "error_task", 0, NULL); resume(p1); sleep(1); npages = get_bs(1, 10); if (npages != 10) kprintf("error_test: Test 3A FAIL!\n"); else kprintf("error_test: Test 3A PASS!\n"); npages = get_bs(1,20); //<-- get_bs should return 10 here if (npages != 10) kprintf("error_test: Test 3B FAIL!\n"); else kprintf("error_test: Test 3B PASS!\n"); npages = get_bs(1,5); //<-- get_bs should return 10 here if (npages != 10) kprintf("error_test: Test 3C FAIL!\n"); else kprintf("error_test: Test 3C PASS!\n"); sleep(1); }
void test_xmmap_share(char *name, char *arg){ kprintf("\nthe data written by previous process should be read\n"); char *addr = (char*) 0x80000000; //1G bsd_t bs = 1; int i = ((unsigned long) addr) >> 12; // the ith page if (xmmap(i, bs, 200) == SYSERR) { kprintf("xmmap call failed\n"); return; // return SYSERR; } for (i = 0; i < 16; i++) { kprintf("\nRead Operation\n==================\n"); kprintf("0x%08x: %c\n", addr, *addr); addr += 4096; //increment by one page each time } xmunmap(0x80000000 >> 12); // return OK; }
int main() { int vpage = 5000; int npages = 100; bsd_t bs = 1; char *addr; int i = 0; int pA = 0; kprintf("\n\nHello World, Xinu lives\n\n"); pA = create(procA, 1024, 20, "procA", 0, 0); addr = (char *) (vpage * NBPG); get_bs(bs, npages); if (xmmap(vpage, bs, npages) == SYSERR) { kprintf("xmmap call failed\n"); return 0; } for (i = 0; i < 26; ++i){ *addr = 'A' + i; addr += NBPG; } kprintf("data in %s..\n", __func__); addr = (char *) (vpage * NBPG); for (i = 0; i < 26; ++i) { kprintf("0x%08x: %c\n", addr, *addr); addr += NBPG; } xmunmap(vpage); release_bs(bs); resume(pA); sleep(10); return 0; }
/*----------------------------------------------------------------*/ void proc_test2(int i,int j,int* ret,int s) { char *addr; int bsize; int r; bsize = get_bs(i, j); if (bsize != 50) *ret = TFAILED; r = xmmap(MYVPNO1, i, j); if (j<=50 && r == SYSERR){ *ret = TFAILED; } if (j> 50 && r != SYSERR){ *ret = TFAILED; } sleep(s); if (r != SYSERR) xmunmap(MYVPNO1); release_bs(i); return; }