~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to compiler-rt/lib/asan/lit_tests/allow_user_segv.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Regression test for
 
2
// https://code.google.com/p/address-sanitizer/issues/detail?id=180
 
3
 
 
4
// RUN: %clangxx_asan -m64 -O0 %s -o %t && ASAN_OPTIONS=allow_user_segv_handler=true %t 2>&1 | FileCheck %s
 
5
// RUN: %clangxx_asan -m64 -O2 %s -o %t && ASAN_OPTIONS=allow_user_segv_handler=true %t 2>&1 | FileCheck %s
 
6
// RUN: %clangxx_asan -m32 -O0 %s -o %t && ASAN_OPTIONS=allow_user_segv_handler=true %t 2>&1 | FileCheck %s
 
7
// RUN: %clangxx_asan -m32 -O2 %s -o %t && ASAN_OPTIONS=allow_user_segv_handler=true %t 2>&1 | FileCheck %s
 
8
 
 
9
#include <signal.h>
 
10
#include <stdio.h>
 
11
 
 
12
struct sigaction user_sigaction;
 
13
struct sigaction original_sigaction;
 
14
 
 
15
void User_OnSIGSEGV(int signum, siginfo_t *siginfo, void *context) {
 
16
  fprintf(stderr, "User sigaction called\n");
 
17
  if (original_sigaction.sa_flags | SA_SIGINFO)
 
18
    original_sigaction.sa_sigaction(signum, siginfo, context);
 
19
  else
 
20
    original_sigaction.sa_handler(signum);
 
21
}
 
22
 
 
23
int DoSEGV() {
 
24
  volatile int *x = 0;
 
25
  return *x;
 
26
}
 
27
 
 
28
int main() {
 
29
  user_sigaction.sa_sigaction = User_OnSIGSEGV;
 
30
  user_sigaction.sa_flags = SA_SIGINFO;
 
31
#if defined(__APPLE__) && !defined(__LP64__)
 
32
  // On 32-bit Darwin KERN_PROTECTION_FAILURE (SIGBUS) is delivered.
 
33
  int signum = SIGBUS;
 
34
#else
 
35
  // On 64-bit Darwin KERN_INVALID_ADDRESS (SIGSEGV) is delivered.
 
36
  // On Linux SIGSEGV is delivered as well.
 
37
  int signum = SIGSEGV;
 
38
#endif
 
39
  if (sigaction(signum, &user_sigaction, &original_sigaction)) {
 
40
    perror("sigaction");
 
41
    return 1;
 
42
  }
 
43
  fprintf(stderr, "User sigaction installed\n");
 
44
  return DoSEGV();
 
45
}
 
46
 
 
47
// CHECK: User sigaction installed
 
48
// CHECK-NEXT: User sigaction called
 
49
// CHECK-NEXT: ASAN:SIGSEGV
 
50
// CHECK: AddressSanitizer: SEGV on unknown address