|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnachos.userprog.UserProcess
public class UserProcess
Encapsulates the state of a user process that is not contained in its user thread (or threads). This includes its address translation state, a file table, and information about the program being executed.
This class is extended by other classes to support additional functionality (such as additional syscalls).
VMProcess
,
NetProcess
Field Summary | |
---|---|
protected Coff |
coff
The program being run by this process. |
protected int |
numPages
The number of contiguous pages occupied by the program. |
protected TranslationEntry[] |
pageTable
This process's page table. |
protected int |
stackPages
The number of pages in the program's stack. |
Constructor Summary | |
---|---|
UserProcess()
Allocate a new process. |
Method Summary | |
---|---|
boolean |
execute(String name,
String[] args)
Execute the specified program with the specified arguments. |
void |
handleException(int cause)
Handle a user exception. |
int |
handleSyscall(int syscall,
int a0,
int a1,
int a2,
int a3)
Handle a syscall exception. |
void |
initRegisters()
Initialize the processor's registers in preparation for running the program loaded into this process. |
protected boolean |
loadSections()
Allocates memory for this process, and loads the COFF sections into memory. |
static UserProcess |
newUserProcess()
Allocate and return a new process of the correct class. |
int |
readVirtualMemory(int vaddr,
byte[] data)
Transfer data from this process's virtual memory to all of the specified array. |
int |
readVirtualMemory(int vaddr,
byte[] data,
int offset,
int length)
Transfer data from this process's virtual memory to the specified array. |
String |
readVirtualMemoryString(int vaddr,
int maxLength)
Read a null-terminated string from this process's virtual memory. |
void |
restoreState()
Restore the state of this process after a context switch. |
void |
saveState()
Save the state of this process in preparation for a context switch. |
protected void |
unloadSections()
Release any resources allocated by loadSections(). |
int |
writeVirtualMemory(int vaddr,
byte[] data)
Transfer all data from the specified array to this process's virtual memory. |
int |
writeVirtualMemory(int vaddr,
byte[] data,
int offset,
int length)
Transfer data from the specified array to this process's virtual memory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Coff coff
protected TranslationEntry[] pageTable
protected int numPages
protected final int stackPages
Constructor Detail |
---|
public UserProcess()
Method Detail |
---|
public static UserProcess newUserProcess()
public boolean execute(String name, String[] args)
name
- the name of the file containing the executable.args
- the arguments to pass to the executable.
public void saveState()
public void restoreState()
public String readVirtualMemoryString(int vaddr, int maxLength)
vaddr
- the starting virtual address of the null-terminated
string.maxLength
- the maximum number of characters in the string,
not including the null terminator.
public int readVirtualMemory(int vaddr, byte[] data)
vaddr
- the first byte of virtual memory to read.data
- the array where the data will be stored.
public int readVirtualMemory(int vaddr, byte[] data, int offset, int length)
vaddr
- the first byte of virtual memory to read.data
- the array where the data will be stored.offset
- the first byte to write in the array.length
- the number of bytes to transfer from virtual memory to
the array.
public int writeVirtualMemory(int vaddr, byte[] data)
vaddr
- the first byte of virtual memory to write.data
- the array containing the data to transfer.
public int writeVirtualMemory(int vaddr, byte[] data, int offset, int length)
vaddr
- the first byte of virtual memory to write.data
- the array containing the data to transfer.offset
- the first byte to transfer from the array.length
- the number of bytes to transfer from the array to
virtual memory.
protected boolean loadSections()
protected void unloadSections()
public void initRegisters()
public int handleSyscall(int syscall, int a0, int a1, int a2, int a3)
syscall# | syscall prototype |
0 | void halt(); |
1 | void exit(int status); |
2 | int exec(char *name, int argc, char **argv); |
3 | int join(int pid, int *status); |
4 | int creat(char *name); |
5 | int open(char *name); |
6 | int read(int fd, char *buffer, int size); |
7 | int write(int fd, char *buffer, int size); |
8 | int close(int fd); |
9 | int unlink(char *name); |
syscall
- the syscall number.a0
- the first syscall argument.a1
- the second syscall argument.a2
- the third syscall argument.a3
- the fourth syscall argument.
public void handleException(int cause)
cause
- the user exception that occurred.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |