首页 > > 详细

System Calls讲解、辅导C/C++语言、讲解Software、辅导C/C++程序 解析R语言编程|讲解R语言程序

Nachos Project 2 Part 2: System Calls
Due date: 11:59 PM, December 6, 2018. Your required part must
be submitted on time (by December 6th) and work properly before
you can attempt the bonus part. The usual two-day grace period
applies. However, we will not accept any submissions after the
grace period (i.e., midnight Sunday). Note that you have two
submission sites: the required and bonus sites.
1 A few more words on submissions
As mentioned above, your required part must be submitted on time (by December 6th) and work
properly before you can attempt the bonus part. The usual two day grace period applies. However,
we will not accept any submissions after the grace period (i.e., midnight Sunday). Therefore, your
options are: (1) attempt only the required part and submit it within the grace period; and (2)
finish the required part and submit it by December 6th and finish and submit the bonus part by
the grace period.
Note that you have two submission sites: the required and bonus sites.
2 An Important Reminder
It is a good time to review the academic integrity policy of the university (http://class.syr.
edu/academic-integrity) and the course honor pledge you submitted at the beginning of the
semester. For this programming project (Part 1 and Part 2), we will use moss (https://theory.
stanford.edu/~aiken/moss/), A System for Detecting Software Similarity, extensively to detect
plagiarism among your program submissions. Please remember that violating academic integrity
policy will greatly jeopardize your grade as you agreed on the honor pledge.
13 Overview
This part of Project 2 is 60 points with an additional 25 points of bonus. You need to implement
the following system calls:
Written Part (required: 15 points): This written part is to read and understand addrspace.[cc|h]
and other related files such as machine/machine.[cc|h]. Refer back to Part 1. When you run
Nachos with ./nachos -quantum -x ../test/prog1 -x ../test/prog2,
prog1 and prog2 are loaded in the main memory, which is an array of characters defined
in machine/machine.[cc|h]. addrspace.[cc|h] creates an address space for each of prog1
and prog2. The main memory is divided into page frames as you know. The size of a page
frame is the same as PageSize.
1. (2 points) How big is the main memory in KB (i.e., kibibytes)?
2. (2 points) How big is one page size and how many page frames are there in the main
memory?
3. (7 points) Modify addrspace.[cc|h] so that it will printout which virtual pages are
loaded in which corresponding page frames for prog1 and prog2. For example, output
should look like:
[Your SUID, Name] Page Frame 0 contains Page 0 of Program ../test/prog1
[Your SUID, Name] Page Frame 1 contains Page 1 of Program ../test/prog1
etc..
4. (2 points) For prog1, how big is the uninitialized data segment size? Can you tell this
by just analyzing the source code, prog1.c? If so, how?
5. (2 points) For prog2, which page frames contain the code segments?
What to submit: a document that contains your answers to the questions and the screenshot
of the program output for Question 3.
Write() (required: 15 points): a system call that uses printf to print characters to screen.
Note that using printf directly instead of going through console.[cc|h] is sort of faking it
to make the implementation of this part easy.
Exec() (required: 15 points; bonus: 10 points): a combination of the fork() and
exec() UNIX system calls that creates process to run user program.
Join() (bonus: 10 points): similar to the waitpid() UNIX system call that blocks the
calling process to wait for another process.
2 Exit() (required: 15 points; bonus: 5 points): required implementation requires a
single Thread::Finish() call, bonus implementation is similar to the exit() UNIX system
call that wakes up any waiting process.
There are three testing user programs, prog3.c, prog3b.c and prog4.c. prog3 is for testing
the required part, prog3b is for testing the bonus part, and prog4 is called by the other two and
is not intend to be executed directly.
4 Requirements
1. Write() system call writes string to a specified destination. In this project we’re faking it
using printf, therefore it always writes to the screen. The system call takes three arguments:
a char* buffer, an int size, and an OpenFileId. Since we’re faking it and not utilizing
the Nachos file system, we can ignore the OpenFileId parameter. You need to obtain the first
two arguments from the user program (see 5 below) and print an character at a time using
printf. Refer to the comments in exception.cc for hints on how to obtain the parameter
values.
2. Exec() takes one string argument that is the file name of a user program. The way Exec()
creates threads is similar to what you did for the -x flag in Part 1. When a user program
calls Exec(), Nachos kernel creates a new thread for the executable file name given as the
argument for Exec(). Nachos creates address space, initializes states and registers, and jumps
to user level, as is done in RunUserProg(). For the bonus, Exec() also needs to return a
SpaceId (defined in syscall.h) of the new thread, which can be used as the argument of
Join(). See the source code of the test programs for the usage and refer to the comments in
exception.cc for hints on how to return a value from system call.
3. Join() (bonus) takes one argument that is the SpaceId of the joined thread. SpaceId is
an integer, you can use it as a pointer to a corresponding kernel thread, or as an index to a
kernel thread table. Either way, the caller (joining thread) needs to be associated with the
joined thread so that the joined thread can wake it up later. Then the joining thread calls
Thread::Sleep() to get blocked.
4. For the required part, Exit() can be implemented with a simple call to Thread::Finish().
For the bonus, Exit() is where a joined thread wakes up its joining threads. This is possible
because in Join(), the joining threads are already associated with the joined thread using
either a pointer or an index. Now the caller (joined thread) can wake up the joining threads
using Scheduler::ReadyToRun().
35. You can use Machine::ReadRegister() to read registers, Machine::WriteRegister() to
write registers, and Machine::ReadMem() to read from a virtual memory address. Note that
Machine::ReadMem() performs virtual to physical translation using Machine::Translate().
5 Tests and Output
The required part is tested with the command “./nachos -x ../test/prog3”. The output should
be:
Hello from prog3
Hello from prog4
The bonus part is tested with the command “./nachos -x ../test/prog3b”. The output should
be:
Hello from prog4
Hello from prog3b
6 What to Submit
For the written part, a document that contains your answers to the questions and the screenshot
of the program output for Question 3. The project is due by the end of Thursday, December 6,
2018. Please compress your whole os folder and a screenshot of your output, name the compressed
file LastName,FirstName.zip (NOTE: .zip ONLY!) and submit it on Blackboard.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!