Skip to content

Commit acaca56

Browse files
committed
[HWASan] Test longjmp(jmpbuf, 0).
Our interceptor needs to change retval to 1 when 0 is passed. Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D109788
1 parent 385f380 commit acaca56

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
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
24
// Only implemented for interceptor ABI on AArch64.
35
// REQUIRES: aarch64-target-arch
46

7+
#include <assert.h>
58
#include <setjmp.h>
69
#include <stdio.h>
10+
#include <stdlib.h>
711

812
/* Testing longjmp/setjmp should test that accesses to scopes jmp'd over are
913
caught. */
1014
int __attribute__((noinline))
1115
uses_longjmp(int **other_array, int num, jmp_buf env) {
1216
int internal_array[100] = {0};
1317
*other_array = &internal_array[0];
14-
if (num % 2)
15-
longjmp(env, num);
16-
else
17-
return num % 8;
18+
longjmp(env, num);
1819
}
1920

2021
int __attribute__((noinline)) uses_setjmp(int num) {
@@ -23,6 +24,7 @@ int __attribute__((noinline)) uses_setjmp(int num) {
2324
sigjmp_buf cur_env;
2425
int temp = 0;
2526
if ((temp = sigsetjmp(cur_env, 1)) != 0) {
27+
assert((num == 0 && temp == 1) || (num != 0 && temp == num));
2628
// We're testing that our longjmp interceptor untagged the previous stack.
2729
// Hence the tag in memory should be zero.
2830
if (other_array != NULL)
@@ -33,7 +35,9 @@ int __attribute__((noinline)) uses_setjmp(int num) {
3335
return uses_longjmp(&other_array, num, cur_env);
3436
}
3537

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);
3842
return 0;
3943
}

0 commit comments

Comments
 (0)