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