[PATCH v3 11/12] tools/nolibc: add ptrace support
Thomas Weißschuh
linux at weissschuh.net
Thu Sep 25 09:28:41 PDT 2025
On 2025-09-24 16:20:58+0200, Benjamin Berg wrote:
> From: Benjamin Berg <benjamin.berg at intel.com>
>
> Add ptrace support, as it will be useful in UML.
>
> Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
>
> ---
> v3:
> - Only use variardic for ptrace and not for sys_ptrace
> ---
> tools/include/nolibc/Makefile | 1 +
> tools/include/nolibc/nolibc.h | 1 +
> tools/include/nolibc/sys/ptrace.h | 44 ++++++++++++++++++++
> tools/testing/selftests/nolibc/nolibc-test.c | 2 +
> 4 files changed, 48 insertions(+)
> create mode 100644 tools/include/nolibc/sys/ptrace.h
(...)
> diff --git a/tools/include/nolibc/sys/ptrace.h b/tools/include/nolibc/sys/ptrace.h
> new file mode 100644
> index 000000000000..5d1e52965878
> --- /dev/null
> +++ b/tools/include/nolibc/sys/ptrace.h
> @@ -0,0 +1,44 @@
> +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
> +/*
> + * ptrace for NOLIBC
> + * Copyright (C) 2017-2021 Willy Tarreau <w at 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);
> + */
> +static __attribute__((unused))
> +long sys_ptrace(int op, pid_t pid, void *addr, void *data)
> +{
> + return my_syscall4(__NR_ptrace, op, pid, addr, data);
> +}
> +
> +static __attribute__((unused))
> +ssize_t ptrace(int op, pid_t pid, ...)
> +{
> + ssize_t ret;
> + va_list args;
> +
> + va_start(args, pid);
> + ret = __sysret(sys_ptrace(op, pid,
> + va_arg(args, void *),
> + va_arg(args, void *)));
> + va_end(args);
My understanding of the last discussion was not to use varargs here
either. Instead I wanted to stick to the prototype from the manpage.
> +
> + return ret;
> +}
> +
> +#endif /* _NOLIBC_SYS_PTRACE_H */
(...)
More information about the linux-um
mailing list