2 # SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
5 # lttng-get-syscall-inout.sh table-syscall-inout.txt select 1
11 GENERIC_INOUT_DESCRIPTION_FILE
="$(dirname "$0")/table-syscall-inout.txt"
13 # Delete temp file on exit
14 trap 'rm -f "$TMPFILE"' EXIT
16 if [ "${GENERIC_INOUT_DESCRIPTION_FILE}" = "" ]; then
17 echo "Error: Please specify input file name as first argument" >&2
21 if [ "${SYSCALL_NAME}" = "" ]; then
22 echo "Error: Please specify system call name as second argument" >&2
26 if [[ "${ARG_NR}" = "" ||
${ARG_NR} == 0 ]]; then
27 echo "Error: Please specify argument number larger than 0 as third argument" >&2
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.
35 # Returns 0 if a description was found and written to the output file, 1 otherwise.
36 function write_inout_description
()
41 local description_files
=("$(dirname "$0")/table-syscall-inout-${arch_name}-override.txt" "$GENERIC_INOUT_DESCRIPTION_FILE")
44 for file in "${description_files[@]}"; do
45 if [ ! -f "$file" ]; then
49 # Look for the syscall's in/out description
50 grep "^syscall ${syscall_name} " "${file}" > "${output_file}" || true
52 # Error out if we got more than one syscall
53 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 for ${SYSCALL_NAME}" >&2
58 elif [ "${match_count}" -eq 1 ]; then
67 # Abort on error and undefined variable
71 # Default to sc_inout for unknown syscalls
72 if ! 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
79 # Get the number of argument
80 SC_ARGS
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) .*/\2/g' "${TMPFILE}")
82 if [ "${ARG_NR}" -gt "${SC_ARGS}" ]; then
83 echo "Error: argument number (${ARG_NR}) for ${SYSCALL_NAME} is larger than number of syscall arguments (${SC_ARGS})" >&2
87 if [ "${ARG_NR}" == 1 ]; then
88 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: (\([^,)]*\).*/\3/g' "${TMPFILE}")
91 if [ "${ARG_NR}" == 2 ]; then
92 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
95 if [ "${ARG_NR}" == 3 ]; then
96 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
99 if [ "${ARG_NR}" == 4 ]; then
100 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
103 if [ "${ARG_NR}" == 5 ]; then
104 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
107 if [ "${ARG_NR}" == 6 ]; then
108 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
112 if [ "${SC_ARG_TYPE}" = "r" ]; then
115 if [ "${SC_ARG_TYPE}" = "w" ]; then
118 if [ "${SC_ARG_TYPE}" = "rw" ]; then