tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

netbsd32_{,u}int64 in sys/types.h for compat/sys/siginfo.h



Hi,

In order to distangle circular dependency between
<sys/compat/sys/siginfo.h> v.s. <machine/netbsd32_machdep.h>,
I propose

(1) Move NETBSD32_INT64_ALIGN from <machine/netbsd32_machdep.h> to
<machine/types.h>

(2) Move netbsd32_{,u}int64 from <sys/compat/netbsd32/netbsd32.h> to
<sys/types.h>

See attached patch for example on amd64.

Background is:

Now, gdb for i386 does not work again on amd64 (both on -current and
netbsd-9) with:

	ptrace: Invalid arguments.

This is because sizeof(struct netbsd32_ptrace_siginfo) is 128+4+4=136
on amd64 whereas sizeof(struct ptrace_siginfo) is 128+4=132 on i386;
netbsd32_ptrace_siginfo has uint64_t members via siginfo32_t via
__ksiginfo32 since compat/sys/siginfo.h rev 1.5:

	http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/compat/sys/siginfo.h#rev1.5

As a result, netbsd32_ptrace_siginfo requires 4-byte tail padding on
amd64. However, tail padding does not appear on i386, since 64-bit
objects only need 4-byte alignment on i386.

Actually, gdb/i386 becomes sane with this hack:

