Source-Changes-HG archive

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

[src/trunk]: src/sys Properly translate struct swapent for COMPAT_NETBSD32



details:   https://anonhg.NetBSD.org/src/rev/b9c8b2007751
branches:  trunk
changeset: 793305:b9c8b2007751
user:      manu <manu%NetBSD.org@localhost>
date:      Mon Feb 03 13:20:20 2014 +0000

description:
Properly translate struct swapent for COMPAT_NETBSD32

diffstat:

 sys/compat/netbsd32/netbsd32_netbsd.c |  56 +++++++++++++++++++++++++++++++++-
 sys/uvm/uvm_swap.c                    |   8 +---
 sys/uvm/uvm_swap.h                    |   4 +-
 3 files changed, 60 insertions(+), 8 deletions(-)

diffs (154 lines):

diff -r e1bfcc2b18bb -r b9c8b2007751 sys/compat/netbsd32/netbsd32_netbsd.c
--- a/sys/compat/netbsd32/netbsd32_netbsd.c     Mon Feb 03 05:56:23 2014 +0000
+++ b/sys/compat/netbsd32/netbsd32_netbsd.c     Mon Feb 03 13:20:20 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_netbsd.c,v 1.183 2014/01/25 03:31:12 christos Exp $   */
+/*     $NetBSD: netbsd32_netbsd.c,v 1.184 2014/02/03 13:20:20 manu Exp $       */
 
 /*
  * Copyright (c) 1998, 2001, 2008 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.183 2014/01/25 03:31:12 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_netbsd.c,v 1.184 2014/02/03 13:20:20 manu Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ddb.h"
@@ -56,6 +56,7 @@
 #include <sys/mbuf.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
+#include <sys/swap.h>
 #include <sys/time.h>
 #include <sys/signalvar.h>
 #include <sys/ptrace.h>
@@ -73,6 +74,7 @@
 #include <sys/vfs_syscalls.h>
 
 #include <uvm/uvm_extern.h>
+#include <uvm/uvm_swap.h>
 
 #include <sys/syscallargs.h>
 #include <sys/proc.h>
@@ -1748,6 +1750,51 @@
        return (sys___posix_rename(l, &ua, retval));
 }
 
+static int
+netbsd32_swapctl_stats(struct lwp *l, struct sys_swapctl_args *uap, register_t *retval)
+{
+       struct swapent *ksep;
+       struct netbsd32_swapent *usep32;
+       struct netbsd32_swapent se32;
+       int count = SCARG(uap, misc);
+       int i, error = 0;
+       size_t ksep_len;
+
+       /* Make sure userland cannot exhaust kernel memory */
+       if ((size_t)count > (size_t)uvmexp.nswapdev)
+               count = uvmexp.nswapdev;
+
+       ksep_len = sizeof(*ksep) * count;
+       ksep = kmem_alloc(ksep_len, KM_SLEEP);
+       usep32 = (struct netbsd32_swapent *)SCARG(uap, arg);
+
+       uvm_swap_stats(SWAP_STATS, ksep, count, retval);
+       count = *retval;
+
+       if (count < 1)
+               goto out;
+
+       for (i = 0; i < count; i++) {
+               se32.se_dev = ksep[i].se_dev;
+               se32.se_flags = ksep[i].se_flags;
+               se32.se_nblks = ksep[i].se_nblks;
+               se32.se_inuse = ksep[i].se_inuse;
+               se32.se_priority = ksep[i].se_priority;
+               memcpy(se32.se_path, ksep[i].se_path,
+                       sizeof(se32.se_path));
+
+               error = copyout(&se32, usep32 + i, sizeof(se32));
+               if (error)
+                       break;
+       }
+
+       
+out:
+       kmem_free(ksep, ksep_len);
+
+       return error;
+}
+
 int
 netbsd32_swapctl(struct lwp *l, const struct netbsd32_swapctl_args *uap, register_t *retval)
 {
@@ -1761,6 +1808,11 @@
        NETBSD32TO64_UAP(cmd);
        NETBSD32TOP_UAP(arg, void);
        NETBSD32TO64_UAP(misc);
+
+       /* SWAP_STATS50 and SWAP_STATS13 structures need no translation */
+       if (SCARG(&ua, cmd) == SWAP_STATS)
+               return netbsd32_swapctl_stats(l, &ua, retval);
+       
        return (sys_swapctl(l, &ua, retval));
 }
 
diff -r e1bfcc2b18bb -r b9c8b2007751 sys/uvm/uvm_swap.c
--- a/sys/uvm/uvm_swap.c        Mon Feb 03 05:56:23 2014 +0000
+++ b/sys/uvm/uvm_swap.c        Mon Feb 03 13:20:20 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_swap.c,v 1.165 2013/11/23 14:50:40 christos Exp $  */
+/*     $NetBSD: uvm_swap.c,v 1.166 2014/02/03 13:20:21 manu Exp $      */
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.165 2013/11/23 14:50:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.166 2014/02/03 13:20:21 manu Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -237,8 +237,6 @@
 static int swap_on(struct lwp *, struct swapdev *);
 static int swap_off(struct lwp *, struct swapdev *);
 
-static void uvm_swap_stats(int, struct swapent *, int, register_t *);
-
 static void sw_reg_strategy(struct swapdev *, struct buf *, int);
 static void sw_reg_biodone(struct buf *);
 static void sw_reg_iodone(struct work *wk, void *dummy);
@@ -733,7 +731,7 @@
  * is not known at build time. Hence it would not be possible to
  * ensure it would fit in the stackgap in any case.
  */
-static void
+void
 uvm_swap_stats(int cmd, struct swapent *sep, int sec, register_t *retval)
 {
        struct swappri *spp;
diff -r e1bfcc2b18bb -r b9c8b2007751 sys/uvm/uvm_swap.h
--- a/sys/uvm/uvm_swap.h        Mon Feb 03 05:56:23 2014 +0000
+++ b/sys/uvm/uvm_swap.h        Mon Feb 03 13:20:20 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_swap.h,v 1.19 2013/11/23 14:32:13 christos Exp $   */
+/*     $NetBSD: uvm_swap.h,v 1.20 2014/02/03 13:20:21 manu Exp $       */
 
 /*
  * Copyright (c) 1997 Matthew R. Green
@@ -48,8 +48,10 @@
 void   uvm_swap_free(int, int);
 void   uvm_swap_markbad(int, int);
 bool   uvm_swapisfull(void);
+void   uvm_swap_stats(int, struct swapent *, int, register_t *);
 #else /* defined(VMSWAP) */
 #define        uvm_swapisfull()        true
+#define uvm_swap_stats(c, sep, count, retval) { *retval = 0; }
 #endif /* defined(VMSWAP) */
 void   uvm_swap_shutdown(struct lwp *);
 



Home | Main Index | Thread Index | Old Index