Jos-lab3 Exercise 7&9
来源:互联网 发布:mysql约束是什么 编辑:程序博客网 时间:2024/04/28 05:10
Exercise 7.Add a handler in the kernelfor interrupt vectorT_SYSCALL
.You will have to edit kern/trapentry.S and kern/trap.c'strap_init()
. You also need to change trap_dispatch()
to handle thesystem call interrupt by callingsyscall()
(defined in kern/syscall.c)with the appropriate arguments,and then arranging for the return value to be passed back to the user processin%eax
.Finally, you need to implement syscall()
inkern/syscall.c.Make suresyscall()
returns -E_INVAL
if the system call number is invalid.You should read and understandlib/syscall.c(especially the inline assembly routine) in order to confirm your understanding of the system call interface.You may also find it helpful to readinc/syscall.h.
A: Need to be very careful when dealing kernel code.
At first, when I finished this exercise, running hello will cause a vicious cycle in printing "hello world" endless. After tracing the code, I found that the tf->tf_eip always point to the "__start" in user code, which means the curenv->tf wasn't set well.
The root cause is when I set the SYSCALL handler, it should be TRAPHANDLER_NOEC(), but I used the TRAPHANDLER(), so it pushed one more byte into the tf->tf_eip.
Exercise 9.Change kern/trap.c
to panic if a page fault happens in kernel mode.
Hint: to determine whether a fault happened in user mode orin kernel mode, check the low bits of thetf_cs
.
Read user_mem_assert
in kern/pmap.c and implement user_mem_check
in that same file.
Change kern/syscall.c to sanity check argumentsto system calls.
Boot your kernel, running user/buggyhello.The environment should be destroyed,and the kernel shouldnot panic.You should see:
[00001000] user_mem_check assertion failure for va 00000001[00001000] free env 00001000Destroyed the only environment - nothing more to do!
Finally, change debuginfo_eip
inkern/kdebug.c to call user_mem_check
onusd
, stabs
, andstabstr
. If you now runuser/breakpoint, you should be able to runbacktrace from the kernel monitor and see thebacktrace traverse intolib/libmain.c before thekernel panics with a page fault. What causes this page fault?You don't need to fix it, but you should understand why ithappens.
583 int
584 user_mem_check(struct Env *env, const void *va, size_t len, int perm)
585 {
586 // LAB 3: Jacky 140125.
587 uint32_t iter;
588 pte_t *pte;
589 if ((uint32_t)(va + len) >= ULIM) {
590 user_mem_check_addr = (uintptr_t)(va + len);
591 return -E_FAULT;
592 }
593 for (iter = (uint32_t)va; iter < (uint32_t)ROUNDUP((va + len), PGSIZE) ; iter += PGSIZE) {
594 pte = pgdir_walk(curenv->env_pgdir, (void *)iter, 0);
595 if ((*pte & perm) != perm) {
596 cprintf("Need perm = %x, but *pte is %x!\n", perm, *pt e);
597 user_mem_check_addr = iter;
598 return -E_FAULT;
599 }
600 }
601
602 return 0;
603 }
- Jos-lab3 Exercise 7&9
- Jos-lab3 (Exercise 1 & 2)
- JOS实验——Exercise 9
- JOS实验——Exercise 7
- Jos-lab2 (Exercise 1)
- Jos-lab2(Exercise 4)
- Jos-lab2(Exercise 5)
- MIT 操作系统实验 MIT JOS lab3
- JOS lab3 部分用户程序分析
- JOS实验——Exercise 8
- JOS实验——Exercise 10
- JOS实验——lab2 exercise 5
- lab3
- Lab3
- Lab3
- lab3
- jos
- Exercise #9
- ubuntu 12.04中安装thrift-0.9.1
- Unity3D教程宝典之 FX Maker
- CRM上线之路 走上了CRM实施顾问-第123天上班 -第25周
- 系统设计文档结构体例理解与决策
- 关于spring的配置文件的分模块策略
- Jos-lab3 Exercise 7&9
- nyoj-216-A problem is easy
- vb.net 读取内存地址
- 汇编EXTERN用法
- HDU3342--Legal or Not(强连通)
- URLLoader
- php 获取当前时间的毫秒数
- 中国将打造世界第一执法船队
- VB.NET动态加载C#或VB.NET生成的DLL文件调用动画教程[黑白智慧写](动态调用DLL).txt