From: Benjamin Berg <benjamin@sipsolutions.net>
To: linux-um@lists.infradead.org, "Willy Tarreau" <w@1wt.eu>,
"Thomas Weißschuh" <linux@weissschuh.net>,
linux-kselftest@vger.kernel.org,
"Arnaldo Carvalho de Melo" <acme@redhat.com>
Cc: linux-kernel@vger.kernel.org, Benjamin Berg <benjamin.berg@intel.com>
Subject: [PATCH v2 10/11] tools/nolibc: add ptrace support
Date: Fri, 19 Sep 2025 17:34:19 +0200 [thread overview]
Message-ID: <20250919153420.727385-11-benjamin@sipsolutions.net> (raw)
In-Reply-To: <20250919153420.727385-1-benjamin@sipsolutions.net>
From: Benjamin Berg <benjamin.berg@intel.com>
Add ptrace support, as it will be useful in UML.
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
---
tools/include/nolibc/Makefile | 1 +
tools/include/nolibc/nolibc.h | 1 +
tools/include/nolibc/sys/ptrace.h | 52 ++++++++++++++++++++
tools/testing/selftests/nolibc/nolibc-test.c | 2 +
4 files changed, 56 insertions(+)
create mode 100644 tools/include/nolibc/sys/ptrace.h
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index 9bbbba32dac6..8e0cac3ac522 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -53,6 +53,7 @@ all_files := \
sys/mman.h \
sys/mount.h \
sys/prctl.h \
+ sys/ptrace.h \
sys/random.h \
sys/reboot.h \
sys/resource.h \
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index b4bc1c9b883d..590eef545ca6 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -101,6 +101,7 @@
#include "sys/mman.h"
#include "sys/mount.h"
#include "sys/prctl.h"
+#include "sys/ptrace.h"
#include "sys/random.h"
#include "sys/reboot.h"
#include "sys/resource.h"
diff --git a/tools/include/nolibc/sys/ptrace.h b/tools/include/nolibc/sys/ptrace.h
new file mode 100644
index 000000000000..3119abdeeecb
--- /dev/null
+++ b/tools/include/nolibc/sys/ptrace.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
+/*
+ * ptrace for NOLIBC
+ * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
+ * Copyright (C) 2025 Intel Corporation
+ */
+
+/* make sure to include all global symbols */
+#include "../nolibc.h"
+
+#ifndef _NOLIBC_SYS_PTRACE_H
+#define _NOLIBC_SYS_PTRACE_H
+
+#include "../sys.h"
+#include "uio.h"
+
+
+#include <linux/ptrace.h>
+
+/*
+ * long ptrace(int op, pid_t pid, void *addr, void *data);
+ *
+ * However, addr may also be an integer in some cases.
+ */
+static __attribute__((unused))
+long sys_vptrace(int op, pid_t pid, va_list args)
+{
+ return my_syscall4(__NR_ptrace, op, pid,
+ va_arg(args, void *), va_arg(args, void *));
+}
+
+static __attribute__((unused))
+ssize_t sys_ptrace(int op, pid_t pid, ...)
+{
+ va_list args;
+
+ va_start(args, pid);
+ return sys_vptrace(op, pid, args);
+ va_end(args);
+}
+
+static __attribute__((unused))
+ssize_t ptrace(int op, pid_t pid, ...)
+{
+ va_list args;
+
+ va_start(args, pid);
+ return __sysret(sys_vptrace(op, pid, args));
+ va_end(args);
+}
+
+#endif /* _NOLIBC_SYS_PTRACE_H */
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 1907128bc3f6..4c1b9ee32b7d 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -17,6 +17,7 @@
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/prctl.h>
+#include <sys/ptrace.h>
#include <sys/random.h>
#include <sys/reboot.h>
#include <sys/resource.h>
@@ -1404,6 +1405,7 @@ int run_syscall(int min, int max)
CASE_TEST(readv_zero); EXPECT_SYSZR(1, readv(1, NULL, 0)); break;
CASE_TEST(writev_badf); EXPECT_SYSER(1, writev(-1, &iov_one, 1), -1, EBADF); break;
CASE_TEST(writev_zero); EXPECT_SYSZR(1, writev(1, NULL, 0)); break;
+ CASE_TEST(ptrace); EXPECT_SYSER(1, ptrace(PTRACE_CONT, getpid(), NULL, NULL), -1, ESRCH); break;
CASE_TEST(syscall_noargs); EXPECT_SYSEQ(1, syscall(__NR_getpid), getpid()); break;
CASE_TEST(syscall_args); EXPECT_SYSER(1, syscall(__NR_statx, 0, NULL, 0, 0, NULL), -1, EFAULT); break;
CASE_TEST(namespace); EXPECT_SYSZR(euid0 && proc, test_namespace()); break;
--
2.51.0
next prev parent reply other threads:[~2025-09-19 15:36 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-19 15:34 [PATCH v2 00/11] Start porting UML to nolibc Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 01/11] tools compiler.h: fix __used definition Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 02/11] um: use tools/include for user files Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 03/11] tools/nolibc/stdio: remove perror if NOLIBC_IGNORE_ERRNO is set Benjamin Berg
2025-09-21 7:55 ` Willy Tarreau
2025-09-21 16:37 ` Thomas Weißschuh
2025-09-21 17:05 ` Benjamin Berg
2025-09-21 17:13 ` Willy Tarreau
2025-09-21 17:16 ` Benjamin Berg
2025-09-21 17:23 ` Willy Tarreau
2025-09-21 18:26 ` Thomas Weißschuh
2025-09-21 18:28 ` Willy Tarreau
2025-09-21 17:09 ` Willy Tarreau
2025-09-19 15:34 ` [PATCH v2 04/11] tools/nolibc/dirent: avoid errno in readdir_r Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 05/11] tools/nolibc: use __fallthrough__ rather than fallthrough Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 06/11] tools/nolibc: add option to disable runtime Benjamin Berg
2025-09-20 9:08 ` Thomas Weißschuh
2025-09-19 15:34 ` [PATCH v2 07/11] um: add infrastructure to build files using nolibc Benjamin Berg
2025-09-21 8:13 ` Willy Tarreau
2025-09-22 7:11 ` Berg, Benjamin
2025-09-19 15:34 ` [PATCH v2 08/11] um: use nolibc for the --showconfig implementation Benjamin Berg
2025-09-19 15:34 ` [PATCH v2 09/11] tools/nolibc: add uio.h with readv and writev Benjamin Berg
2025-09-20 9:11 ` Thomas Weißschuh
2025-09-19 15:34 ` Benjamin Berg [this message]
2025-09-20 9:27 ` [PATCH v2 10/11] tools/nolibc: add ptrace support Thomas Weißschuh
2025-09-21 8:19 ` Willy Tarreau
2025-09-19 15:34 ` [PATCH v2 11/11] um: switch ptrace FP register access to nolibc Benjamin Berg
2025-09-19 20:50 ` kernel test robot
2025-09-19 15:40 ` [PATCH v2 00/11] Start porting UML " Christoph Hellwig
2025-09-22 7:41 ` Johannes Berg
2025-09-23 23:58 ` Hajime Tazaki
2025-09-24 3:32 ` Willy Tarreau
2025-09-24 7:55 ` Benjamin Berg
2025-09-25 1:05 ` Hajime Tazaki
2025-09-20 9:30 ` Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250919153420.727385-11-benjamin@sipsolutions.net \
--to=benjamin@sipsolutions.net \
--cc=acme@redhat.com \
--cc=benjamin.berg@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=linux@weissschuh.net \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox