Example #1
0
int sock_tcp_acceptnewconn (int mainfd)
{
   int newfd;
   struct sockaddr_in clientaddr;
   int clientaddrlen = sizeof (struct sockaddr_in);
   int ret;
/*
printf ("off to accept\n");
*/
   StaticAssert (sizeof (struct sockaddr_in) >= sizeof (struct sockaddr));
   if ((newfd = accept (mainfd, (struct sockaddr *) &clientaddr, &clientaddrlen)) == -1) {
      perror ("Failed to accept new connection");
      exit(0);
   }
/*
printf ("accepted %d\n", newfd);
*/
   if (((ret = fcntl (newfd, F_GETFL, 0)) < 0) || (fcntl (newfd, F_SETFL, (ret | O_NONBLOCK)) < 0)) {
      printf ("sock_tcp_acceptnewconn: Unable to make it nonblocking (errno %d)\n", errno);
      exit (0);
   }
   ret = 16384;
   if (setsockopt (newfd, SOL_SOCKET, SO_RCVBUF, &ret, sizeof (int)) < 0) {
      printf ("sock_tcp_acceptnewconn: failed to set SO_RCVBUF: %s\n", strerror (errno));
      exit (0);
   }
   if (setsockopt (newfd, SOL_SOCKET, SO_SNDBUF, &ret, sizeof (int)) < 0) {
      printf ("sock_tcp_acceptnewconn: failed to set SO_SNDBUF: %s\n", strerror (errno));
      exit (0);
   }

   return (newfd);
}
Example #2
0
void v3m_batch_info::Dbg_Print()
{
	const UINT sizeInDWords = 56/4;
	StaticAssert( sizeof *this == sizeInDWords * sizeof U4 );
	DEVOUT("=== Model batch header: ===\n");
	for( UINT i=0; i < sizeInDWords; i++ )
	{
		const U4 x = (c_cast(const U4*) this) [i];
		DEVOUT("0x%X ", x);
	}
	DEVOUT("\n");
}
Example #3
0
File: pty.c Project: aunali1/exopc
int
pty_init(void) {
    int i;
    int status;
    struct pty *ptyp;
#ifdef AEGIS
    tmp_putchr = putchr;
    putchr = ae_putc;
#endif /* AEGIS */

    DPRINTF(CLUHELP_LEVEL,("pty_init"));

    status = fd_shm_alloc(FD_SHM_OFFSET + PTY_TYPE,
			   (sizeof(struct pty_shared_data)),
			   (char *)PTY_SHARED_REGION);

    StaticAssert((sizeof(struct pty_shared_data)) <= PTY_SHARED_REGION_SZ);
    pty_shared_data = (struct pty_shared_data *) PTY_SHARED_REGION;


    demand(pty_shared_data, pty_shared_data getting bad pointer);

    if (status == -1) {
	demand(0, problems attaching shm);
	return -1;
    }

    if (status) {
#ifdef AEGIS
	ae_putc('P');
	ae_putc('I');
#endif /* AEGIS */
	init_pty_shared_lock();
	for (i = 0; i < NR_PTY; i++) {
	    ptyp = MAKEPTYP(i);
	    init_lock_pty(ptyp);
	    CLR_PTY_INUSE(0,ptyp);
	    CLR_PTY_INUSE(1,ptyp);
	}
    } else {
	/*printf("This is not first process, just attaching memory\n");  */
    }
    register_file_ops((struct file_ops *)&pty_file_ops, PTY_TYPE);
#ifdef AEGIS
    putchr = tmp_putchr;
#endif /* AEGIS */


    
    return 0;
}
Example #4
0
void io_initialize (int standalone)
{
   if (disksim->iosim_info == NULL) {
      iosim_initialize_iosim_info ();
   }

   bus_set_depths();
   // fprintf (outputfile, "Back from bus_set_depths\n");

   StaticAssert (sizeof(ioreq_event) <= DISKSIM_EVENT_SIZE);
   device_initialize();
   bus_initialize();
   controller_initialize();
   iodriver_initialize(standalone);
}
Example #5
0
static void allocateextra ()
{
   int i;
   event *temp = NULL;

   StaticAssert (sizeof(event) == DISKSIM_EVENT_SIZE);
   if ((temp = (event *)DISKSIM_malloc(ALLOCSIZE)) == NULL) {
      fprintf (stderr, "*** error: failed to allocate space for events\n");
      exit(1);
   }
   for (i=0; i<((ALLOCSIZE/DISKSIM_EVENT_SIZE)-1); i++) {
      temp[i].next = &temp[i+1];
   }
   temp[((ALLOCSIZE/DISKSIM_EVENT_SIZE)-1)].next = disksim->extraq;
   disksim->extraq = temp;
   disksim->extraqlen = ALLOCSIZE / DISKSIM_EVENT_SIZE;
}
Example #6
0
static void 
cachedev_initialize (struct cache_if *c, 
		     void (**issuefunc)(void *,ioreq_event *), 
		     void *issueparam, 
		     struct ioq * (**queuefind)(void *,int), 
		     void *queuefindparam, 
		     void (**wakeupfunc)(void *, struct cacheevent *), 
		     void *wakeupparam, 
		     int numdevs)
{
  struct cache_dev *cache = (struct cache_dev *)c;
  StaticAssert (sizeof(struct cache_dev_event) <= DISKSIM_EVENT_SIZE);

#ifdef DEBUG_CACHEDEV
   fprintf (outputfile, "*** %f: Entered cachedev::cachedev_initialize\n", simtime );
#endif

   cache->issuefunc = issuefunc;
   cache->issueparam = issueparam;
   cache->queuefind = queuefind;
   cache->queuefindparam = queuefindparam;
   cache->wakeupfunc = wakeupfunc;
   cache->wakeupparam = wakeupparam;
   cache->bufferspace = 0;
   cache->ongoing_requests = NULL;
   bzero (cache->validmap, bitstr_size(cache->size));
   bzero (cache->dirtymap, bitstr_size(cache->size));
   cachedev_resetstats(c);

   if (cache->flush_idledelay > 0.0) {
      struct ioq *queue = (*queuefind)(queuefindparam,cache->real_devno);
      ASSERT (queue != NULL);
      ioqueue_set_idlework_function (queue, 
				     &disksim->idlework_cachedev, 
				     cache, 
				     cache->flush_idledelay);
   }

   if (device_get_number_of_blocks(cache->cache_devno) < cache->size) {
      fprintf (stderr, "Size of cachedev exceeds that of actual cache device (devno %d): %d > %d\n", cache->cache_devno, cache->size, device_get_number_of_blocks(cache->cache_devno));
      ddbg_assert(0);
   }
}
Example #7
0
int synch_init(void) {
  int status;
  int i;
  hz = 1000000 / __sysinfo.si_rate;

  status = fd_shm_alloc(SYNCH_SHM_OFFSET,
			sizeof(struct synch_table),
			(char *)SYNCH_SHARED_REGION);
  StaticAssert((sizeof(struct synch_table)) <= SYNCH_SHARED_REGION_SZ);
  if (status == -1) demand(0, problems attaching shm);

  synch_table = (struct synch_table *)SYNCH_SHARED_REGION;
  if (status) {
    /* first process */
    for (i = 0; i < NENV; i++) 
      synch_table->wchan[i] = NULL;
  }
  return 0;
}
Example #8
0
File: npty.c Project: aunali1/exopc
int
npty_init(void) {

    int status,i;

    DPRINTF(CLUHELP_LEVEL,("pty_init"));

    status = fd_shm_alloc(FD_SHM_OFFSET + NPTY_TYPE + 990,
			  (sizeof(struct npty_shared_data)),
			  (char *)NPTY_SHARED_REGION);
    demand(npty_shared_data != 0, pty_shared_data getting bad pointer);
    
    StaticAssert((sizeof(struct npty_shared_data)) <= NPTY_SHARED_REGION_SZ);


    if (status == -1) {
	demand(0, problems attaching shm);
	return -1;
    }
    if (status) {
k1printf("npty_init first %d\n",NPTY_TYPE);
      bzero(npty_shared_data,(sizeof(struct npty_shared_data)));
      npty_tty_init();			/* initialize tty, clists */
      pt_softc_init(1);
      init_npty_shared_lock();
      for (i = 0; i < NPTY; i++) {
	init_lock_pty(i);
	npty_shared_data->refcount[0][i] = 0;
	npty_shared_data->refcount[1][i] = 0;

      }
      //npty_sched_init(1);
    } else {
k1printf("npty_init second+ %d\n",NPTY_TYPE);
      //npty_sched_init(0);
      pt_softc_init(0);
    }
    k1printf("pty_init: envid: %d\n",__envid);
    register_file_ops((struct file_ops *)&pty_file_ops, NPTY_TYPE);

    return 0;
}
Example #9
0
void 
ExosLocksInit()
{
  int Segment;
  int NeedsInit = 0;

  StaticAssert(EXOS_LOCKS_SHM_SZ < EXOS_LOCKS_SHARED_REGION_SZ);

  /* see if the shared segment already created */
  Segment = shmget(EXOS_LOCKS_SHM_OFFSET, EXOS_LOCKS_SHM_SZ, 0);

  /* if not, create it */
  if (Segment == -1) {
    if (errno == ENOENT) {
      /* create shared segment */
      Segment = shmget(EXOS_LOCKS_SHM_OFFSET, EXOS_LOCKS_SHM_SZ, IPC_CREAT);
      NeedsInit = 1;
    }

    if (Segment == -1) {
      panic ("ExosLocksInit: Could not create shared segment for MP locks");
    }
  }

  if ((global_lock = (exos_lock_t*) 
      shmat(Segment, (char*)EXOS_LOCKS_SHARED_REGION, 0)) == (exos_lock_t*)-1) 
  {
    global_lock = (exos_lock_t*) 0;
    panic("ExosLocksInit: Could not attach global_lock");
  }

  if (NeedsInit)
    /* if we just created the lock, initialize it */
  {
    exos_lock_init(global_lock);
  }
#ifdef __LOCKS_DEBUG__
  exos_locks_debug_init();
#endif
  
  dprintf("ExosLocksInit: SHM obtained\n");
}
Example #10
0
int
arp_init(void) {
  int status;
  

  status = fd_shm_alloc(ARP_SHM_OFFSET,
			sizeof(arp_table_t),
			(char *)ARP_SHARED_REGION);
  arp_table = (arp_table_p)ARP_SHARED_REGION;

  StaticAssert((sizeof(arp_table_t)) <= ARP_SHARED_REGION_SZ);

  if (status == -1) {
    demand(0, problems attaching shm);
    return -1;
  }

  if (status) {
    arp_init_table();
  } 
  protect_arp_table();
  return 0;
}
Example #11
0
int
ip_init() {
  int status;

  status = fd_shm_alloc(IP_SHM_OFFSET,
			sizeof(ip_table_t),
			(char *)IP_SHARED_REGION);
  ip_table = (ip_table_p)IP_SHARED_REGION;

  StaticAssert((sizeof(ip_table_t)) <= IP_SHARED_REGION_SZ);

  if (status == -1) {
    demand(0, problems attaching shm);
    return -1;
  }

  if (status) {
    ip_init_table();
  } 
  mk_ip_table_ro();
  return 0;

}
Example #12
0
bool F_Compose_File_Path(PCHARS szProjFilePath, PCHARS fileExtensionWithDot,
						ANSICHAR (&destBuf)[BUF_SIZE])
{
	AssertPtr( szProjFilePath );
	AssertPtr( destBuf );
	StaticAssert( BUF_SIZE > 0 );

	// pure name (e.g. "MyProject")
	ANSICHAR	projName[ 128 ];
	V_FileBase( szProjFilePath, projName, NUMBER_OF(projName) );

	// path relative to exe (e.g. "Projects/MyProject/")
	ANSICHAR	projFilePath[ FS_MAX_PATH ];
	VRET_FALSE_IF_NOT( V_ExtractFilePath( szProjFilePath, projFilePath, NUMBER_OF(projFilePath) ) );

	// path to .INI file relative to exe (e.g. "Projects/MyProject/MyProject.INI")
	ANSICHAR	outFilePath[ FS_MAX_PATH ];
	V_ComposeFileName( projFilePath, projName, outFilePath, NUMBER_OF(outFilePath) );
	V_SetExtension( outFilePath, fileExtensionWithDot, NUMBER_OF(outFilePath) );

	mxStrCpyNAnsi( destBuf, outFilePath, NUMBER_OF(destBuf) );

	return true;
}
Example #13
0
// int cffsd_fsupdate_dinode (u_int sn, int action, struct dinode *d, u_int param1, u_int param2, u_int param3)
int serv_fsupdate_dinode (u_int client_eid, int action, struct cffsd_fsupdate_dinode_arg *arg)
{
    int i;
    char *indirblock;
    struct dinode *d;
    u_int param1 = arg->param1;
    u_int param2 = arg->param2;
    u_int param3 = arg->param3;

    dinode_t *dinode;

    debug_request = 1;

    dinode = d  = translate_address (&arg->dinode);

    if (dinode == NULL) {
        kprintf ("sys_fsupdate_dinode: bad address supplied\n");
        return (-E_INVAL);
    }

    StaticAssert (sizeof(dinode_t) == CFFS_DINODE_SIZE);
    /*
       printf ("sys_fsupdate_dinode: action %d, param1 %d (%x), param2 %d\n", action, param1, param1, (u_int)param2);
       printf ("dinodeNum %d\n", dinode->dinodeNum);
    */

    switch (action) {
    case CFFS_DINODE_SETMASK:
        cffs_dinode_setMask (dinode, (mode_t)param1);
        break;
    case CFFS_DINODE_SETUID:
        cffs_dinode_setUid (dinode, (uid_t)param1);
        break;
    case CFFS_DINODE_SETGID:
        cffs_dinode_setGid (dinode, (gid_t)param1);
        break;
    case CFFS_DINODE_SETACCTIME:
        cffs_dinode_setAccTime (dinode, param1);
        break;
    case CFFS_DINODE_SETMODTIME:
        cffs_dinode_setModTime (dinode, param1);
        break;
    case CFFS_DINODE_SETCRETIME:
        cffs_dinode_setCreTime (dinode, param1);
        break;
    case CFFS_DINODE_SETLENGTH:
        cffs_dinode_setLength (dinode, param2);
        assert (dinode->length == param2);
        break;

    case CFFS_DINODE_SETTYPE:
        if (dinode->type == param1) {
            return (0);
        }
        if ((dinode->dinodeNum != 0) && ((cffs_dinode_isDir(dinode)) || (param1 == S_IFDIR))) {
            printf ("sys_fsupdate_dinode (%d): trying to change type to or from directory (%d -> %d)\n", action, dinode->type, param1);
            return (-E_INVAL);
        }
        cffs_dinode_setType (dinode, (u_int16_t)param1);
        break;

    case CFFS_DINODE_SETLINKCOUNT:
        if ((dinode->dinodeNum != 0) && (dinode->linkCount != param1)) {
            printf ("sys_fsupdate_dinode (%d): changing link count directly (%d -> %d)\n", action, dinode->linkCount, param1);
            //return (-E_INVAL);
        }
        cffs_dinode_setLinkCount (dinode, (nlink_t)param1);
        break;

    case CFFS_DINODE_SETOPENCOUNT:
        cffs_dinode_setOpenCount (dinode, param1);
        break;

    case CFFS_DINODE_SETDIRNUM:
        if (cffs_dinode_isDir(dinode)) {
            printf ("sys_fsupdate_dinode (%d): trying to change dirNum of directory directly (%d -> %d) requested\n", action, dinode->dirNum, param1);
            return (-E_INVAL);
        }
        cffs_dinode_setDirNum (dinode, param1);
        break;

    case CFFS_DINODE_SETDIRECT:
        cffs_dinode_setDirect (dinode, param1, (u_int)param2);
        break;

    case CFFS_DINODE_SETINDIRECT:
        cffs_dinode_setIndirect (dinode, param1, (u_int)param2);
        break;

    case CFFS_DINODE_SETGROUPSTART:
        cffs_dinode_setGroupstart (dinode, param1);
        break;
    case CFFS_DINODE_SETGROUPSIZE:
        cffs_dinode_setGroupsize (dinode, param1);
        break;
    case CFFS_DINODE_CLEARBLOCKPOINTERS:
        cffs_dinode_clearBlockPointers(dinode, param2);
        break;

    case CFFS_DINODE_DELAYEDFREE:
        if ((dinode->linkCount > (cffs_dinode_isDir(dinode))) || (dinode->openCount != 0)) {
            printf ("sys_fsupdate_dinode (%d): can't free dinode with links or opens (%d, %d) requested\n", action, dinode->linkCount, dinode->openCount);
            return (-E_INVAL);
        }
        for (i=0; i<NUM_DIRECT; i++) {
            if (dinode->directBlocks[i] != 0) {
                printf ("sys_fsupdate_dinode (%d): can't free dinode with direct blocks (%d == %d) requested\n", action, i, dinode->directBlocks[i]);
                return (-E_INVAL);
            }
        }
        for (i=0; i<NUM_INDIRECT; i++) {
            if (dinode->indirectBlocks[i] != 0) {
                printf ("sys_fsupdate_dinode (%d): can't free dinode with indirect blocks (%d == %d) requested\n", action, i, dinode->indirectBlocks[i]);
                return (-E_INVAL);
            }
        }
        /* In the real system, this wants to occur only after the block is written (unless it is not dirty) */
        dinode->dinodeNum = 0;
        break;

    case CFFS_DINODE_INITINDIRBLOCK:
        indirblock = (char *) dinode;

        /* XXX % */
        if ((indirblock == NULL) || ((u_int)indirblock % BLOCK_SIZE)) {
            printf ("sys_fsupdate_dinode (%d): bad indirblock address supplied (%p)\n", action, indirblock);
            return (-E_INVAL);
        }
        bzero (indirblock, BLOCK_SIZE);
        break;
    case CFFS_DINODE_INITDINODE:
        bzero ((char *)dinode, CFFS_DINODE_SIZE);
        dinode->memory_sanity = CFFS_DINODE_MEMORYSANITY;
        dinode->type = param1;
        dinode->linkCount = (cffs_dinode_isDir(dinode)) ? 2 : 1;
        dinode->dinodeNum = param2;
        dinode->dirNum = param3;
        break;

    default:
        printf ("sys_fsupdate_dinode: unknown action (%d) requested\n", action);
        return (-E_INVAL);
    }

    return (0);
}
Example #14
0
// int cffsd_fsupdate_superblock (u_int sn, int action, struct superblock *superblock, u_int param1, u_int param2)
int serv_fsupdate_superblock (u_int client_eid, int action, struct cffsd_fsupdate_superblock_arg *arg)
{
    struct superblock *superblock;
    u_int param1 = arg->param1;
    u_int param2 = arg->param2;

    debug_request = 2;

    superblock = translate_address (&arg->superblock);

    StaticAssert (sizeof(struct superblock) == NBPG);
    StaticAssert (BLOCK_SIZE == NBPG);

    //   superblock = (struct superblock *) translate_address ((uint)superblock, NBPG);
    if (superblock == NULL) {
        return (-E_INVAL);
    }

    if (action == CFFS_SUPERBLOCK_SETDIRTY) {
        /* allow anyone to set dirty to a non-zero value at any time.    */
        /* However, must verify that there are no dirty blocks from this */
        /* file system before allowing anyone to set dirty to 0.         */
        superblock->dirty = param1;

    } else if (action == CFFS_SUPERBLOCK_SETROOTDINODENUM) {
        /* verify that the provided rootDInodeNum is in fact the correct     */
        /* system value -- we should know this based on the superblocks addr */
        superblock->rootDInodeNum = param1;

    } else if (action == CFFS_SUPERBLOCK_SETFSNAME) {
        /* verify that the provided fsname is in fact the correct value */
        /* -- should match XN's expectation...                          */
        /* Also, don't allow it to go out of bounds in superblock...    */
        //     char *str = (char *) trup(param1); /* XXX */
        strcpy (superblock->fsname, CFFS_FSNAME);
    } else if (action == CFFS_SUPERBLOCK_DELETE) {
        superblock->fsname[0] = 0;	/* just clear the name for now */
    } else if (action == CFFS_SUPERBLOCK_SETFSDEV) {
        /* verify that the provided fsdev is in fact the correct system value */
        /* -- XN should certainly know this...                                */
        superblock->fsdev = param1;

    } else if (action == CFFS_SUPERBLOCK_SETALLOCMAP) {
        /* this is a totally temporary call.  This field should be maintained */
        /* solely by XN...                                                    */
        superblock->allocMap = param1;

    } else if (action == CFFS_SUPERBLOCK_SETNUMBLOCKS) {
        /* this is a totally temporary call.  This field should be maintained */
        /* solely by XN...                                                    */
        superblock->numblocks = param1;

    } else if (action == CFFS_SUPERBLOCK_SETSIZE) {
        /* this is a totally temporary call.  This field should be maintained */
        /* solely by XN...                                                    */
        superblock->size = param1;

    } else if (action == CFFS_SUPERBLOCK_SETNUMALLOCED) {
        /* this is a totally temporary call.  This field should be maintained */
        /* by the ALLOCATE and DEALLOCATE methods...                          */
        superblock->numalloced = param1;

    } else if (action == CFFS_SUPERBLOCK_SETXNTYPE) {
        /* this is a totally temporary call.  This field should be maintained */
        /* and updated only by newfs!!...                                     */
        if ((param1 < 0) || (param1 >= CFFS_MAX_XNTYPES)) {
            printf ("sys_fsupdate_superblock (%d): bad typeno %d (NUM %d)\n", action, param1, CFFS_MAX_XNTYPES);
            return -E_INVAL;
        }
        superblock->xntypes[param1] = param2;

    } else if (action == CFFS_SUPERBLOCK_INIT) {
        /* this is a totally temporary call.  Just for when not using XN */
        bzero (superblock, BLOCK_SIZE);

    } else if (action == CFFS_SUPERBLOCK_SETBLK) {
        superblock->blk = param1;
    } else if (action == CFFS_SUPERBLOCK_SETQUOTA) {
        if (param1 > superblock->numblocks) {
            printf ("sys_fsupdate_superblock (%d): quota (%d) is bigger than available space (%d)\n", action, param1, superblock->numblocks);
            return -E_INVAL;
        }
        superblock->quota = param1;
    } else {
        printf ("sys_fsupdate_superblock: unknown action requested (%d)\n", action);
        return (-E_INVAL);
    }

    return (0);
}
Example #15
0
int
fd_fast_tcp_init(void) {
    int i;
    int status;
    START(fd_op[TCP_SOCKET_TYPE],init);
    DPRINTF(CLUHELP_LEVEL,("tcp_socket_init\n"));
    
#if 0
    printf("tcpsocket_init: just to test the memory, but tcp\n"
	   "uses its own static structures\n");
#endif
#ifdef AEGIS

    status = fd_shm_alloc(FD_SHM_OFFSET + TCP_SOCKET_TYPE,
			   (sizeof(struct tcp_shared_data)),
			   (char *)TCP_SHARED_REGION);

    StaticAssert((sizeof(struct tcp_shared_data)) <= TCP_SHARED_REGION_SZ);
    tcp_shared_data = (struct tcp_shared_data *) TCP_SHARED_REGION;
#endif /* AEGIS */
#ifdef EXOPC

    status = 1;
    tcp_shared_data = (struct tcp_shared_data *) 
      malloc(sizeof(struct tcp_shared_data));
    assert(tcp_shared_data);

#endif /* EXOPC */



    if (status == -1) {
	demand(0, problems attaching shm);
	STOP(fd_op[TCP_SOCKET_TYPE],init);
	return -1;
    }

    if (status) {
	/* 	printf("Initializing tcp shared data structture\n"); */
      assert(sizeof(struct tcp_socket_data) <= FILE_DATA_SIZE);

	for (i = 0; i < NR_SOCKETS; i++)
	    tcp_shared_data->used_ports[i] = 0;
#if 0				
	/* Using local structures */
	for (i = 0; i < MAX_CONNECTION; i++)
	    tcb_release(&(tcp_shared_data->connection[i]));
#endif
	tcp_shared_data->next_port = (getpid() << 9) | random();

    } else {
	/* printf("This is not first process, just attaching memory\n"); */
    }
    /* AF_UNIX, SOCK_STREAM, TCP */
    register_family_type_protocol(2,1,6,tcp_socket);
    /* AF_UNIX, SOCK_STREAM, IP */
    register_family_type_protocol(2,1,0,tcp_socket);
    register_file_ops(&tcp_file_ops, TCP_SOCKET_TYPE);
#if 0 /* commented out for now */
    init_handoff();
#endif
    STOP(fd_op[TCP_SOCKET_TYPE],init);
    return 0;
}