tech-kern archive

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

Re: compat_netbsd32 swapctl



On Wed, Jan 29, 2014 at 01:48:35PM +0100, Martin Husemann wrote:
> My vote for this special case: hard code it #ifdef __x86_64__.
> If we run into other instances, we can add a define (like: DEV_T_ALIGN_32).

Here is a patch that fixes the problem.

Index: sys/compat/netbsd32/netbsd32_netbsd.c
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_netbsd.c,v
retrieving revision 1.179
diff -U 4 -r1.179 netbsd32_netbsd.c
--- sys/compat/netbsd32/netbsd32_netbsd.c       1 Feb 2012 05:43:54 -0000       
1.179
+++ sys/compat/netbsd32/netbsd32_netbsd.c       29 Jan 2014 15:33:47 -0000
@@ -63,8 +63,9 @@
 #include <sys/trace.h>
 #include <sys/resourcevar.h>
 #include <sys/pool.h>
 #include <sys/vnode.h>
+#include <sys/swap.h>
 #include <sys/file.h>
 #include <sys/filedesc.h>
 #include <sys/namei.h>
 #include <sys/dirent.h>
@@ -1740,8 +1741,69 @@
 
        NETBSD32TO64_UAP(cmd);
        NETBSD32TOP_UAP(arg, void);
        NETBSD32TO64_UAP(misc);
+
+#ifdef __amd64__
+       if (SCARG(&ua, cmd) == SWAP_STATS
+#if defined(COMPAT_50)
+           || SCARG(&ua, cmd) == SWAP_STATS50
+#endif
+#if defined(COMPAT_13)
+           || SCARG(&ua, cmd) == SWAP_STATS13
+#endif  
+       ) {
+               struct sys_swapctl_args ssa;
+               register_t rv;
+               size_t swapctl32_len;
+               int i, error = 0;
+               
+               /*
+                * The amgic numbers are sizeof(struct swapent) 
+                * on i386. They are padded to end on a 4 bytes
+                * boundary, we we have no way to discover that
+                * from amd64 code.
+                */
+               switch(SCARG(&ua, cmd)) {
+               case SWAP_STATS:
+                       swapctl32_len = 1052; 
+                       break;
+#if defined(COMPAT_50)
+               case SWAP_STATS50:
+                       swapctl32_len = 1048;
+#endif
+#if defined(COMPAT_13)
+               case SWAP_STATS13:
+                       swapctl32_len = 20;
+                       break;
+#endif
+               default:
+                       panic("unexpected cmd = %d", SCARG(&ua, cmd));
+                       break;
+               }
+
+               *retval = 0;
+               SCARG(&ssa, cmd) = SCARG(&ua, cmd);
+               SCARG(&ssa, misc) = 1;
+
+               for (i = 0; i < SCARG(&ua, misc); i++) {
+                       SCARG(&ssa, arg) = 
+                           (char *)SCARG(&ua, arg) + (i * swapctl32_len);
+
+                       if ((error = sys_swapctl(l, &ssa, &rv)) != 0) {
+                               *retval = rv;
+                               break;
+                       }
+
+                       if (rv == 1)
+                               *retval = *retval + 1;
+                       else if (rv != 0)
+                               *retval = rv;
+
+               }
+               return error;                   
+       }
+#endif
        return (sys_swapctl(l, &ua, retval));
 }
 
 int
-- 
Emmanuel Dreyfus
manu%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index