Hi all,
Kindly comment on the attached patch for SIGNAL and Address Fault
handling in mmap1 testcase by [EMAIL PROTECTED]
Regards--
Subrata
Index: mtest06/mmap1.c
===================================================================
--- mtest06.orig/mmap1.c
+++ mtest06/mmap1.c
@@ -69,6 +69,17 @@
/* by jerrywei. */
/* email:[EMAIL PROTECTED] */
/* */
+/* Jul - 13 - 2007 Modified - use siginfo_t to detect the */
+/* faulting address. Now this works fine on all */
+/* architectures. - Suzuki K P */
+/* email:[EMAIL PROTECTED] */
+/* */
+/* Jul - 18 - 2007 Modified - Add SA_NODEFER flag to avoid */
+/* the chances of missing a SIGSEGV handling. */
+/* Do not mask SIGSEGV - Suzuki K P */
+/* email:[EMAIL PROTECTED] */
+/* */
+/* */
/* File: mmap1.c */
/* */
/* Description: Test the LINUX memory manager. The program is aimed at */
@@ -149,84 +160,28 @@ sigjmp_buf jmpbuf; /* argument to sigse
/******************************************************************************/
static void
sig_handler(int signal, /* signal number, set to handle SIGALRM */
- int code,
+ siginfo_t *info,
struct ucontext *ut)/* contains pointer to sigcontext structure */
{
-#ifdef __i386__
- unsigned long except; /* exception type. */
- int ret = 0; /* exit code from signal handler. */
- struct sigcontext *scp = /* pointer to sigcontext structure */
- (struct sigcontext *)&ut->uc_mcontext;
-#endif
-
- if (signal == SIGALRM)
- {
- fprintf(stdout, "Test ended, success\n");
- exit(0);
- }
-#ifdef __i386__
- else
+ switch (signal)
{
- except = scp->trapno;
- fprintf(stderr, "signal caught - [%d] exception - [%ld]\n",
- signal, except);
- }
+ case SIGALRM:
+ fprintf(stdout, "Test ended, success\n");
+ exit(0);
+
+ case SIGSEGV:
+ if (info->si_code == SEGV_MAPERR &&
+ info->si_addr == map_address)
+ {
+ fprintf(stdout, "page fault at %p - ignore\n",map_address);
+ longjmp(jmpbuf, 1);
+ }
- switch(except)
- {
- case 10:
- fprintf(stderr,
- "Exception - invalid TSS, exception #[%ld]\n", except);
- break;
- case 11:
- fprintf(stderr,
- "Exception - segment not present, exception #[%ld]\n",
- except);
- break;
- case 12:
- fprintf(stderr,
- "Exception - stack segment not present, exception #[%ld]\n",
- except);
- break;
- case 13:
- fprintf(stderr,
- "Exception - general protection, exception #[%ld]\n",
- except);
- break;
- case 14:
- fprintf(stderr,
- "Exception - page fault, exception #[%ld]\n",
- except);
- ret = 1;
- break;
default:
- fprintf(stderr,
- "Exception type not handled... unknown exception #[%ld]\n",
- except);
- break;
- }
-
- if (ret)
- {
- if (scp->eax == (int)map_address)
- {
- fprintf(stdout,
- "page fault at %#lx\n"
- " - ignore\n", scp->eax);
- longjmp(jmpbuf, 1);
- }
- else
- {
- fprintf(stderr, "bad page fault exit test\n");
- exit (-1);
- }
+ fprintf(stderr, "caught unexpected signal - %d --- exiting\n",
+ signal);
+ exit(-1);
}
- else
- exit (-1);
-#else
- fprintf(stderr, "caught signal %d -- exiting.\n", signal);
- exit (-1);
-#endif
}
@@ -581,12 +536,14 @@ main(int argc, /* number of input para
set_timer(exec_time);
/* set up signals */
+ /* Do not mask SIGSEGV, as we are interested in handling it. */
+
sigptr.sa_handler = (void (*)(int signal))sig_handler;
sigfillset(&sigptr.sa_mask);
- sigptr.sa_flags = SA_SIGINFO;
+ sigdelset(&sigptr.sa_mask, SIGSEGV);
+ sigptr.sa_flags = SA_SIGINFO | SA_NODEFER;
for (sig_ndx = 0; sig_info[sig_ndx].signum != -1; sig_ndx++)
{
- sigaddset(&sigptr.sa_mask, sig_info[sig_ndx].signum);
if (sigaction(sig_info[sig_ndx].signum, &sigptr,
(struct sigaction *)NULL) == -1 )
{
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list