Richard
Richard

Reputation: 15592

Find syscall signatures, automatically

I want to write a script (or c code) that can automatically print the list of supported sys calls (the full function signature; specially, their names, return type and argument list)?

I have searched for the solutions for a while, and know syscall names are present in . But there is no argument list or return type?

My target platform is Linux (specifically, Ubuntu) and c .

PS: By syscall, I mean the libc wrapper functions for syscall...

Upvotes: 2

Views: 726

Answers (2)

Tibor Vass
Tibor Vass

Reputation: 167

Here's an AWK version of @Richard's answer, that squashes multiple line definitions into one.

awk '/^asmlinkage.*sys_/{gsub(/[[:space:]]+/, " "); printf $0; while ($0 !~ /;/) { getline; gsub(/[[:space:]]+/, " "); printf $0 } printf "\n" }'  /usr/src/linux-headers-$(uname -r)/include/linux/syscalls.h

EDIT using man pages:

I've combined my previous answer with awking the man page which sometimes has better type information in the signature:

awk '
/^asmlinkage.*sys_/ {
    gsub(/[[:space:]]+/, " ")
    printf $0
    while ($0 !~ /;/) {
        getline
        gsub(/[[:space:]]+/, " ")
        printf $0
    }
    printf "\n"
}' /usr/src/linux-headers-$(uname -r)/include/linux/syscalls.h | \
sed -E 's/.* sys_([_a-z0-9]+)\(.+/\1/' | \
while read syscall; do \
    man 2 "$syscall" | \
    awk '
        /DESCRIPTION/ { exit }
        /^ *[_ a-zA-Z0-9*]+ '"$syscall"'\([a-zA-Z][_0-9A-Za-z]+/ {
            gsub(/[[:space:]]+/, " ")
            printf $0
            while ($0 !~ /;/) {
                getline
                gsub(/[[:space:]]+/, " ")
                printf $0
            }
            printf "\n"
        }';
done

Note that not all syscalls have man page entries, so it's not replacing parsing the headers.

Upvotes: 0

Richard
Richard

Reputation: 15592

Based on @knm241 's comments, this will work:

grep '^asmlinkage.*sys_' /usr/src/linux-headers-3.16.0-30/include/linux/syscalls.h

Upvotes: 3

Related Questions