Esempio n. 1
0
/* Stop the process and the thread it runs in. Sets the return value as well */
void process_finish(int retval) {
  thread_table_t *thr;
  thr = thread_get_current_thread_entry();
  process_table[process_get_current_process()].state = ZOMBIE;
  process_table[process_get_current_process()].retval = retval;
  vm_destroy_pagetable(thr->pagetable);
  thr->pagetable = NULL;
  thread_finish();
}
Esempio n. 2
0
int process_join(process_id_t pid) {
    int retval;
    interrupt_status_t intr_status;

    /* Only join with legal pids */
    if (pid < 0 || pid >= PROCESS_MAX_PROCESSES ||
            process_table[pid].parent != process_get_current_process())
        return PROCESS_ILLEGAL_JOIN;

    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);

    /* The thread could be zombie even though it wakes us (maybe). */
    while (process_table[pid].state != PROCESS_ZOMBIE) {
        sleepq_add(&process_table[pid]);
        spinlock_release(&process_table_slock);
        thread_switch();
        spinlock_acquire(&process_table_slock);
    }

    retval = process_table[pid].retval;
    process_reset(pid);

    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);
    return retval;
}
Esempio n. 3
0
void process_finish(int retval) {
    interrupt_status_t intr_status;
    thread_table_t *thr = thread_get_current_thread_entry();
    process_id_t pid = process_get_current_process();
    
    int i;
    // remove parent references in other processes
    for (i = 0; i < PROCESS_MAX_PROCESSES; ++i) {
        intr_status = _interrupt_disable();
        spinlock_acquire(&process_table_slock);
        if (process_table[i].parent_id == pid)
            process_table[i].parent_id = -1;
        spinlock_release(&process_table_slock);
        _interrupt_set_state(intr_status);
    }
    
    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);
    
    process_table[pid].retval = retval;
    process_table[pid].state = PROCESS_ZOMBIE;
    
    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);
    
    // clean up virtual memory
    vm_destroy_pagetable(thr->pagetable);
    thr->pagetable = NULL;
    
    thread_finish();
}
Esempio n. 4
0
process_id_t process_spawn(const char *executable, const char **argv)
{
  TID_t thread;
  process_id_t pid = alloc_process_id();
  int ret;

  if (pid == PROCESS_MAX_PROCESSES) {
    return PROCESS_PTABLE_FULL;
  }

  spinlock_acquire(&process_table_slock);
  process_table[pid].parent = process_get_current_process();
  thread = thread_create((void (*)(uint32_t))(&process_run), pid);
  ret = setup_new_process(thread, executable, argv,
                          &process_table[pid].entry_point,
                          &process_table[pid].stack_top);

  if (ret != 0) {
    process_table[pid].state = PROCESS_ZOMBIE;
    ret = -1;
  } else {
    ret = pid;
  }

  thread_run(thread);
  spinlock_release(&process_table_slock);
  return ret;
}
Esempio n. 5
0
/* Sets every entry in the table to free */
void process_init() {
  for (int i = 0; i < PROCESS_MAX_PROCESSES; i++) {
    process_table[i].state = FREE;
    process_table[i].pid = i;
    process_table[i].parent_id = process_get_current_process();
  }
}
Esempio n. 6
0
process_id_t process_spawn(const char* executable)
{
  TID_t thread;
  interrupt_status_t intr_status;
  process_id_t my_pid = process_get_current_process();
  process_id_t pid = alloc_process_id(PROCESS_RUNNING);

  if (pid < 0) { /* Process table full */
    return -1;
  }
  stringcopy(process_table[pid].executable, executable, PROCESS_NAME_MAX);
  process_table[pid].retval = 0;
  process_table[pid].first_zombie = -1;
  process_table[pid].prev_zombie = -1;
  process_table[pid].next_zombie = -1;
  process_table[pid].parent = my_pid;
  process_table[pid].children = 0;

  intr_status = _interrupt_disable();
  spinlock_acquire(&process_table_slock);

  if (my_pid >= 0) {
    process_table[my_pid].children++;
  }

  spinlock_release(&process_table_slock);
  _interrupt_set_state(intr_status);

  thread = thread_create((void (*)(uint32_t))(&process_start), (uint32_t)pid);
  thread_run(thread);
  return pid;
}
Esempio n. 7
0
int process_join(process_id_t pid)
{
  process_id_t my_pid;
  uint32_t retval;
  interrupt_status_t intr_status;

  my_pid = process_get_current_process();
  if (pid < 0
      || pid >= PROCESS_MAX_PROCESSES
      || process_table[pid].parent != my_pid) {
    return -1;
  }

  intr_status = _interrupt_disable();
  spinlock_acquire(&process_table_slock);

  /* Loop until the process we are joining is a zombie. */
  while (process_table[pid].state != PROCESS_ZOMBIE) {
    sleepq_add(&process_table[pid]);
    spinlock_release(&process_table_slock);
    thread_switch();
    spinlock_acquire(&process_table_slock);
  }
  retval = process_table[pid].retval;

  /* Let children see it is gone. */
  process_table[pid].retval = -1;
  /* Make sure we can't join it again. */
  process_table[pid].parent = -1;

  if (process_table[pid].children == 0) {

    process_table[my_pid].children--;

    /* Remove the zombie child from our list of zombie children. */
    if (process_table[my_pid].first_zombie == pid) {
      process_id_t next = process_table[pid].next_zombie;
      process_table[my_pid].first_zombie = next;
      if (next >= 0) {
        process_table[next].prev_zombie = -1;
      }
    } else {
      process_id_t prev = process_table[pid].prev_zombie;
      process_id_t next = process_table[pid].next_zombie;
      process_table[prev].next_zombie = next;
      if (next >= 0) {
        process_table[next].prev_zombie = prev;
      }
    }

    process_reset(pid);

  }

  spinlock_release(&process_table_slock);
  _interrupt_set_state(intr_status);
  return retval;
}
Esempio n. 8
0
int process_join(process_id_t pid) {
// kprintf("PROCESS JOIN ER STARTET\n");

 spinlock_t lock;
   if (!(process_table[pid].parent_id = process_get_current_process()))
     return PROCESS_ILLEGAL_JOIN;

//  kprintf("PROCESS JOIN ER LEGAL\n");
  // disable interrupts.
  _interrupt_disable();
//  kprintf("interrupts disabled\n"); 
  //acquire the resource spinlock
  spinlock_reset(&lock);
  spinlock_acquire(&lock);
//  kprintf("LOCK er ACQUIRED\n");
  //add to sleeq..
  process_table[process_get_current_process()].state = WAITING;
  while(!(process_table[pid].state == ZOMBIE)) {
   sleepq_add(&process_table[pid]);

  //release the resource spinlock.
   spinlock_release(&lock);
//  kprintf("TRÅD BLIVER SAT I SENG\n");

  //thread_switch()
   thread_switch();

  //Acquire the resource spinlock.
   spinlock_acquire(&lock);
  }

  //Do your duty with the resource (Frigøre processen, nu hvor den er færdig)
  process_table[pid].state = FREE;

  //release the resource spinlock
  spinlock_release(&lock);
  process_table[process_get_current_process()].state = RUNNING;
  //Restore the interrupt mask.
  _interrupt_enable();

//  kprintf("PROCESS_JOIN ER KOMMET IGENNEM\n");
  return process_table[process_get_current_process()].retval;
}
Esempio n. 9
0
int process_check_file(openfile_t fd) {
    process_id_t cur = process_get_current_process();
    int i;
    
    for (i = 0; i < PROCESS_MAX_FILES; i++) {
        if (process_table[cur].files[i] == fd) {
            return 0;
        }
    }
    return -1;
}
Esempio n. 10
0
int process_rem_file(openfile_t fd) {
    process_id_t cur = process_get_current_process();
    int i;
    
    for (i = 0; i < PROCESS_MAX_FILES; i++) {
        if (process_table[cur].files[i] == fd) {
            // -1(NULL) is free space in table 
            process_table[cur].files[i] = -1;
            return 0;
        }
    }
    
    return -1;
}
Esempio n. 11
0
process_id_t process_spawn(const char *executable) {
    TID_t thread;
    process_id_t pid = alloc_process_id();

    if (pid == PROCESS_MAX_PROCESSES)
        return PROCESS_PTABLE_FULL;

    /* Remember to copy the executable name for use in process_start */
    stringcopy(process_table[pid].executable, executable, PROCESS_MAX_FILELENGTH);
    process_table[pid].parent = process_get_current_process();

    thread = thread_create((void (*)(uint32_t))(&process_start), pid);
    thread_run(thread);
    return pid;
}
Esempio n. 12
0
process_id_t process_spawn(char const *executable) {
  TID_t newThread;
  int i = findFreeBlock();
  if(i < 0)  
    return PROCESS_PTABLE_FULL;
    
  process_table[i].exec = executable;
  process_table[i].parent_id = process_get_current_process(); 
  process_table[i].state = RUNNING;
  newThread = thread_create((void*)process_start,(uint32_t)i);
  thread_run(newThread);
//  kprintf("PROCESS SPAWN ER STARTET\n");

  return i; /* pid of new process */
}
Esempio n. 13
0
/* Stop the current process and the kernel thread in which it runs
   Argument: return value */
