0

I am trying to create a simple top utility xv6. To do this, I have created a system call that will allow me to to access the kernel space. I have followed many guides on how to create system calls and my code compiles without issues.

My problem exists when I try running top in qemu. I will get a trap 14 error whenever I try to access my struct array whether it be in kernel or user space.

To break things down a little, I have a top.c file:

...
int main(){
  struct uproc table[MAX];//where MAX is defined as 10
  if(!getprocs(MAX, table))
     printf("YAY");
...

in sysproc.c:

...
int
sys_getprocs(int max, struct uproc table[]){
    return gettable(table);
}

and then in procs.c

....
int gettable(struct uproc table[]){
    struct uproc u;
    struct proc *p;
    int i = 0;
    aquire(&ptable.lock);
    for(p->state.proc; p < &ptable.proc[NPROC];p++){
        if(//p->state is valid){
           u.state = p->state;
           ...
           table[i] = u;//where I get the trap 14 error
        }
    }
}

Again, my assumption is that when I pass table around from user to kernel it's getting corrupted, but with that said I'm not sure how I could properly pass it.

1 Answers1

1

All xv6 sys_* functions are parameterless. Read the argint, argstr, and argptr functions in order to figure our how to pass parameters to the kernel from user mode,

Morass
  • 323
  • 1
  • 5