Beispiel #1
0
static int translate(const char *ifile, const char *ofile)
{
    struct vector *v = vec_new();
    vec_push(v, (char *)ifile);
    vec_push_safe(v, (char *)ofile);
    return runproc(program, v);
}
Beispiel #2
0
void execdllfunc(HSPCTX * hspctx,int cmd,int num,void **args,int *argtypes)
{
  STRUCTDAT *st;
  int size;
  HSPROUTINE *r;
  char *p;
  STRUCTPRM *prm;
  char *out;
  st = &hspctx->mem_finfo[cmd];
  size = sizeof(HSPROUTINE) + st->size;
  r = (HSPROUTINE *)StackPushSize( TYPE_EX_CUSTOMFUNC, size );
  p = (char *)(r+1);
  prm = &hspctx->mem_minfo[ st->prmindex ];
  for(int i=0;i<num;i++)
  {
    out = p + prm->offset;
    switch(argtypes[i])
    {
      case MPTYPE_STRING://2
      {
        char *ss;
        ss = sbAlloc( (int)strlen(((char*)args[i])+1 ));
        strcpy( ss, (char*)args[i] );
        *(char **)out = ss;
        break;
      }
      case MPTYPE_DNUM://3
      {
        memcpy(out, args[i], sizeof(double));
        break;
      }
      case MPTYPE_INUM://4
      {
        *(int *)out = (int)args[i];
        break;
      }
    }
    prm++;
  }
  r->oldtack = hspctx->prmstack;
  hspctx->prmstack = (void *)p;
  r->mcsret = code_getpcbak();
  r->stacklev = hspctx->sublev++;
  r->param = st;
  code_setpc((unsigned short *)( hspctx->mem_mcs + (hspctx->mem_ot[ st->otindex ]) ));
  runproc();
}
Beispiel #3
0
Datei: proc.c Projekt: 8l/inferno
void
sched(void)
{
	if(up) {
		splhi();
		procsave(up);
		if(setlabel(&up->sched)) {
			/* procrestore(up); */
			spllo();
			return;
		}
		gotolabel(&m->sched);
	}
	up = runproc();
	up->state = Running;
	up->mach = MACHP(m->machno);	/* m might be a fixed address; use MACHP */
	m->proc = up;
	gotolabel(&up->sched);
}
Beispiel #4
0
/*
 * refresh all areas that need it
 *  this entails running a command 'zonerefreshprogram'.  This could
 *  copy over databases from elsewhere or just do a zone transfer.
 */
void
refresh_areas(Area *s)
{
	Waitmsg *w;
	char *argv[3];
	
	argv[0] = zonerefreshprogram;
	argv[1] = "XXX";
	argv[2] = nil;

	for(; s != nil; s = s->next){
		if(!s->needrefresh)
			continue;

		if(zonerefreshprogram == nil){
			s->needrefresh = 0;
			continue;
		}

		argv[1] = s->soarr->owner->name;
		w = runproc(argv[0], argv, 0);
		free(w);
	}
}
Beispiel #5
0
int main(int argc, char *argv[]) {
   char cmd[MAX_CANON];
   int history = 1;

   if (argc == 1)
      history = 0;
   else if ((argc > 2) || strcmp(argv[1], "history")) {
      fprintf(stderr, "Usage: %s [history]\n", argv[0]);
      return 1; 
   }   
   while(fgets(cmd, MAX_CANON, stdin) != NULL) {
      if (*(cmd + strlen(cmd) - 1) == '\n')
          *(cmd + strlen(cmd) - 1) = 0;
      if (history && !strcmp(cmd, "history"))
         showhistory(stdout);
      else if (runproc(cmd)) {
         perror("Failed to execute command");
         break;
      }
   }  
   printf("\n\n>>>>>>The list of commands executed is:\n");
   showhistory(stdout);
   return 0; 
}
Beispiel #6
0
/*
 *  If changing this routine, look also at sleep().  It
 *  contains a copy of the guts of sched().
 */
