From patchwork Fri Jul 12 22:31:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1960038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=S11AQz2i; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WLRHg6F22z1xqx for ; Sat, 13 Jul 2024 08:35:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F7FA385DDF1 for ; Fri, 12 Jul 2024 22:35:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by sourceware.org (Postfix) with ESMTPS id 89443385C6CB for ; Fri, 12 Jul 2024 22:33:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89443385C6CB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 89443385C6CB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823692; cv=none; b=nnJR+RvK1vwidRJUim3Ruk69BqkhsBMa++mIGwPPN8Kz7lHD6VpmXUOl+nbDUR2yY0+5gjZ81LUYMnKxuxACByyGEp83Ae8X/zAhA7NEld53OZiHYAlDI1zknFFDbVdxvuh0vsUiNkbIJCU9GeF5s0B5J5HvfZsAWXSMo7ZDldo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720823692; c=relaxed/simple; bh=dzIRQtrmL4FV6Nn52OpDiucMQJVnyl2qGld+ef0BSmk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YMxc7DlvPtezetRSyic6D2fU2fTCmdHhYgsxjdQTgc+nIGMIDeG99gjwbiJ0eQ95i4xYmt/KC2msJsZjw0nDNzEiysbNl22aVWJSYG27sArwXZrp+6l1QAySDRPxvG5C07M/TZerNxjbUf31Ns819DRnfaUgwWERkJhqVGoNNSk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-6512866fa87so26863327b3.2 for ; Fri, 12 Jul 2024 15:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720823631; x=1721428431; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=V1PFJzq/selgIdrmZukNmxIqoIHPgifvgdt1454mTOU=; b=S11AQz2izbKDi31yeLmFoTZ+FCEw2JcG59OjrhaJkN/7wv2IVOKrylrU4dATiq+nin DWKZoiSLa5hOBNnnw3rjj+hx7Y/2rs4BANIbs5QyzMAuvrCoqBJADrWL11u+nPVCy3JQ YM0br51cNcb53HACRcyYII3tA6myJ+ECxSimHcvB4AWoeQRlTe6tPnN7+w/3iN5WgjVl CYRSLeUZBh0sUDDHBL1lDb4fxpAjEqV3Ydn/K8Sz0H60WEyXHzUQ9eX6EtnZH0kOgg0V yBKISRCiDvwsO5uHCnEnoLcVuNoHdVLIAeojikzbE/8RmOCekDGZIkWL2QRsbCLvORBe Et3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720823631; x=1721428431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V1PFJzq/selgIdrmZukNmxIqoIHPgifvgdt1454mTOU=; b=wOgoxjDyhy3byMKC4jqMTGREceh0o6wFCCuJK8IdPFMto5gJ2n62Q7RBg4UC24kzhV U6E83xDaPVkOvhl6l4O7lM6TdpEtNypQ8Qcrqp3vzOjK2ZwvmIYJzt/cwYxz+4luSTmW MRnhY7qiNzDligzEpzNpUYeQgxFCgEvRgZsWrL3jyFvI9sZbeNvFw6ds9uPX6xUpkOjH VhRQQES/iHVdQXvWt34cCNhyTt/VmC4v0HIBBZuJnMaSMlTTm7MQJKVwqwKFQimQU/wT Efv64nGXJEg6qG3rs7fAkxQ2UhjACMd/JbVopxT1yKzC5vfyEFomN5LVaTjB3Sxui5cf HvDQ== X-Gm-Message-State: AOJu0YxJFgrQgTM+Aw6bL67H79sA4ITHQK2bXJLjIDolaRFEOLcXbYfD XYhE7yYGPUIzKKD5A863x9ts6Ito6BhIp8TP+tLhKv01jatzzD0I0Rqotulc1uHNVw== X-Google-Smtp-Source: AGHT+IH0Ojd/ojK7Fo7fOulpgxBLT5rbPmX079ottU/SuFsaiJVAPvbT+8S3yPUZumHG7pncpFctDA== X-Received: by 2002:a0d:e307:0:b0:651:79ee:d13f with SMTP id 00721157ae682-658eed60361mr138574547b3.20.1720823630576; Fri, 12 Jul 2024 15:33:50 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.160.179]) by smtp.gmail.com with ESMTPSA id 00721157ae682-658e4a316e9sm16556017b3.17.2024.07.12.15.33.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 15:33:50 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id A3B3AC0227 for ; Fri, 12 Jul 2024 15:31:47 -0700 (PDT) From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH 2/3] Support: Add linux-support.h Date: Fri, 12 Jul 2024 15:31:46 -0700 Message-ID: <20240712223147.1809816-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240712223147.1809816-1-hjl.tools@gmail.com> References: <20240712223147.1809816-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Add linux-support.h with /* Return an unsigned int from version, patch level and sub level of Linux kernel. */ extern unsigned int make_linux_kernel_version (unsigned int __version, unsigned int __patch, unsigned int __sub); /* Similar to make_linux_kernel_version, but version, patch level and sub level are retrieved from the uname system call. */ extern unsigned int get_linux_kernel_version (void); Signed-off-by: H.J. Lu --- sysdeps/unix/sysv/linux/Makefile | 8 +++ .../unix/sysv/linux/linux-kernel-version.c | 62 +++++++++++++++++++ sysdeps/unix/sysv/linux/linux-support.h | 38 ++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/linux-kernel-version.c create mode 100644 sysdeps/unix/sysv/linux/linux-support.h diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 097b5a26fc..7a1798f2f1 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -661,3 +661,11 @@ tests-internal += \ tst-rseq-nptl \ # tests-internal endif + +ifeq ($(subdir),support) +linux-support-routines += \ + linux-kernel-version \ +# linux-support-routines +libsupport-routines += $(linux-support-routines) +libsupport-static-only-routines += $(linux-support-routines) +endif diff --git a/sysdeps/unix/sysv/linux/linux-kernel-version.c b/sysdeps/unix/sysv/linux/linux-kernel-version.c new file mode 100644 index 0000000000..2968c528b6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/linux-kernel-version.c @@ -0,0 +1,62 @@ +/* Initialize CPU feature data. AArch64 version. + This file is part of the GNU C Library. + Copyright (C) 2017-2024 Free Software Foundation, Inc. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +unsigned int +make_linux_kernel_version (unsigned int version, unsigned int patch, + unsigned int sub) +{ + TEST_VERIFY_EXIT (version <= 0xff); + TEST_VERIFY_EXIT (patch <= 0xff); + TEST_VERIFY_EXIT (sub <= 0xffff); + /* Return an unsigned int with VVPPSSSS. */ + return (version << 24) | (patch << 16) | sub; +} + +unsigned int +get_linux_kernel_version (void) +{ + struct utsname buf; + const char *p = &buf.release[0]; + unsigned int version; + unsigned int patch; + unsigned int sub; + + TEST_VERIFY_EXIT (uname (&buf) == 0); + + /* Get kernel version. */ + for (version = 0; *p >= '0' && *p <= '9'; p++) + version = version * 10 + *p - '0'; + TEST_VERIFY_EXIT (*p == '.'); + p++; + + /* Get kernel patch level. */ + for (patch = 0; *p >= '0' && *p <= '9'; p++) + patch = patch * 10 + *p - '0'; + TEST_VERIFY_EXIT (*p == '.'); + p++; + + /* Get kernel sub level. */ + for (sub = 0; *p >= '0' && *p <= '9'; p++) + sub = sub * 10 + *p - '0'; + + return make_linux_kernel_version (version, patch, sub); +} diff --git a/sysdeps/unix/sysv/linux/linux-support.h b/sysdeps/unix/sysv/linux/linux-support.h new file mode 100644 index 0000000000..a7c03040b1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/linux-support.h @@ -0,0 +1,38 @@ +/* Linux-specific support functions. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef LINUX_SUPPORT_H +#define LINUX_SUPPORT_H + +#include + +__BEGIN_DECLS + +/* Return an unsigned int from version, patch level and sub level of + Linux kernel. */ +extern unsigned int make_linux_kernel_version (unsigned int __version, + unsigned int __patch, + unsigned int __sub); + +/* Similar to make_linux_kernel_version, but version, patch level and + sub level are retrieved from the uname system call. */ +extern unsigned int get_linux_kernel_version (void); + +__END_DECLS + +#endif /* LINUX_SUPPORT_H */