From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: Re: [PATCH 01/26] Linux: Enhance glibcsyscalls.h to support listing system calls
Date: Thu, 27 Feb 2020 22:14:00 -0000 [thread overview]
Message-ID: <e359e772-40ac-cf38-d558-d9597d965115@linaro.org> (raw)
In-Reply-To: <aff7fcc5ee68faa1334ccfe8066ae3c42d927fe8.1581279333.git.fweimer@redhat.com>
On 09/02/2020 17:19, Florian Weimer wrote:
> The script can now be called to query the definition status of
> system call numbers across all architectures, like this:
>
> $ python3 sysdeps/unix/sysv/linux/glibcsyscalls.py query-syscall sync_file_range sync_file_range2
> sync_file_range:
> defined: aarch64 alpha csky hppa i386 ia64 m68k microblaze mips/mips32 mips/mips64/n32 mips/mips64/n64 nios2 riscv/rv64 s390/s390-32 s390/s390-64 sh sparc/sparc32 sparc/sparc64 x86_64/64 x86_64/x32
> undefined: arm powerpc/powerpc32 powerpc/powerpc64
> sync_file_range2:
> defined: arm powerpc/powerpc32 powerpc/powerpc64
> undefined: aarch64 alpha csky hppa i386 ia64 m68k microblaze mips/mips32 mips/mips64/n32 mips/mips64/n64 nios2 riscv/rv64 s390/s390-32 s390/s390-64 sh sparc/sparc32 sparc/sparc64 x86_64/64 x86_64/x32
> ---
> sysdeps/unix/sysv/linux/glibcsyscalls.py | 86 +++++++++++++++++++++++-
> 1 file changed, 85 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/glibcsyscalls.py b/sysdeps/unix/sysv/linux/glibcsyscalls.py
> index de4d707e48..5beac42cb4 100644
> --- a/sysdeps/unix/sysv/linux/glibcsyscalls.py
> +++ b/sysdeps/unix/sysv/linux/glibcsyscalls.py
> @@ -17,9 +17,12 @@
> # License along with the GNU C Library; if not, see
> # <http://www.gnu.org/licenses/>.
>
> +import os
> import re
Now that this would be used as a script issued directly by the
user, I think it is worth to add a more comprehensible description
(one that can be used as __doc__).
>
> -import glibcextract
> +if __name__ != '__main__':
> + # When called as a main program, this is not needed.
> + import glibcextract
>
> def extract_system_call_name(macro):
> """Convert the macro name (with __NR_) to a system call name."""
> @@ -168,3 +171,84 @@ def linux_kernel_version(cc):
> val = glibcextract.compute_c_consts(sym_data, cc)['LINUX_VERSION_CODE']
> val = int(val)
> return ((val & 0xff0000) >> 16, (val & 0xff00) >> 8)
> +
> +class ArchSyscall:
> + """Canonical name and location of a syscall header."""
> +
> + def __init__(self, name, path):
> + self.name = name
> + self.path = path
> +
> + def __repr__(self):
> + return 'ArchSyscall(name={!r}, patch={!r})'.format(
> + self.name, self.path)
> +
> +def list_arch_syscall_headers(topdir):
> + """A generator which returns all the ArchSyscall objects in a tree."""
> +
> + sysdeps = os.path.join(topdir, 'sysdeps', 'unix', 'sysv', 'linux')
> + for root, dirs, files in os.walk(sysdeps):
> + if root != sysdeps:
> + for filename in files:
> + if filename == 'arch-syscall.h':
> + yield ArchSyscall(
> + name=os.path.relpath(root, sysdeps),
> + path=os.path.join(root, filename))
> +
> +def __main():
> + """Entry point when called as the main program."""
> +
> + import sys
> +
> + # Top-level directory of the source tree.
> + topdir = os.path.realpath(os.path.join(
> + os.path.dirname(os.path.realpath(__file__)), *('..',) * 4))
> +
> + def usage(status):
> + print('usage: glibcsyscalls list-headers')
> + print(' glibcsyscalls query-syscall SYSCALL...')
> + sys.exit(status)
> +
> + if len(sys.argv) <= 1:
> + usage(0)
> +
> + command = sys.argv[1]
> + if command == 'list-headers':
> + # Print the absolute paths of all arch-syscall.h header files.
> + if len(sys.argv) != 2:
> + usage(1)
> + for header in sorted([syscall.path for syscall
> + in list_arch_syscall_headers(topdir)]):
> + print(header)
> +
> + elif command == 'query-syscall':
> + # Summarize the implementation status of the specified system calls.
> + if len(sys.argv) < 3:
> + usage(1)
Why not follow other scripts and use argparser as well? Something like:
--
def main(argv):
"""Entry point when called as the main program."""
import argparse
# Top-level directory of the source tree.
topdir = os.path.realpath(os.path.join(
os.path.dirname(os.path.realpath(__file__)), *('..',) * 4))
def get_parser():
parser = argparse.ArgumentParser(description=__doc__)
subparsers = parser.add_subparsers(dest='command', required=True)
parser_a = subparsers.add_parser('list-headers');
parser_b = subparsers.add_parser('query-syscall');
parser_b.add_argument('syscalls',
help='Which syscalls to check',
nargs='+')
return parser
parser = get_parser();
opts = parser.parse_args(argv)
if opts.command == 'list-headers':
[...]
--
> +
> + # List of system call tables.
> + tables = sorted(list_arch_syscall_headers(topdir),
> + key=lambda syscall: syscall.name)
> + for table in tables:
> + table.numbers = load_arch_syscall_header(table.path)
> +
> + for nr in sys.argv[2:]:
> + defined = [table.name for table in tables
> + if nr in table.numbers]
> + undefined = [table.name for table in tables
> + if nr not in table.numbers]
> + if not defined:
> + print('{}: not defined on any architecture'.format(nr))
> + elif not undefined:
> + print('{}: defined on all architectures'.format(nr))
> + else:
> + print('{}:'.format(nr))
> + print(' defined: {}'.format(' '.join(defined)))
> + print(' undefined: {}'.format(' '.join(undefined)))
> +
> + else:
> + # Unrecognized command.
> + usage(1)
> +
> +if __name__ == '__main__':
> + __main()
>
I don't think double underscore is required here.
next prev parent reply other threads:[~2020-02-27 22:14 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-09 20:19 [PATCH 00/26] Linux cleanups enabled by built-in system call tables Florian Weimer
2020-02-09 20:19 ` [PATCH 01/26] Linux: Enhance glibcsyscalls.h to support listing system calls Florian Weimer
2020-02-27 22:14 ` Adhemerval Zanella [this message]
2020-05-11 10:10 ` Florian Weimer
2020-02-09 20:19 ` [PATCH 04/26] Linux: mlock2 syscall number is always available Florian Weimer
2020-02-27 23:06 ` Adhemerval Zanella
2020-02-09 20:19 ` [PATCH 02/26] Linux: renameat2 " Florian Weimer
2020-02-27 23:06 ` Adhemerval Zanella
2020-02-09 20:19 ` [PATCH 03/26] Linux: copy_file_range " Florian Weimer
2020-02-27 23:06 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 12/26] Linux: Clean up preadv, pwritev system call names Florian Weimer
2020-02-27 23:19 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 11/26] Linux: Clean up preadv2, pwritev2 " Florian Weimer
2020-02-27 23:19 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 14/26] Linux: rt_sigqueueinfo syscall number is always available Florian Weimer
2020-02-27 23:31 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 08/26] Linux: sched_getaffinity " Florian Weimer
2020-02-27 23:06 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 07/26] Linux: sched_setaffinity " Florian Weimer
2020-02-27 23:06 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 15/26] Linux: pkey_mprotect " Florian Weimer
2020-02-27 23:31 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 09/26] Linux: sigaltstack " Florian Weimer
2020-02-27 23:06 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 10/26] Linux: Clean up pread64/pwrite64 system call names Florian Weimer
2020-02-27 23:08 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 06/26] Linux: statx syscall number is always available Florian Weimer
2020-02-27 23:06 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 13/26] Linux: getrandom " Florian Weimer
2020-02-27 23:20 ` Adhemerval Zanella
2020-02-09 20:20 ` [PATCH 05/26] Linux: mq_* syscall numbers are " Florian Weimer
2020-02-27 23:06 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 22/26] ia64: Do not define __NR_semtimedop in <sysdep.h> Florian Weimer
2020-02-27 23:46 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 17/26] Linux: exit_group syscall number is always available Florian Weimer
2020-02-27 23:31 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 23/26] x86_64: Do not define __NR_semtimedop in <sysdep.h> Florian Weimer
2020-02-27 23:46 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 19/26] Linux: pciconfig_iobase syscall number is always available on alpha Florian Weimer
2020-02-27 23:31 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 21/26] Linux: open_by_handle_at syscall number is always available Florian Weimer
2020-02-27 23:46 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 24/26] Linux: epoll_pwait " Florian Weimer
2020-02-27 23:47 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 20/26] Linux: set_robust_list " Florian Weimer
2020-02-27 23:46 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 25/26] m68k: getpagesize " Florian Weimer
2020-02-27 23:47 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 16/26] Linux: set_tid_address " Florian Weimer
2020-02-27 23:31 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 26/26] microblaze: vfork " Florian Weimer
2020-02-27 23:47 ` Adhemerval Zanella
2020-02-09 20:21 ` [PATCH 18/26] Linux: getdents64 syscall number is always available on MIPS Florian Weimer
2020-02-27 23:31 ` Adhemerval Zanella
2020-02-10 23:25 ` [PATCH 00/26] Linux cleanups enabled by built-in system call tables Lukasz Majewski
2020-02-10 23:56 ` Joseph Myers
2020-02-11 7:47 ` Florian Weimer
2020-02-11 11:07 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e359e772-40ac-cf38-d558-d9597d965115@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).