Author: kib
Date: Sun Feb 10 19:01:05 2019
New Revision: 343966
URL: https://svnweb.freebsd.org/changeset/base/343966

Log:
  struct xswdev on amd64 requires compat32 shims after ino64.
  
  i386 is the only architecture where uint64_t does not specify 8-bytes
  alignment, which makes struct xswdev layout not compatible between
  64bit and i386.
  
  Reported and tested by:       pho
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week

Modified:
  head/sys/vm/swap_pager.c

Modified: head/sys/vm/swap_pager.c
==============================================================================
--- head/sys/vm/swap_pager.c    Sun Feb 10 18:28:37 2019        (r343965)
+++ head/sys/vm/swap_pager.c    Sun Feb 10 19:01:05 2019        (r343966)
@@ -2478,10 +2478,23 @@ struct xswdev11 {
 };
 #endif
 
+#if defined(__amd64__) && defined(COMPAT_FREEBSD32)
+struct xswdev32 {
+       u_int   xsw_version;
+       u_int   xsw_dev1, xsw_dev2;
+       int     xsw_flags;
+       int     xsw_nblks;
+       int     xsw_used;
+};
+#endif
+
 static int
 sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
 {
        struct xswdev xs;
+#if defined(__amd64__) && defined(COMPAT_FREEBSD32)
+       struct xswdev32 xs32;
+#endif
 #if defined(COMPAT_FREEBSD11)
        struct xswdev11 xs11;
 #endif
@@ -2492,6 +2505,18 @@ sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
        error = swap_dev_info(*(int *)arg1, &xs, NULL, 0);
        if (error != 0)
                return (error);
+#if defined(__amd64__) && defined(COMPAT_FREEBSD32)
+       if (req->oldlen == sizeof(xs32)) {
+               xs32.xsw_version = XSWDEV_VERSION;
+               xs32.xsw_dev1 = xs.xsw_dev;
+               xs32.xsw_dev2 = xs.xsw_dev >> 32;
+               xs32.xsw_flags = xs.xsw_flags;
+               xs32.xsw_nblks = xs.xsw_nblks;
+               xs32.xsw_used = xs.xsw_used;
+               error = SYSCTL_OUT(req, &xs32, sizeof(xs32));
+               return (error);
+       }
+#endif
 #if defined(COMPAT_FREEBSD11)
        if (req->oldlen == sizeof(xs11)) {
                xs11.xsw_version = XSWDEV_VERSION_11;
@@ -2500,9 +2525,10 @@ sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
                xs11.xsw_nblks = xs.xsw_nblks;
                xs11.xsw_used = xs.xsw_used;
                error = SYSCTL_OUT(req, &xs11, sizeof(xs11));
-       } else
+               return (error);
+       }
 #endif
-               error = SYSCTL_OUT(req, &xs, sizeof(xs));
+       error = SYSCTL_OUT(req, &xs, sizeof(xs));
        return (error);
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to