[LTP] [PATCH] lapi/procfs.h: Add elf_prstatus and elf_prpsinfo fallbacks

Wake Liu wakel@google.com
Fri Oct 2 15:05:56 CEST 2026


Bionic's <sys/procfs.h> provides elf_gregset_t and struct elf_siginfo,
but not struct elf_prstatus or struct elf_prpsinfo, so coredump02
fails to build on Android:

    error: incomplete definition of type 'const struct elf_prstatus'

Add configure checks and fallback definitions which follow
include/linux/elfcore.h. The timevals and pr_uid/pr_gid use the kernel
types, so the layout matches the native core dump format, e.g. 16-bit
pr_uid on 32-bit x86 and arm. Use the new header in coredump02.

Fixes: 72a170823fb0 ("coredump02: Verify ELF structure and notes")
Signed-off-by: Wake Liu <wakel@google.com>
---
 configure.ac                           |  1 +
 include/lapi/procfs.h                  | 56 ++++++++++++++++++++++++++
 testcases/kernel/coredump/coredump02.c |  2 +-
 3 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 include/lapi/procfs.h

diff --git a/configure.ac b/configure.ac
index e979de0e7..370c2e74f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -201,6 +201,7 @@ AC_CHECK_TYPES([struct acct_v3],,,[#include <sys/acct.h>])
 AC_CHECK_TYPES([struct af_alg_iv, struct sockaddr_alg],,,[# include <linux/if_alg.h>])
 AC_CHECK_TYPES([struct clone_args],,,[#include <sched.h>])
 AC_CHECK_TYPES([struct sched_attr],,,[#include <sched.h>])
+AC_CHECK_TYPES([struct elf_prpsinfo, struct elf_prstatus],,,[#include <sys/procfs.h>])
 AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_error,
 		struct fanotify_event_info_header, struct fanotify_event_info_pidfd,
 		struct fanotify_event_info_range],,,[#include <sys/fanotify.h>])
diff --git a/include/lapi/procfs.h b/include/lapi/procfs.h
new file mode 100644
index 000000000..598d91bf1
--- /dev/null
+++ b/include/lapi/procfs.h
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Google LLC
+ */
+
+#ifndef LAPI_PROCFS_H__
+#define LAPI_PROCFS_H__
+
+#include "config.h"
+#include <sys/types.h>
+#include <sys/procfs.h>
+#include "lapi/posix_types.h"
+
+/*
+ * Bionic does not provide the core dump note descriptors. The fallbacks
+ * follow include/linux/elfcore.h, using the kernel types so that the layout
+ * matches the native ABI on every architecture.
+ */
+#ifndef HAVE_STRUCT_ELF_PRSTATUS
+struct elf_prstatus {
+	struct elf_siginfo pr_info;
+	short pr_cursig;
+	unsigned long pr_sigpend;
+	unsigned long pr_sighold;
+	pid_t pr_pid;
+	pid_t pr_ppid;
+	pid_t pr_pgrp;
+	pid_t pr_sid;
+	struct {
+		__kernel_long_t tv_sec;
+		__kernel_long_t tv_usec;
+	} pr_utime, pr_stime, pr_cutime, pr_cstime;
+	elf_gregset_t pr_reg;
+	int pr_fpvalid;
+};
+#endif
+
+#ifndef HAVE_STRUCT_ELF_PRPSINFO
+struct elf_prpsinfo {
+	char pr_state;
+	char pr_sname;
+	char pr_zomb;
+	char pr_nice;
+	unsigned long pr_flag;
+	__kernel_uid_t pr_uid;
+	__kernel_gid_t pr_gid;
+	pid_t pr_pid;
+	pid_t pr_ppid;
+	pid_t pr_pgrp;
+	pid_t pr_sid;
+	char pr_fname[16];
+	char pr_psargs[ELF_PRARGSZ];
+};
+#endif
+
+#endif /* LAPI_PROCFS_H__ */
diff --git a/testcases/kernel/coredump/coredump02.c b/testcases/kernel/coredump/coredump02.c
index 7b0b4c43e..6657a3d71 100644
--- a/testcases/kernel/coredump/coredump02.c
+++ b/testcases/kernel/coredump/coredump02.c
@@ -40,9 +40,9 @@
  */
 
 #include <link.h>
-#include <sys/procfs.h>
 
 #include "coredump_common.h"
+#include "lapi/procfs.h"
 
 #define NOTE_ALIGN(x) (((x) + 3) & ~3U)
 
-- 
2.56.0.rc1.315.gc6ed9934b7-goog



More information about the ltp mailing list