title: malloc a struct in kernel header file error :invalid application of 'sizeof' to incomplete type
body: <p>I'm new to linux.
  I'm practice syscall and I want to copy struct to user.</p>
  
  <p>So I write a syscall which is using copy_to_user().</p>
  
  <p>But When I write and compile test.c to test my syscall appear some error.</p>
  
  <p>in linux/sched.h has defined:</p>
  
  <pre><code>struct pacct_struct {
      int ac_flag;
      long ac_exitcode;
      unsigned long ac_mem;
      cputime_t ac_utime, ac_stime;
      unsigned long ac_minflt, ac_majflt;
  };
  </code></pre>
  
  <p>and then I write a program that use this struct(test.c)</p>
  
  <pre><code>#include "linux/sched.h"
  #include &lt;stdlib.h&gt;
  int main(){
      struct pacct_struct *ts;
      ts = (struct pacct_struct *)malloc(sizeof(struct pacct_struct));
      return 0;
  }
  </code></pre>
  
  <p>and gcc show the follow error message:</p>
  
  <pre><code>test.c:6:44: error: invalid application of 'sizeof' to incomplete type 'struct pacct_struct'
  </code></pre>
  
  <p>I wonder to know if it's fine to use kernel struct by include header file. 
  If so, do I miss something? How to make pacct_struct become a 'complete type'?</p>
  
  <p>thanks.   </p>
  
  <p><strong>addition</strong>:</p>
  
  <p>I check preprocessor with gcc -E</p>
  
  <p>I found that seems no "struct pacct_struct" being included.</p>
  
  <p>Next, I going to view sched.h that I included which was created by "make headers_install" after I compile the kernel.</p>
  
  <p>The file only contains some cloning flags such like "#define CSIGNAL 0x000000ff"</p>
  
  <p>So, I tried to include original source file of sched.h in dir "/usr/src/linux-2.6.39.4/include/linux", but it continue showing same error 'incomplete type'.</p>
  
  <p>Then I check preprocessor again.</p>
  
  <p>I still can't find 'struct pacct_struct' even I include original header file</p>
  
  <p>Anything in sched.h after <code>#ifdef __KERNEL__</code> is disappear, What happened?</p>