Ejemplo n.º 1
0
int 
nfs_rmdir(struct file *dir_filp, const char *name) {
  struct nfs_fh *dhandle;
  int status;

  fprintf(stderr,"nfs_rmdir %p ino: %d name: %s\n",dir_filp, 
	  dir_filp->f_ino, name);
  DPRINTF(CLU_LEVEL,("nfs_rmdir:\n"));
  demand(dir_filp, bogus dir_filp);
  demand(name, empty name given to nfs_rmdir);

PR;
  dhandle = GETFHANDLE(dir_filp);

PR;
  status = nfs_proc_rmdir(dhandle, name);
PR;
   fprintf(stderr,"status %d\n",status);
  
PR;
  nfs_cache_remove(dir_filp,name);
PR;
  if (status == 0) {
    nfs_flush_filp(dir_filp);
    return 0;
  } else {
      errno = status; return -1;
  }
}
Ejemplo n.º 2
0
Archivo: mult.c Proyecto: berkus/lang-e
/* 
 * There are two problems here, both resulting from rd and rs conflicts:
 *	1. rr is used to store the initial value of rs
 *	2. rd == rs, then conflict.
 */
static void mgeni (v_reg_type rd, v_reg_type rs, v_reg_type t, int x) {
     char *p = mlookup[x];
     v_reg_type rr, t2 = 0, lastr;
     int equal;
     demand(x, bogus value);
     if (x >= LSIZE) {
	  v_mulii(rd, rs, x);
	  return;
     }
     p++;
     lastr = rd;
     if((equal = isequal(rd,rs))) {
	  if(v_getreg(&rd, V_I, V_TEMP) < 0) 
	       v_fatal("mgen: out of registers\n");
	  t2 = rd;
     }
     rr = rs;
     while(1) {
	  switch(*p++) {
	  case NEGATE: if(*p == DONE) rd = lastr;
	       v_negi(rd, rr);
	       break;
	  case SHIFT_ADD: v_lshii(t, rr, *p++);
	       if(*p == DONE) rd = lastr;
	       v_addi(rd, t, rs);
	       break;
	  case SHIFT_SUB: v_lshii(t, rr, *p++);
	       if(*p == DONE) rd = lastr;
	       v_subi(rd, t, rs);
	       break;
	  case SHIFT_REV: v_lshii(t, rr, *p++);
	       if(*p == DONE) rd = lastr;
	       v_subi(rd, rs, t);
	       break;
	  case FACTOR_ADD: v_lshii(t, rr, *p++);
	       if(*p == DONE) v_addi(lastr, t, rd);
	       else    v_addi(rd, t, rd);
	       break;
	  case FACTOR_SUB: 
	       v_lshii(t, rr, *p++);
	       if(*p == DONE) v_subi(lastr, t, rd);
	       else v_subi(rd, t, rd);
	       break;
	  case FACTOR_REV: 
	       v_lshii(t, rr, *p++);
	       if(*p == DONE) v_subi(lastr, rd, t);
	       else    v_subi(rd, rd, t);
	       break;
	  case SHIFT:	  if(p[1] == DONE) rd = lastr;
	       v_lshii(rd, rr, *p++);
	       break;
	  case DONE:	  goto quit;
	  default:	  demand(0, bogus op);
	  }	  
	  rr = rd;
     }	  
quit:	 
	  if(equal) 
	       v_putreg(t2, V_I );
} 
Ejemplo n.º 3
0
Archivo: npty.c Proyecto: aunali1/exopc
static int
pty_write(struct file *filp, char *buffer, int nbyte, int blocking) {
  int master,status;
  struct uio uio;
  struct iovec iov[4];
  char buf[CLALLOCSZ*8];
  int i;

  demand(filp, bogus filp);
  DPRINTF(CLU_LEVEL,
	  ("pty_write: filp: %08x offset: %qd nbyte: %d\n",
	   (int)filp, filp->f_pos, nbyte));
  master = filp->f_pos;

  demand (master == 1 || master == 0,master flag set improperly);
  assert(nbyte <= CLALLOCSZ*8);
  memcpy(buf,buffer,nbyte);
  iov[0].iov_base = buf;
  iov[0].iov_len = nbyte;
  uio.uio_iov = iov;
  uio.uio_iovcnt = 1;
  uio.uio_offset = 0;
  uio.uio_resid = nbyte;
  uio.uio_rw = UIO_WRITE;
  k0printf("Write: %d: ",uio.uio_resid);
  for (i = 0; i < uio.uio_resid; i++) 
    k0printf("-%d (%c)",(unsigned int)buf[i],buf[i]);

  if (master) {
    k0printf("write: locking %d...\n",minor(filp->f_dev));
    lock_pty(minor(filp->f_dev));
    k0printf("write: locking done\n");
    k0printf("ptcwrite :%d...\n",nbyte);
    pr_uio(&uio);
    status = ptcwrite(filp->f_dev,&uio,GENFLAG(filp));
    k0printf("ptcwrite returned %d, wrote: %d\n",status,nbyte - uio.uio_resid);
    pr_uio(&uio);
  } else {
    k0printf("write: locking %d...\n",minor(filp->f_dev));
    lock_pty(minor(filp->f_dev));
    k0printf("write: locking done\n");
    k0printf("ptswrite %d...\n",nbyte);
    pr_uio(&uio);
    status = ptswrite(filp->f_dev,&uio,GENFLAG(filp));
    k0printf("ptswrite returned %d wrote: %d\n",status,nbyte - uio.uio_resid);
    pr_uio(&uio);
  }
  k0printf("write: unlocking %d...\n",minor(filp->f_dev));
  unlock_pty(minor(filp->f_dev));
  k0printf("write: unlocking done\n");

  if (status == 0) {
    return nbyte - uio.uio_resid;
  } else {
    errno = status; return -1;
  }
}
Ejemplo n.º 4
0
// load program "fn" into memory
void load_program(uint8_t* mem, size_t memsize, const char* fn, int disasm)
{
  int fd, i, j;
  size_t size;
  struct stat s;
  char* buf;
  const Elf32_Ehdr* eh;
  const Elf32_Shdr* sh;
  const Elf32_Phdr* ph;

  fd = open(fn, O_RDONLY);
  demand(fd != -1, "Couldn't open executable file %s!", fn);

  demand(fstat(fd,&s) != -1, "Couldn't access executable file %s!", fn);
  size = s.st_size;

  buf = (char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
  eh = (const Elf32_Ehdr*)buf;
  demand(buf != MAP_FAILED, "Couldn't read executable file %s!", fn);

  close(fd);

  demand(size >= sizeof(Elf32_Ehdr) &&
         strncmp((const char*)eh->e_ident,ELFMAG,strlen(ELFMAG)) == 0 &&
         eh->e_ident[EI_CLASS] == ELFCLASS32 &&
         size >= eh->e_phoff + eh->e_phnum*sizeof(Elf32_Ehdr),
         "Invalid executable file %s!", fn);

  sh = (const Elf32_Shdr*)(buf+eh->e_shoff);
  for(i = 0; i < eh->e_shnum; i++, sh++)
  {
    if(disasm)
    {
      if(sh->sh_type == SHT_PROGBITS && (sh->sh_flags & SHF_EXECINSTR))
      {
        for(j = 0; j < sh->sh_size/4; j++)
        {
          printf("%08x: ", sh->sh_offset + 4*j);
          disassemble(*(inst_t*)((uint8_t*)buf + sh->sh_offset + 4*j));
        }
      }
    }
  }

  ph = (const Elf32_Phdr*)(buf+eh->e_phoff);
  for(i = 0; i < eh->e_phnum; i++, ph++)
  {
      if(ph->p_type == SHT_PROGBITS && ph->p_memsz)
      {
        demand(size >= ph->p_offset + ph->p_filesz &&
               ph->p_vaddr + ph->p_memsz <= memsize,
               "Invalid executable file %s!", fn);
        memcpy(mem + ph->p_vaddr, (uint8_t*)buf + ph->p_offset, ph->p_filesz);
        memset(mem + ph->p_vaddr+ph->p_filesz, 0, ph->p_memsz - ph->p_filesz);
      }
  }
}
Ejemplo n.º 5
0
int main(){
	srand((unsigned)time(NULL));	
	CGraph *G=new CGraph("inputFile//graph.txt");
	CGraph *GOR=new CGraph("inputFile//graphOR.txt");

	vector<demand> eqOR;
	vector<demand> eqTE;
	vector<demand> eqbase;
	FILE *out = fopen("outputFile//objsamemlu.txt", "a");
	int CASEnum=2;
	for(int casenum=0;casenum<CASEnum;casenum++){

		eqbase.clear();//随机产生TE的demand,相当于background流 //有背景流
		for(int i = 0; i < NUMDEMAND; i++){
			int s = rand()%G->n, t;
			do{
				t = rand()%G->n;
			}while(s == t);
			eqbase.push_back(demand(s, t, rand()%(MAXDEMAND)+8));
		}
		////Overlay   产生demand
		eqOR.clear(); //产生Overlay节点对之间的流量需求
		for(int i=0;i<GOR->m;i++)
			eqOR.push_back(demand(GOR->Link[i]->tail,GOR->Link[i]->head,rand()%(MAXDEMAND)+1));

		//////////////////// ①①①①① Nash 博弈  ////////////////////////
		eqTE.clear(); 
		for(unsigned int i=0;i<eqOR.size();i++)
			eqTE.push_back(eqOR[i]);			
		for(unsigned int i=0;i<eqbase.size();i++)
			eqTE.push_back(eqbase[i]);
		fprintf(out, "TEvsOR    博弈:\n");
		G->clearOcc();
		for(int demo =1; demo <= 100; demo++){
			double te=0,or=0;
			te +=G->TEcplex(eqTE,GOR);
			if(te>=INF) { fprintf(out, "TE unfeasible\n");break;}
			or += GOR->ORcplex(&eqOR);
			if(or>=INF) { fprintf(out, "OR unfeasible\n");break;}
			eqTE.clear();
			for(unsigned int i=0;i<GOR->eqfo.size();i++)
				eqTE.push_back(GOR->eqfo[i]);				
			for(unsigned int i=0;i<eqbase.size();i++)
				eqTE.push_back(eqbase[i]);
			fprintf(out, "%f\t%f\n", te,or);
		}
		fprintf(out, "\n\n"); 

	}
	fclose(out);
	delete G;
	delete GOR;
	system("pause");
	return 0;

}
Ejemplo n.º 6
0
Archivo: link.c Proyecto: berkus/lang-e
/* go through and link the current guy */
void v_link(void) {
	extern v_label_type v_epilogue_l;
	extern int v_restore_p(void);
 	int restore_p = v_restore_p();
	v_code *last_ip = v_ip - 1;

        for(ltp--; ltp >= &link_table[0]; ltp--) {
		switch(ltp->type) {
		case V_JUMP: {
                	unsigned    	*dst = labels[ltp->label].addr,
                        		*src = ltp->addr;
			/* relative offset between label and delay slot */
                	int disp;
                	demand(dst != FLAG, not linked);

			if(ltp->label == _vlr(v_epilogue_l)) {
				/* if this is the last jump, delete it.  */
				if(ltp->addr == last_ip) {
#if 0
                			labels[ltp->label].addr--; /* xxx */
#endif
					v_ip--;
					break;
				/* reorder for better code. */
				} else {
					/* Flip this and last statement */
					unsigned tmp = *src;
					src[0] = src[-1];
					src[-1] = tmp;
					ltp->addr--;

					/* 
					 * function doesn't restore registers, 
					 * insert return instead of jump.
					 */
					if(!restore_p) {
						*ltp->addr = 0x3e00008;
						break;
					}
				}
			}
 			disp = (((int)dst  - (int)src) - 4) / 4;
                	*ltp->addr |= (unsigned short)disp;
			break;
		} 
		case V_DATA:
			*ltp->addr = (unsigned)labels[ltp->label].addr;
			/* printf("linked label %d to %x\n",ltp->label, ltp->addr); */
			break;
		default: demand(0, bogus type);
		}
        }
	v_link_reset();
}
Ejemplo n.º 7
0
Archivo: pty.c Proyecto: 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;
}
Ejemplo n.º 8
0
int 
nfs_mkdir(struct file *dir_filp, const char *name, mode_t mode) {
  struct nfs_fh *dhandle, temp_fhandle;
  struct nfs_fattr temp_fattr;
  struct nfs_sattr temp_sattr;
  int status;

  DPRINTF(CLU_LEVEL,("nfs_mkdir:\n"));
  demand(dir_filp, bogus dir_filp);
  demand(name, empty name given to nfs_mkdir);

  dhandle = GETFHANDLE(dir_filp);

  k2printf("nfs_mkdir: nfs_proc_getattr\n");
  status = nfs_proc_getattr(dhandle,&temp_fattr);

  if (status != 0) {
    fprintf(stderr,"nfs_mkdir, was not able to do getattr\n"
	     "on a NFS filp\n");
      errno = status;
      return -1;
  }
  
  temp_sattr.mode = ((temp_fattr.mode & 0xfffffe00) | (mode & 0x000001ff));
  temp_sattr.uid  = __current->uid;
  temp_sattr.gid  = (temp_fattr.gid) ? temp_fattr.gid : __current->egid;
  temp_sattr.size = 1024;
  temp_sattr.atime.seconds  = -1;
  temp_sattr.atime.useconds = -1;
  temp_sattr.mtime.seconds  = -1;
  temp_sattr.mtime.useconds = -1;
  status = nfs_proc_mkdir(dhandle,
			  name,
			  &temp_sattr,
			  &temp_fhandle,
			  &temp_fattr);
  
  
  nfs_flush_filp(dir_filp);
  nfs_cache_remove(dir_filp,name);
  if (status == 0) {
    nfs_cache_add_devino(FHGETDEV(dhandle),temp_fattr.fileid,"..", 
			 GETNFSCE(dir_filp));
    return 0;
  } else {
    errno = status; return -1;
  }
}
Ejemplo n.º 9
0
Archivo: type.c Proyecto: aunali1/exopc
/* Does the parent pointer propogate down? */
int type_is_sticky(xn_elem_t type) {
        struct udf_type *t;

        t = type_lookup(type);
	demand(t, impossible);
	return t->is_sticky;
}
Ejemplo n.º 10
0
int 
nfs_symlink(struct file *dir_filp, 
	   const char *name,const char *to) {
  struct nfs_fh *dhandle;

  struct nfs_sattr temp_sattr;

  int status;

  DPRINTF(CLU_LEVEL,("nfs_symlink:\n"));
  demand(dir_filp, bogus dir_filp);

  dhandle = GETFHANDLE(dir_filp);

  temp_sattr.mode = 0100666; 
  temp_sattr.uid  = __current->uid;
  temp_sattr.gid  = __current->egid;
  temp_sattr.size = strlen(to);
  temp_sattr.atime.seconds  = -1;
  temp_sattr.atime.useconds = -1;
  temp_sattr.mtime.seconds  = -1;
  temp_sattr.mtime.useconds = -1;
  status = nfs_proc_symlink(dhandle,
			    name,
			    to,
			    &temp_sattr);
  
  if (status == 0) {
    nfs_flush_filp(dir_filp);
    nfs_cache_remove(dir_filp,name);
    return 0;
  } else {
      errno = status; return -1;
  }
}
Ejemplo n.º 11
0
int 
nfs_stat(struct file *filp, struct stat *buf) {
    nfsc_p e;
    int dev,ino;
    int status = 0;

    DPRINTF(CLU_LEVEL,("nfs_stat: ino %d\n",filp->f_ino));
    demand(filp, bogus filp);

    e = GETNFSCE(filp);
    
    dev = GETNFSCEDEV(e);
    ino = GETNFSCEINO(e);

    status = nfsc_checkchange(e, NFSSTATMIN);
    switch(status) {
    case 0:
      nfsc_copyout_sb(e,*buf);
       break;
    case 1:
      nfs_flush_filp(filp);
      /* if a directory has changed, we remove all names cached for it */
      if (S_ISDIR(e->sb.st_mode)) {nfs_cache_remove(filp,NULL);}
      *buf = e->sb;
      break;
    case -1:
      /* errno is set by nfsc_checkchange */
      DPRINTF(CLU_LEVEL,("nfs_stat: nfsc_checkchange failed errno: %d\n",errno));
      return status;
    }
    buf->st_dev = GETNFSCEDEV(e);
    return 0;
}
Ejemplo n.º 12
0
Archivo: cdev.c Proyecto: aunali1/exopc
static int 
cdev_lookup(struct file *from, const char *name,struct file *to) {
  dev_t device;
  int flags = 0;
  demand(to,bogus filp);

  if ((device = name2dev((char *)name)) != -1) {
    to->f_dev = device;
    to->f_mode = S_IFCHR && 0644;
    to->f_pos = 0;
    to->f_flags = flags;
    filp_refcount_init(to);
    filp_refcount_inc(to);
    to->f_owner = __current->uid;
    to->op_type = CDEV_TYPE;
    return 0;
  }
  if (!strcmp(name,".")) {
    *to = *from;
    filp_refcount_init(to);
    filp_refcount_inc(to);
    return 0;
  }
					
  CHECKDEVS(name,to);

  errno = ENOENT;
  return -1;
}
Ejemplo n.º 13
0
/*!
  \param[in] pred The node preceding this node (in the path).
  \param[in] cargoLimit The cargo limit of the vehicle.
  */
