chendoy
chendoy

Reputation: 275

adding exit code to processes in xv6

I'm trying to add exit status code to processes in XV6.

I've made the following changes:

1) to sysproc.c:

int
sys_exit(int status)
{
  exit(status);
  return 0;  // not reached
}

2) to defs.h:

...
void            exit(int);
...

3) to proc.h:

struct proc {
  PCB struct elements...
  ...
  int status;                  // added
};

4) to proc.c:

void
exit(int status)
{
  struct proc *curproc = myproc();
  struct proc *p;
  int fd;

  cprintf("exit received: %d\n",status); // for debugging purposes

  curproc->status = status; // added

  ...rest of exit system call...
  }

5) to user.h:

// system calls

...
int exit(int) __attribute__((noreturn));
...

Then I wanted to test the added "functionality" by a simple user-space program:

int
main (int argc, char *argv[]) {
    exit(3);
}

But the following was printed (notice the cprintf call for debugging in proc.c):

$ exittest
exit received: -2146420507

What have I done wrong?

Thanks

Upvotes: 1

Views: 2233

Answers (1)

Mathieu
Mathieu

Reputation: 9629

You cannot read the syscall argument like in a 'normal' function, you must use argint function (see other syscalls, like sys_kill)

So your corrected syscall should be:

int
sys_exit(void)
{
  int status;
  if(argint(n, &i) < 0) 
      // not arg:pass 0 to exit
      exit(0);
  exit(status);
  return 0;  // not reached
}

Upvotes: 1

Related Questions