Cleanup unused Makefile
[lttng-modules.git] / include / instrumentation / syscalls / lttng-get-syscall-inout.sh
... / ...
CommitLineData
1#!/bin/bash
2# SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
3
4# example usage:
5# lttng-get-syscall-inout.sh table-syscall-inout.txt select 1
6
7ARCH_NAME=$1
8SYSCALL_NAME=$2
9ARG_NR=$3
10TMPFILE=$(mktemp)
11GENERIC_INOUT_DESCRIPTION_FILE="$(dirname "$0")/table-syscall-inout.txt"
12
13# Delete temp file on exit
14trap 'rm -f "$TMPFILE"' EXIT
15
16if [ x"${GENERIC_INOUT_DESCRIPTION_FILE}" = x"" ]; then
17 echo "Error: Please specify input file name as first argument" >&2
18 exit 1
19fi
20
21if [ x"${SYSCALL_NAME}" = x"" ]; then
22 echo "Error: Please specify system call name as second argument" >&2
23 exit 1
24fi
25
26if [[ x"${ARG_NR}" = x"" || ${ARG_NR} == 0 ]]; then
27 echo "Error: Please specify argument number larger than 0 as third argument" >&2
28 exit 1
29fi
30
31# Search for the in/out description of a syscall. This function attempts to find
32# a matching description in the per-architecture description override file (if it exists)
33# and falls back to the generic description file otherwise.
34#
35# Returns 0 if a description was found and written to the output file, 1 otherwise.
36function write_inout_description ()
37{
38 local arch_name=$1
39 local syscall_name=$2
40 local output_file=$3
41 local description_files=("$(dirname "$0")/table-syscall-inout-${arch_name}-override.txt" "$GENERIC_INOUT_DESCRIPTION_FILE")
42 local found=0
43
44 for file in ${description_files[@]}; do
45 if [ ! -f "$file" ]; then
46 continue
47 fi
48
49 # Look for the syscall's in/out description
50 grep "syscall ${syscall_name} " "${file}" > "${output_file}" || true
51
52 # Error out if we got more than one syscall
53 local match_count=$(wc -l < "${output_file}")
54 if [ "${match_count}" -gt 1 ]; then
55 # Fatal error; invalid description file
56 echo "Error: more than one system call match" >&2
57 exit 1
58 elif [ "${match_count}" -eq 1 ]; then
59 # Description found
60 return 0
61 fi
62 done
63
64 return 1
65}
66
67# Abort on error and undefined variable
68set -eu
69
70
71# Default to sc_inout for unknown syscalls
72if ! write_inout_description "$ARCH_NAME" "$SYSCALL_NAME" "$TMPFILE"; then
73 echo "Warning: no match for syscall '${SYSCALL_NAME}', set to 'inout'" >&2
74 # no match, default to inout
75 echo "sc_inout"
76 exit 0
77fi
78
79# Get the number of argument
80SC_ARGS=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) .*/\2/g' "${TMPFILE}")
81
82if [ "${ARG_NR}" -gt "${SC_ARGS}" ]; then
83 echo "Error: argument number (${ARG_NR}) is larger than number of syscall arguments (${SC_ARGS})" >&2
84 exit 1
85fi
86
87if [ "${ARG_NR}" == 1 ]; then
88 SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: (\([^,)]*\).*/\3/g' "${TMPFILE}")
89fi
90
91if [ "${ARG_NR}" == 2 ]; then
92 SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
93fi
94
95if [ "${ARG_NR}" == 3 ]; then
96 SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
97fi
98
99if [ "${ARG_NR}" == 4 ]; then
100 SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
101fi
102
103if [ "${ARG_NR}" == 5 ]; then
104 SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
105fi
106
107if [ "${ARG_NR}" == 6 ]; then
108 SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
109fi
110
111
112if [ "${SC_ARG_TYPE}" = "r" ]; then
113 echo "sc_in"
114fi
115if [ "${SC_ARG_TYPE}" = "w" ]; then
116 echo "sc_out"
117fi
118if [ "${SC_ARG_TYPE}" = "rw" ]; then
119 echo "sc_inout"
120fi
121
122# EOF
This page took 0.023362 seconds and 4 git commands to generate.