void
Vehicle_node::evaluate(const Vehicle_node &pred, double cargoLimit) {
    /* time */
    m_travel_time    = pred.travel_time_to(*this);
    m_arrival_time   = pred.departure_time() + travel_time();
    m_wait_time      = is_early_arrival(arrival_time()) ?
                       opens() - m_arrival_time :
                       0;
    m_departure_time = arrival_time() + wait_time() + service_time();

    /* time aggregates */
    m_tot_travel_time = pred.total_travel_time() + travel_time();
    m_tot_wait_time    = pred.total_wait_time()    + wait_time();
    m_tot_service_time = pred.total_service_time() + service_time();

    /* cargo aggregates */
    if (is_dump() &&  pred.cargo() >= 0) {
        m_demand = -pred.cargo();
    }
    m_cargo = pred.cargo() + demand();

    /* cargo aggregates */

    m_twvTot = has_twv() ? pred.twvTot() + 1 : pred.twvTot();
    m_cvTot = has_cv(cargoLimit) ? pred.cvTot() + 1 : pred.cvTot();
    m_delta_time = departure_time() - pred.departure_time();
}
Ejemplo n.º 14
0
Archivo: npty.c Proyecto: aunali1/exopc
static int 
pty_close(struct file * filp) {
  int master;
  int status;
  int ptynumber;
  DPRINTF(CLU_LEVEL,("pty_close\n"));
  demand(filp, bogus filp);

  master = filp->f_pos;
  ptynumber = minor(filp->f_dev);
  lock_pty(ptynumber);

  if (master) {
    if (--npty_shared_data->refcount[1][ptynumber] == 0) {
      status = ptcclose(filp->f_dev,GENFLAG(filp),0,0);
    } else {status = 0;}
    k0printf("ptcclose returned %d\n",status);
  } else {
    if (--npty_shared_data->refcount[0][ptynumber] == 0) {
      status = ptsclose(filp->f_dev,GENFLAG(filp),0,0);
    } else {status = 0;}
    k0printf("ptsclose returned %d\n",status);
  }
  unlock_pty(minor(filp->f_dev));

  if (status == 0) {
    return 0;
  } else {
    errno = status; return -1;
  }
}
Ejemplo n.º 15
0
off_t 
nfs_lseek(struct file *filp, off_t offset, int whence)
{
  off_t tmp;
  nfsc_p e;
  size_t size;

  demand(filp, bogus filp);

  e = GETNFSCE(filp);
  size = nfsc_get_size(e);

  tmp = filp->f_pos;

  switch (whence) {
  case SEEK_SET:
    tmp = offset;
    break;
  case SEEK_CUR:
    tmp += offset;
    break;
  case SEEK_END:
    tmp = size + offset;
    break;
  default:
    errno = EINVAL;
    return -1;
    break;
  }
  if (tmp < 0) {errno = EINVAL; return -1;}

  filp->f_pos = tmp;
  return tmp;
}
Ejemplo n.º 16
0
Archivo: npty.c Proyecto: aunali1/exopc
static int 
pty_lookup(struct file *from, const char *name,struct file *to) {
  int master,pty_number;
  int flags = 0;
  demand(to,bogus filp);

  CHECKDEVS(name,to);

  if (!strcmp(name,".")) {
    *to = *from;
    filp_refcount_init(to);
    filp_refcount_inc(to);
    return 0;
  }

  if (check_name(name, &master,&pty_number) == -1) return -1;

  to->f_dev = makedev(master,pty_number);
  to->f_mode = S_IFCHR && 0644;
  to->f_pos = master;
  to->f_flags = 0;
  filp_refcount_init(to);
  filp_refcount_inc(to);
  to->f_owner = __current->uid;
  to->op_type = NPTY_TYPE;
  return 0;
}
Ejemplo n.º 17
0
Archivo: link.c Proyecto: berkus/lang-e
static void mark(void *addr, v_label_type l, int type) {
	ltp->addr = addr;
	ltp->label = _vlr(l);
	ltp->type = type;
	ltp++;
        demand(ltp < &link_table[MAXLINKS], too many links);
}
Ejemplo n.º 18
0
Archivo: link.c Proyecto: berkus/lang-e
void v_link(void) {
	/* NOTE: it is important that we traverse backwards.  Need to 
	   subtract one off of the epilogue label if we delete the jump. */
        for(ltp--; ltp >= &link_table[0]; ltp--) {
		switch(ltp->type) {
		case V_JUMP: {
                	unsigned    	*dst = labels[ltp->label].addr,
                        		*src = ltp->addr;
			unsigned _dst = *dst;
			unsigned _src1 = *(src+1);
			/* relative offset between label and delay slot */
                	long disp;
                	if(dst == FLAG)
				v_fatal("label %d has not been positioned.\n",
					ltp->label);
			if (_dst && _is_nop(_src1) && _can_delay(_dst)) {
			     *(src+1) = _dst;
			     ++dst;
			}

 			disp = (((long)dst  - (long)src)) / 4;
			/* get lower 22 bits */
#			define LOWER22(x) ((~0 >> 11) & (x)) 
			disp = LOWER22((unsigned)SIGN_EXT22(disp));
                	*ltp->addr |= disp;
			break;
		} 
		case V_DATA:
			*(unsigned long *)ltp->addr = (unsigned long)labels[ltp->label].addr;
			break;
		default: demand(0, bogus type);
		}
        }
	v_link_reset();
}
Ejemplo n.º 19
0
Archivo: link.c Proyecto: berkus/lang-e
/* go through and link the current guy */
void v_link(void) {
	extern int v_restore_p(void);
	int restore_p = v_restore_p();
	v_code *last_ip = v_ip - 1;

	/* NOTE: it is important that we traverse backwards.  Need to 
	   subtract one off of the epilogue label if we delete the jump. */
        for(ltp--; ltp >= &link_table[0]; ltp--) {
		switch(ltp->type) {
		case V_JUMP: {
                	unsigned    	*dst = labels[ltp->label].addr,
                        		*src = ltp->addr;
			/* relative offset between label and delay slot */
                	long disp;
                	if(dst == FLAG)
				v_fatal("label %d has not been positioned.\n", ltp->label);

 			disp = (((long)dst  - (long)src)) / 4;
			/* 
			 * If this is the last jump delete it. Additionally, we 
			 * special case functions which do not have to restore 
			 * any registers, and inline the return.
			 */
			if(ltp->label == _vlr(v_epilogue_l)) {
				/* is the last jump and has to restore registers. */
				if(ltp->addr == last_ip) {
					v_ip--;
					/* adjust the label! */
					labels[ltp->label].addr --;
					break;
				/* 
			 	 * Else if do not have to restore registers, inline
				 * return.
			 	 */
				} 
				else if(!restore_p) {
					/* Return instruction */
					*ltp->addr = 0x6bfa8001;
					continue;
				}
			}
			/* need to subtract one off. */
			disp--;
			/* get lower 21 bits */
#			define LOWER21(x) (((unsigned)~0 >> 12) & (x))	
			disp = disp & 0x1fffffUL;
			/* LOWER21((unsigned)SIGN_EXT21(disp)); */
                	*ltp->addr |= disp;
			break;
		} 
		case V_DATA:
			*(unsigned long *)ltp->addr = (unsigned long)labels[ltp->label].addr;
			/* printf("linked label %d to %x\n",ltp->label, ltp->addr); */
			break;
		default: demand(0, bogus type);
		}
        }
	v_link_reset();
}
Ejemplo n.º 20
0
static void cktrie(Atom parent, Atom a, int refcnt) {
        int n, htn;
        Ht ht;
        Atom or, prev;

	if(!a)
		return;

        for(prev = 0, n = 0; a; prev = a, a = a->sibs.le_next) {
                if(a->parent != parent) {
			printf("\n********\nbogus parent!\n\n");
			dpf_output();
 			fatal(bogus parent);
		}
                n += a->refcnt;

                demand(!seen_pid(a->pid), already seen pid);

                if(!(ht = a->ht)) {
                        cktrie(a, a->kids.lh_first, a->refcnt - !!a->pid);
                        continue;
                }
		demand(!a->pid, ht should not have a pid);

		for(htn = 0, or = a->kids.lh_first; or; or = or->sibs.le_next) {
                	demand(or->parent == a, bogus parent);
                	htn += or->refcnt;
                	cktrie(or, or->kids.lh_first, or->refcnt - !!or->pid);
		}
	
                if(htn != a->refcnt) {
                        printf("****\na->refcnt == %d, htn = %d\n\n",
                                a->refcnt, htn);
                        dpf_output();
                        fatal(bogus refcnt);
                }
        }

        if(n == refcnt)
                return;

        printf("****\nrefcnt == %d, n = %d\n\n", refcnt, n);
        dpf_output();
        fatal(bogus refcnt);
}
Ejemplo n.º 21
0
int db_alloc(db_t db, size_t n) {
    long base;
    base = db;
    if(db >= XN_NBLOCKS || !db_isfree(base, n))
        return 0;
    Bit_set(free_map, base, base + n - 1);
    demand(!db_isfree(base, n), must be alloced);
    return base;
}
Ejemplo n.º 22
0
Archivo: npty.c Proyecto: aunali1/exopc
static int
pty_read(struct file *filp, char *buffer, int nbyte, int blocking) {
  int status;
  int master;
  struct uio uio;
  struct iovec iov[4];

  demand(filp, bogus filp);
  DPRINTF(CLU_LEVEL,
	  ("pty_read: filp: %08x offset: %qd nbyte: %d\n",
	   (int)filp, filp->f_pos, nbyte));
  master = filp->f_pos;
  if (nbyte > CLALLOCSZ) {fprintf(stderr,"npty_read, warn large nbyte\n");}
  iov[0].iov_base = buffer;
  iov[0].iov_len = nbyte;
  uio.uio_iov = iov;
  uio.uio_iovcnt = 1;
  uio.uio_offset = 0;
  uio.uio_resid = nbyte;
  uio.uio_rw = UIO_READ;

  if (master) {

    k0printf("ptcread %d...\n",nbyte);
    pr_uio(&uio);

    k0printf("read: locking master...\n");
    lock_pty(minor(filp->f_dev));
    k0printf("locked\n");
    status = ptcread(filp->f_dev,&uio,GENFLAG(filp));
    unlock_pty(minor(filp->f_dev));
    k0printf("ptcread returned %d\n",status);
    pr_uio(&uio);

  } else {

    k0printf("ptsread %d...\n",nbyte);
    pr_uio(&uio);
    k0printf("read: locking slave...\n");
    lock_pty(minor(filp->f_dev));
    k0printf("locked\n");
    status = ptsread(filp->f_dev,&uio,GENFLAG(filp));
    unlock_pty(minor(filp->f_dev));
    k0printf("ptsread returned %d\n",status);
    pr_uio(&uio);

  }

  k0printf("Read: %d: ",nbyte - uio.uio_resid);
  if (status == 0) {
    return nbyte - uio.uio_resid;
  } else {
    errno = status; return -1;
  }
}
Ejemplo n.º 23
0
Archivo: npty.c Proyecto: 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;
}
Ejemplo n.º 24
0
int 
nfs_rename(struct file *filpfrom, const char *namefrom, 
	   struct file *filpto,   const char *nameto) {
    /* it will be guaranteed that both filp are the same type
       I guess I will have to make sure that they are in the same 
       server ??
       */
    struct nfs_fh *fhandlefrom, *fhandleto;
    int status;

    DPRINTF(CLU_LEVEL,("nfs_rename:\n"));

    if (namefrom == NULL || nameto == NULL) {
	errno = EFAULT;
	return -1;
    } else if (*namefrom == (char)NULL || *nameto == (char)NULL) {
	errno = ENOENT;
	return -1;
    }
    
    demand(filpfrom, bogus filp);
    demand(filpto, bogus filp);
    demand(filpfrom->op_type == filpto->op_type,
	   filpfrom and filpto are of different types!!);
    
    fhandlefrom = GETFHANDLE(filpfrom);
    fhandleto = GETFHANDLE(filpto);

    status = nfs_proc_rename(fhandlefrom,namefrom,
			     fhandleto, nameto);
			     
    if (status != 0) {
	errno = status;
	return -1;
    } else {
      nfs_cache_remove(filpfrom,namefrom);
      nfs_cache_remove(filpto,nameto); /* should be adding this entry */
      nfs_flush_filp(filpfrom);
      if (filpfrom != filpto) nfs_flush_filp(filpto);
      return 0;
    }
}
Ejemplo n.º 25
0
/*
 * Copyright (C) 1997 Massachusetts Institute of Technology 
 *
 * This software is being provided by the copyright holders under the
 * following license. By obtaining, using and/or copying this software,
 * you agree that you have read, understood, and will comply with the
 * following terms and conditions:
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose and without fee or royalty is
 * hereby granted, provided that the full text of this NOTICE appears on
 * ALL copies of the software and documentation or portions thereof,
 * including modifications, that you make.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
 * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE,
 * BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
 * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
 * THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
 * THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. COPYRIGHT
 * HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE OR
 * DOCUMENTATION.
 *
 * The name and trademarks of copyright holders may NOT be used in
 * advertising or publicity pertaining to the software without specific,
 * written prior permission. Title to copyright in this software and any
 * associated documentation will at all times remain with copyright
 * holders. See the file AUTHORS which should have accompanied this software
 * for a list of all copyright holders.
 *
 * This file may be derived from previously copyrighted software. This
 * copyright applies only to those changes made by the copyright
 * holders listed in the AUTHORS file. The rest of this file is covered by
 * the copyright notices, if any, listed below.
 */

