Main Page | Alphabetical List | Class List | File List | Class Members | File Members

sysdep.h File Reference

#include "copyright.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.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)


Function Documentation

void Abort  ) 
 

Definition at line 417 of file sysdep.cc.

00418 { 00419 abort(); 00420 }

char* AllocBoundedArray int  size  ) 
 

Definition at line 469 of file sysdep.cc.

00470 { 00471 int pgSize = getpagesize(); 00472 char *ptr = new char[pgSize * 2 + size]; 00473 00474 mprotect(ptr, pgSize, 0); 00475 mprotect(ptr + pgSize + size, pgSize, 0); 00476 return ptr + pgSize; 00477 }

void AssignNameToSocket char *  socketName,
int  sockID
 

Definition at line 312 of file sysdep.cc.

References ASSERT, and DEBUG().

Referenced by Network::Network().

00313 { 00314 struct sockaddr_un uName; 00315 int retVal; 00316 00317 (void) unlink(socketName); // in case it's still around from last time 00318 00319 InitSocketName(&uName, socketName); 00320 retVal = bind(sockID, (struct sockaddr *) &uName, sizeof(uName)); 00321 ASSERT(retVal >= 0); 00322 DEBUG('n', "Created socket %s\n", socketName); 00323 }

void CallOnUserAbort VoidNoArgFunctionPtr  cleanUp  ) 
 

Definition at line 393 of file sysdep.cc.

References VoidFunctionPtr, and VoidNoArgFunctionPtr.

Referenced by Initialize().

00394 { 00395 (void)signal(SIGINT, (VoidFunctionPtr) func); 00396 }

void Close int  fd  ) 
 

Definition at line 247 of file sysdep.cc.

References ASSERT.

Referenced by Console::~Console(), and Disk::~Disk().

00248 { 00249 int retVal = close(fd); 00250 ASSERT(retVal >= 0); 00251 }

void CloseSocket int  sockID  ) 
 

Definition at line 288 of file sysdep.cc.

Referenced by Network::~Network().

00289 { 00290 (void) close(sockID); 00291 }

void DeallocBoundedArray char *  p,
int  size
 

Definition at line 488 of file sysdep.cc.

Referenced by Thread::~Thread().

00489 { 00490 int pgSize = getpagesize(); 00491 00492 mprotect(ptr - pgSize, pgSize, PROT_READ | PROT_WRITE | PROT_EXEC); 00493 mprotect(ptr + size, pgSize, PROT_READ | PROT_WRITE | PROT_EXEC); 00494 delete [] (ptr - pgSize); 00495 }

void DeAssignNameToSocket char *  socketName  ) 
 

Definition at line 330 of file sysdep.cc.

Referenced by Network::~Network().

00331 { 00332 (void) unlink(socketName); 00333 }

void Delay int  seconds  ) 
 

Definition at line 406 of file sysdep.cc.

Referenced by main().

00407 { 00408 (void) sleep((unsigned) seconds); 00409 }

void Exit int  exitCode  ) 
 

Definition at line 428 of file sysdep.cc.

Referenced by Cleanup().

00429 { 00430 exit(exitCode); 00431 }

void Lseek int  fd,
int  offset,
int  whence
 

Definition at line 219 of file sysdep.cc.

References ASSERT.

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

00220 { 00221 int retVal = lseek(fd, offset, whence); 00222 ASSERT(retVal >= 0); 00223 }

int OpenForReadWrite char *  name,
bool  crashOnError
 

Definition at line 168 of file sysdep.cc.

References ASSERT.

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

00169 { 00170 int fd = open(name, O_RDWR, 0); 00171 00172 ASSERT(!crashOnError || fd >= 0); 00173 return fd; 00174 }

int OpenForWrite char *  name  ) 
 

Definition at line 151 of file sysdep.cc.

References ASSERT.

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

