mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: none <ytrezq@sdf-eu.org>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>,
	linux-x86_64@vger.kernel.org
Subject: Re: Getting the way a SIGSEGV append when catching a SIGSEGV from within
Date: Mon, 27 Mar 2017 21:20:47 +0200	[thread overview]
Message-ID: <2de78272-1cd7-ca1a-c3a3-950de331b727@nod.at> (raw)
In-Reply-To: <e5e4ccc4b652ca65a9a02288060c46b9@mx.sdfeu.org>

Am 27.03.2017 um 20:55 schrieb none:
> Le 2017-03-27 17:30, Richard Weinberger a écrit :
>> On Mon, Mar 27, 2017 at 4:45 PM, none <ytrezq@sdf-eu.org> wrote:
>>> Hello,
>>>
>>> There’s three way to perform an invalid memory access :
>>>
>>> The attempt to execute/jump at an invalid address.
>>> The attempt to read at an invalid address.
>>> The attempt to write at an invalid address.
>>>
>>> Determining the execute case with rt_sigaction is easy : the last value of
>>> eip match the value of the address which caused the segfault.
>>>
>>> But how to know if the SIGSEGV occurred by a read or by a write attempt ? In
>>> the same time shouldn’t that information belong in the mmu ?
>>
>> Did you look at the machine specific context of SIGSEGV?
>> It will give you access to the error code and the trap number.
> 
> Sorry but so, in the case of x86_64, which is the struct member I need to look at ?

ucontext_t *c = context; // context is the 3rd parameter to your SIGSEGV handler when SA_SIGINFO is set
mcontext_t m = c->uc_mcontext;

m.gregs[REG_ERR] and m.gregs[REG_TRAPNO] are what you want.

HTH,
//richard

      reply	other threads:[~2017-03-27 19:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27 14:45 none
2017-03-27 15:30 ` Richard Weinberger
2017-03-27 18:55   ` none
2017-03-27 19:20     ` Richard Weinberger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2de78272-1cd7-ca1a-c3a3-950de331b727@nod.at \
    --to=richard@nod.at \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-x86_64@vger.kernel.org \
    --cc=ytrezq@sdf-eu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®