void process_exit(int retval){
  process_id_t pid;
  thread_table_t * thr;

  kprintf("starten af exit. reval: %d \n",retval);
  if (retval < 0){
    return;
  }

  // gets the process id
  pid = process_get_current_process();

  thr = thread_get_current_thread_entry();

  //spinlock
  spinlock_acquire(&process_table_slock);

  //Disbale interrupt
  _interrupt_set_state(_interrupt_disable());

  // set the process state to ZOMBIE
  process_table[pid].state = STATE_ZOMBIE;

  // Set the process retval to given retval  
  process_table[pid].retval = retval;

  //cleanup
  vm_destroy_pagetable(thr->pagetable);
  thr->pagetable = NULL;

  /* Wake process */
  sleepq_wake_all(&process_table[pid]);

  /* Unlock the process table */
  spinlock_release(&process_table_slock);
  
   //enable interrupts
  _interrupt_set_state(_interrupt_disable());

  kprintf("slutningen af exit :O \n");

  thread_finish();
}
Esempio n. 14
0
process_id_t process_spawn(const char* executable)
{
    TID_t thread;
    interrupt_status_t intr_status;
    process_id_t my_pid = process_get_current_process();
    process_id_t pid = alloc_process_id(PROCESS_RUNNING);

    if (pid < 0) { /* Process table full */
        return -1;
    }
    stringcopy(process_table[pid].executable, executable, PROCESS_NAME_MAX);
    process_table[pid].retval = 0;
    process_table[pid].first_zombie = -1;
    process_table[pid].prev_zombie = -1;
    process_table[pid].next_zombie = -1;
    process_table[pid].parent = my_pid;

    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);

    if (my_pid >= 0) {
        process_table[my_pid].children++;
    }

    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);

    process_table[pid].children = 0;
    process_table[pid].threads = 1;
    process_table[pid].stack_end =
        (USERLAND_STACK_TOP & PAGE_SIZE_MASK)
        - CONFIG_USERLAND_STACK_SIZE*PAGE_SIZE;
    process_table[pid].bot_free_stack = 0;

    for(int i = 0 ; i < MAX_OPEN_FILES ; i++) {
        process_table[pid].open_files[i] = -1;
    }

    thread = thread_create((void (*)(uint32_t))(&process_start), (uint32_t)pid);
    thread_run(thread);
    return pid;
}
Esempio n. 15
0
void process_finish(int retval) {
    interrupt_status_t intr_status;
    process_id_t cur = process_get_current_process();
    thread_table_t *thread = thread_get_current_thread_entry();

    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);

    process_table[cur].state = PROCESS_ZOMBIE;
    process_table[cur].retval = retval;

    /* Remember to destroy the pagetable! */
    vm_destroy_pagetable(thread->pagetable);
    thread->pagetable = NULL;

    sleepq_wake_all(&process_table[cur]);

    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);
    thread_finish();
}
Esempio n. 16
0
/**
 * Terminates the current process and sets a return value
 */
