#include "copyright.h"#include <stdio.h>#include <string.h>#include <signal.h>#include <sys/types.h>#include <sys/time.h>#include <sys/socket.h>#include <sys/file.h>#include <sys/un.h>#include <sys/mman.h>#include "interrupt.h"#include "system.h"Go to the source code of this file.
Functions | |
| int | creat (const char *name, unsigned short mode) |
| int | open (const char *name, int flags,...) |
| int | select (int numBits, void *readFds, void *writeFds, void *exceptFds, struct timeval *timeout) |
| int | unlink (char *name) |
| int | read (int filedes, char *buf, int numBytes) |
| int | write (int filedes, char *buf, int numBytes) |
| int | lseek (int filedes, int offset, int whence) |
| int | tell (int filedes) |
| int | close (int filedes) |
| void | srand (unsigned seed) |
| int | rand (void) |
| unsigned | sleep (unsigned) |
| void | abort () |
| void | exit () |
| int | mprotect (char *addr, int len, int prot) |
| int | socket (int, int, int) |
| int | bind (int, const void *, int) |
| int | getpagesize () |
| 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 | InitSocketName (struct sockaddr_un *uname, char *name) |
| 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 | CallOnUserAbort (VoidNoArgFunctionPtr func) |
| void | Delay (int seconds) |
| void | Abort () |
| void | Exit (int exitCode) |
| void | RandomInit (unsigned seed) |
| int | Random () |
| char * | AllocBoundedArray (int size) |
| void | DeallocBoundedArray (char *ptr, int size) |
|
|
Definition at line 430 of file sysdep.cc. References abort.
00431 {
00432 abort();
00433 }
|
|
|
Referenced by Abort. |
|
|
Definition at line 482 of file sysdep.cc. References getpagesize, and mprotect.
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 }
|
|
||||||||||||
|
Definition at line 319 of file sysdep.cc. References ASSERT, bind, DEBUG, InitSocketName, and unlink.
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 }
|
|
||||||||||||||||
|
Referenced by AssignNameToSocket. |
|
|
Definition at line 406 of file sysdep.cc. References VoidFunctionPtr, and VoidNoArgFunctionPtr.
00407 {
00408 (void)signal(SIGINT, (VoidFunctionPtr) func);
00409 }
|
|
|
Definition at line 254 of file sysdep.cc.
|
|
|
Referenced by Close, CloseSocket, and main. |
|
|
Definition at line 295 of file sysdep.cc. References close.
00296 {
00297 (void) close(sockID);
00298 }
|
|
||||||||||||
|
|
|
||||||||||||
|
Definition at line 501 of file sysdep.cc. References getpagesize, and mprotect.
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 }
|
|
|
Definition at line 337 of file sysdep.cc. References unlink.
00338 {
00339 (void) unlink(socketName);
00340 }
|
|
|
Definition at line 419 of file sysdep.cc. References sleep.
00420 {
00421 (void) sleep((unsigned) seconds);
00422 }
|
|
|
Definition at line 441 of file sysdep.cc. References exit.
00442 {
00443 exit(exitCode);
00444 }
|
|
|
|
|
|
Referenced by AllocBoundedArray, and DeallocBoundedArray. |
|
||||||||||||
|
Definition at line 306 of file sysdep.cc. References strcpy. Referenced by AssignNameToSocket, and SendToSocket.
00307 {
00308 uname->sun_family = AF_UNIX;
00309 strcpy(uname->sun_path, name);
00310 }
|
|
||||||||||||||||
|
Definition at line 226 of file sysdep.cc.
|
|
||||||||||||||||
|
Referenced by Lseek, main, system_trap, and Tell. |
|
||||||||||||||||
|
Referenced by AllocBoundedArray, and DeallocBoundedArray. |
|
||||||||||||||||
|
Referenced by main, OpenForReadWrite, and OpenForWrite. |
|
||||||||||||
|
Definition at line 175 of file sysdep.cc.
|
|
|
Definition at line 158 of file sysdep.cc.
|
|
|
Definition at line 279 of file sysdep.cc. References ASSERT, and socket. Referenced by Network::Network.
|
|
|
Definition at line 124 of file sysdep.cc. References ASSERT, FALSE, IdleMode, select, and TRUE.
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 }
|
|
|
Definition at line 348 of file sysdep.cc. References PollFile.
00349 {
00350 return PollFile(sockID); // on UNIX, socket ID's are just file ID's
00351 }
|
|
|
Referenced by Random. |
|
|
Definition at line 464 of file sysdep.cc. References rand. Referenced by Network::Send, and Timer::TimeOfNextInterrupt.
00465 {
00466 return rand();
00467 }
|
|
|
Definition at line 453 of file sysdep.cc. References srand.
00454 {
00455 srand(seed);
00456 }
|
|
||||||||||||||||
|
Definition at line 189 of file sysdep.cc.
|
|
||||||||||||||||
|
Referenced by Read, and ReadPartial. |
|
||||||||||||||||
|
Definition at line 358 of file sysdep.cc. References ASSERT.
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 }
|
|
||||||||||||||||
|
Definition at line 202 of file sysdep.cc. References read.
00203 {
00204 return read(fd, buffer, nBytes);
00205 }
|
|
||||||||||||||||||||||||
|
Referenced by PollFile. |
|
||||||||||||||||||||
|
Definition at line 382 of file sysdep.cc. References ASSERT, and InitSocketName.
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 }
|
|
|
Referenced by Delay. |
|
||||||||||||||||
|
Referenced by OpenSocket. |
|
|
Referenced by RandomInit. |
|
|
Definition at line 238 of file sysdep.cc.
|
|
|
Referenced by Tell. |
|
|
Definition at line 266 of file sysdep.cc. References unlink.
00267 {
00268 return unlink(name);
00269 }
|
|
|
Referenced by AssignNameToSocket, DeAssignNameToSocket, main, Read, Unlink, and Write. |
|
||||||||||||||||
|
|
|
||||||||||||||||
|
Definition at line 214 of file sysdep.cc.
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002