XV6 LAB: System calls过程记录
一、阅读chapter2和Sections 4.3 and 4.4 of Chapter 4
chapter2
操作系统的三个要求
-
multiplexing
A key requirement for an operating system is to support several activities at once.
操作系统的一个关键要求是能够同时支持多个活动(activities)。
-
isolation
The operating system must also arrange for isolation between the processes.
操作系统必须提供进程间隔离(virtual memory、process、
-
interaction
Complete isolation, however, is too strong, since it should be possible for processes to intentionally interact; pipelines are an example.
本章主要内容
-
介绍操作系统中如何达成上面三个要求:
-
抽象硬件资源 to services
To achieve strong isolation it’s helpful to forbid applications from directly accessing sensitive hardware resources, and instead to abstract the resources into services.
文件系统 file system
分时共享 time-sharing
useexec
to build up memory image, instead of directly interacting with physical memory.
…
-
-
xv6进程简介
This chapter also provides an overview of an xv6 process, which is the unit of isolation in xv6, and the creation of the first process when xv6 starts.
进程和isolation的关系 & 实现隔离的机制
The unit of isolation in xv6 (as in other Unix operating systems) is a process .
The mechanisms used by the kernel to implement processes include the user/supervisor mode flag, address spaces, and time-slicing of threads.
有的没的笔记
This book focuses on these core ideas.
They implement system calls, they use page tables, they handle interrupts, they support processes, they use locks for concurrency control, they implement a file system, etc.
进程的两个design ideas:
- an address space to give a process the illusion of its own memory
- a thread, to give the process the illusion of its own CPU
xv6中一个进程包括一个address space和一个thread。
xv6的启动顺序
- boot loader 加载内核代码到0x80000000, which is
_entry
(在 kernel/entry.S里). - _entry给每个hart(hardware thread)设置4096大小的stack (stack0 + 4096 * Nhart)(stack0在start.c中定义,但是stack0具体会放在内存的哪里捏?)
- _entry跳转到start.c
- start.c干的事情:
- 从machine mode切换到supervisor mode (设置
mstatus
中的相关bit) mepc
设置为main()
的地址(mret后直接跳转到main)- disable virtual address translation(往
satp
页表寄存器里写0) - delegate all interrupts and exceptions to supervisor mode(没看懂)
- programs the clock chip to generate timer interrupts
- mret to
main()
- 从machine mode切换到supervisor mode (设置
- mian.c:
- 初始化several设备和子系统(devices and subsystems)
- 执行
userinit()
exec()
to user space(user/init.c里的init()
)init()
启动console- done!
ch4.4
The exec system call, for example, passes the kernel an array of pointers referring to string arguments in user space. These pointers pose two challenges. First, the user program may be buggy or malicious, and may pass the kernel an invalid pointer or a pointer intended to trick the kernel into accessing kernel memory instead of user memory. Second, the xv6 kernel page table mappings are not the same as the user page table mappings, so the kernel cannot use ordinary instructions to load or store from user-supplied addresses.
4.4最后两段没看懂,明天结合代码再看一遍。