title: How to identify read or write operations of page fault when using sigaction handler on SIGSEGV?(LINUX)
body: <p>I use sigaction to handle page fault exception, and the handler function is defind like this:</p>
  
  <pre><code>void sigaction_handler(int signum, siginfo_t *info, void *_context)
  </code></pre>
  
  <p>So it's easy to get page fault address by reading <strong>info->si_addr</strong>.</p>
  
  <p>The question is, how to know whether this operation is memory <strong>READ</strong> or <strong>WRITE</strong> ?</p>
  
  <p>I found the type of <strong>_context</strong> parameter is <strong>ucontext_t</strong> defined in /usr/include/sys/<a href="http://stuff.mit.edu/afs/athena.mit.edu/contrib/watchmaker/src/ofiles/h/ucontext.h" rel="noreferrer">ucontext.h</a></p>
  
  <p>There is a <strong>cr2</strong> field defined in mcontext_t, but unforunately, it is only avaliable when <strong>x86_64</strong> is not defind, thus I could not used cr2 to identify read/write operations.</p>
  
  <p>On anotherway, there is a struct named <strong>sigcontext</strong> defined in /usr/include/bits/<a href="http://repo-genesis3.cbi.utsa.edu/crossref/ns-sli/usr/include/bits/sigcontext.h.html" rel="noreferrer">sigcontext.h</a>
  This struct contains <strong>cr2</strong> field. But I don't know where to get it.</p>