#if 0
#undef PRINTF_LEVEL
#define PRINTF_LEVEL 99
#endif
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <string.h>

#include <sys/times.h>

#include <fd/proc.h>
#include <fd/path.h>
#include <exos/debug.h>
#include "nfs_rpc.h"
#include "nfs_rpc_procs.h"
#include "nfs_xdr.h"

#include "errno.h"
#include "assert.h"
#include "malloc.h"

#define kprintf if (1) printf

#if 0  /* AE_RECV procedures */
static void pr_ae_recv(struct ae_recv *send_recv) {
    int i,j = 0;
    printf("NFS ae_recv: %p, ae_recv->n: %d\n",send_recv,send_recv->n);
    for (i=0; i < send_recv->n; i++) {
	printf("[%02d] data: %08x, sz: %2d\t",
	       i, (int)send_recv->r[i].data, send_recv->r[i].sz);
	j += send_recv->r[i].sz;
	demand (j <= (8192+300), too much data to send);
    }
    printf("total size: %d\n",j);
}
Ejemplo n.º 26
0
static inline int 
load_lhs(unsigned *lhs, uint8 *msg, unsigned nbytes, struct ir *ir, int aligned, int unchecked) {
	unsigned off;

	off = ir->u.eq.offset;
	if(unchecked)
		demand(off < nbytes, bogus offset);
	else if(off >= nbytes)
		return 0;

	if(!aligned)
		memcpy(lhs, msg+off, 4);
	else {
		demand((unsigned long)(msg + off) % 4 == 0, bogus alignment);
		*lhs = *(unsigned *)(msg+off);
	}

	*lhs &= ir->u.eq.mask;
	return 1;
}
Ejemplo n.º 27
0
void kernel_init(void) {
    static int init;

    pmap_start = 1;
    if(init) {
        Bit_clear(free_map, 0, XN_NBLOCKS-1);
        return;
    }
    init = 1;
    pages = (void *)malloc(XN_BLOCK_SIZE * (PHYS_MEM+1));
    assert(pages);
    pages = (void *)roundup((unsigned)pages, XN_BLOCK_SIZE);
    demand((unsigned) pages % XN_BLOCK_SIZE == 0, Bogus alignment);

    pmap = Bit_new(PHYS_MEM);
    free_map = Bit_new(XN_NBLOCKS);
    demand(db_isfree(0, 1), should have allocated);
    db_alloc(0, 1);
    demand(!db_isfree(0, 1), should have allocated);
}
Ejemplo n.º 28
0
Archivo: tcb.c Proyecto: aunali1/exopc
struct tcb *
tcb_acquire(void)
{
    struct tcb *tcb;

    for (tcb = connection; tcb < connection + MAX_CONNECTION; tcb++) {
	if (tcb->state == TCB_ST_FREE)
	    return(tcb);
    }
    demand(0, to many open connections);
    return((struct tcb *)0);  /* to appease ansi warning generator */
}
Ejemplo n.º 29
0
static int
search_n_handoff(int parent) {
  int fd;
  struct file *filp;
  struct tcp_socket_data *sock;
  struct tcb *tcb_tmp;
  extern struct tcb *tcp_handoff(struct tcb *parent);
  extern void tcp_free(struct tcb *tcb);


  printf("start search_n_handoff: %d\n",parent);
  for(fd = 0; fd < NR_OPEN ; fd++) {
    if (__current->fd[fd] != NULL) {
      filp = __current->fd[fd];
      if (filp->op_type == TCP_SOCKET_TYPE) {
	if (parent) {
	  printf("SENDING fd: %d\n",fd);
	  pr_filp(filp,"SENDING FILP");
	  /* put the tcb in our shared table */
	  sock = (struct tcp_socket_data *) &filp->data;
	  printf("SOCK addr %p\n",sock);
	  /* now sock->tcb will point to a shared location */
	  demand(sock->tcb, bogus tcb);
	  printf("\ntcb before\n");
	  tcb_print(sock->tcb);
	  tcb_tmp = sock->tcb;
	  sock->tcb = puttcb(sock->tcb);
	  printf("\ntcb after\n");
	  tcb_print(sock->tcb);
	  tcp_free(tcb_tmp);
	  printf("--\n");
	} else {
	  printf("RECEIVING fd: %d\n",fd);
	  pr_filp(filp,"RECEIVING FILP");

	  /* grab the tcb from the shared table */
	  sock = (struct tcp_socket_data *) &filp->data;
	  printf("SOCK addr %p\n",sock);
	  /* now sock->tcb will point to a local structure */
	  printf("\ntcb before\n");
	  tcb_print(sock->tcb);
	  printf("\ntcb handoff\n");
	  sock->tcb = tcp_handoff(sock->tcb);
	  printf("\ntcb after\n");
	  tcb_print(sock->tcb);
	  printf("--\n");
	}
      }
    }
  }
  printf("done search_n_handoff %d\n",parent);
  return 0;
}
Ejemplo n.º 30
0
int
nfs_chmod(struct file *filp, mode_t mode) {
  struct nfs_fh *fhandle;
  struct nfs_fattr temp_fattr;
  struct nfs_sattr temp_sattr;

  int status;

  DPRINTF(CLU_LEVEL,("nfs_chmod:\n"));
  demand(filp, bogus filp);

  fhandle = GETFHANDLE(filp);

  k2printf("nfs_chmod: nfs_proc_getattr\n");
  status = nfs_proc_getattr(fhandle,&temp_fattr);

  if (status == 0) {

    /* ALLPERMS is  07777 */
    temp_sattr.mode = ((temp_fattr.mode & ~ALLPERMS) |  (mode & ALLPERMS)); 

    DPRINTF(CLU_LEVEL,("nfs_chmod: nfs_proc_getattr returned %d, "
		       "new mode %08x, old %08x, setmode: %08x\n",
		       status,mode,temp_fattr.mode,temp_sattr.mode));
    /* do only permissions, also should use macro definitions */
    temp_sattr.uid  = -1; 
    temp_sattr.gid  = -1; 
    temp_sattr.size = -1; 
    temp_sattr.atime.seconds  = -1;
    temp_sattr.atime.useconds = -1;
    temp_sattr.mtime.seconds  = -1;
    temp_sattr.mtime.useconds = -1;
    
    status = nfs_proc_setattr(fhandle,
			      &temp_sattr,
			      &temp_fattr);

    DPRINTF(CLU_LEVEL,("nfs_chmod: nfs_proc_setattr returned %d\n",status));
    if (status == 0) {
      filp->f_mode = temp_sattr.mode;
      nfs_fill_stat(&temp_fattr, GETNFSCE(filp));
    }

    return(status);}
  else {
    fprintf(stderr,"warning: nfs_chmod, was not able to do getattr\n"
	   "on a NFS filp\n");
    errno = EACCES;
    return -1;
  }

}