void process_finish(uint32_t retval) {
    interrupt_status_t intr_status;
    process_id_t pid;
	thread_table_t *my_thread;

    // Find out who we are.
    pid = process_get_current_process();
    my_thread = thread_get_current_thread_entry();

    // Ensure that we're the only ones touching the process table.
    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);

    // Mark the stack as free so new threads can reuse it.
    process_free_stack(my_thread);

    if(--process_table[pid].threads == 0) {
        // Last thread in process; now we die.

        // Mark ourself as dying.
        process_table[pid].retval = retval;
        process_table[pid].state = PROCESS_DYING;

        vm_destroy_pagetable(my_thread->pagetable);

        // Wake whomever may be sleeping for the process
        sleepq_wake(&process_table[pid]);
    }

    // Free our locks.
    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);

    my_thread->pagetable = NULL;

    // Kill the thread.
    thread_finish();
}
Esempio n. 17
0
uint32_t process_join(process_id_t pid)
{
    process_id_t my_pid;
    uint32_t retval;
    interrupt_status_t intr_status;
  
    my_pid = process_get_current_process();
    if (pid < 0
        || pid >= MAX_PROCESSES
        || process_table[pid].parent != my_pid) {
        return -1;
    }

    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);

    while (process_table[pid].state != PROCESS_ZOMBIE) {
        sleepq_add(&process_table[pid]);
        spinlock_release(&process_table_slock);
        thread_switch();
        spinlock_acquire(&process_table_slock);
    }
    retval = process_table[pid].retval;
    process_table[my_pid].children--;

    /* Let children see it is gone. */
    process_table[pid].retval = -1;
    /* Make sure we can't join it again. */
    process_table[pid].parent = -1;

    if (process_table[pid].children == 0) {
        process_table[pid].state = PROCESS_FREE;
    }

    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);
    return retval;
}
Esempio n. 18
0
process_control_block_t *process_get_current_process_entry(void)
{
  return &process_table[process_get_current_process()];
}
Esempio n. 19
0
process_table_t *process_get_current_process_entry(void)
{
    return &process_table[process_get_current_process()];
}