1
- // RUN: %clang_hwasan -g %s -o %t && not %run %t 2>&1 | FileCheck %s
1
+ // RUN: %clang_hwasan -g %s -o %t
2
+ // RUN: not %run %t 0 2>&1 | FileCheck %s
3
+ // RUN: not %run %t -33 2>&1 | FileCheck %s
2
4
// Only implemented for interceptor ABI on AArch64.
3
5
// REQUIRES: aarch64-target-arch
4
6
7
+ #include <assert.h>
5
8
#include <setjmp.h>
6
9
#include <stdio.h>
10
+ #include <stdlib.h>
7
11
8
12
/* Testing longjmp/setjmp should test that accesses to scopes jmp'd over are
9
13
caught. */
10
14
int __attribute__((noinline ))
11
15
uses_longjmp (int * * other_array , int num , jmp_buf env ) {
12
16
int internal_array [100 ] = {0 };
13
17
* other_array = & internal_array [0 ];
14
- if (num % 2 )
15
- longjmp (env , num );
16
- else
17
- return num % 8 ;
18
+ longjmp (env , num );
18
19
}
19
20
20
21
int __attribute__((noinline )) uses_setjmp (int num ) {
@@ -23,6 +24,7 @@ int __attribute__((noinline)) uses_setjmp(int num) {
23
24
sigjmp_buf cur_env ;
24
25
int temp = 0 ;
25
26
if ((temp = sigsetjmp (cur_env , 1 )) != 0 ) {
27
+ assert ((num == 0 && temp == 1 ) || (num != 0 && temp == num ));
26
28
// We're testing that our longjmp interceptor untagged the previous stack.
27
29
// Hence the tag in memory should be zero.
28
30
if (other_array != NULL )
@@ -33,7 +35,9 @@ int __attribute__((noinline)) uses_setjmp(int num) {
33
35
return uses_longjmp (& other_array , num , cur_env );
34
36
}
35
37
36
- int __attribute__((noinline )) main () {
37
- uses_setjmp (1 );
38
+ int __attribute__((noinline )) main (int argc , char * argv []) {
39
+ assert (argc == 2 );
40
+ int longjmp_retval = atoi (argv [1 ]);
41
+ uses_setjmp (longjmp_retval );
38
42
return 0 ;
39
43
}
0 commit comments