Skip to contentSkip to conversation

psmisc: Remove including sys/user.h and __WORDSIZE

PATCH In review Khem Raj 2 participants 3 messages Mar 30, 2016

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH v2 1/1 psmisc: Remove including sys/user.h and __WORDSIZE

We can replace __WORDSIZE with UINTPTR_MAX sys/user.h is in conflict with asm/ptrace.h on musl

---
Change from v1 to v2:
- Fix build regression on arches which do require user_regs_struct from glibc

 ...001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch | 51 ++++++++++++++++++++++
 meta/recipes-extended/psmisc/psmisc_22.21.bb       |  8 ++--
 2 files changed, 56 insertions(+), 3 deletions(-)
 create mode 100644 meta/recipes-extended/psmisc/psmisc/0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch
meta/recipes-extended/psmisc/psmisc/0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch new file +51 -0
new file mode 100644
index 0000000..b57a006
@@ -0,0 +1,51 @@
+From 5dc872bb2fba6421cb8e1ee578f7bd4aaed55f61 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Thu, 24 Mar 2016 15:46:14 +0000
+Subject: [PATCH] Use UINTPTR_MAX instead of __WORDSIZE
+
+Do not include sys/user.h since it conflicts with
+pt_regs struct from kernel APIs in asm/ptrace.h
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+Upstream-Status: Pending
+
+ src/peekfd.c | 13 ++++++++-----
+ 1 file changed, 8 insertions(+), 5 deletions(-)
+
+diff --git a/src/peekfd.c b/src/peekfd.c
+index cba2130..0d39878 100644
+--- a/src/peekfd.c
++++ b/src/peekfd.c
+@@ -30,8 +30,11 @@
+ #include <asm/ptrace.h>
+ #include <byteswap.h>
+ #include <endian.h>
++#ifdef __GLIBC__
+ #include <sys/user.h>
++#endif
+ #include <stdlib.h>
++#include <stdint.h>
+ #include <getopt.h>
+ #include <ctype.h>
+ 
+@@ -228,11 +231,11 @@ int main(int argc, char **argv)
+ 		if (WIFSTOPPED(status)) {
+ #ifdef PPC
+ 			struct pt_regs regs;
+-			regs.gpr[0] = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_R0, 0);
+-			regs.gpr[3] = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_R3, 0);
+-			regs.gpr[4] = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_R4, 0);
+-			regs.gpr[5] = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_R5, 0);
+-			regs.orig_gpr3 = ptrace(PTRACE_PEEKUSER, pid, __WORDSIZE/8 * PT_ORIG_R3, 0);
++			regs.gpr[0] = ptrace(PTRACE_PEEKUSER, pid, UINTPTR_MAX/8 * PT_R0, 0);
++			regs.gpr[3] = ptrace(PTRACE_PEEKUSER, pid, UINTPTR_MAX/8 * PT_R3, 0);
++			regs.gpr[4] = ptrace(PTRACE_PEEKUSER, pid, UINTPTR_MAX/8 * PT_R4, 0);
++			regs.gpr[5] = ptrace(PTRACE_PEEKUSER, pid, UINTPTR_MAX/8 * PT_R5, 0);
++			regs.orig_gpr3 = ptrace(PTRACE_PEEKUSER, pid, UINTPTR_MAX/8 * PT_ORIG_R3, 0);
+ #elif defined(ARM)
+ 			struct pt_regs regs;
+ 			ptrace(PTRACE_GETREGS, pid, 0, &regs);
+-- 
+1.9.1
+
meta/recipes-extended/psmisc/psmisc_22.21.bb +5 -3
index 66aba9e..1c6473e 100644
@@ -5,6 +5,8 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3"
 SRC_URI[md5sum] = "935c0fd6eb208288262b385fa656f1bf"
 SRC_URI[sha256sum] = "97323cad619210845b696d7d722c383852b2acb5c49b5b0852c4f29c77a8145a"
 
-SRC_URI += "file://0001-Typo-in-fuser-makes-M-on-all-the-time.patch \
-            file://0002-Include-limits.h-for-PATH_MAX.patch \
-            "
+SRC_URI = "${SOURCEFORGE_MIRROR}/psmisc/psmisc-${PV}.tar.gz \
+           file://0001-Typo-in-fuser-makes-M-on-all-the-time.patch \
+           file://0002-Include-limits.h-for-PATH_MAX.patch \
+           file://0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch \
+           "
Signature · 1 line
1.9.1
#1 lore raw

