title: Where is the definition of the sync(2) Linux function call for x86_64 processors
body: <p>I'm trying to find the <strong>Linux 3.2.21 x86_64</strong> implementation of the <a href="http://linux.die.net/man/2/sync" rel="nofollow"><code>sync(2)</code></a> Unix function declared in the <em>unistd.h</em> header. Looking at the Linux <em>unistd.h</em> yields this prototype:</p>
  
  <pre><code>/* Make all changes done to all files actually appear on disk.  */
  extern void sync (void) __THROW;
  </code></pre>
  
  <p>So I take that to mean that <code>sync</code> is defined outside of the Linux kernel and looking inside <strong>glibc 2.7</strong>, which gives me me this definition in <a href="http://fossies.org/dox/glibc-2.17/misc_2sync_8c_source.html" rel="nofollow"><em>glibc-2.17/misc/sync.c</em></a>:</p>
  
  <pre><code>/* Make all changes done to all files actually appear on disk. */
  void
  sync ()
  {
    __set_errno (ENOSYS);
  }
  </code></pre>
  
  <p>So that means <code>sync</code> does nothing other than set the value of <code>errno</code>.</p>
  
  <p>However, when I disassemble <strong>/usr/lib/x86_64-linux-gnu/libc.a</strong> on system, I find that the <em>sync</em> section makes a system call, passing the value <code>162</code> (so it is doing something).</p>
  
  <p>Looking at the Linux source again at <a href="http://lxr.free-electrons.com/source/arch/x86/include/asm/unistd_64.h?v=3.2#L370" rel="nofollow">arch/x86/include/asm/unistd_64.h</a>, I see:</p>
  
  <pre><code>#define __NR_sync               162
  __SYSCALL(__NR_sync, sys_sync)
  </code></pre>
  
  <p>Now I'm really confused.</p>
  
  <p>If <code>sync(2)</code> is defined outside of Linux, why is there a system call for it? Where is the definition of <code>sync</code> for the x86_64 architecture?</p>
  
  <p><strong>P.S.</strong>: I did find the preprocessor definition of <code>__SYSCALL</code> at <a href="http://lxr.free-electrons.com/source/arch/x86/kernel/syscall_64.c?v=3.2#L10" rel="nofollow">arch/x86/kernel/syscall_64.c</a>, but this seems to imply that the <code>sync</code> system call just calls an external function declared as <code>void sys_sync(void)</code>. Where is the definition for this function?</p>