




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 ISO/IEC 27403:2024 EN Cybersecurity – IoT security and privacy – Guidelines for IoT-domotics
- 2025年無機(jī)分離膜材料合作協(xié)議書
- 2025版安置房買賣合同范本:限價(jià)房交易政策范本
- 2025年度廠區(qū)門衛(wèi)智能化升級(jí)改造服務(wù)合同范本
- 2025年高壓清洗車合作協(xié)議書
- 社團(tuán)活動(dòng)反饋與改進(jìn)方案計(jì)劃
- 教學(xué)資源整合與優(yōu)化策略計(jì)劃
- 企業(yè)未來發(fā)展的創(chuàng)新思考計(jì)劃
- 財(cái)務(wù)企劃管理計(jì)劃
- 建立健全院內(nèi)溝通反饋機(jī)制的計(jì)劃
- 新部編版小學(xué)六年級(jí)下冊(cè)語文第二單元測(cè)試卷及答案
- 5《這些事我來做》(說課稿)-部編版道德與法治四年級(jí)上冊(cè)
- 2025年福建福州市倉山區(qū)國(guó)有投資發(fā)展集團(tuán)有限公司招聘筆試參考題庫附帶答案詳解
- 2025年廣東省深圳法院招聘書記員招聘144人歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025年人教版新教材數(shù)學(xué)一年級(jí)下冊(cè)教學(xué)計(jì)劃(含進(jìn)度表)
- GB/T 45107-2024表土剝離及其再利用技術(shù)要求
- 2025長(zhǎng)江航道工程局招聘101人歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 2025年春西師版一年級(jí)下冊(cè)數(shù)學(xué)教學(xué)計(jì)劃
- 2025年國(guó)新國(guó)際投資有限公司招聘筆試參考題庫含答案解析
- 2025年八省聯(lián)考四川高考生物試卷真題答案詳解(精校打印)
- 《供電營(yíng)業(yè)規(guī)則》
評(píng)論
0/150
提交評(píng)論