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
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 [ "${GENERIC_INOUT_DESCRIPTION_FILE}" = "" ]; then
18 echo "Error: Please specify input file name as first argument" >&2
22 if [ "${SYSCALL_NAME}" = "" ]; then
23 echo "Error: Please specify system call name as second argument" >&2
27 if [[ "${ARG_NR}" = "" ||
${ARG_NR} == 0 ]]; then
28 echo "Error: Please specify argument number larger than 0 as third argument" >&2
32 # Search for the in/out description of a syscall. This function attempts to find
33 # a matching description in the per-architecture description override file (if it exists)
34 # and falls back to the generic description file otherwise.
36 # Returns 0 if a description was found and written to the output file, 1 otherwise.
37 function write_inout_description
()
43 local description_files
=("$(dirname "$0")/table-syscall-inout-${arch_name}-override.txt" "$GENERIC_INOUT_DESCRIPTION_FILE")
46 for file in "${description_files[@]}"; do
47 if [ ! -f "$file" ]; then
51 # Look for the syscall's in/out description
52 grep "^syscall ${syscall_name} " "${file}" > "${output_file}" || true
54 # Error out if we got more than one syscall
55 match_count
=$
(wc -l < "${output_file}")
56 if [ "${match_count}" -gt 1 ]; then
57 # Fatal error; invalid description file
58 echo "Error: more than one system call match for ${SYSCALL_NAME}" >&2
60 elif [ "${match_count}" -eq 1 ]; then
61 if ! grep -q "^syscall ${syscall_name} nbargs ${nb_args}" "${output_file}"; then
62 echo "Error: number of arguments doesn't match for ${SYSCALL_NAME}" >&2
73 # Abort on error and undefined variable
77 # Default to sc_inout for unknown syscalls
78 if ! write_inout_description
"$ARCH_NAME" "$SYSCALL_NAME" "$NB_ARGS" "$TMPFILE"; then
79 echo "Warning: no match for syscall '${SYSCALL_NAME}', set to 'inout'" >&2
80 # no match, default to inout
85 # Get the number of argument
86 SC_ARGS
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) .*/\2/g' "${TMPFILE}")
88 if [ "${ARG_NR}" -gt "${SC_ARGS}" ]; then
89 echo "Error: argument number (${ARG_NR}) for ${SYSCALL_NAME} is larger than number of syscall arguments (${SC_ARGS})" >&2
93 if [ "${ARG_NR}" == 1 ]; then
94 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: (\([^,)]*\).*/\3/g' "${TMPFILE}")
97 if [ "${ARG_NR}" == 2 ]; then
98 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
101 if [ "${ARG_NR}" == 3 ]; then
102 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
105 if [ "${ARG_NR}" == 4 ]; then
106 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
109 if [ "${ARG_NR}" == 5 ]; then
110 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
113 if [ "${ARG_NR}" == 6 ]; then
114 SC_ARG_TYPE
=$
(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}")
118 if [ "${SC_ARG_TYPE}" = "r" ]; then
121 if [ "${SC_ARG_TYPE}" = "w" ]; then
124 if [ "${SC_ARG_TYPE}" = "rw" ]; then