void
sched(void)
{
	Proc *p;

	if(m->ilockdepth)
		panic("cpu%d: ilockdepth %d, last lock %#p at %#p, sched called from %#p",
			m->machno,
			m->ilockdepth,
			up != nil ? up->lastilock: nil,
			(up != nil && up->lastilock != nil) ? up->lastilock->pc: 0,
			getcallerpc(&p+2));
	if(up != nil) {
		/*
		 * Delay the sched until the process gives up the locks
		 * it is holding.  This avoids dumb lock loops.
		 * Don't delay if the process is Moribund.
		 * It called sched to die.
		 * But do sched eventually.  This avoids a missing unlock
		 * from hanging the entire kernel. 
		 * But don't reschedule procs holding palloc or procalloc.
		 * Those are far too important to be holding while asleep.
		 *
		 * This test is not exact.  There can still be a few instructions
		 * in the middle of taslock when a process holds a lock
		 * but Lock.p has not yet been initialized.
		 */
		if(up->nlocks)
		if(up->state != Moribund)
		if(up->delaysched < 20
		|| palloc.Lock.p == up
		|| procalloc.Lock.p == up){
			up->delaysched++;
 			delayedscheds++;
			return;
		}
		up->delaysched = 0;

		splhi();

		/* statistics */
		m->cs++;

		procsave(up);
		if(setlabel(&up->sched)){
			procrestore(up);
			spllo();
			return;
		}
		gotolabel(&m->sched);
	}
	p = runproc();
	if(p->edf == nil){
		updatecpu(p);
		p->priority = reprioritize(p);
	}
	if(p != m->readied)
		m->schedticks = m->ticks + HZ/10;
	m->readied = nil;
	up = p;
	up->state = Running;
	up->mach = MACHP(m->machno);
	m->proc = up;
	mmuswitch(up);
	gotolabel(&up->sched);
}
Beispiel #7
0
int main(int argc, char *argv[]) {
    /* Allocate enough space on the stack
     * for a long command
     */
    char cmd[MAX_CANON];
    int history = 1;

    /* The command was executed without arguments */
    if (argc == 1) {
        history = 0;
    }
    else if ((argc > 2) || strcmp(argv[1], "history")) {
        /* Either too many arguments given, or the
         * command was not executed with "history"
         * as the first parameter.
         *
         * Print a usage message to stderr, and exit with
         * return value 1.
         */
        fprintf(stderr, "Usage: %s [history]\n", argv[0]);
        return 1;
    }

    /* Read from stdin until we get to EOF, '\n', or
     * MAX_CANON - 1, and store what was read into
     * cmd.
     *
     * If fgets() fails, it will return NULL, and so
     * its return value is properly checked here.
     */
    while (fgets(cmd, MAX_CANON, stdin) != NULL) {
        /* We are not assuming that a new line character
         * is read to avoid input truncation.
         *
         * If a newline character was read, then NULL
         * terminate the string by overwriting '\n' with 0.
         */
        if (*(cmd + strlen(cmd) - 1) == '\n') {
            *(cmd + strlen(cmd) - 1) = 0;
        }

        /*
         * If the history command was read, and the history
         * flag was set as an argument, the print the history
         * to stdout.
         */
        if (history && !strcmp(cmd, "history")) {
            showhistory(stdout);
        }
            /* Otherwise, run the command.
             *
             * There's a bug here. An error won't be detected
             * if runproc() does not return 0. This can happen
             * if, for example, time() returns -1.
             */
        else if (runproc(cmd)) {
            perror("Failed to execute command");
            break;
        }
    }

    /* We're done executing user commands.
     * Show the command history and exit with
     * return value 0.
     */
    printf("\n\n>>>>>The list of commands executed is:\n");
    showhistory(stdout);
    return 0;
}
Beispiel #8
0
/*
 *  If changing this routine, look also at sleep().  It
 *  contains a copy of the guts of sched().
 */
void
sched(void)
{
	Mach *m = machp();
	Proc *p;

	if(m->ilockdepth)
		panic("cpu%d: ilockdepth %d, last lock %#p at %#p, sched called from %#p",
			m->machno,
			m->ilockdepth,
			m->externup? m->externup->lastilock: nil,
			(m->externup && m->externup->lastilock)? m->externup->lastilock->_pc: 0,
			getcallerpc(&p+2));

	kstackok();
	if(m->externup){
		/*
		 * Delay the sched until the process gives up the locks
		 * it is holding.  This avoids dumb lock loops.
		 * Don't delay if the process is Moribund.
		 * It called sched to die.
		 * But do sched eventually.  This avoids a missing unlock
		 * from hanging the entire kernel.
		 * But don't reschedule procs holding palloc or procalloc.
		 * Those are far too important to be holding while asleep.
		 *
		 * This test is not exact.  There can still be a few
		 * instructions in the middle of taslock when a process
		 * holds a lock but Lock.p has not yet been initialized.
		 */
		if(m->externup->nlocks)
		if(m->externup->state != Moribund)
		if(m->externup->delaysched < 20
		|| pga.Lock.p == m->externup
		|| procalloc.Lock.p == m->externup){
			m->externup->delaysched++;
 			run.delayedscheds++;
			return;
		}
		m->externup->delaysched = 0;

		splhi();
		/* statistics */
		if(m->externup->nqtrap == 0 && m->externup->nqsyscall == 0)
			m->externup->nfullq++;
		m->cs++;

		procsave(m->externup);
		mmuflushtlb(m->pml4->pa);
		if(setlabel(&m->externup->sched)){
			procrestore(m->externup);
			spllo();
			return;
		}
		/*debug*/gotolabel(&m->sched);
	}

	m->inidle = 1;
	p = runproc();	/* core 0 never returns */
	m->inidle = 0;

	if(!p->edf){
		updatecpu(p);
		p->priority = reprioritize(p);
	}
	if(nosmp){
		if(p != m->readied)
			m->schedticks = m->ticks + HZ/10;
	m->readied = 0;
	}
	m->externup = p;
	m->qstart = m->ticks;
	m->externup->nqtrap = 0;
	m->externup->nqsyscall = 0;
	m->externup->state = Running;
	//m->externup->mach = m;
	m->externup->mach = sys->machptr[m->machno];
	m->proc = m->externup;
//	iprint("m->externup->sched.sp %p * %p\n", up->sched.sp,
//		*(void **) m->externup->sched.sp);
	mmuswitch(m->externup);

	assert(!m->externup->wired || m->externup->wired == m);
	if (0) hi("gotolabel\n");
	/*debug*/gotolabel(&m->externup->sched);
}