'proc' undefined when trying to add a system call to xv6

0

I'm trying to add a "clone" system call to the xv6 os. The call creates a new kernel thread which shares the calling process’s address space. The following is my code in proc.c

int clone(void(*fcn)(void*), void* arg, void* stack)
{
int i, pid;
struct proc *np;
int *myarg;
int *myret;

if((np = allocproc()) == 0)
  return -1;

np->pgdir = proc->pgdir;   //Here's where it tell's me proc is undefined
np->sz = proc->sz;
np->parent = proc;
*np->tf = *proc->tf;
np->stack = stack;

np->tf->eax = 0;

np->tf->eip = (int)fcn;

myret = stack + 4096 - 2 * sizeof(int *);
*myret = 0xFFFFFFFF;

myarg = stack + 4096 - sizeof(int *);
*myarg = (int)arg;

np->tf->esp = (int)stack +  PGSIZE - 2 * sizeof(int *);
np->tf->ebp = np->tf->esp;

np->isthread = 1;

for(i = 0; i < NOFILE; i++)
  if(proc->ofile[i])
    np->ofile[i] = filedup(proc->ofile[i]);
np->cwd = idup(proc->cwd);

safestrcpy(np->name, proc->name, sizeof(proc->name));

pid = np->pid;

acquire(&ptable.lock);
np->state = RUNNABLE;
release(&ptable.lock);

return pid;

}

Most of the implementations I found look just like this, however, whenever I try to make it tells me that 'proc' is undefined. Most implementations of clone that I've seen look nearly identical, with all of them utilizing proc. I'd be happy to share my sysproc.c code as well if that would help in any way.

Thank you!

system
clone
call
proc
xv6
asked on Stack Overflow Feb 21, 2019 by nhlyoung

1 Answer

0

This has nothing to do with your system call's implementation because proc global variable is being set by the scheduler right before resuming a selected "runnable" process.

The reason for null would probably be because calling this function from a wrong context. A system call implementation is expected to be executed from a wrapping function named sys_mysysfunc that syscall function called due to a system call inerrupt initiated by a user application code.

Please share with us your entire implementation flow for additional assistance.

answered on Stack Overflow Feb 23, 2019 by Omer Efrat

User contributions licensed under CC BY-SA 3.0