Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/nolibc: add uio.h with readv and writev

This is generally useful and struct iovec is also needed for other
purposes such as ptrace.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

authored by

Benjamin Berg and committed by
Thomas Weißschuh
4bb30188 3d66c4e1

+60
+1
tools/include/nolibc/Makefile
··· 62 62 sys/time.h \ 63 63 sys/timerfd.h \ 64 64 sys/types.h \ 65 + sys/uio.h \ 65 66 sys/utsname.h \ 66 67 sys/wait.h \ 67 68 time.h \
+1
tools/include/nolibc/nolibc.h
··· 109 109 #include "sys/sysmacros.h" 110 110 #include "sys/time.h" 111 111 #include "sys/timerfd.h" 112 + #include "sys/uio.h" 112 113 #include "sys/utsname.h" 113 114 #include "sys/wait.h" 114 115 #include "ctype.h"
+49
tools/include/nolibc/sys/uio.h
··· 1 + /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ 2 + /* 3 + * uio for NOLIBC 4 + * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu> 5 + * Copyright (C) 2025 Intel Corporation 6 + */ 7 + 8 + /* make sure to include all global symbols */ 9 + #include "../nolibc.h" 10 + 11 + #ifndef _NOLIBC_SYS_UIO_H 12 + #define _NOLIBC_SYS_UIO_H 13 + 14 + #include "../sys.h" 15 + #include <linux/uio.h> 16 + 17 + 18 + /* 19 + * ssize_t readv(int fd, const struct iovec *iovec, int count); 20 + */ 21 + static __attribute__((unused)) 22 + ssize_t sys_readv(int fd, const struct iovec *iovec, int count) 23 + { 24 + return my_syscall3(__NR_readv, fd, iovec, count); 25 + } 26 + 27 + static __attribute__((unused)) 28 + ssize_t readv(int fd, const struct iovec *iovec, int count) 29 + { 30 + return __sysret(sys_readv(fd, iovec, count)); 31 + } 32 + 33 + /* 34 + * ssize_t writev(int fd, const struct iovec *iovec, int count); 35 + */ 36 + static __attribute__((unused)) 37 + ssize_t sys_writev(int fd, const struct iovec *iovec, int count) 38 + { 39 + return my_syscall3(__NR_writev, fd, iovec, count); 40 + } 41 + 42 + static __attribute__((unused)) 43 + ssize_t writev(int fd, const struct iovec *iovec, int count) 44 + { 45 + return __sysret(sys_writev(fd, iovec, count)); 46 + } 47 + 48 + 49 + #endif /* _NOLIBC_SYS_UIO_H */
+9
tools/testing/selftests/nolibc/nolibc-test.c
··· 25 25 #include <sys/sysmacros.h> 26 26 #include <sys/time.h> 27 27 #include <sys/timerfd.h> 28 + #include <sys/uio.h> 28 29 #include <sys/utsname.h> 29 30 #include <sys/wait.h> 30 31 #include <dirent.h> ··· 1283 1282 int proc; 1284 1283 int test; 1285 1284 int tmp; 1285 + struct iovec iov_one = { 1286 + .iov_base = &tmp, 1287 + .iov_len = 1, 1288 + }; 1286 1289 int ret = 0; 1287 1290 void *p1, *p2; 1288 1291 int has_gettid = 1; ··· 1400 1395 CASE_TEST(waitpid_child); EXPECT_SYSER(1, waitpid(getpid(), &tmp, WNOHANG), -1, ECHILD); break; 1401 1396 CASE_TEST(write_badf); EXPECT_SYSER(1, write(-1, &tmp, 1), -1, EBADF); break; 1402 1397 CASE_TEST(write_zero); EXPECT_SYSZR(1, write(1, &tmp, 0)); break; 1398 + CASE_TEST(readv_badf); EXPECT_SYSER(1, readv(-1, &iov_one, 1), -1, EBADF); break; 1399 + CASE_TEST(readv_zero); EXPECT_SYSZR(1, readv(1, NULL, 0)); break; 1400 + CASE_TEST(writev_badf); EXPECT_SYSER(1, writev(-1, &iov_one, 1), -1, EBADF); break; 1401 + CASE_TEST(writev_zero); EXPECT_SYSZR(1, writev(1, NULL, 0)); break; 1403 1402 CASE_TEST(syscall_noargs); EXPECT_SYSEQ(1, syscall(__NR_getpid), getpid()); break; 1404 1403 CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_statx, 0, NULL, 0, 0, NULL), -1, EFAULT); break; 1405 1404 CASE_TEST(namespace); EXPECT_SYSZR(euid0 && proc, test_namespace()); break;