Main Page   Compound List   File List   Compound Members   File Members  

sysdep.h File Reference

#include "copyright.h"
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Functions

bool PollFile (int fd)
int OpenForWrite (char *name)
int OpenForReadWrite (char *name, bool crashOnError)
void Read (int fd, char *buffer, int nBytes)
int ReadPartial (int fd, char *buffer, int nBytes)
void WriteFile (int fd, char *buffer, int nBytes)
void Lseek (int fd, int offset, int whence)
int Tell (int fd)
void Close (int fd)
bool Unlink (char *name)
int OpenSocket ()
void CloseSocket (int sockID)
void AssignNameToSocket (char *socketName, int sockID)
void DeAssignNameToSocket (char *socketName)
bool PollSocket (int sockID)
void ReadFromSocket (int sockID, char *buffer, int packetSize)
void SendToSocket (int sockID, char *buffer, int packetSize, char *toName)
void Abort ()
void Exit (int exitCode)
void Delay (int seconds)
void CallOnUserAbort (VoidNoArgFunctionPtr cleanUp)
void RandomInit (unsigned seed)
int Random ()
char * AllocBoundedArray (int size)
void DeallocBoundedArray (char *p, int size)
int atoi (const char *str)
double atof (const char *str)
int abs (int i)


Function Documentation

void Abort  
 

Definition at line 430 of file sysdep.cc.

00431 {
00432     abort();
00433 }

int abs int    i
 

Referenced by Disk::TimeToSeek.

char* AllocBoundedArray int    size
 

Definition at line 482 of file sysdep.cc.

Referenced by Thread::StackAllocate.

00483 {
00484     int pgSize = getpagesize();
00485     char *ptr = new char[pgSize * 2 + size];
00486 
00487     mprotect(ptr, pgSize, 0);
00488     mprotect(ptr + pgSize + size, pgSize, 0);
00489     return ptr + pgSize;
00490 }

void AssignNameToSocket char *    socketName,
int    sockID
 

Definition at line 319 of file sysdep.cc.

Referenced by Network::Network.

00320 {
00321     struct sockaddr_un uName;
00322     int retVal;
00323 
00324     (void) unlink(socketName);    // in case it's still around from last time
00325 
00326     InitSocketName(&uName, socketName);
00327     retVal = bind(sockID, (struct sockaddr *) &uName, sizeof(uName));
00328     ASSERT(retVal >= 0);
00329     DEBUG('n', "Created socket %s\n", socketName);
00330 }

double atof const char *    str
 

Referenced by Initialize.

int atoi const char *    str
 

Referenced by Initialize, and main.

void CallOnUserAbort VoidNoArgFunctionPtr    cleanUp
 

Definition at line 406 of file sysdep.cc.

Referenced by Initialize.

00407 {
00408     (void)signal(SIGINT, (VoidFunctionPtr) func);
00409 }

void Close int    fd
 

void CloseSocket int    sockID
 

Definition at line 295 of file sysdep.cc.

Referenced by Network::~Network.

00296 {
00297     (void) close(sockID);
00298 }

void DeallocBoundedArray char *    p,
int    size
 

Definition at line 501 of file sysdep.cc.

Referenced by Thread::~Thread.

00502 {
00503     int pgSize = getpagesize();
00504 
00505     mprotect(ptr - pgSize, pgSize, PROT_READ | PROT_WRITE | PROT_EXEC);
00506     mprotect(ptr + size, pgSize, PROT_READ | PROT_WRITE | PROT_EXEC);
00507     delete [] (ptr - pgSize);
00508 }

void DeAssignNameToSocket char *    socketName
 

Definition at line 337 of file sysdep.cc.

Referenced by Network::~Network.

00338 {
00339     (void) unlink(socketName);
00340 }

void Delay int    seconds
 

Definition at line 419 of file sysdep.cc.

Referenced by main.

00420 {
00421     (void) sleep((unsigned) seconds);
00422 }

void Exit int    exitCode
 

void Lseek int    fd,
int    offset,
int    whence
 

Definition at line 226 of file sysdep.cc.

Referenced by Disk::Disk, Disk::ReadRequest, and Disk::WriteRequest.

00227 {
00228     int retVal = lseek(fd, offset, whence);
00229     ASSERT(retVal >= 0);
00230 }

int OpenForReadWrite char *    name,
bool    crashOnError
 

Definition at line 175 of file sysdep.cc.

Referenced by Console::Console, and Disk::Disk.

00176 {
00177     int fd = open(name, O_RDWR, 0);
00178 
00179     ASSERT(!crashOnError || fd >= 0);
00180     return fd;
00181 }

int OpenForWrite char *    name
 

Definition at line 158 of file sysdep.cc.

