操作系統(tǒng)期中期末試題11_第1頁
操作系統(tǒng)期中期末試題11_第2頁
操作系統(tǒng)期中期末試題11_第3頁
操作系統(tǒng)期中期末試題11_第4頁
操作系統(tǒng)期中期末試題11_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、 A 2011 04 12 9:5011:50 :1. ? ? ? ? ?2. ? ?, ? , ? ?3. ?, ?4. ? ? ? ? 7 ? ? ? 7 ?5.?, ? ? (15?)?ucore? ? ?kern/trap/trap.h.struct trapframe struct pushregs tf_regs;u u u u u/* u u u u u/ u uu16_t16_t16_t16_t32_t below 32_ttf_es; tf_padding1; tf_ds; tf_padding2; tf_trapno;here defined by x86 hardware

2、 */tf_err;ptr_t tf_eip;16_t16_t32_t belowtf_cs; tf_padding3; tf_eflags;here only whencrossing rings, suchas from user to kernelptr_t tf_esp;16_t16_ttf_ss;tf_padding4; attribute (packed);.kern/trap/trap.c.sic 1 / 7 pgfault_handler(struct trapframe *tf) extern struct mm_struct *check_mm_struct; pr_pgf

3、ault(tf);if (check_mm_struct != NULL) return do_pgfault(check_mm_struct, tf tf_err, rcr2();panic(unhandled page fault.n);sic voidtrap_dispatch(struct trapframe *tf) char c;ret;switch ( -YOUR CODE 1- ) .case T_PGFLT:if ( -YOUR CODE 2- ) != 0) pr_trapframe(tf); if (current = NULL) panic(handle pgfault

4、 failed. %en, ret);else . break;.voidtrap(struct trapframe *tf) / dispatch based on what type of trap occurred trap_dispatch(tf);./ do_pgfaulterrupndler to pros the page fault execptiondo_pgfault(struct mm_struct *mm, u32_t error_code, uptr_t addr)ret =E_INVAL;struct vma_struct *vma = find_vma(mm, a

5、ddr); if (vma = NULL | vma vm_start addr) goto failed;switch (error_code & 3) default:/* default is 3: write, present */case 2: /* write, not present */ 2 / 7 if (!(vma vm_flags & VM_WRITE) goto failed;break;case 1: /* read, present */ goto failed;case 0: /* read, not present */if (!(vma vm_flags &

6、(VM_READ | goto failed;VM_EXEC)u32_t perm = PTE_U;if (vma vm_flags & VM_WRITE) perm |= PTE_W;addr = ROUNDDOWN(addr, PGSIZE);ret =E_NO_MEM;if (pgdir_alloc_page(mm pgdir, goto failed;ret = 0;addr,perm)=0)failed:return ret;.Pmm.h./ppn is physical page numbersic inline ppn_tpage2ppn(struct Page *page) r

7、eturn -YOUR CODE 3-;/pa is physical addresssic inline uptr_tpage2pa(struct Page *page) return -YOUR CODE 4-;. 3 / 7 pmm.c./ virtual address of struct Page *pages;/ amount of physical size_t npage = 0;/ virtual address ofphysicall page arraymemory (in pages)boot time page directorypde_t *boot_pgdir =

8、 NULL;/pgdir_alloc_pagecall alloc_page & page_insert functions toallocate a page size memorypala with linear address& setup an addr mapla and the PDT pgdirstructPage *pgdir_alloc_page(pde_t *pgdir, uptr_t la, u32_t perm) struct Page *page = alloc_page();if (page != NULL) if (page_insert(pgdir, free_

9、page(page); return NULL;page, la, perm) != 0) return page;./page_insertbuild the mapof phy addr of an Page with the linearaddr la/paramemters:pgdir: the kernel virtualbase address of PDTpage: la: perm:returnthe Page which need to mapthe linear addreeed to mapthe permisvalue: always 0of this Page whi

10、ch is setted in related pte/note: PT is changed, so the TLB need to be invalidatepage_insert(pde_t *pgdir, struct Page *page, u pte_t *ptep = get_pte(pgdir, la, 1);if (ptep = NULL) ptr_t la, u32_t perm) returnE_NO_MEM;page_ref_inc(page); if (*ptep & PTE_P) struct Page *p = pte2page(*ptep); if (p = p

11、age) page_ref_dec(page); 4 / 7 else page_remove_pte(pgdir, la, ptep);*ptep = -YOUR CODE 5-tlb_invalidate(pgdir, la);return 0;? (17?)?1? ?-? ?(Buddy System)?2? ?1MB? ? ? ?1)?A ?34KB?2)?B ?66KB?3)?C ?35KB?4)?D ?67KB?5)?C6)?A7)?B8)?D? (16?) ? ? (10?)?1? ? ?Clock Page Replacement?2? ? ?4? ?c, a, d,b, e,

12、 c, b, a, d, b, c, a, d?|? ? ? (20?)?1? ?_? ? ?2? ?32? ? ? ?=?0X87654321?& ?= ? ?%? (10?)$?fork.c?#? ?1?get()getp()? ?!? ? 0?123?12?2?|?,?4?56?12?7?819A? (?B?56?C?12-1000?fork.c/* Includes */#include #include #include#include/* Symbolic Constants */* Primitive System Da/* Errors */* Input/Output */y

13、pes */ 5 / 7 #include #include /* Wait for Pros Termination */* General Utilities */main()_t childretval; sus; /*variable to store the childs*/* child pro/* parent pros: usrovided returncode */*/s: childs exit sus/* only 1variable is needed because each proswould have itsown instance of the variable

14、here, 2variables are used for clarity */* now create new pros */child= fork();if(child= 0) /* fork succeeded */if (child= 0) /* fork() returns 0 to the child pros */pr pr pr prprf(CHILD:f(CHILD:f(CHILD:I am the childpros!n);Heres myMy parents:%dn, getis: %dn,();getp();f(CHILD: The value of my copy o

15、f childf(CHILD: Sleng for 1 second.n);is: %dn, child);sleep(1); /* sleep for 1 second */prf(CHILD: Enter an exit value (0 to 255): );scanf( %d, &retval);prf(CHILD: Goodbye!n);exit(retval); /* child exits with usrovided return code */else /*pr pr pr prfork() returns newto the parent pros */f(PARENT:

16、I am the parent pros!n);f(PARENT: Heres my: %dn, get();is %dn, childf(PARENT: The value of my copy of child);f(PARENT: I will now wait for my child to exit.n);wait(&sus); /* wait for child to exit, and store its sus */us);prprf(PARENT: Childs exit code is: %dn, WEXITSf(PARENT: Goodbye!n);US(sexit(0); /* parent exits */else /* fork returns1 on failure */perror(fork); /* display error message */ 6 / 7 exit(0);D? (12?) ? ? ?=?E

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論