Skip to content

Commit

Permalink
Add/fix tests for new shadow stack allocation scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
vext01 committed Dec 19, 2024
1 parent a0ab0f1 commit af1f876
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/c/guard_consting.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// stderr:
// ...
// %{{30}}: i1 = sgt %{{_}}, 0i32
// guard true, %{{30}}, [{{0}}:%{{0_2}}: %{{0}}, {{0}}:%{{0_6}}: %{{1}}, {{0}}:%{{0_7}}: %{{2}}, {{0}}:%{{0_8}}: %{{3}}, {{0}}:%{{0_9}}: %{{4}}, {{0}}:%{{9_1}}: 0i1] ; ...
// guard true, %{{22}}, [{{0}}:%{{0_8}}: %{{0}}, {{0}}:%{{0_9}}: %{{1}}, {{0}}:%{{0_10}}: %{{2}}, {{0}}:%{{0_11}}: %{{3}}, {{0}}:%{{9_1}}: 0i1] ; ...
// ...

// Check that if a guard's life variables include the condition operand, that
Expand Down
68 changes: 68 additions & 0 deletions tests/c/shadow_longjmp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Run-time:
// env-var: YKD_LOG_IR=aot,jit-pre-opt
// env-var: YKD_SERIALISE_COMPILATION=1
// env-var: YK_LOG=4
// stderr:
// 11
// 10
// 9
// longjmp
// 8
// 7
// 6
// longjmp
// 5
// 4
// 3
// longjmp
// 2
// 1
// 0
// longjmp

// Check that the ykllvm shadow stack pass works at runtime in the presence of
// setjmp and longjump.

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <yk.h>
#include <yk_testing.h>
#include <setjmp.h>

__attribute__((noinline))
void g(int i, jmp_buf *env) {
fprintf(stderr, "%d\n", i);
if (i % 3 == 0) {
fprintf(stderr, "longjmp\n");
longjmp(*env, 1);
}
}

__attribute__((noinline))
void f(int i, jmp_buf *env) {
while (i >= 0) {
g(i, env);
i--;
}
}

int main(int argc, char **argv) {
YkMT *mt = yk_mt_new(NULL);
jmp_buf env;

int i = 11;
NOOPT_VAL(i);
while (i > 0) {
// Passing a NULL location. We never JIT. Just checking AOT behaviour.
yk_mt_control_point(mt, NULL);
if (setjmp(env) != 0) {
i -= 3;
}
f(i, &env);
i--;
}
yk_mt_shutdown(mt);
return (EXIT_SUCCESS);
}
6 changes: 3 additions & 3 deletions tests/c/simple_peeling.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
// ...
// header_start ...
// ...
// header_end [%{{0}}, %{{1}}, %{{2}}, %{{3}}, %{{4}}, %{{25}}]
// header_end [%{{0}}, %{{1}}, %{{2}}, %{{3}}, %{{4}}]
// ...
// body_start [%{{30}}, %{{31}}, %{{32}}, %{{33}}, %{{34}}, %{{35}}]
// body_start [%{{19}}, %{{20}}, %{{21}}, %{{22}}, %{{23}}]
// ...
// body_end ...
// ...
// --- End jit-post-opt ---
// ...

// Check that basic trace compilation works.
// Check that basic trace peeling works.

#include <assert.h>
#include <stdio.h>
Expand Down

0 comments on commit af1f876

Please sign in to comment.