summaryrefslogtreecommitdiff
path: root/testcase/userstack.c
diff options
context:
space:
mode:
Diffstat (limited to 'testcase/userstack.c')
-rw-r--r--testcase/userstack.c119
1 files changed, 70 insertions, 49 deletions
diff --git a/testcase/userstack.c b/testcase/userstack.c
index 5da72c7..578b2c0 100644
--- a/testcase/userstack.c
+++ b/testcase/userstack.c
@@ -1,12 +1,15 @@
#include <stdio.h>
// #include <libunwind.h>
-#include <unistd.h>
#include <pthread.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+
// void customFunction1(int n);
-void *customFunction1(void *n);
-void customFunction2(int n);
-void customFunction3(int n);
+// void *customFunction1(void *n);
+// void customFunction2(int n);
+// void customFunction3(int n);
// Call this function to get a backtrace.
// void backtrace() {
@@ -35,61 +38,79 @@ void customFunction3(int n);
// }
// }
-void *customFunction1(void *n) {
- int num = *((int *)n);
- if(num <= 0) {
- printf("End of recursion\n");
- printf("pid: %d\n", getpid());
- while (1) {
- sleep(1);
- } // never return, keep stack
- // return NULL;
- } else {
- printf("Calling customFunction2\n");
- customFunction2(num-1);
- }
- return NULL;
+pid_t gettid() {
+ return syscall(SYS_gettid);
+}
+
+static void additionalFunction(int n) {
+ printf("Additional function called with n = %d\n", n);
+}
+
+static void customFunction3(int n) {
+ printf("Calling customFunction3\n");
+ additionalFunction(n);
+ if (n <= 0) {
+ printf("End of recursion\n");
+ printf("pid: %d\n", getpid());
+ while (1) {
+ sleep(1);
+ } // never return, keep stack
+ // return NULL;
+ }
+ customFunction2(n - 1);
}
void customFunction2(int n) {
+ printf("Calling customFunction2\n");
+ additionalFunction(n);
+ if (n <= 0) {
+ printf("End of recursion\n");
+ printf("pid: %d\n", getpid());
+ while (1) {
+ sleep(1);
+ } // never return, keep stack
+ // return NULL;
+ }
+ customFunction3(n - 1);
+}
+
+void *customFunction1(void *n) {
+ int num = *((int *)n);
+ if (num <= 0) {
+ printf("End of recursion\n");
+ printf("pid: %d\n", getpid());
+ while (1) {
+ sleep(1);
+ } // never return, keep stack
+ // return NULL;
+ } else {
printf("Calling customFunction2\n");
- if(n <= 0) {
- printf("End of recursion\n");
- printf("pid: %d\n", getpid());
- while (1) {
- sleep(1);
- } // never return, keep stack
- // return NULL;
- }
- customFunction3(n-1);
+ customFunction2(num - 1);
+ }
+ return NULL;
}
-void customFunction3(int n) {
- printf("Calling customFunction3\n");
- if(n <= 0) {
- printf("End of recursion\n");
- printf("pid: %d\n", getpid());
- while (1) {
- sleep(1);
- } // never return, keep stack
- // return NULL;
- }
- customFunction2(n-1);
+void *customFunction122(void *n) {
+ printf("tid: %d\n", gettid());
+ while (1)
+ {
+ /* code */
+ }
}
int main() {
- int num1 = 4;
- int num2 = 5;
- int num3 = 6;
+ int num1 = 10;
+ int num2 = 11;
+ int num3 = 12;
- pthread_t thread_id1, thread_id2, thread_id3;
+ pthread_t thread_id1, thread_id2, thread_id3;
- pthread_create(&thread_id1, NULL, customFunction1, &num1);
- pthread_create(&thread_id2, NULL, customFunction1, &num2);
- pthread_create(&thread_id3, NULL, customFunction1, &num3);
+ pthread_create(&thread_id2, NULL, customFunction1, &num2);
+ pthread_create(&thread_id3, NULL, customFunction1, &num3);
+ pthread_create(&thread_id1, NULL, customFunction122, &num1);
- pthread_join(thread_id1, NULL);
- pthread_join(thread_id2, NULL);
- pthread_join(thread_id3, NULL);
- return 0;
+ pthread_join(thread_id1, NULL);
+ pthread_join(thread_id2, NULL);
+ pthread_join(thread_id3, NULL);
+ return 0;
} \ No newline at end of file