Module Name:    src
Committed By:   pgoyette
Date:           Sat Sep 22 10:33:51 UTC 2018

Modified Files:
        src/sys/opencrypto [pgoyette-compat]: cryptodev.c ocryptodev.c
            ocryptodev.h
        src/sys/sys [pgoyette-compat]: compat_stub.h

Log Message:
When the compat code needs to callback to the original code, we cannot
call directly via the routines' global symbols, since the original code
might not be built-in.  So, the original code that calls compat code
needs to pass in the addresses of the callbacks.  This allows for the
compat code to be built whether or not the original (calling) code is
included.

XXX Done for cryptodev, will need to do the same thing for ccd(4) and
XXX vnd(4)


To generate a diff of this commit:
cvs rdiff -u -r1.98.2.4 -r1.98.2.5 src/sys/opencrypto/cryptodev.c
cvs rdiff -u -r1.11.2.3 -r1.11.2.4 src/sys/opencrypto/ocryptodev.c
cvs rdiff -u -r1.3.16.1 -r1.3.16.2 src/sys/opencrypto/ocryptodev.h
cvs rdiff -u -r1.1.2.33 -r1.1.2.34 src/sys/sys/compat_stub.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/opencrypto/cryptodev.c
diff -u src/sys/opencrypto/cryptodev.c:1.98.2.4 src/sys/opencrypto/cryptodev.c:1.98.2.5
--- src/sys/opencrypto/cryptodev.c:1.98.2.4	Tue Sep 18 23:03:55 2018
+++ src/sys/opencrypto/cryptodev.c	Sat Sep 22 10:33:50 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cryptodev.c,v 1.98.2.4 2018/09/18 23:03:55 pgoyette Exp $ */
+/*	$NetBSD: cryptodev.c,v 1.98.2.5 2018/09/22 10:33:50 pgoyette Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $	*/
 /*	$OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $	*/
 
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.98.2.4 2018/09/18 23:03:55 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptodev.c,v 1.98.2.5 2018/09/22 10:33:50 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -219,11 +219,24 @@ cryptof_write(file_t *fp, off_t *poff,
 	return EIO;
 }
 
-/* Hook the ocryptodev 50 compat code */
+/*
+ * Hook the ocryptodev 50 compat code
+ *
+ * This is a bit messy because we need to pass local stuff to the
+ * compat routines.  The compat routines may be built-in to a
+ * kernel which doesn't contain the local stuff, so the compat
+ * code cannot directly reference them as globals.
+ */
 MODULE_CALL_HOOK_DECL(ocryptof_50_hook, f,
-    (struct file *fp, u_long cmd, void *data), (fp, cmd, data), enosys());
+    (struct file *fp, u_long cmd, void *data),
+    (fp, cmd, data, cryptodev_mtx, cryptodev_session, cryptodev_op,
+	cryptodev_mop, cryptodev_csefind),
+    enosys());
 MODULE_CALL_HOOK(ocryptof_50_hook, f,
-    (struct file *fp, u_long cmd, void *data), (fp, cmd, data), enosys());
+    (struct file *fp, u_long cmd, void *data),
+    (fp, cmd, data, &cryptodev_mtx, cryptodev_session, cryptodev_op,
+	cryptodev_mop, cryptodev_csefind),
+    enosys());
 
 /* ARGSUSED */
 int

Index: src/sys/opencrypto/ocryptodev.c
diff -u src/sys/opencrypto/ocryptodev.c:1.11.2.3 src/sys/opencrypto/ocryptodev.c:1.11.2.4
--- src/sys/opencrypto/ocryptodev.c:1.11.2.3	Tue Sep 18 23:03:55 2018
+++ src/sys/opencrypto/ocryptodev.c	Sat Sep 22 10:33:50 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ocryptodev.c,v 1.11.2.3 2018/09/18 23:03:55 pgoyette Exp $ */
+/*	$NetBSD: ocryptodev.c,v 1.11.2.4 2018/09/22 10:33:50 pgoyette Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/cryptodev.c,v 1.4.2.4 2003/06/03 00:09:02 sam Exp $	*/
 /*	$OpenBSD: cryptodev.c,v 1.53 2002/07/10 22:21:30 mickey Exp $	*/
 
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ocryptodev.c,v 1.11.2.3 2018/09/18 23:03:55 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ocryptodev.c,v 1.11.2.4 2018/09/22 10:33:50 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -101,14 +101,23 @@ __KERNEL_RCSID(0, "$NetBSD: ocryptodev.c
 #include <opencrypto/xform.h>
 
 static int	ocryptodev_op(struct csession *, struct ocrypt_op *,
-		    struct lwp *);
+		    struct lwp *, int (*)(struct csession *, 
+					struct crypt_op *, struct lwp *));
 static int	ocryptodev_mop(struct fcrypt *, struct ocrypt_n_op *, int,
-		    struct lwp *);
-static int	ocryptodev_session(struct fcrypt *, struct osession_op *);
-static int	ocryptodev_msession(struct fcrypt *, struct osession_n_op *, int);
+		    struct lwp *,
+		    int (*real_mop)(struct fcrypt *, struct crypt_n_op *,
+			 int, struct lwp *));
+static int	ocryptodev_session(struct fcrypt *, struct osession_op *,
+		    	int(*)(struct fcrypt *, struct session_op *));
+static int	ocryptodev_msession(struct fcrypt *, struct osession_n_op *,
+			int, int (*)(struct fcrypt *, struct session_op *));
 
 int
