tac0S
Template Affectional Command Operating System
Functions
sysdep.h File Reference

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...
 

Detailed Description

System-dependent interface.

Author
Olivier Hureau, Hugo Feydel , Julien ALaimo Nachos uses the routines defined here, rather than directly calling the UNIX library functions, to simplify porting between versions of UNIX, and even to other systems, such as MSDOS and the Macintosh.

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.

Function Documentation

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.

Returns
Return an array, with the two pages just before and after the array unmapped, to catch illegal references off the end of the array. Particularly useful for catching overflow beyond fixed-size thread execution stacks.

Note: Just return the useful part!

Parameters
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.

Parameters
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.

Returns
Return the file descriptor, or error if it doesn't exist.
Parameters
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.

Returns
Return the file descriptor.
Parameters
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).

Parameters
fd– the file descriptor of the file to be polled
bool PollSocket ( int  sockID)

PollSocket.

Returns
Return TRUE if there are any messages waiting to arrive on the IPC port.
int Random ( )

Random.

Returns
Return a pseudo-random number.
void RandomInit ( unsigned  seed)

Initialize the pseudo random number generator.

Initialize the pseudo random number generator.