----
Index: sys/compat/sys/siginfo.h
===================================================================
RCS file: /home/netbsd/src/sys/compat/sys/siginfo.h,v
retrieving revision 1.8
diff -p -u -r1.8 siginfo.h
--- sys/compat/sys/siginfo.h	30 Sep 2019 21:13:33 -0000	1.8
+++ sys/compat/sys/siginfo.h	12 Nov 2019 11:04:58 -0000
@@ -34,6 +34,12 @@
#ifdef _KERNEL +typedef uint64_t _args_t
+#ifdef __x86_64__
+    __attribute__((__aligned__(4)))
+#endif
+    ;
+
 typedef union sigval32 {
 	int sival_int;
 	uint32_t sival_ptr;
@@ -73,7 +79,7 @@ struct __ksiginfo32 {
 			int	_sysnum;
 			int	_retval[2];
 			int	_error;
-			uint64_t _args[8]; /* SYS_MAXSYSARGS */
+			_args_t	_args[8]; /* SYS_MAXSYSARGS */
 		} _syscall;
struct {
----

We provide netbsd32_uint64 for this purpose:

	typedef uint64_t netbsd32_uint64 NETBSD32_INT64_ALIGN;

and NETBSD32_INT64_ALIGN is __attribute__((__aligned__(4))) on amd64.
However, unfortunately, NETBSD32_INT64_ALIGN is defined in
<machine/netbsd32_machdep.h>, and <machine/netbsd32_machdep.h> requires
<sys/compat/siginfo.h>.

Thoughts? Any comments or objections?

Thanks,
rin
Index: sys/compat/netbsd32/netbsd32.h
===================================================================
RCS file: /home/netbsd/src/sys/compat/netbsd32/netbsd32.h,v
retrieving revision 1.128
diff -p -u -r1.128 netbsd32.h
--- sys/compat/netbsd32/netbsd32.h	7 Nov 2019 15:21:55 -0000	1.128
+++ sys/compat/netbsd32/netbsd32.h	17 Nov 2019 03:11:34 -0000
@@ -37,6 +37,7 @@
  */
 
 #include <sys/param.h> /* precautionary upon removal from ucred.h */
+#include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
@@ -72,7 +73,11 @@ typedef int32_t netbsd32_key_t;
 typedef int32_t netbsd32_intptr_t;
 typedef uint32_t netbsd32_uintptr_t;
 
-/* netbsd32_[u]int64 are machine dependent and defined below */
+/*
+ * netbsd32_[u]int64 are machine dependent and defined in <sys/types.h>:
+ * 64 bit integers only have 4-byte alignment on some 32 bit ports,
+ * but always have 8-byte alignment on 64 bit systems.
+ */
 
 /*
  * machine dependant section; must define:
@@ -154,15 +159,6 @@ netbsd32_ptr32_incr(netbsd32_pointer_t *
 #undef NETBSD32_POINTER_TYPE
 
 /*
- * 64 bit integers only have 4-byte alignment on some 32 bit ports,
- * but always have 8-byte alignment on 64 bit systems.
- * NETBSD32_INT64_ALIGN may be __attribute__((__aligned__(4)))
- */
-typedef int64_t netbsd32_int64 NETBSD32_INT64_ALIGN;
-typedef uint64_t netbsd32_uint64 NETBSD32_INT64_ALIGN;
-#undef NETBSD32_INT64_ALIGN
-
-/*
  * all pointers are netbsd32_pointer_t (defined in <machine/netbsd32_machdep.h>)
  */
 
Index: sys/compat/sys/siginfo.h
===================================================================
RCS file: /home/netbsd/src/sys/compat/sys/siginfo.h,v
retrieving revision 1.8
diff -p -u -r1.8 siginfo.h
--- sys/compat/sys/siginfo.h	30 Sep 2019 21:13:33 -0000	1.8
+++ sys/compat/sys/siginfo.h	17 Nov 2019 03:17:02 -0000
@@ -34,6 +34,8 @@
 
 #ifdef _KERNEL
 
+#include <sys/types.h>
+
 typedef union sigval32 {
 	int sival_int;
 	uint32_t sival_ptr;
@@ -73,7 +75,7 @@ struct __ksiginfo32 {
 			int	_sysnum;
 			int	_retval[2];
 			int	_error;
-			uint64_t _args[8]; /* SYS_MAXSYSARGS */
+			netbsd32_uint64 _args[8]; /* SYS_MAXSYSARGS */
 		} _syscall;
 
 		struct {
Index: sys/sys/types.h
===================================================================
RCS file: /home/netbsd/src/sys/sys/types.h,v
retrieving revision 1.102
diff -p -u -r1.102 types.h
--- sys/sys/types.h	6 Nov 2018 16:26:44 -0000	1.102
+++ sys/sys/types.h	17 Nov 2019 03:22:49 -0000
@@ -348,6 +348,16 @@ struct	uio;
 #define	CLR(t, f)	((t) &= ~(f))
 #endif
 
+#if defined(_KERNEL) && defined(_LP64)
+/*
+ * See comments in <sys/compat/netbsd32/netbsd32.h> for more details.
+ * _NETBSD32_INT64_ALIGN may be __attribute__((__aligned__(4))).
+ */
+typedef int64_t netbsd32_int64 _NETBSD32_INT64_ALIGN;
+typedef uint64_t netbsd32_uint64 _NETBSD32_INT64_ALIGN;
+#undef _NETBSD32_INT64_ALIGN
+#endif
+
 #if !defined(_KERNEL) && !defined(_STANDALONE)
 #if (_POSIX_C_SOURCE - 0L) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
     defined(_NETBSD_SOURCE)
Index: sys/arch/amd64/include/types.h
===================================================================
RCS file: /home/netbsd/src/sys/arch/amd64/include/types.h,v
retrieving revision 1.64
diff -p -u -r1.64 types.h
--- sys/arch/amd64/include/types.h	14 Nov 2019 16:23:52 -0000	1.64
+++ sys/arch/amd64/include/types.h	17 Nov 2019 03:08:26 -0000
@@ -44,6 +44,9 @@
 typedef struct label_t {
 	long val[8];
 } label_t;
+
+/* i386 has 32bit aligned 64bit integers */
+#define _NETBSD32_INT64_ALIGN __attribute__((__aligned__(4)))
 #endif
 
 #if defined(_KERNEL) || defined(_KMEMUSER) || defined(_KERNTYPES) || defined(_STANDALONE)


Home | Main Index | Thread Index | Old Index