tac0S
Template Affectional Command Operating System
|
System-dependent interface. More...
#include "copyright.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Go to the source code of this file.
Functions | |
bool | PollFile (int fd) |
PollFile Check open file or open socket to see if there are any characters that can be read immediately. If so, read them in, and return TRUE. More... | |
int | OpenForWrite (const char *name) |
OpenForWrite Open a file for writing. Create it if it doesn't exist; truncate it if it does already exist. More... | |
int | OpenForReadWrite (const char *name, bool crashOnError) |
OpenForReadWrite Open a file for reading or writing. More... | |
void | Read (int fd, char *buffer, int nBytes) |
Read Read characters from an open file. Abort if read fails. | |
int | ReadPartial (int fd, char *buffer, int nBytes) |
ReadPartial Read characters from an open file, returning as many as are available. | |
void | WriteFile (int fd, const char *buffer, int nBytes) |
WriteFile Write characters to an open file. Abort if write fails. | |
void | Lseek (int fd, int offset, int whence) |
Lseek Change the location within an open file. Abort on error. | |
int | Tell (int fd) |
Tell Report the current location within an open file. | |
void | Close (int fd) |
Close Close a file. Abort on error. | |
bool | Unlink (const char *name) |
Unlink Delete a file. | |
int | OpenSocket () |
OpenSocket Open an interprocess communication (IPC) connection. For now, just open a datagram port where other Nachos (simulating workstations on a network) can send messages to this Nachos. | |
void | CloseSocket (int sockID) |
CloseSocket Close the IPC connection. | |
void | AssignNameToSocket (const char *socketName, int sockID) |
AssignNameToSocket Give a UNIX file name to the IPC port, so other instances of Nachos can locate the port. | |
void | DeAssignNameToSocket (const char *socketName) |
DeAssignNameToSocket Delete the UNIX file name we assigned to our IPC port, on cleanup. | |
bool | PollSocket (int sockID) |
PollSocket. More... | |
void | ReadFromSocket (int sockID, char *buffer, int packetSize) |
ReadFromSocket Read a fixed size packet off the IPC port. Abort on error. | |
void | SendToSocket (int sockID, const char *buffer, int packetSize, const char *toName) |
SendToSocket Transmit a fixed size packet to another Nachos' IPC port. Abort on error. | |
void | Abort () |
Process control: abort, exit, and sleep. More... | |
void | Exit (int exitCode) |
Exit Quit without dropping core. | |
void | Delay (int seconds) |
Sleep Put the UNIX process running Nachos to sleep for x seconds, to give the user time to start up another invocation of Nachos in a different UNIX shell. | |
void | CallOnUserAbort (VoidNoArgFunctionPtr cleanUp) |
Initialize system so that cleanUp routine is called when user hits ctl-C. More... | |
void | RandomInit (unsigned seed) |
Initialize the pseudo random number generator. More... | |
int | Random () |
Random. More... | |
char * | AllocBoundedArray (int size) |
Allocate, de-allocate an array, such that de-referencing just beyond either end of the array will cause an error. More... | |
void | DeallocBoundedArray (char *p, int size) |
DeallocBoundedArray Deallocate an array of integers, unprotecting its two boundary pages. More... | |
System-dependent interface.
Copyright (c) 1992-1993 The Regents of the University of California. All rights reserved. See copyright.h for copyright notice and limitation of liability and disclaimer of warranty provisions.
void Abort | ( | ) |
Process control: abort, exit, and sleep.
Process control: abort, exit, and sleep.
char* AllocBoundedArray | ( | int | size | ) |
Allocate, de-allocate an array, such that de-referencing just beyond either end of the array will cause an error.
Allocate, de-allocate an array, such that de-referencing just beyond either end of the array will cause an error.
Note: Just return the useful part!
size | – amount of useful space needed (in bytes) |
void CallOnUserAbort | ( | VoidNoArgFunctionPtr | func | ) |
Initialize system so that cleanUp routine is called when user hits ctl-C.
Initialize system so that cleanUp routine is called when user hits ctl-C.
void DeallocBoundedArray | ( | char * | ptr, |
int | size | ||
) |
DeallocBoundedArray Deallocate an array of integers, unprotecting its two boundary pages.
ptr | – the array to be deallocated |
size | – amount of useful space in the array (in bytes) |
int OpenForReadWrite | ( | const char * | name, |
bool | crashOnError | ||
) |
OpenForReadWrite Open a file for reading or writing.
name | – file name |
int OpenForWrite | ( | const char * | name | ) |
OpenForWrite Open a file for writing. Create it if it doesn't exist; truncate it if it does already exist.
name | – file name |
bool PollFile | ( | int | fd | ) |
PollFile Check open file or open socket to see if there are any characters that can be read immediately. If so, read them in, and return TRUE.
In the network case, if there are no threads for us to run, and no characters to be read, we need to give the other side a chance to get our host's CPU (otherwise, we'll go really slowly, since UNIX time-slices infrequently, and this would be like busy-waiting). So we delay for a short fixed time, before allowing ourselves to be re-scheduled (sort of like a Yield, but cast in terms of UNIX).
fd | – the file descriptor of the file to be polled |
bool PollSocket | ( | int | sockID | ) |
PollSocket.
int Random | ( | ) |
Random.
void RandomInit | ( | unsigned | seed | ) |
Initialize the pseudo random number generator.
Initialize the pseudo random number generator.