xv6-simplified 0.1
简化版xv6
Loading...
Searching...
No Matches
Functions | Variables
proc.c File Reference

进程相关定义 More...

#include "include/types.h"
#include "include/riscv.h"
#include "include/defs.h"
#include "include/param.h"
#include "include/fat32.h"
#include "include/file.h"
#include "include/proc.h"
#include "include/memlayout.h"
Include dependency graph for proc.c:

Functions

void forkret (void)
 fork申请的新进程初始化后第一步进入的函数,以返回用户空间
 
void proc_mapstacks (pagetable_t kpgtbl)
 给每个进程的内核栈申请一个页,将其映射到内存高地址,后面紧跟着一个无效保护页
 
void procinit (void)
 初始化进程
 
int cpuid ()
 得到当前cpu的id,(此时中断需要禁用以防止进程间竞争挪到其他CPU)
 
struct cpumycpu (void)
 得到当前运行的cpu(结构体),(此时中断需要禁用)
 
struct procmyproc (void)
 返回当前运行的进程(结构体指针),若没有返回0
 
int allocpid ()
 申请下一个进程的id
 
pagetable_t proc_pagetable (struct proc *p)
 给进程p创建一个不带用户内存的用户页表,但带有trampoline和trapframe页
 
void proc_freepagetable (pagetable_t pagetable, uint64 sz)
 释放进程页表并释放其引用的物理内存
 
void userinit (void)
 初始化第一个进程
 
int growproc (int n)
 扩充或缩减进程的用户内存
 
void reparent (struct proc *p)
 将进程p的废弃子进程全都移交给零号进程
 
void scheduler (void)
 进程调度
 
void exit (int status)
 退出当前进程,不返回,该退出的进程在其父进程调用wait()之前保持僵尸进程状态
 
int wait (uint64 addr)
 等待子进程退出
 
void sched (void)
 返回到调度器scheduler(),必须保证proc->state已经改变
 
void sleep (void *chan)
 将进程p沉睡
 
void wakeup (void *chan)
 唤醒chan链上的所有进程
 
void yield (void)
 当前进程放弃CPU,切换上下文给其他进程
 
int kill (int pid)
 kill给定pid的进程,但函数内不会直接让进程退出,只是设置killed状态为1,直到该进程试图返回用户空间时才会退出
 
void setkilled (struct proc *p)
 将给定进程状态设置为killed
 
int killed (struct proc *p)
 给定进程是否已被killed
 
int either_copyout (int usr_dst, uint64 dst, void *src, uint64 len)
 要么向用户地址复制,要么向内核地址复制内容
 
int either_copyin (void *dst, int usr_src, uint64 src, uint64 len)
 要么从用户地址复制,要么从内核地址复制内容
 
void procdump (void)
 用于debug,打印进程状态列表
 

Variables

struct cpu cpus [NCPU]
 
struct proc proc [NPROC]
 
struct procinitproc
 
int nextpid = 1
 
char trampoline []
 
uchar initcode []
 

Detailed Description

进程相关定义

Date
23.04.26
Author
xin
Version
0.1 @status Unstable

Function Documentation

◆ allocpid()

int allocpid ( )

申请下一个进程的id

Returns
申请到的进程id

◆ cpuid()

int cpuid ( void  )

得到当前cpu的id,(此时中断需要禁用以防止进程间竞争挪到其他CPU)

Returns
tp存储的cpuid
Here is the caller graph for this function:

◆ either_copyin()

int either_copyin ( void *  dst,
int  user_src,
uint64  src,
uint64  len 
)

要么从用户地址复制,要么从内核地址复制内容

Parameters
user_src1:从用户地址复制;0:从内核地址复制
dst复制的目标地址
src源地址
len复制的长度
Returns
0:复制成功;-1:复制失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ either_copyout()

int either_copyout ( int  user_dst,
uint64  dst,
void *  src,
uint64  len 
)

要么向用户地址复制,要么向内核地址复制内容

Parameters
user_dst1:向用户地址复制;0:向内核地址复制
dst复制的目标地址
src源地址
len复制的长度
Returns
0:复制成功;-1:复制失败
Here is the call graph for this function:
Here is the caller graph for this function:

◆ exit()

void exit ( int  status)

退出当前进程,不返回,该退出的进程在其父进程调用wait()之前保持僵尸进程状态

