Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp824710lqp; Sun, 14 Apr 2024 00:56:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW2eaVvG4te/hwicU1JvYL2EcC1EpZp5UI5Ab9n0P6xmHU1r7uCYvWAOj+kNAg8EzXn/wFahy6J3WErlcdXTuxZWrRam4ped75EJXgFew== X-Google-Smtp-Source: AGHT+IGwNnO3BBKaYz7bIa19qTSyI3uV37J7SbOoFimkMQXhGIpIg7QMuWCEmGUzpen1mE0IZMjC X-Received: by 2002:a05:620a:135c:b0:78e:cc40:b7e0 with SMTP id c28-20020a05620a135c00b0078ecc40b7e0mr7399805qkl.30.1713081417043; Sun, 14 Apr 2024 00:56:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713081417; cv=pass; d=google.com; s=arc-20160816; b=hRoizvuZ6pQ7JSgpAautx9F7dUPyjrRu9mtaEytVCCWPkn/OFlR1VWi9x0c6evHEtM 8ljhny0NgTe+TANq39Jipk9h4Pkzh1Uz0GJSERiOaYzj8bptOIEui5xdCTqvqbCQ5H6V UyW15S8bj4WbAhosbHAx2WiwihlZgzdFuMJcL4fNJupTtGHj5ouWqAW3XxpBNQ7gVQ/O yAYTzDngw4n0Jm0nPFskgKwxMAW5Kb8LgBBipbGo8oRFRgHfpNuD50LCfpytpaIbPf6Q vSzrs2AgWgvfkWYpI8aLn+vz7hIM2BLy39CWbZ9OCOvFEEGOerX1eD5ze8HWtpARUGNS yh0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=C3miigoT5FTo/9q95kurlPDb5FQ52yksx1gn01ip8TU=; fh=Qbk0RS4bf6GjbhGkpgFoVgYg5V+1DfWcZ6CAErfO2MQ=; b=PWEfOqbnEHlkP9p9c8RuatydbriA9BuZEL53kcSgFs1tK5KpHv+XrS5r67AFYlBQqn LBmCBq8JFUdS0868bpOaAejYqBbjAXXL4X56wzZ7qwLCCCqMyTqFhlu8M6qzd6Pf9vxz Qu9K0pl8I6YTi/QtQdNOTUaaVaD8DsM0muTMD0CAmMnXSkyHXwEjFf+Te96mRcksDkqL MvojS88PCccyVi/Yu2rICgYUcjOKmNLyEAdtEC6lFP78wbkl2IOhtOS6NrSP9Zu1WLa5 DE6An4Q5Yhx816Aue7nImIg1umeFIMuUqWcmq0tAqTWaKjW9NFWqjp7xf+jl/NbMmcrk EWHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=oTWaWeHu; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-144033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144033-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id de41-20020a05620a372900b0078d4e0e5ea6si8324441qkb.738.2024.04.14.00.56.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Apr 2024 00:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=oTWaWeHu; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-144033-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144033-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 478121C212CE for ; Sun, 14 Apr 2024 07:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F521219E4; Sun, 14 Apr 2024 07:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="oTWaWeHu" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C15215E9B; Sun, 14 Apr 2024 07:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713081401; cv=none; b=PwgMA71XRYSCoCP6IpYgw4kxF6IDlY53NjBf+JdMLmK1RyimODOwxsBNjRNgPGU/YsaGHSIDkNVgMyB6PgZycc/B0eRReOBn5UIQCji4OZI8xoDM4qXZ5Mk8ezBl2M4drtzPpPgz6I8XN/Pj00oWUx6y0G0V4OcvYWLde00/1Lk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713081401; c=relaxed/simple; bh=txG+MaiGhkYK6WZayglTtsGLPC9RsnrKCz2cnhHMAtg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=YFxidvVyRY9q9MgW6rBNqiL43FnnAuBR39wj1K3bKv6mKu2TGcUoDuJIbwK17cmTnE2VUr3ZsIhBAl2yKr3up2sEAJXoIYbkwaUq9ucdQJI3cLhfhHWAa6MZesuCXr8ZLOwe6MX+X+EI08VRvn+boeRGbgB75dIx6lGvEjaRPSk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=oTWaWeHu; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1713081388; bh=txG+MaiGhkYK6WZayglTtsGLPC9RsnrKCz2cnhHMAtg=; h=From:Date:Subject:To:Cc:From; b=oTWaWeHuxUAT50GTvGTwOMRFrD2NUDOHWRd5cI7jxTMSQUSghN4eDwDr1v8soR7LM 86elWuuny7t4N+Wn+CJ7HEi6q56rTdP5N9eyh9K8VOk0vHvsmHDoG8EKs31SIf84vt +/G/Y/dIjO3jpWoR1pK6ngcf1ccBXYFt2hcRqKe0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 14 Apr 2024 09:56:23 +0200 Subject: [PATCH] tools/nolibc: add support for uname(2) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240414-nolibc-uname-v1-1-28a1fdbd5c64@weissschuh.net> X-B4-Tracking: v=1; b=H4sIACaMG2YC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDE0MT3bz8nMykZN3SvMTcVN2UVGMLS9NEExMj0zQloJaCotS0zAqwcdG xtbUA0uBRgF4AAAA= To: Willy Tarreau , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1713081387; l=3814; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=txG+MaiGhkYK6WZayglTtsGLPC9RsnrKCz2cnhHMAtg=; b=iSSLGnCYRC5zFPlphtA8E3uU1uI7QrmwEbQ5wteqb1DtG8koyghnwfl11QJTXB5WelscFbjuU 4RAJBHppMilDQrg2YMcU28DkJ42anKlzxR4bLNYjIKYW2x7sf9Km13M X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= All supported kernels are assumed to use struct new_utsname. This is validated in test_uname(). uname(2) can for example be used in ksft_min_kernel_version() from the kernels selftest framework. Link: https://lore.kernel.org/lkml/20240412123536.GA32444@redhat.com/ Signed-off-by: Thomas Weißschuh --- tools/include/nolibc/sys.h | 27 ++++++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 42 ++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index dda9dffd1d74..7b82bc3cf107 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -22,6 +22,7 @@ #include /* for statx() */ #include #include +#include #include "arch.h" #include "errno.h" @@ -1139,6 +1140,32 @@ int umount2(const char *path, int flags) } +/* + * int uname(struct utsname *buf); + */ + +struct utsname { + char sysname[65]; + char nodename[65]; + char release[65]; + char version[65]; + char machine[65]; + char domainname[65]; +}; + +static __attribute__((unused)) +int sys_uname(struct utsname *buf) +{ + return my_syscall1(__NR_uname, buf); +} + +static __attribute__((unused)) +int uname(struct utsname *buf) +{ + return __sysret(sys_uname(buf)); +} + + /* * int unlink(const char *path); */ diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 6ba4f8275ac4..3c9a9bd38194 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -761,6 +762,45 @@ int test_stat_timestamps(void) return 0; } +int test_uname(void) +{ + struct utsname buf; + char osrelease[sizeof(buf.release)]; + ssize_t r; + int fd; + + memset(&buf.domainname, 'P', sizeof(buf.domainname)); + + if (uname(&buf)) + return 1; + + if (strncmp("Linux", buf.sysname, sizeof(buf.sysname))) + return 1; + + fd = open("/proc/sys/kernel/osrelease", O_RDONLY); + if (fd == -1) + return 1; + + r = read(fd, osrelease, sizeof(osrelease)); + if (r == -1) + return 1; + + close(fd); + + if (osrelease[r - 1] == '\n') + r--; + + /* Validate one of the later fields to ensure field sizes are correct */ + if (strncmp(osrelease, buf.release, r)) + return 1; + + /* Ensure the field domainname is set, it is missing from struct old_utsname */ + if (strnlen(buf.domainname, sizeof(buf.domainname)) == sizeof(buf.domainname)) + return 1; + + return 0; +} + int test_mmap_munmap(void) { int ret, fd, i, page_size; @@ -966,6 +1006,8 @@ int run_syscall(int min, int max) CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; CASE_TEST(stat_timestamps); EXPECT_SYSZR(1, test_stat_timestamps()); break; CASE_TEST(symlink_root); EXPECT_SYSER(1, symlink("/", "/"), -1, EEXIST); break; + CASE_TEST(uname); EXPECT_SYSZR(1, test_uname()); break; + CASE_TEST(uname_fault); EXPECT_SYSER(1, uname(NULL), -1, EFAULT); break; CASE_TEST(unlink_root); EXPECT_SYSER(1, unlink("/"), -1, EISDIR); break; CASE_TEST(unlink_blah); EXPECT_SYSER(1, unlink("/proc/self/blah"), -1, ENOENT); break; CASE_TEST(wait_child); EXPECT_SYSER(1, wait(&tmp), -1, ECHILD); break; --- base-commit: 4cece764965020c22cff7665b18a012006359095 change-id: 20240414-nolibc-uname-de3895a4425f Best regards, -- Thomas Weißschuh