Giter Club home page Giter Club logo

Comments (4)

SKTT1Ryze avatar SKTT1Ryze commented on July 30, 2024

建议给具体代码,更加详细地描述一下,方便项目维护者理解

from xv6-k210.

ckf104 avatar ckf104 commented on July 30, 2024

具体来说,可以删除proc结构体的kpagetable成员。然后这样实现proc_pagetable函数,该函数为进程初始化页表

int
Proc::proc_pagetable(){
	pagetable = (pagetable_t)kalloc(); // 申请页表
       if(pagetable == 0)
            return 0;
	
	kstack = (uint64)kalloc(); // 申请内核栈
	if(kstack == 0){
		kfree(pagetable);
		return 0;
	}
        memmove(pagetable, kernel_pagetable, PGSIZE); //现在有了映射到内核的页表项
	for(uint i=0; i < PX(2, MAXUVA); ++i){
		pagetable[i] = 0;
	}
	
	trapframe = (Trapframe*)kalloc();  // 申请trapframe页
	if(trapframe == 0){
		kfree(pagetable);
		kfree((void*)kstack);
		return 0;
	}
	return 1;
}

pagetable的前两项用于用户空间的映射,对应地址空间为0x0 -> 0x80000000
限制了地址空间后,省去了为每个用户进程建立trapframe和kstack的页表映射的麻烦。proc->kstack,proc->trapframe分别记录内核栈和trapframe页的物理地址,usertrapret返回时不再使用虚地址TRAMFRAME,而直接使用物理地址p->trapframe。
以后为用户空间建立地址映射时,就不需要分别为pagetable,kpagetable建立映射了,只给pagetable建立地址映射即可。

from xv6-k210.

retrhelo avatar retrhelo commented on July 30, 2024

from xv6-k210.

SKTT1Ryze avatar SKTT1Ryze commented on July 30, 2024

它这样的做法也是能保证禁止用户访问内核态的地址空间的,U 特权级只能访问有 U 权限的页表

from xv6-k210.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.