-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'origin/master' into fedora/master
- Loading branch information
Showing
28 changed files
with
632 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* Test case mostly written by Paolo Bonzini <pbonzini@redhat.com>. */ | ||
#include <assert.h> | ||
#include <setjmp.h> | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/time.h> | ||
#include <sys/resource.h> | ||
|
||
|
||
static jmp_buf mainloop; | ||
static sigset_t mainsigset; | ||
static int pass; | ||
|
||
|
||
static void | ||
stackoverflow_handler (int sig) | ||
{ | ||
stack_t altstack; | ||
pass++; | ||
sigaltstack (NULL, &altstack); | ||
/* Using printf is not really kosher in signal handlers but we know | ||
it will work. */ | ||
printf ("%*sin signal handler\n", pass, ""); | ||
if (altstack.ss_flags & SS_ONSTACK) | ||
printf ("%*son alternate stack\n", pass, ""); | ||
siglongjmp (mainloop, pass); | ||
} | ||
|
||
|
||
static volatile int * | ||
recurse_1 (int n, volatile int *p) | ||
{ | ||
if (n >= 0) | ||
*recurse_1 (n + 1, p) += n; | ||
return p; | ||
} | ||
|
||
|
||
static int | ||
recurse (int n) | ||
{ | ||
int sum = 0; | ||
return *recurse_1 (n, &sum); | ||
} | ||
|
||
|
||
static int | ||
do_test (void) | ||
{ | ||
char mystack[SIGSTKSZ]; | ||
stack_t altstack; | ||
struct sigaction action; | ||
sigset_t emptyset; | ||
/* Before starting the endless recursion, try to be friendly to the user's | ||
machine. On some Linux 2.2.x systems, there is no stack limit for user | ||
processes at all. We don't want to kill such systems. */ | ||
struct rlimit rl; | ||
rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */ | ||
setrlimit (RLIMIT_STACK, &rl); | ||
/* Install the alternate stack. */ | ||
altstack.ss_sp = mystack; | ||
altstack.ss_size = sizeof (mystack); | ||
altstack.ss_flags = 0; /* no SS_DISABLE */ | ||
if (sigaltstack (&altstack, NULL) < 0) | ||
{ | ||
puts ("first sigaltstack failed"); | ||
return 0; | ||
} | ||
/* Install the SIGSEGV handler. */ | ||
sigemptyset (&action.sa_mask); | ||
action.sa_handler = &stackoverflow_handler; | ||
action.sa_flags = SA_ONSTACK; | ||
sigaction (SIGSEGV, &action, (struct sigaction *) NULL); | ||
sigaction (SIGBUS, &action, (struct sigaction *) NULL); | ||
|
||
/* Save the current signal mask. */ | ||
sigemptyset (&emptyset); | ||
sigprocmask (SIG_BLOCK, &emptyset, &mainsigset); | ||
|
||
/* Provoke two stack overflows in a row. */ | ||
if (sigsetjmp (mainloop, 1) != 0) | ||
{ | ||
assert (pass != 0); | ||
printf ("%*sout of signal handler\n", pass, ""); | ||
} | ||
else | ||
assert (pass == 0); | ||
|
||
sigaltstack (NULL, &altstack); | ||
if (altstack.ss_flags & SS_ONSTACK) | ||
printf ("%*son alternate stack\n", pass, ""); | ||
else | ||
printf ("%*snot on alternate stack\n", pass, ""); | ||
|
||
if (pass < 2) | ||
{ | ||
recurse (0); | ||
puts ("recurse call returned"); | ||
return 2; | ||
} | ||
|
||
altstack.ss_flags |= SS_DISABLE; | ||
if (sigaltstack (&altstack, NULL) == -1) | ||
printf ("disabling alternate stack failed\n"); | ||
else | ||
printf ("disabling alternate stack succeeded \n"); | ||
|
||
return 0; | ||
} | ||
|
||
#define TEST_FUNCTION do_test () | ||
#include "../test-skeleton.c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1 @@ | ||
/* Copyright (C) 2001,2004,2005,2006,2009 Free Software Foundation, Inc. | ||
This file is part of the GNU C Library. | ||
The GNU C Library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
The GNU C Library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with the GNU C Library; if not, write to the Free | ||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
02111-1307 USA. */ | ||
|
||
.section .rodata.str1.1,"aMS",@progbits,1 | ||
.type longjmp_msg,@object | ||
longjmp_msg: | ||
.string "longjmp causes uninitialized stack frame" | ||
.size longjmp_msg, .-longjmp_msg | ||
|
||
|
||
#define __longjmp ____longjmp_chk | ||
|
||
#ifdef PIC | ||
# define CALL_FAIL movl %ebx, %ecx; \ | ||
cfi_register(%ebx,%ecx); \ | ||
LOAD_PIC_REG (bx); \ | ||
leal longjmp_msg@GOTOFF(%ebx), %eax; \ | ||
call __GI___fortify_fail@PLT | ||
#else | ||
# define CALL_FAIL movl $longjmp_msg, %eax; \ | ||
call __fortify_fail | ||
#endif | ||
|
||
#define CHECK_ESP(reg) \ | ||
cmpl reg, %esp; \ | ||
jbe .Lok; \ | ||
CALL_FAIL; \ | ||
.Lok: | ||
|
||
#include "__longjmp.S" | ||
#error "OS-specific version needed" |
Oops, something went wrong.