OS Project2
OS Project2
Operating System
System calls
Content
1 Introduction 1
1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Project Notes . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Work Distribution . . . . . . . . . . . . . . . . . . . . . . 1
1.4 Development Environment . . . . . . . . . . . . . . . . . 1
2 Solutions 1
2.1 Using GDB . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.2 System Call . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 System Call . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3 References 4
1.1 Overview
This project focuses on implementing and understanding system calls in the xv6 operating
system. The main tasks involve adding new system calls and understanding kernel debugging
using GDB. The project aims to deepen our understanding of kernel internals and system call
mechanisms.
2 Solutions
1
2.2 System Call
To add a new system call named trace, we followed these steps [1].
int trace(int);
entry("trace");
#define SYS_trace 22
uint64
sys_trace(void)
{
int mask;
argint(0, &mask);
struct proc *p = myproc();
p->trace_mask = mask;
return 0;
}
entry("sysinfo");
#define SYS_sysinfo 22
2
extern uint64 sys_sysinfo(void);
...
[SYS_sysinfo] sys_sysinfo,
#include "sysinfo.h"
uint64
sys_sysinfo(void)
{
struct sysinfo info;
uint64 addr;
struct proc *p = myproc();
argaddr(0, &addr);
struct sysinfo {
uint64 freemem;
uint64 nproc;
uint64 loadavg;
};
uint64
freemem(void)
{
uint64 free_mem = 0;
struct run *r;
acquire(&kmem.lock);
r = kmem.freelist;
for (; r; r = r->next) {
free_mem += PGSIZE;
}
3
release(&kmem.lock);
return free_mem;
}
uint64
nproc(void)
{
uint64 num = 0;
struct proc *p;
return num;
}
uint64
average_load(void)
{
uint64 num_run = 0;
uint64 total = 0;
struct proc *p;
3 References
1. Instructions from: https://drive.google.com/drive/folders/1ySOIPYnQiUzBhAoKoZ_
dXb_Y0kOL22GH