2 # SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
5 # lttng-get-syscall-inout.sh arm-64 select 5 1
12 GENERIC_INOUT_DESCRIPTION_FILE
="$(dirname "$0")/table-syscall-inout.txt"
14 # Delete temp file on exit
15 trap 'rm -f "$TMPFILE"' EXIT
17 if [ "${ARCH_NAME}" = "" ]; then
18 echo "Error: Please specify the arch name as first argument" >&2
22 if [ "${SYSCALL_NAME}" = "" ]; then
23 echo "Error: Please specify the system call name as second argument" >&2
27 if [[ "${NB_ARGS}" = "" ]]; then
28 echo "Error: Please specify a number of arguments as third argument" >&2
32 if [[ "${ARG_NR}" = "" ||
${ARG_NR} == 0 ]]; then
33 echo "Error: Please specify an argument number larger than 0 as fourth argument" >&2
37 # Search for the in/out description of a syscall. This function attempts to find
38 # a matching description in the per-architecture description override file (if it exists)
39 # and falls back to the generic description file otherwise.
41 # Returns 0 if a description was found and written to the output file, 1 otherwise.
42 function write_inout_description
()
48 local description_files
=("$(dirname "$0")/table-syscall-inout-${arch_name}-override.txt" "$GENERIC_INOUT_DESCRIPTION_FILE")
51 for file in "${description_files[@]}"; do
52 if [ ! -f "$file" ]; then
56 # Look for the syscall's in/out description
57 grep "^syscall ${syscall_name} " "${file}" > "${output_file}" || true
59 # Error out if we got more than one syscall
60 match_count
=$
(wc -l < "${output_file}")
61 if [ "${match_count}" -gt 1 ]; then
62 # Fatal error; invalid description file
63 echo "Error: more than one system call match for ${SYSCALL_NAME}" >&2
65 elif [ "${match_count}" -eq 1 ]; then
66 if ! grep -q "^syscall ${syscall_name} nbargs ${nb_args}" "${output_file}"; then
67 echo "Error: number of arguments doesn't match for ${SYSCALL_NAME}" >&2
78 # Abort on error and undefined variable
82 # Default to sc_inout for unknown syscalls
83 if ! write_inout_description
"$ARCH_NAME" "$SYSCALL_NAME" "$NB_ARGS" "$TMPFILE"; then
84 echo "Warning: no match for syscall '${SYSCALL_NAME}', set to 'inout'" >&2
85 # no match, default to inout
90 # Get the number of argument
91 SC_ARGS
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) .*/\2/g' "${TMPFILE}")
93 if [ "${ARG_NR}" -gt "${SC_ARGS}" ]; then
94 echo "Error: argument number (${ARG_NR}) for ${SYSCALL_NAME} is larger than number of syscall arguments (${SC_ARGS})" >&2
98 if [ "${ARG_NR}" == 1 ]; then
99 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: (\([^,)]*\).*/\3/g' "${TMPFILE}")
102 if [ "${ARG_NR}" == 2 ]; then
103 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
106 if [ "${ARG_NR}" == 3 ]; then
107 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
110 if [ "${ARG_NR}" == 4 ]; then
111 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
114 if [ "${ARG_NR}" == 5 ]; then
115 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
118 if [ "${ARG_NR}" == 6 ]; then
119 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
123 if [ "${SC_ARG_TYPE}" = "r" ]; then
126 if [ "${SC_ARG_TYPE}" = "w" ]; then
129 if [ "${SC_ARG_TYPE}" = "rw" ]; then