title: How to implement a system call that has structure parameter?
body: <p>I want to implement a system call where I pass in a reference to a structure variable, then I would like display the values in the same file. </p>
  
  <p>For example I have the following structure.</p>
  
  <pre><code>struct procInfo{
  int processID[64]; // the PID of each process
  };
  </code></pre>
  
  <p>Let's say the system call I want to implement is <code>int getProcessIds(struct procInfo*)</code> and I call it inside a file called <code>pcid.c</code>. </p>
  
  <p>I want the system call to grab the process ids from the scheduler inside <code>proc.c</code> file so I can print them inside my <code>pcid.c</code> file. </p>
  
  <p>I know how to create regular system calls that don't have input parameters. I also know how to print the process ids using this system call inside <code>proc.c</code> file, however I don't know how to print them inside <code>pcid.c</code> file. I don't understand how the strucutre pointer is returned so I can print it inside the <code>pcid.c</code>. </p>
  
  <p>I followed a similar system call <code>int fstat(int fd, struct stat*)</code> but I don't see how the structure pointer is returned. </p>
  
  <p>I hope my question is clear, I am using XV6 operating system, thanks! </p>
  
  <p><strong>Updated</strong></p>
  
  <p>I was able to get it to work, I didn't need to use malloc to allocate memory. Here is the strange thing though, I added another variable to my structure so here is what it became.</p>
  
  <pre><code>struct procInfo{
  int processID[64]; // the PID of each process
  char processname[64][16] // the name of each process
  };
  </code></pre>
  
  <p>After the system call inside the <code>proc.c</code> file, here is how I am printing the values.  </p>
  
  <pre><code>printf(1,"Name = %s\n" ,procInfo-&gt;processname[0]);
  printf(1,"PID = %d\n" , procInfo-&gt;processID[0] );
  </code></pre>
  
  <p>But the strange thing is that I get the <code>trap 14 err 4 on cpu 1 eip 0x510 addr 0x7417ba08--kill proc</code>, however I tried printing only one value and it worked. </p>
  
  <pre><code>printf(1,"Name = %s\n" ,procInfo-&gt;processname[0]);
  //printf(1,"PID = %d\n" , procInfo-&gt;processID[0] );
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>//printf(1,"Name = %s\n" ,procInfo-&gt;processname[0]);
  printf(1,"PID = %d\n" , procInfo-&gt;processID[0] );
  </code></pre>
  
  <p>Why did it work when I only print one of them ? Am I printing correctly? </p>