fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / tests / utils / testapp / gen-syscall-events-callstack / gen-syscall-events-callstack.c
1 /*
2 * Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #include "utils.h"
9
10 #include <fcntl.h>
11 #include <signal.h>
12 #include <stdbool.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <sys/syscall.h>
17 #include <sys/types.h>
18 #include <unistd.h>
19
20 /**
21 * The process waits for the creation of a file passed as argument from an
22 * external processes to execute a syscall and exiting. This is useful for tests
23 * in combinaison with LTTng's PID tracker feature where we can trace the kernel
24 * events generated by our test process only.
25 */
26
27 #if defined(__clang__)
28 #define nooptimization __attribute__((noinline)) __attribute__((optnone))
29 #else
30 #define nooptimization __attribute__((noinline)) __attribute__((optimize(0)))
31 #endif
32
33 volatile int val = 0;
34
35 long nooptimization my_gettid(void);
36 long nooptimization my_gettid(void)
37 {
38 long ret;
39 #ifdef __x86_64
40 asm volatile("syscall" : "=a"(ret) : "0"(__NR_gettid) : "cc", "rcx", "r11", "memory");
41 #elif defined(__i386)
42 asm volatile("int $0x80" : "=a"(ret) : "0"(__NR_gettid) : "cc", "edi", "esi", "memory");
43 #else
44 #error "Userspace callstack test not supported for this architecture."
45 #endif
46 return ret;
47 }
48
49 int nooptimization fct_c(void);
50 int nooptimization fct_c(void)
51 {
52 return my_gettid();
53 }
54
55 int nooptimization fct_b(void);
56 int nooptimization fct_b(void)
57 {
58 val += fct_c();
59 return val;
60 }
61
62 int nooptimization fct_a(void);
63 int nooptimization fct_a(void)
64 {
65 val += fct_b();
66 return val;
67 }
68
69 int main(int argc, char **argv)
70 {
71 int ret = 0;
72 char *start_file;
73
74 if (argc != 2) {
75 fprintf(stderr, "Error: Missing argument\n");
76 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE\n", argv[0]);
77 ret = -1;
78 goto error;
79 }
80
81 start_file = argv[1];
82
83 /*
84 * Wait for the start_file to be created by an external process
85 * (typically the test script) before executing the syscall
86 */
87 ret = wait_on_file(start_file);
88 if (ret != 0) {
89 goto error;
90 }
91
92 /* Start the callchain to the syscall */
93 ret = fct_a();
94
95 /* Return success */
96 if (ret >= 0) {
97 ret = 0;
98 }
99
100 error:
101 return ret;
102 }
This page took 0.030782 seconds and 4 git commands to generate.