tests: add declarations for functions in gen-syscall-events-callstack.c
[lttng-tools.git] / tests / utils / testapp / gen-syscall-events-callstack / gen-syscall-events-callstack.c
CommitLineData
591ee332
FD
1/*
2 * Copyright (C) - 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by the
6 * Free Software Foundation; version 2.1 of the License.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18#include <fcntl.h>
19#include <signal.h>
20#include <stdbool.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/syscall.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include "utils.h"
29
30/**
31 * The process waits for the creation of a file passed as argument from an
32 * external processes to execute a syscall and exiting. This is useful for tests
33 * in combinaison with LTTng's PID tracker feature where we can trace the kernel
34 * events generated by our test process only.
35 */
36
51c2fb6c
FD
37#if defined(__clang__)
38#define nooptimization __attribute__((noinline)) __attribute__((optnone))
39#else
40#define nooptimization __attribute__((noinline)) __attribute__((optimize(0)))
41#endif
42
591ee332
FD
43volatile int val = 0;
44
701a99d1 45long nooptimization my_gettid(void);
51c2fb6c 46long nooptimization
591ee332
FD
47my_gettid(void)
48{
49 long ret;
50#ifdef __x86_64
51 asm volatile
52 (
53 "syscall"
54 : "=a" (ret)
55 : "0"(__NR_gettid)
56 : "cc", "rcx", "r11", "memory"
57 );
58#elif __i386
59 asm volatile
60 (
61 "int $0x80"
62 : "=a" (ret)
63 : "0"(__NR_gettid)
64 : "cc", "edi", "esi", "memory"
65 );
66#else
67#error "Userspace callstack test not supported for this architecture."
68#endif
69 return ret;
70}
71
701a99d1 72int nooptimization fct_c(void);
51c2fb6c 73int nooptimization
591ee332
FD
74fct_c(void)
75{
76 return my_gettid();
77}
78
701a99d1 79int nooptimization fct_b(void);
51c2fb6c 80int nooptimization
591ee332
FD
81fct_b(void)
82{
83 val += fct_c();
84 return val;
85}
86
701a99d1 87int nooptimization fct_a(void);
51c2fb6c 88int nooptimization
591ee332
FD
89fct_a(void)
90{
91 val += fct_b();
92 return val;
93}
94
95int main(int argc, char **argv)
96{
97 int ret = 0;
98 char *start_file;
99
100 if (argc != 2) {
101 fprintf(stderr, "Error: Missing argument\n");
102 fprintf(stderr, "USAGE: %s PATH_WAIT_FILE\n", argv[0]);
103 ret = -1;
104 goto error;
105 }
106
107 start_file = argv[1];
108
109 /*
110 * Wait for the start_file to be created by an external process
111 * (typically the test script) before executing the syscall
112 */
113 ret = wait_on_file(start_file);
114 if (ret != 0) {
115 goto error;
116 }
117
118 /* Start the callchain to the syscall */
119 ret = fct_a();
120
121 /* Return success */
122 if (ret >= 0) {
123 ret = 0;
124 }
125
126error:
127 return ret;
128}
This page took 0.056971 seconds and 4 git commands to generate.