Module Name:    src
Committed By:   manu
Date:           Mon Feb  3 13:20:21 UTC 2014

Modified Files:
        src/sys/compat/netbsd32: netbsd32_netbsd.c
        src/sys/uvm: uvm_swap.c uvm_swap.h

Log Message:
Properly translate struct swapent for COMPAT_NETBSD32


To generate a diff of this commit:
cvs rdiff -u -r1.183 -r1.184 src/sys/compat/netbsd32/netbsd32_netbsd.c
cvs rdiff -u -r1.165 -r1.166 src/sys/uvm/uvm_swap.c
cvs rdiff -u -r1.19 -r1.20 src/sys/uvm/uvm_swap.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_netbsd.c
diff -u src/sys/compat/netbsd32/netbsd32_netbsd.c:1.183 src/sys/compat/netbsd32/netbsd32_netbsd.c:1.184
--- src/sys/compat/netbsd32/netbsd32_netbsd.c:1.183	Sat Jan 25 03:31:12 2014
+++ src/sys/compat/netbsd32/netbsd32_netbsd.c	Mon Feb  3 13:20:20 2014
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_net
 #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 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_net
 #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 @@ netbsd32___posix_rename(struct lwp *l, c
 	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 @@ netbsd32_swapctl(struct lwp *l, const st
 	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));
 }
 

Index: src/sys/uvm/uvm_swap.c
diff -u src/sys/uvm/uvm_swap.c:1.165 src/sys/uvm/uvm_swap.c:1.166
--- src/sys/uvm/uvm_swap.c:1.165	Sat Nov 23 14:50:40 2013
+++ src/sys/uvm/uvm_swap.c	Mon Feb  3 13:20:21 2014
@@ -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 void		 swaplist_trim(void);
 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 @@ out:
  * 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;

Index: src/sys/uvm/uvm_swap.h
diff -u src/sys/uvm/uvm_swap.h:1.19 src/sys/uvm/uvm_swap.h:1.20
--- src/sys/uvm/uvm_swap.h:1.19	Sat Nov 23 14:32:13 2013
+++ src/sys/uvm/uvm_swap.h	Mon Feb  3 13:20:21 2014
@@ -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 @@ int	uvm_swap_alloc(int *, bool);
 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 *);
 

Reply via email to