-ocryptof_ioctl(struct file *fp, u_long cmd, void *data)
+ocryptof_ioctl(struct file *fp, u_long cmd, void *data, kmutex_t *mtx,
+    int (*real_session)(struct fcrypt *, struct session_op *),
+    int (*real_op)(struct csession *, struct crypt_op *, struct lwp *),
+    int (*real_mop)(struct fcrypt *, struct crypt_n_op *, int, struct lwp *),
+    struct csession * (*real_csefind)(struct fcrypt *, u_int32_t))
 {
 	struct fcrypt *fcr = fp->f_fcrypt;
 	struct csession *cse;
@@ -124,7 +133,7 @@ ocryptof_ioctl(struct file *fp, u_long c
 	switch (cmd) {
 	case OCIOCGSESSION:
 		osop = (struct osession_op *)data;
-		error = ocryptodev_session(fcr, osop);
+		error = ocryptodev_session(fcr, osop, real_session);
 		break;
 	case CIOCNGSESSION:
 		osgop = (struct ocrypt_sgop *)data;
@@ -141,7 +150,8 @@ ocryptof_ioctl(struct file *fp, u_long c
 			goto mbail;
 		}
 
-		error = ocryptodev_msession(fcr, osnop, osgop->count);
+		error = ocryptodev_msession(fcr, osnop, osgop->count,
+		    real_session);
 		if (error) {
 			goto mbail;
 		}
@@ -154,13 +164,13 @@ mbail:
 	case OCIOCCRYPT:
 		mutex_enter(&cryptodev_mtx);
 		ocop = (struct ocrypt_op *)data;
-		cse = cryptodev_csefind(fcr, ocop->ses);
+		cse = (*real_csefind)(fcr, ocop->ses);
 		mutex_exit(&cryptodev_mtx);
 		if (cse == NULL) {
 			DPRINTF("csefind failed\n");
 			return EINVAL;
 		}
-		error = ocryptodev_op(cse, ocop, curlwp);
+		error = ocryptodev_op(cse, ocop, curlwp, real_op);
 		DPRINTF("ocryptodev_op error = %d\n", error);
 		break;
 	case OCIOCNCRYPTM:
@@ -175,7 +185,8 @@ mbail:
 		error = copyin(omop->reqs, ocnop,
 		    (omop->count * sizeof(struct ocrypt_n_op)));
 		if(!error) {
-			error = ocryptodev_mop(fcr, ocnop, omop->count, curlwp);
+			error = ocryptodev_mop(fcr, ocnop, omop->count,
+			    curlwp, real_mop);
 			if (!error) {
 				error = copyout(ocnop, omop->reqs, 
 				    (omop->count * sizeof(struct ocrypt_n_op)));
@@ -192,7 +203,8 @@ mbail:
 
 
 static int
-ocryptodev_op(struct csession *cse, struct ocrypt_op *ocop, struct lwp *l)
+ocryptodev_op(struct csession *cse, struct ocrypt_op *ocop, struct lwp *l,
+    int (*real_op)(struct csession *, struct crypt_op *, struct lwp *))
 {
 	struct crypt_op cop;
 
@@ -206,13 +218,15 @@ ocryptodev_op(struct csession *cse, stru
 	cop.iv = ocop->iv;
 	cop.dst_len = 0;
 
-	return cryptodev_op(cse, &cop, l);
+	return real_op(cse, &cop, l);
 };
 
 static int 
 ocryptodev_mop(struct fcrypt *fcr, 
               struct ocrypt_n_op *ocnop,
-              int count, struct lwp *l)
+              int count, struct lwp *l,
+	      int (*real_mop)(struct fcrypt *, struct crypt_n_op *, int,
+				struct lwp *))
 {
 	int res;
 
@@ -234,7 +248,7 @@ ocryptodev_mop(struct fcrypt *fcr, 
 	cnop.mac = ocnop->mac;
 	cnop.iv = ocnop->iv;
 	cnop.dst_len = 0;
-	res = cryptodev_mop(fcr, &cnop, count, l);
+	res = (*real_mop)(fcr, &cnop, count, l);
 	ocnop->reqid = cnop.reqid;
 	ocnop->status = cnop.status;
 
@@ -243,7 +257,8 @@ ocryptodev_mop(struct fcrypt *fcr, 
 
 
 static int
-ocryptodev_session(struct fcrypt *fcr, struct osession_op *osop) 
+ocryptodev_session(struct fcrypt *fcr, struct osession_op *osop,
+    int (*real_session)(struct fcrypt *, struct session_op *))
 {
 	struct session_op sop;
 	int res;
@@ -255,7 +270,7 @@ ocryptodev_session(struct fcrypt *fcr, s
 	sop.key = osop->key;
 	sop.mackeylen = osop->mackeylen;
 	sop.mackey = osop->mackey;
-	res = cryptodev_session(fcr, &sop);
+	res = (*real_session)(fcr, &sop);
 	if (res)
 		return res;
 	osop->ses = sop.ses;
@@ -265,7 +280,8 @@ ocryptodev_session(struct fcrypt *fcr, s
 
 static int
 ocryptodev_msession(struct fcrypt *fcr, struct osession_n_op *osn_ops,
-		   int count)
+		   int count,
+		   int (*real_session)(struct fcrypt *, struct session_op *))
 {
 	int i;
 
@@ -278,7 +294,7 @@ ocryptodev_msession(struct fcrypt *fcr, 
 		os_op.mackeylen =	osn_ops->mackeylen;
 		os_op.mackey =		osn_ops->mackey;
 
-		osn_ops->status = ocryptodev_session(fcr, &os_op);
+		osn_ops->status = ocryptodev_session(fcr, &os_op, real_session);
 		osn_ops->ses =		os_op.ses;
 	}
 

Index: src/sys/opencrypto/ocryptodev.h
diff -u src/sys/opencrypto/ocryptodev.h:1.3.16.1 src/sys/opencrypto/ocryptodev.h:1.3.16.2
--- src/sys/opencrypto/ocryptodev.h:1.3.16.1	Fri Mar 23 09:41:10 2018
+++ src/sys/opencrypto/ocryptodev.h	Sat Sep 22 10:33:50 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: ocryptodev.h,v 1.3.16.1 2018/03/23 09:41:10 pgoyette Exp $ */
+/*	$NetBSD: ocryptodev.h,v 1.3.16.2 2018/09/22 10:33:50 pgoyette Exp $ */
 /*	$FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $	*/
 /*	$OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $	*/
 
@@ -170,9 +170,11 @@ struct ocrypt_mop {
 #define OCIOCCRYPT	_IOWR('c', 103, struct ocrypt_op)
 #define OCIOCNCRYPTM	_IOWR('c', 107, struct ocrypt_mop)
 
-int ocryptof_ioctl(struct file *, u_long, void *);
-
-extern int (*ocryptof50_ioctl)(struct file *, u_long, void *);
+int ocryptof_ioctl(struct file *, u_long, void *, kmutex_t *,
+    int (*)(struct fcrypt *, struct session_op *),
+    int (*)(struct csession *, struct crypt_op *, struct lwp *),
+    int (*)(struct fcrypt *, struct crypt_n_op *, int, struct lwp *),
+    struct csession * (*)(struct fcrypt *, u_int32_t));
 
 void cryptodev_50_init(void);
 void cryptodev_50_fini(void);

Index: src/sys/sys/compat_stub.h
diff -u src/sys/sys/compat_stub.h:1.1.2.33 src/sys/sys/compat_stub.h:1.1.2.34
--- src/sys/sys/compat_stub.h:1.1.2.33	Fri Sep 21 03:42:20 2018
+++ src/sys/sys/compat_stub.h	Sat Sep 22 10:33:51 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.h,v 1.1.2.33 2018/09/21 03:42:20 pgoyette Exp $	*/
+/* $NetBSD: compat_stub.h,v 1.1.2.34 2018/09/22 10:33:51 pgoyette Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -86,7 +86,17 @@ MODULE_HOOK(sppp_params_50_hook, (struct
  * cryptodev compatability ioctl
  */
 
-MODULE_HOOK(ocryptof_50_hook, (struct file *, u_long, void *));
+struct fcrypt;
+struct session_op;
+struct csession;
+struct crypt_op;
+struct crypt_n_op;
+struct kmutex_t;
+MODULE_HOOK(ocryptof_50_hook, (struct file *, u_long, void *, kmutex_t *,
+    int (*)(struct fcrypt *, struct session_op *),
+    int (*)(struct csession *, struct crypt_op *, struct lwp *),
+    int (*)(struct fcrypt *, struct crypt_n_op *, int, struct lwp *),
+    struct csession * (*)(struct fcrypt *, u_int32_t)));
 
 /*
  * raidframe compatability

Reply via email to