1From 26c104adf6c5162572b7aa2fac89d0835b7f8f0b Mon Sep 17 00:00:00 2001
2From: Randy MacLeod <Randy.MacLeod@windriver.com>
3Date: Tue, 16 Oct 2018 21:27:46 -0400
4Subject: [PATCH] context APIs are not available on musl
5
6Updated patch for valgrind-3.14
7
8Signed-off-by: Khem Raj <raj.khem@gmail.com>
9Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com>
10
11Apply same patch to drd/tests/swapcontext.c
12for valgrind-3.17.
13
14Upstream-Status: Submitted [https://bugs.kde.org/show_bug.cgi?id=434775]
15
16Signed-off-by: Yi Fan Yu <yifan.yu@windriver.com>
17---
18 drd/tests/swapcontext.c              | 6 ++++++
19 memcheck/tests/linux/stack_changes.c | 7 ++++++-
20 2 files changed, 12 insertions(+), 1 deletion(-)
21
22diff --git a/drd/tests/swapcontext.c b/drd/tests/swapcontext.c
23index 622c70bc5..5e72bb0f3 100644
24--- a/drd/tests/swapcontext.c
25+++ b/drd/tests/swapcontext.c
26@@ -20,6 +20,7 @@
27
28 #define STACKSIZE (PTHREAD_STACK_MIN + 4096)
29
30+#ifdef __GLIBC__
31 typedef struct thread_local {
32   ucontext_t uc[3];
33   size_t nrsw;
34@@ -67,9 +68,11 @@ void *worker(void *data)
35   swapcontext(&tlocal->uc[0], &tlocal->uc[1]);
36   return NULL;
37 }
38+#endif
39
40 int main(int argc, char *argv[])
41 {
42+#ifdef __GLIBC__
43   enum { NR = 32 };
44   thread_local_t tlocal[NR];
45   pthread_t thread[NR];
46@@ -94,6 +97,9 @@ int main(int argc, char *argv[])
47
48   for (i = 0; i < NR; i++)
49     pthread_join(thread[i], NULL);
50+#else
51+    printf("libc context call APIs e.g. getcontext() are deprecated by posix\n");
52+#endif
53
54   return 0;
55 }
56diff --git a/memcheck/tests/linux/stack_changes.c b/memcheck/tests/linux/stack_changes.c
57index 7f97b90a5..a26cb4ae6 100644
58--- a/memcheck/tests/linux/stack_changes.c
59+++ b/memcheck/tests/linux/stack_changes.c
60@@ -10,6 +10,7 @@
61 // This test is checking the libc context calls (setcontext, etc.) and
62 // checks that Valgrind notices their stack changes properly.
63
64+#ifdef __GLIBC__
65 typedef  ucontext_t  mycontext;
66
67 mycontext ctx1, ctx2, oldc;
68@@ -51,9 +52,11 @@ int init_context(mycontext *uc)
69
70     return ret;
71 }
72+#endif
73
74 int main(int argc, char **argv)
75 {
76+#ifdef __GLIBC__
77     int c1 = init_context(&ctx1);
78     int c2 = init_context(&ctx2);
79
80@@ -66,6 +69,8 @@ int main(int argc, char **argv)
81     //free(ctx1.uc_stack.ss_sp);
82     VALGRIND_STACK_DEREGISTER(c2);
83     //free(ctx2.uc_stack.ss_sp);
84-
85+#else
86+    printf("libc context call APIs e.g. getcontext() are deprecated by posix\n");
87+#endif
88     return 0;
89 }
90--
912.17.1
92
93