00152 { 00153 int fd = open(name, O_RDWR|O_CREAT|O_TRUNC, 0666); 00154 00155 ASSERT(fd >= 0); 00156 return fd; 00157 }

int OpenSocket  ) 
 

Definition at line 272 of file sysdep.cc.

References ASSERT.

Referenced by Network::Network().

00273 { 00274 int sockID; 00275 00276 sockID = socket(AF_UNIX, SOCK_DGRAM, 0); 00277 ASSERT(sockID >= 0); 00278 00279 return sockID; 00280 }

bool PollFile int  fd  ) 
 

Definition at line 117 of file sysdep.cc.

References ASSERT, FALSE, Interrupt::getStatus(), IdleMode, interrupt, and TRUE.

Referenced by Console::CheckCharAvail(), and PollSocket().

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

bool PollSocket int  sockID  ) 
 

Definition at line 341 of file sysdep.cc.

References PollFile().

Referenced by Network::CheckPktAvail().

00342 { 00343 return PollFile(sockID); // on UNIX, socket ID's are just file ID's 00344 }

int Random  ) 
 

Definition at line 451 of file sysdep.cc.

Referenced by Network::Send(), and Timer::TimeOfNextInterrupt().

00452 { 00453 return rand(); 00454 }

void RandomInit unsigned  seed  ) 
 

Definition at line 440 of file sysdep.cc.

Referenced by Initialize().

00441 { 00442 srand(seed); 00443 }

void Read int  fd,
char *  buffer,
int  nBytes
 

Definition at line 182 of file sysdep.cc.

References ASSERT.

Referenced by Console::CheckCharAvail(), Disk::Disk(), and Disk::ReadRequest().

00183 { 00184 int retVal = read(fd, buffer, nBytes); 00185 ASSERT(retVal == nBytes); 00186 }

void ReadFromSocket int  sockID,
char *  buffer,
int  packetSize
 

Definition at line 351 of file sysdep.cc.

References ASSERT.

Referenced by Network::CheckPktAvail().

00352 { 00353 int retVal; 00354 //extern int errno; 00355 int errno; 00356 struct sockaddr_un uName; 00357 int size = sizeof(uName); 00358 00359 retVal = recvfrom(sockID, buffer, packetSize, 0, 00360 (struct sockaddr *) &uName, (socklen_t*)&size); 00361 00362 if (retVal != packetSize) { 00363 perror("in recvfrom"); 00364 printf("called: %x, got back %d, %d\n", buffer, retVal, errno); 00365 } 00366 ASSERT(retVal == packetSize); 00367 }

int ReadPartial int  fd,
char *  buffer,
int  nBytes
 

Definition at line 195 of file sysdep.cc.

00196 { 00197 return read(fd, buffer, nBytes); 00198 }

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

Definition at line 375 of file sysdep.cc.

References ASSERT.

Referenced by Network::Send().

00376 { 00377 struct sockaddr_un uName; 00378 int retVal; 00379 00380 InitSocketName(&uName, toName); 00381 retVal = sendto(sockID, buffer, packetSize, 0, (const sockaddr*)&uName, sizeof(uName)); 00382 ASSERT(retVal == packetSize); 00383 }

int Tell int  fd  ) 
 

Definition at line 231 of file sysdep.cc.

00232 { 00233 #ifdef HOST_i386 00234 return lseek(fd,0,SEEK_CUR); // 386BSD doesn't have the tell() system call 00235 #else 00236 return tell(fd); 00237 #endif 00238 }

bool Unlink char *  name  ) 
 

Definition at line 259 of file sysdep.cc.

00260 { 00261 return unlink(name); 00262 }

void WriteFile int  fd,
char *  buffer,
int  nBytes
 

Definition at line 207 of file sysdep.cc.

References ASSERT.

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

00208 { 00209 int retVal = write(fd, buffer, nBytes); 00210 ASSERT(retVal == nBytes); 00211 }


Generated on Thu Sep 16 12:33:47 2004 for NachOS by doxygen 1.3.8