linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "John Chris Wren" <jcwren@jcwren.com>
To: <linux-kernel@vger.kernel.org>
Subject: Question about signal handling
Date: Thu, 14 Jun 2001 01:33:08 -0400	[thread overview]
Message-ID: <NDBBKBJHGFJMEMHPOPEGAEJPCJAA.jcwren@jcwren.com> (raw)
In-Reply-To: <20010614050151.3779.qmail@nwcst292.netaddress.usa.net>


	Hopefully I'm not asking a really stupid question here, but...

	When setting up a signal handler, using sa_handler, there is a
quasi-documented 2nd parameter of 'struct context ctx' passed to the signal
handler.  This seems to work on 2.2.12, 2.2.18, and 2.4.5-ac2.  According to
various documents, when using sa_siginfo (and setting SA_SIGINFO), the third
parameter to the handler is defined as a 'void *', but actually passes a
'ucontext_t' data type.  Which is not defined in any kernel code, except for
the sparc64 branch.  Casting this to a 'struct context' or a 'struct context
*' doesn't seem to achieve the desired results on any of the three kernels I
tested.

	Google searches indicate different things.  POSIX 1 compliance says it
should be a 'ucontext_t *'
(www.opengroup.org/onlinepubs/007908799/xsh/sigaction.html+sigcontext+siginf
o_t+sigaction&hl=en&lr=lang_en) (I realize that's the Open standard, but the
comments at the bottom talk about POSIX compliance).  Other searches say it
returns as a 'struct context *'.

	I tried following the code through the kernel, but I'm not familiar enough
with yet to really understand how it's getting scheduled, and exactly which
parameters are getting passed back.

	What is the correct behavior supposed to be?  And if using sa_siginfo, how
does one get at the context parameters to find the EIP the fault occurred
at?

	Here's a sample bit of code I used for testing.  Leaving #define SIGACTION
demonstrates the third parameter not (seemingly) being passed as a context
pointer, #undef demonstrates the sa_handler 2 paramter handler, which
returns a correct context.

#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <string.h>

#define SIGACTION

#ifdef SIGACTION
void fSegvHandler (int sigNo, siginfo_t *si, void *p)
{
   struct sigcontext *context = (struct sigcontext *) p;
#else
void fSegvHandler (int sigNo, void *p)
{
   struct sigcontext *context = (struct sigcontext *) &p;
#endif

   printf ("\nContext: %08X\n",context);
   fflush (stdout);
   printf ("gs:  %04X\tfs:  %04X\tes:  %04X\tds:  %04X\n"
           "edi: %08X\tesi: %08X\tebp: %04X\tesp: %04X\n"
           "ebx: %08X\tedx: %08X\tecx: %08X\teax: %08X\n"
           "trap: %d\terr: %d\teip: %08X\tcs:  %04X\n"
           "flag: %08X\tSP: %08X\tss:  %04X\tcr2: %08X\n",
           context->gs, context->fs, context->es, context->ds,
           context->edi, context->esi, context->ebp, context->esp,
           context->ebx, context->edx, context->ecx, context->eax,
           context->trapno, context->err, context->eip, context->cs,
           context->eflags, context->esp_at_signal, context->ss,
context->cr2);
   fflush (stdout);
   exit (0);
}

int main (int argc, char **argv)
{
   struct sigaction sSegvHdl;

   sigemptyset (&sSegvHdl.sa_mask);
   sigaddset (&sSegvHdl.sa_mask, SIGSEGV);

#ifdef SIGACTION
   sSegvHdl.sa_flags   = SA_SIGINFO | SA_ONESHOT;
   sSegvHdl.sa_sigaction = fSegvHandler;
#else
   sSegvHdl.sa_flags   = SA_ONESHOT;
   sSegvHdl.sa_handler = fSegvHandler;
#endif

   if (sigaction (SIGSEGV, &sSegvHdl, NULL))
      perror ("sigaction");
   else
      *(char *) 0x0 = 0x01;
}

	-- John




      parent reply	other threads:[~2001-06-14  5:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-14  5:01 inetd missing Blesson Paul
2001-06-14  5:18 ` [OT] " J Sloan
2001-06-14  5:33 ` John Chris Wren [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=NDBBKBJHGFJMEMHPOPEGAEJPCJAA.jcwren@jcwren.com \
    --to=jcwren@jcwren.com \
    --cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).