From 29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:21:29 +0200 Subject: Adding upstream version 1:0.1.9998svn3589+dfsg. Signed-off-by: Daniel Baumann --- src/lib/kStuff/kProfiler2/tstlongjmp.c | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/lib/kStuff/kProfiler2/tstlongjmp.c (limited to 'src/lib/kStuff/kProfiler2/tstlongjmp.c') diff --git a/src/lib/kStuff/kProfiler2/tstlongjmp.c b/src/lib/kStuff/kProfiler2/tstlongjmp.c new file mode 100644 index 0000000..d6e2b49 --- /dev/null +++ b/src/lib/kStuff/kProfiler2/tstlongjmp.c @@ -0,0 +1,62 @@ + +#include +#include + +/* just try trick the compiler into not optimizing stuff by + making it "uncertain" which path to take. */ +int always_true(void) +{ + time_t t = time(NULL); + if (t == time(NULL)) + return 1; + if (t != time(NULL)) + return 1; + if (t == time(NULL)) + return 1; + if (t != time(NULL)) + return 1; + return 0; +} + +jmp_buf g_JmpBuf; + +int onelevel(void) +{ + if (always_true()) + longjmp(g_JmpBuf, 1); + return 0; +} + + +int twolevels_inner(void) +{ + if (always_true()) + longjmp(g_JmpBuf, 1); + return 0; +} + +int twolevels_outer(void) +{ + int rc; + always_true(); + rc = twolevels_inner(); + always_true(); + return rc; +} + + +int main() +{ + int rc = 1; + + /* first */ + if (!setjmp(g_JmpBuf)) + rc = onelevel(); + + /* second */ + if (!setjmp(g_JmpBuf)) + rc = twolevels_outer(); + + return rc != 1; +} + -- cgit v1.2.3