Referenced by Console::Console, and Disk::Disk.

00159 {
00160     int fd = open(name, O_RDWR|O_CREAT|O_TRUNC, 0666);
00161 
00162     ASSERT(fd >= 0); 
00163     return fd;
00164 }

int OpenSocket  
 

Definition at line 279 of file sysdep.cc.

00280 {
00281     int sockID;
00282     
00283     sockID = socket(AF_UNIX, SOCK_DGRAM, 0);
00284     ASSERT(sockID >= 0);
00285 
00286     return sockID;
00287 }

bool PollFile int    fd
 

Definition at line 124 of file sysdep.cc.

Referenced by Console::CheckCharAvail, and PollSocket.

00125 {
00126     int rfd = (1 << fd), wfd = 0, xfd = 0, retVal;
00127     struct timeval pollTime;
00128 
00129 // decide how long to wait if there are no characters on the file
00130     pollTime.tv_sec = 0;
00131     if (interrupt->getStatus() == IdleMode)
00132         pollTime.tv_usec = 20000;               // delay to let other nachos run
00133     else
00134         pollTime.tv_usec = 0;                   // no delay
00135 
00136 // poll file or socket
00137 #if   defined(HOST_i386) || defined(HOST_SVR4)
00138     retVal = select(32, (fd_set*)&rfd, (fd_set*)&wfd, (fd_set*)&xfd, &pollTime);
00139 #else
00140     retVal = select(32, &rfd, &wfd, &xfd, &pollTime);
00141 #endif
00142 
00143     ASSERT((retVal == 0) || (retVal == 1));
00144     if (retVal == 0)
00145         return FALSE;                           // no char waiting to be read
00146     return TRUE;
00147 }

bool PollSocket int    sockID
 

Definition at line 348 of file sysdep.cc.

Referenced by Network::CheckPktAvail.

00349 {
00350     return PollFile(sockID);    // on UNIX, socket ID's are just file ID's
00351 }

int Random  
 

Definition at line 464 of file sysdep.cc.

00465 {
00466     return rand();
00467 }

void RandomInit unsigned    seed
 

Definition at line 453 of file sysdep.cc.

Referenced by Initialize.

00454 {
00455     srand(seed);
00456 }

void Read int    fd,
char *    buffer,
int    nBytes
 

void ReadFromSocket int    sockID,
char *    buffer,
int    packetSize
 

Definition at line 358 of file sysdep.cc.

Referenced by Network::CheckPktAvail.

00359 {
00360     int retVal;
00361     extern int errno;
00362     struct sockaddr_un uName;
00363     int size = sizeof(uName);
00364    
00365     retVal = recvfrom(sockID, buffer, packetSize, 0,
00366                                    (struct sockaddr *) &uName, &size);
00367 
00368     if (retVal != packetSize) {
00369         perror("in recvfrom");
00370         printf("called: %x, got back %d, %d\n", (unsigned int) buffer, 
00371                retVal, errno);
00372     }
00373     ASSERT(retVal == packetSize);
00374 }

int ReadPartial int    fd,
char *    buffer,
int    nBytes
 

Definition at line 202 of file sysdep.cc.

00203 {
00204     return read(fd, buffer, nBytes);
00205 }

void SendToSocket int    sockID,
char *    buffer,
int    packetSize,
char *    toName
 

Definition at line 382 of file sysdep.cc.

Referenced by Network::Send.

00383 {
00384     struct sockaddr_un uName;
00385     int retVal;
00386 
00387     InitSocketName(&uName, toName);
00388     retVal = sendto(sockID, buffer, packetSize, 0,
00389 #ifdef        HOST_SVR4
00390                     (sockaddr *) &uName, 
00391 #else
00392                     (char *) &uName, 
00393 #endif        /* HOST_SVR4 */
00394                     sizeof(uName));
00395     ASSERT(retVal == packetSize);
00396 }

int Tell int    fd
 

Definition at line 238 of file sysdep.cc.

00239 {
00240 #ifdef HOST_i386
00241     return lseek(fd,0,SEEK_CUR); // 386BSD doesn't have the tell() system call
00242 #else
00243     return tell(fd);
00244 #endif
00245 }

bool Unlink char *    name
 

Definition at line 266 of file sysdep.cc.

00267 {
00268     return unlink(name);
00269 }

void WriteFile int    fd,
char *    buffer,
int    nBytes
 

Definition at line 214 of file sysdep.cc.

Referenced by Disk::Disk, Console::PutChar, and Disk::WriteRequest.

00215 {
00216     int retVal = write(fd, buffer, nBytes);
00217     ASSERT(retVal == nBytes);
00218 }


Generated on Mon Feb 10 09:54:52 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees