From nobody Sun Feb 8 02:42:08 2026 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (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 537D013AA2F for ; Sun, 2 Nov 2025 10:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762080390; cv=none; b=SMVfaLDrqIGs2LEs12i1sBQXXOrm+9UpPsBUXeZVLBKWfzlexyu2KX15YuLzWjuSciULm2FXUPhKpnSOLKXx2kJB/u89pqDv0FFMgulK3hpOUJFIvl1YYItSoh9fgSmm8STargt71dw/dg7D9ikhCp8QtJeG4gbicK22F1494+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762080390; c=relaxed/simple; bh=eX4Vn9mFeW02xdtCaP4bKsXAOT/5cf4DZrw/nYYN6jQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=PzgKea4arqXRZE6ENFfnPE+Z9crKxdwxx/4c3D9jgShh2JIXEDee9VPHZdFv39JlfRqVcFY5iMJyPVxjsMMLD23yXCl07ypWakMtJ8UvXwX5cVRdR5hUS3teuDvIc46El054IqbXJ6ELnwKdQNPhYqObBwJMBeylrenHAo0fu7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=B1MXkcEq; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="B1MXkcEq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1762080387; bh=riWRpdOx+q4QSoALbcMfrfoEGkpzcCDRZmG6gniWz5o=; h=From:Message-Id:From; b=B1MXkcEqFU6na5rxsmJB/lqsJFU3H7VXVuihqbVMztqyPaSPNLO+HjEuJ1F9E40iF ba4+ppFWhZIKVd1hJOiJb8ZkJeKzsdsJDTP2DLnH3ZE7saOIWJPKS7T70BtFgwF3Ns FpjCNwsHqDn6FIsZ2X77IU8ygzPQL0uNztPWbNFk= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id D2DAEC06EE; Sun, 02 Nov 2025 11:46:27 +0100 (CET) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 5A2AkJ68024501; Sun, 2 Nov 2025 11:46:19 +0100 From: Willy Tarreau To: linux@weissschuh.net Cc: shuah@kernel.org, linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path Date: Sun, 2 Nov 2025 11:46:08 +0100 Message-Id: <20251102104611.24454-2-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20251102104611.24454-1-w@1wt.eu> References: <20251102104611.24454-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The help message says the headers are going to be installed into tools/include/nolibc but this is only the default if $OUTPUT is not set, so better clarify this (the current value of $OUTPUT is already shown). Signed-off-by: Willy Tarreau --- tools/include/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 143c2d2c2ba6..4f617d91a5ff 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -79,7 +79,7 @@ help: @echo "Supported targets under nolibc:" @echo " all call \"headers\"" @echo " clean clean the sysroot" - @echo " headers prepare a sysroot in tools/include/nolibc/sy= sroot" + @echo " headers prepare a sysroot in \$${OUTPUT}sysroot" @echo " headers_standalone like \"headers\", and also install kernel he= aders" @echo " help this help" @echo "" --=20 2.17.5 From nobody Sun Feb 8 02:42:08 2026 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (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 DD19E2AD2C for ; Sun, 2 Nov 2025 10:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762080384; cv=none; b=YIAnr6mcvZJU7dtTIXJnMk91bC88MamhotmYxWu5nICVBftu/ZMYe0xmZ1N0aVClhCtKd+kvv9PgsRwG4xBfxYLuRIakoRAMbPSUULyaTdLna73c4bYjQW8SoJC6yEEYbL6J9/BhyvD+eVKKv/c2J45LEj1bdTdgi1CGhQkqBGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762080384; c=relaxed/simple; bh=BJFldBb7E4BDpFWi9SM/MvEx/koRmsrytfUq9han2DY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=q5k3n84xeijn17/Y99w/nvUwKX5izZ/hRTDlmHhVSxnk5HGF1s/n+YOM6mZBdh5f02OzSQUyB/p5h9JPmlZYtFobcesFippTydEeijmj+Qwjm9+Lh4eepToNmkFIZTkCvPmyZ4joL3qKAQnehrjrk62XBjtzHQvBQdHDb5MEMpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=Ey1vju6j; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="Ey1vju6j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1762080380; bh=8rxloVPacP7eWnfAHkA7M3DFF/jwKsYjtau41FN2yVw=; h=From:Message-Id:From; b=Ey1vju6jnUMOf6chVNPVPJZR8Hur4qFo+lCJGdMpJSIuTcFQDp0T4J3HMfDcEOKrY jLDL+7OC3aGfk7ylWcJS65V+Vq5mo6CpPLSeJUlvR4rEHXBlyICre5H5IaCvU/CpFe 3qbkIx4JtZePGo5CH49JVJOKQnv+l5hVf4VF98PA= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id E9973C06F2; Sun, 02 Nov 2025 11:46:19 +0100 (CET) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 5A2AkJPb024502; Sun, 2 Nov 2025 11:46:19 +0100 From: Willy Tarreau To: linux@weissschuh.net Cc: shuah@kernel.org, linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h Date: Sun, 2 Nov 2025 11:46:09 +0100 Message-Id: <20251102104611.24454-3-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20251102104611.24454-1-w@1wt.eu> References: <20251102104611.24454-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's often recommended to only use inttypes.h instead of stdint.h for portability reasons since the former is always present when the latter is present, but not conversely, and the former includes the latter. Due to this some simple programs fail to build when including inttypes.h. Let's add one that simply includes stdint.h to better support these programs. Signed-off-by: Willy Tarreau --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/inttypes.h | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tools/include/nolibc/inttypes.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 4f617d91a5ff..0d312f1159ec 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -33,6 +33,7 @@ all_files :=3D \ errno.h \ fcntl.h \ getopt.h \ + inttypes.h \ limits.h \ math.h \ nolibc.h \ diff --git a/tools/include/nolibc/inttypes.h b/tools/include/nolibc/inttype= s.h new file mode 100644 index 000000000000..1088034ef7cc --- /dev/null +++ b/tools/include/nolibc/inttypes.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#ifndef _NOLIBC_INTTYPES_H +#define _NOLIBC_INTTYPES_H + +#include "stdint.h" + +#endif /* _NOLIBC_INTTYPES_H */ --=20 2.17.5 From nobody Sun Feb 8 02:42:08 2026 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (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 45F5B78F29 for ; Sun, 2 Nov 2025 10:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762080384; cv=none; b=ESfVPluCzQ3yfArVAWR1GlbepJGF+dmfW8/7xLvEUh4urH2RvAMy72tu+DPO5/fuST7lrOTlzZkNhGSaA8QRvdiFE8Yq8rVlqQMuD58794W5dgun29MfPoJmwOlzjzAB5qu1lBsV77lpdf2rrb7ZoL7brLYknUcLQ8gTWu4UELI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762080384; c=relaxed/simple; bh=n4kw0H2lpqCBtXvMPq7iMlv6W98+HxLSni4vqvlLjhA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=GjPqA/5AlLHUkNCruQ9YJof29A/ru1qKrfRYfr2YpHUpWc7Ag08WVVZBgmOEfRJRttohT5KZSspBDY1rK3vDTSWHQsbSUepD/J0H3VAJu4V8rtKDYOuO522TpdhobF+l82hjSQ5B/pyYnS5TXaPzTBHwDO6AShke2BLpH7AoOqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=dvYtWrnO; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="dvYtWrnO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1762080380; bh=Xr+7y5VPjzaBTsRc1pcafOBiI+MDr/5lAa5dclNG6/s=; h=From:Message-Id:From; b=dvYtWrnOqVnFRm71v9N2v3HIu1xhIVkx0Y7qLYqAsPSKbyBNt1ejF1thM8EQn5AF/ OnwqwxEuPc+GP80j4HCAEvFSoqCQgJvZiEtmsBEifM1ZHNKo1SuToSqPDc/1/tA+Mk vtU3UMRRb/85hpjWmrDlyytm3A7FIvp2LFLmaDGQ= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id F2A12C0952; Sun, 02 Nov 2025 11:46:19 +0100 (CET) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 5A2AkJot024503; Sun, 2 Nov 2025 11:46:19 +0100 From: Willy Tarreau To: linux@weissschuh.net Cc: shuah@kernel.org, linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH v2 3/4] tools/nolibc: add missing memchr() to string.h Date: Sun, 2 Nov 2025 11:46:10 +0100 Message-Id: <20251102104611.24454-4-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20251102104611.24454-1-w@1wt.eu> References: <20251102104611.24454-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Surprisingly we forgot to add this common one. It was added with a per-arch guard allowing to later implement it in arch-specific asm code like was done for a few other ones. The test verifies that we don't search past the indicated length. Signed-off-by: Willy Tarreau --- tools/include/nolibc/string.h | 15 +++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 17 insertions(+) diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h index 163a17e7dd38..4000926f44ac 100644 --- a/tools/include/nolibc/string.h +++ b/tools/include/nolibc/string.h @@ -93,6 +93,21 @@ void *memset(void *dst, int b, size_t len) } #endif /* #ifndef NOLIBC_ARCH_HAS_MEMSET */ =20 +#ifndef NOLIBC_ARCH_HAS_MEMCHR +static __attribute__((unused)) +void *memchr(const void *s, int c, size_t len) +{ + char *p =3D (char *)s; + + while (len--) { + if (*p =3D=3D (char)c) + return p; + p++; + } + return NULL; +} +#endif /* #ifndef NOLIBC_ARCH_HAS_MEMCHR */ + static __attribute__((unused)) char *strchr(const char *s, int c) { diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 2b1fcfaaa60e..7fc937e9a4df 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1558,6 +1558,8 @@ int run_stdlib(int min, int max) CASE_TEST(abs_noop); EXPECT_EQ(1, abs(10), 10); break; CASE_TEST(difftime); EXPECT_ZR(1, test_difftime()); break; CASE_TEST(test_timespec); EXPECT_ZR(1, test_timespec()); break; + CASE_TEST(memchr_foobar6_o); EXPECT_STREQ(1, memchr("foobar", 'o'= , 6), "oobar"); break; + CASE_TEST(memchr_foobar3_b); EXPECT_STRZR(1, memchr("foobar", 'b'= , 3)); break; =20 case __LINE__: return ret; /* must be last */ --=20 2.17.5 From nobody Sun Feb 8 02:42:08 2026 Received: from mta1.formilux.org (mta1.formilux.org [51.159.59.229]) (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 45FB113AA2F for ; Sun, 2 Nov 2025 10:46:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.59.229 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762080384; cv=none; b=VmbAPPCBWpwaWu4SQlM/M6Bz8DoRG/YTPXVwsz3RSErcjtIjSMkLPzAbHV9E9xYbqqBUwSKpg4b7WlrgCvfg2ADiuvJgJ39bjU7bQXXwhsPo+dGXBQXYXEUBi4L4kWlxRNS0D8JpaoeZx6q1GF5rbzomsl4O0zgNIz3hweYnG/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762080384; c=relaxed/simple; bh=KcSxWvaTfgiPznYBJjhM24Y/zlBKF8QAUvPo0Ohw+sM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=mfBWR08l4qBLr4cvITQ/NHOJsAKTHhTU6SYRb4M4r4qJGfsqDRiRQaPaEOcdMCY0wAAL78QBbviqz94fmPktXeshmElESm/V1WZXMU0cMBH66fe569QkmzPCBnOmmZYP0gdcsR7+C1epQcZNou0xpQpq0pbrT6ZJrQAWxQFITdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu; spf=pass smtp.mailfrom=1wt.eu; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b=WFuFja4l; arc=none smtp.client-ip=51.159.59.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=1wt.eu header.i=@1wt.eu header.b="WFuFja4l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1wt.eu; s=mail; t=1762080380; bh=fZvOR2fDFMyEG2JJ7YKCTsBH/z2SenLZ1zI+0eNrGLA=; h=From:Message-Id:From; b=WFuFja4lSiVOUtvfQhNfSxZ1MwST1GDE8F47xWS/QTPeg6ZTYaSb8bEvGvyVJ/R2l lBdcCtiguK8y/CAlCvcZ6DTQm4jP5uFW7LAhfPiU2HfBfTJOM+8nJkpG0xZQVd8AqT bWaoVNLxJ3qpKR14kAIfBBW35Bv4IMzmWQJ7T9qs= Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by mta1.formilux.org (Postfix) with ESMTP id 0EC0AC0953; Sun, 02 Nov 2025 11:46:20 +0100 (CET) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 5A2AkJC9024504; Sun, 2 Nov 2025 11:46:19 +0100 From: Willy Tarreau To: linux@weissschuh.net Cc: shuah@kernel.org, linux-kernel@vger.kernel.org, Willy Tarreau Subject: [PATCH v2 4/4] tools/nolibc: provide the portable sys/select.h Date: Sun, 2 Nov 2025 11:46:11 +0100 Message-Id: <20251102104611.24454-5-w@1wt.eu> X-Mailer: git-send-email 2.17.5 In-Reply-To: <20251102104611.24454-1-w@1wt.eu> References: <20251102104611.24454-1-w@1wt.eu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Modern programs tend to include sys/select.h to get FD_SET() and FD_CLR() definitions as well as struct fd_set, but in our case it didn't exist. The definitions were moved from types.h to sys/select.h, which is now included from nolibc.h, and the sys_select() definition moved there as well from sys.h. Signed-off-by: Willy Tarreau --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/sys.h | 45 ------------- tools/include/nolibc/sys/select.h | 103 ++++++++++++++++++++++++++++++ tools/include/nolibc/types.h | 47 -------------- 5 files changed, 105 insertions(+), 92 deletions(-) create mode 100644 tools/include/nolibc/sys/select.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 0d312f1159ec..ff0e646acda9 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -57,6 +57,7 @@ all_files :=3D \ sys/random.h \ sys/reboot.h \ sys/resource.h \ + sys/select.h \ sys/stat.h \ sys/syscall.h \ sys/sysmacros.h \ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index d2f5aa085f8e..91e2795ae49c 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -104,6 +104,7 @@ #include "sys/random.h" #include "sys/reboot.h" #include "sys/resource.h" +#include "sys/select.h" #include "sys/stat.h" #include "sys/syscall.h" #include "sys/sysmacros.h" diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index aeb57bb68e92..dc8a83c716ab 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -752,51 +752,6 @@ int sched_yield(void) } =20 =20 -/* - * int select(int nfds, fd_set *read_fds, fd_set *write_fds, - * fd_set *except_fds, struct timeval *timeout); - */ - -static __attribute__((unused)) -int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct = timeval *timeout) -{ -#if defined(__ARCH_WANT_SYS_OLD_SELECT) && !defined(__NR__newselect) - struct sel_arg_struct { - unsigned long n; - fd_set *r, *w, *e; - struct timeval *t; - } arg =3D { .n =3D nfds, .r =3D rfds, .w =3D wfds, .e =3D efds, .t =3D ti= meout }; - return my_syscall1(__NR_select, &arg); -#elif defined(__NR__newselect) - return my_syscall5(__NR__newselect, nfds, rfds, wfds, efds, timeout); -#elif defined(__NR_select) - return my_syscall5(__NR_select, nfds, rfds, wfds, efds, timeout); -#elif defined(__NR_pselect6_time64) - struct __kernel_timespec t; - - if (timeout) { - t.tv_sec =3D timeout->tv_sec; - t.tv_nsec =3D timeout->tv_usec * 1000; - } - return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout = ? &t : NULL, NULL); -#else - struct timespec t; - - if (timeout) { - t.tv_sec =3D timeout->tv_sec; - t.tv_nsec =3D timeout->tv_usec * 1000; - } - return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : = NULL, NULL); -#endif -} - -static __attribute__((unused)) -int select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time= val *timeout) -{ - return __sysret(sys_select(nfds, rfds, wfds, efds, timeout)); -} - - /* * int setpgid(pid_t pid, pid_t pgid); */ diff --git a/tools/include/nolibc/sys/select.h b/tools/include/nolibc/sys/s= elect.h new file mode 100644 index 000000000000..71cdadde32b5 --- /dev/null +++ b/tools/include/nolibc/sys/select.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#include "../nolibc.h" + +#ifndef _NOLIBC_SYS_SELECT_H +#define _NOLIBC_SYS_SELECT_H + +#include +#include + +/* commonly an fd_set represents 256 FDs */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 256 +#endif + +#define FD_SETIDXMASK (8 * sizeof(unsigned long)) +#define FD_SETBITMASK (8 * sizeof(unsigned long)-1) + +/* for select() */ +typedef struct { + unsigned long fds[(FD_SETSIZE + FD_SETBITMASK) / FD_SETIDXMASK]; +} fd_set; + +#define FD_CLR(fd, set) do { \ + fd_set *__set =3D (set); \ + int __fd =3D (fd); \ + if (__fd >=3D 0) \ + __set->fds[__fd / FD_SETIDXMASK] &=3D \ + ~(1U << (__fd & FD_SETBITMASK)); \ + } while (0) + +#define FD_SET(fd, set) do { \ + fd_set *__set =3D (set); \ + int __fd =3D (fd); \ + if (__fd >=3D 0) \ + __set->fds[__fd / FD_SETIDXMASK] |=3D \ + 1 << (__fd & FD_SETBITMASK); \ + } while (0) + +#define FD_ISSET(fd, set) ({ \ + fd_set *__set =3D (set); \ + int __fd =3D (fd); \ + int __r =3D 0; \ + if (__fd >=3D 0) \ + __r =3D !!(__set->fds[__fd / FD_SETIDXMASK] & \ +1U << (__fd & FD_SETBITMASK)); \ + __r; \ + }) + +#define FD_ZERO(set) do { \ + fd_set *__set =3D (set); \ + int __idx; \ + int __size =3D (FD_SETSIZE+FD_SETBITMASK) / FD_SETIDXMASK;\ + for (__idx =3D 0; __idx < __size; __idx++) \ + __set->fds[__idx] =3D 0; \ + } while (0) + +/* + * int select(int nfds, fd_set *read_fds, fd_set *write_fds, + * fd_set *except_fds, struct timeval *timeout); + */ + +static __attribute__((unused)) +int sys_select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct = timeval *timeout) +{ +#if defined(__ARCH_WANT_SYS_OLD_SELECT) && !defined(__NR__newselect) + struct sel_arg_struct { + unsigned long n; + fd_set *r, *w, *e; + struct timeval *t; + } arg =3D { .n =3D nfds, .r =3D rfds, .w =3D wfds, .e =3D efds, .t =3D ti= meout }; + return my_syscall1(__NR_select, &arg); +#elif defined(__NR__newselect) + return my_syscall5(__NR__newselect, nfds, rfds, wfds, efds, timeout); +#elif defined(__NR_select) + return my_syscall5(__NR_select, nfds, rfds, wfds, efds, timeout); +#elif defined(__NR_pselect6_time64) + struct __kernel_timespec t; + + if (timeout) { + t.tv_sec =3D timeout->tv_sec; + t.tv_nsec =3D timeout->tv_usec * 1000; + } + return my_syscall6(__NR_pselect6_time64, nfds, rfds, wfds, efds, timeout = ? &t : NULL, NULL); +#else + struct timespec t; + + if (timeout) { + t.tv_sec =3D timeout->tv_sec; + t.tv_nsec =3D timeout->tv_usec * 1000; + } + return my_syscall6(__NR_pselect6, nfds, rfds, wfds, efds, timeout ? &t : = NULL, NULL); +#endif +} + +static __attribute__((unused)) +int select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time= val *timeout) +{ + return __sysret(sys_select(nfds, rfds, wfds, efds, timeout)); +} + + +#endif /* _NOLIBC_SYS_SELECT_H */ diff --git a/tools/include/nolibc/types.h b/tools/include/nolibc/types.h index 3b086f68b2be..e2216d1e2c3f 100644 --- a/tools/include/nolibc/types.h +++ b/tools/include/nolibc/types.h @@ -77,11 +77,6 @@ struct timespec { #define DT_LNK 0xa #define DT_SOCK 0xc =20 -/* commonly an fd_set represents 256 FDs */ -#ifndef FD_SETSIZE -#define FD_SETSIZE 256 -#endif - /* PATH_MAX and MAXPATHLEN are often used and found with plenty of differe= nt * values. */ @@ -122,48 +117,6 @@ struct timespec { #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 =20 -#define FD_SETIDXMASK (8 * sizeof(unsigned long)) -#define FD_SETBITMASK (8 * sizeof(unsigned long)-1) - -/* for select() */ -typedef struct { - unsigned long fds[(FD_SETSIZE + FD_SETBITMASK) / FD_SETIDXMASK]; -} fd_set; - -#define FD_CLR(fd, set) do { \ - fd_set *__set =3D (set); \ - int __fd =3D (fd); \ - if (__fd >=3D 0) \ - __set->fds[__fd / FD_SETIDXMASK] &=3D \ - ~(1U << (__fd & FD_SETBITMASK)); \ - } while (0) - -#define FD_SET(fd, set) do { \ - fd_set *__set =3D (set); \ - int __fd =3D (fd); \ - if (__fd >=3D 0) \ - __set->fds[__fd / FD_SETIDXMASK] |=3D \ - 1 << (__fd & FD_SETBITMASK); \ - } while (0) - -#define FD_ISSET(fd, set) ({ \ - fd_set *__set =3D (set); \ - int __fd =3D (fd); \ - int __r =3D 0; \ - if (__fd >=3D 0) \ - __r =3D !!(__set->fds[__fd / FD_SETIDXMASK] & \ -1U << (__fd & FD_SETBITMASK)); \ - __r; \ - }) - -#define FD_ZERO(set) do { \ - fd_set *__set =3D (set); \ - int __idx; \ - int __size =3D (FD_SETSIZE+FD_SETBITMASK) / FD_SETIDXMASK;\ - for (__idx =3D 0; __idx < __size; __idx++) \ - __set->fds[__idx] =3D 0; \ - } while (0) - /* for getdents64() */ struct linux_dirent64 { uint64_t d_ino; --=20 2.17.5