XV6 LAB: System calls过程记录

XV6 LAB: System calls过程记录


一、阅读chapter2和Sections 4.3 and 4.4 of Chapter 4

chapter2

操作系统的三个要求
  1. multiplexing

    A key requirement for an operating system is to support several activities at once.

    操作系统的一个关键要求是能够同时支持多个活动(activities)。

  2. isolation

    The operating system must also arrange for isolation between the processes.

    操作系统必须提供进程间隔离(virtual memory、process、

  3. interaction

    Complete isolation, however, is too strong, since it should be possible for processes to intentionally interact; pipelines are an example.

本章主要内容
  1. 介绍操作系统中如何达成上面三个要求:

    • 抽象硬件资源 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
      use exec to build up memory image, instead of directly interacting with physical memory.

  2. 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的启动顺序

  1. boot loader 加载内核代码到0x80000000, which is _entry(在 kernel/entry.S里).
  2. _entry给每个hart(hardware thread)设置4096大小的stack (stack0 + 4096 * Nhart)(stack0在start.c中定义,但是stack0具体会放在内存的哪里捏?)
  3. _entry跳转到start.c
  4. 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()
  5. 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最后两段没看懂,明天结合代码再看一遍。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值