Parameters
status该进程退出时的状态
Here is the call graph for this function:
Here is the caller graph for this function:

◆ forkret()

void forkret ( void  )

fork申请的新进程初始化后第一步进入的函数,以返回用户空间

Here is the call graph for this function:

◆ growproc()

int growproc ( int  n)

扩充或缩减进程的用户内存

Parameters
n扩充的大小(byte)
Returns
0——成功;-1——失败
Here is the call graph for this function:

◆ kill()

int kill ( int  pid)

kill给定pid的进程,但函数内不会直接让进程退出,只是设置killed状态为1,直到该进程试图返回用户空间时才会退出

Parameters
pid要kill的进程id
Returns
找到要kill的进程返回0,否则-1

◆ killed()

int killed ( struct proc p)

给定进程是否已被killed

Parameters
p待判定的进程
Returns
1:是;0:否
Here is the caller graph for this function:

◆ mycpu()

struct cpu * mycpu ( void  )

得到当前运行的cpu(结构体),(此时中断需要禁用)

Returns
当前运行的cpu(结构体)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ myproc()

struct proc * myproc ( void  )

返回当前运行的进程(结构体指针),若没有返回0

Returns
当前运行的进程(结构体指针)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ proc_freepagetable()

void proc_freepagetable ( pagetable_t  pagetable,
uint64  sz 
)

释放进程页表并释放其引用的物理内存

Parameters
pagetable待释放的页表
sz释放的大小
Here is the call graph for this function:
Here is the caller graph for this function:

◆ proc_mapstacks()

void proc_mapstacks ( pagetable_t  kpgtbl)

给每个进程的内核栈申请一个页,将其映射到内存高地址,后面紧跟着一个无效保护页

Parameters
kpgtbl内核页表
Here is the call graph for this function:
Here is the caller graph for this function:

◆ proc_pagetable()

pagetable_t proc_pagetable ( struct proc p)

给进程p创建一个不带用户内存的用户页表,但带有trampoline和trapframe页

Parameters
p给定的进程
Returns
成功创建则返回页表指针,否则返回0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ procdump()

void procdump ( void  )

用于debug,打印进程状态列表

Here is the call graph for this function:
Here is the caller graph for this function:

◆ procinit()

void procinit ( void  )

初始化进程

Here is the caller graph for this function:

◆ reparent()

void reparent ( struct proc p)

将进程p的废弃子进程全都移交给零号进程

Parameters
p待移交子进程的进程
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sched()

void sched ( void  )

返回到调度器scheduler(),必须保证proc->state已经改变

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheduler()

void scheduler ( void  )

进程调度

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setkilled()

void setkilled ( struct proc p)

将给定进程状态设置为killed

Parameters
p待killed的进程
Here is the caller graph for this function:

◆ sleep()

void sleep ( void *  chain)

将进程p沉睡

Parameters
chain等待的资源
Here is the call graph for this function:
Here is the caller graph for this function:

◆ userinit()

void userinit ( void  )

初始化第一个进程

设置第一个用户进程

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait()

int wait ( uint64  addr)

等待子进程退出

Parameters
addr存放子进程退出时状态的地址
Returns
退出的子进程pid
Here is the call graph for this function:

◆ wakeup()

void wakeup ( void *  chan)

唤醒chan链上的所有进程

Parameters
chansleep链,即其他进程申请的资源
Here is the call graph for this function:
Here is the caller graph for this function:

◆ yield()

void yield ( void  )

当前进程放弃CPU,切换上下文给其他进程

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cpus

struct cpu cpus[NCPU]

◆ initcode

uchar initcode[]
Initial value:
= {
0x17, 0x05, 0x00, 0x00, 0x13, 0x05, 0x45, 0x02,
0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x35, 0x02,
0x93, 0x08, 0x70, 0x00, 0x73, 0x00, 0x00, 0x00,
0x93, 0x08, 0x20, 0x00, 0x73, 0x00, 0x00, 0x00,
0xef, 0xf0, 0x9f, 0xff, 0x2f, 0x69, 0x6e, 0x69,
0x74, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
}

◆ initproc

struct proc* initproc

◆ nextpid

int nextpid = 1

◆ proc

struct proc proc[NPROC]

◆ trampoline

char trampoline[]
extern