meta/recipes-extended/psmisc/psmisc/0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch line 9

Quoted 6 lines · Khem Raj
meta/recipes-extended/psmisc/psmisc/0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch new file +6 -0
+Subject: [PATCH] Use UINTPTR_MAX instead of __WORDSIZE
+
+Do not include sys/user.h since it conflicts with
+pt_regs struct from kernel APIs in asm/ptrace.h
+
+Signed-off-by: Khem Raj <[email protected]>

This description (and the subject line of the commit) implies that you are removing the include unconditionally. But actually, you are only removing it for non-glibc platforms.

Also, the change itself seems slightly backwards since the ptrace manpage suggests that <sys/user.h> is actually the right header to be using for these definitions and possibly it's <asm/ptrace.h> that should be eliminated. Maybe that's not feasible here but it would be nice if the patch header explained why. And...

meta/recipes-extended/psmisc/psmisc_22.21.bb LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3" · line 12

Quoted 8 lines
meta/recipes-extended/psmisc/psmisc_22.21.bb +5 -3
-SRC_URI += "file://0001-Typo-in-fuser-makes-M-on-all-the-time.patch \
-            file://0002-Include-limits.h-for-PATH_MAX.patch \
-            "
+SRC_URI = "${SOURCEFORGE_MIRROR}/psmisc/psmisc-${PV}.tar.gz \
+           file://0001-Typo-in-fuser-makes-M-on-all-the-time.patch \
+           file://0002-Include-limits.h-for-PATH_MAX.patch \
+           file://0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch \
+           "

... this change is not mentioned in the commit message. Why have you added the tarball to SRC_URI directly (rather than letting the .inc do that as it did before)?

p.

author
#2 lore raw
Quoted 14 lines · Phil Blundell

meta/recipes-extended/psmisc/psmisc/0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch line 9

Quoted 6 lines · Khem Raj
meta/recipes-extended/psmisc/psmisc/0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch new file +6 -0
+Subject: [PATCH] Use UINTPTR_MAX instead of __WORDSIZE
+
+Do not include sys/user.h since it conflicts with
+pt_regs struct from kernel APIs in asm/ptrace.h
+
+Signed-off-by: Khem Raj <[email protected]>

This description (and the subject line of the commit) implies that you are removing the include unconditionally. But actually, you are only removing it for non-glibc platforms.

OK.

Quoted 6 lines

Also, the change itself seems slightly backwards since the ptrace manpage suggests that <sys/user.h> is actually the right header to be using for these definitions and possibly it's <asm/ptrace.h> that should be eliminated. Maybe that's not feasible here but it would be nice if the patch header explained why. And…

The linux ptrace(2) manpage is written with glibc as the only reference. Unfortunately, its not a POSIX API so there is no standard per se. The motivation for this patch to look for a middle ground, between different libc implementaitons.

musl’s sys/user.h defines elements that conflict with asm/ptrace.h especially on ppc, may be musl community should take a closer look at what can be done since many tracing utilities e.g. strace gdb etc. rely on this, may be its worth a libc item there.

Quoted 17 lines

meta/recipes-extended/psmisc/psmisc_22.21.bb LIC_FILES_CHKSUM = "file://COPYING;md5=0636e73ff0215e8d672dc4c32c317bb3" · line 12

Quoted 9 lines
meta/recipes-extended/psmisc/psmisc_22.21.bb +5 -3
-SRC_URI += "file://0001-Typo-in-fuser-makes-M-on-all-the-time.patch \
-            file://0002-Include-limits.h-for-PATH_MAX.patch \
-            "
+SRC_URI = "${SOURCEFORGE_MIRROR}/psmisc/psmisc-${PV}.tar.gz \
+           file://0001-Typo-in-fuser-makes-M-on-all-the-time.patch \
+           file://0002-Include-limits.h-for-PATH_MAX.patch \
+           file://0001-Use-UINTPTR_MAX-instead-of-__WORDSIZE.patch \
+           "

... this change is not mentioned in the commit message. Why have you added the tarball to SRC_URI directly (rather than letting the .inc do that as it did before)?

p.