From patchwork Sun Feb 9 20:19:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1235546 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-109309-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha1 header.s=default header.b=D94Vpnuj; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NcT4Y1Q8; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48G0kl1RVxz9sRQ for ; Mon, 10 Feb 2020 07:19:42 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:in-reply-to:references :message-id:date:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=db9543arzNPAVoML CIeHXKB44fJV8aQw/eGKIsMqPmFJ3SqmA2gfWBWvsA1nJ0xd95QI2dZpyXFlwI/P Ei1ztyA704v9tHdl6EnLeNikYwxgmP0g1N0XyXGU3WpO83L1U9TbegXp6Gyig1mq 0/6Z58CTssYqz4oiIHYgQhTH8+U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:in-reply-to:references :message-id:date:mime-version:content-type :content-transfer-encoding; s=default; bh=yuJmN/SaoZTbVH+JA9PNEC 5eInQ=; b=D94VpnujyKx4EtZ0qlv6tGXAzI3M+yXrfu1ZRo2NoE+idetvUOadnk /4/MVwURm9lsgXhlYMrPsQwH50xiE7RvjFPO78GalUF1XjhgG1evJiroI9ITMkMN qO3R/Xve5iCegkitcvuw1//Es+Xwek/lwOJkG4VhLS86aRreNfVfs= Received: (qmail 14424 invoked by alias); 9 Feb 2020 20:19:36 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 14409 invoked by uid 89); 9 Feb 2020 20:19:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=canonical, H*i:sk:cover.1, summarize X-HELO: us-smtp-delivery-1.mimecast.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581279572; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A8MM2pHExLDo+jqWTi04sw3ExfFxQY1sjKM9BlzIRqg=; b=NcT4Y1Q89057/GcuIe/4FxSDTQqAu9gd0klyqDlJVO5i6OiC1cDVcZnNR3Ua1ZNHkk/kv1 nIrCJPw2GOIiPH0pI57DYQKBdZ2wEVtuiG+bvr3ymc1/ZXZYMdE2oQ41kTR+C9OVfDdMDv Z4Rwukczw7PYFHk/kMec0i0gsc1Mzns= From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 01/26] Linux: Enhance glibcsyscalls.h to support listing system calls In-Reply-To: References: X-From-Line: aff7fcc5ee68faa1334ccfe8066ae3c42d927fe8 Mon Sep 17 00:00:00 2001 Message-Id: Date: Sun, 09 Feb 2020 21:19:23 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 # . +import os import re -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) + + # 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()