Source-Changes-HG archive

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

[src/pgoyette-compat]: src/sys Clean-up some pre-existing function-pointer co...



details:   https://anonhg.NetBSD.org/src/rev/80a3f0a05b06
branches:  pgoyette-compat
changeset: 830735:80a3f0a05b06
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Fri Sep 21 02:56:22 2018 +0000

description:
Clean-up some pre-existing function-pointer code (related to if_43)
to use the new MP-safe mechanism.

diffstat:

 sys/compat/common/if43_20.c |  13 +++++++----
 sys/compat/common/if_43.c   |  50 +++++++++++++++++++++++++++-----------------
 sys/kern/compat_stub.c      |   9 +++++--
 sys/net/if.c                |  46 ++++++++++++++++-------------------------
 sys/sys/compat_stub.h       |  10 ++++++--
 5 files changed, 70 insertions(+), 58 deletions(-)

diffs (truncated from 342 to 300 lines):

diff -r d1fbb2b451b6 -r 80a3f0a05b06 sys/compat/common/if43_20.c
--- a/sys/compat/common/if43_20.c       Fri Sep 21 02:53:00 2018 +0000
+++ b/sys/compat/common/if43_20.c       Fri Sep 21 02:56:22 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if43_20.c,v 1.1.2.1 2018/03/30 02:28:49 pgoyette Exp $ */
+/*     $NetBSD: if43_20.c,v 1.1.2.2 2018/09/21 02:56:22 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if43_20.c,v 1.1.2.1 2018/03/30 02:28:49 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if43_20.c,v 1.1.2.2 2018/09/21 02:56:22 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -64,7 +64,7 @@
 #include <compat/common/compat_mod.h>
 
 static int
-if43_cvtcmd_20(int ncmd)
+if43_cvtcmd_20(u_long ncmd)
 {
 
        switch (ncmd) {
@@ -76,16 +76,19 @@
        }
 }
 
+MODULE_SET_HOOK(if43_20_hook, "if4320", if43_cvtcmd_20);
+MODULE_UNSET_HOOK(if43_20_hook);
+
 void
 if43_20_init(void)
 {
 
-       if43_20_cvtcmd = if43_cvtcmd_20;
+       if43_20_hook_set();
 }
 
 void
 if43_20_fini(void)
 {
 
-       if43_20_cvtcmd = (void *)enosys;
+       if43_20_hook_unset();
 }
diff -r d1fbb2b451b6 -r 80a3f0a05b06 sys/compat/common/if_43.c
--- a/sys/compat/common/if_43.c Fri Sep 21 02:53:00 2018 +0000
+++ b/sys/compat/common/if_43.c Fri Sep 21 02:56:22 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_43.c,v 1.14.2.4 2018/09/18 23:03:54 pgoyette Exp $  */
+/*     $NetBSD: if_43.c,v 1.14.2.5 2018/09/21 02:56:22 pgoyette Exp $  */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1990, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.14.2.4 2018/09/18 23:03:54 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_43.c,v 1.14.2.5 2018/09/21 02:56:22 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -77,13 +77,31 @@
 #include <compat/common/if_43.h>
 #include <uvm/uvm_extern.h>
 
-/* MODULE_HOOK for replacing the cmdcvt() function */
-MODULE_CALL_HOOK_DECL(ieee80211_get_ostats_20_hook, f, (int cmd), (cmd), cmd);
-MODULE_CALL_HOOK(ieee80211_get_ostats_20_hook, f, (int cmd), (cmd), cmd);
+#if defined(COMPAT_43)
+
+/*
+ * Hook for calling the if43_20 compatability routine.
+ *
+ * XXX The if43_20 routine doesn't really have any effect, since its
+ * XXX return value is ignored (see compat/common/if_43.c)!
+ */
+MODULE_CALL_HOOK_DECL(if43_20_hook, f, (u_long ncmd), (ncmd), enosys());
+MODULE_CALL_HOOK(if43_20_hook, f, (u_long ncmd), (ncmd), enosys());
 
-u_long 
+/* 
+ * Use a wrapper so that the compat_cvtcmd() can return a u_long
+ */
+static int 
+do_compat_cvtcmd(u_long *ncmd, u_long ocmd)
+{ 
+
+       *ncmd = compat_cvtcmd(ocmd);
+       return 0;
+}
+
+u_long
 compat_cvtcmd(u_long cmd)
-{ 
+{
        u_long ncmd;
 
        if (IOCPARM_LEN(cmd) != sizeof(struct oifreq))
@@ -206,7 +224,8 @@
                case TAPGIFNAME:
                        return ncmd;
                default:
-                       return ieee80211_get_ostats_20_hook_f_call(ncmd);
+                       (void)if43_20_hook_f_call(ncmd);
+                       return ncmd;
                }
        }
 }
@@ -282,27 +301,20 @@
        return error;
 }
 
-#if defined(COMPAT_43)
-static u_long (*orig_compat_cvtcmd)(u_long);
-static int (*orig_compat_ifioctl)(struct socket *, u_long, u_long,
-    void *, struct lwp *);
+MODULE_SET_HOOK2(if_43_hook, "if_43", do_compat_cvtcmd, compat_ifioctl);
+MODULE_UNSET_HOOK2(if_43_hook);
 
 void
 if_43_init(void)
 {
 
-       orig_compat_cvtcmd = vec_compat_cvtcmd;
-       vec_compat_cvtcmd = compat_cvtcmd;
-
-       orig_compat_ifioctl = vec_compat_ifioctl;
-       vec_compat_ifioctl =  compat_ifioctl;
+       if_43_hook_set();
 }
 
 void
 if_43_fini(void)
 {
 
-       vec_compat_cvtcmd = orig_compat_cvtcmd;
-       vec_compat_ifioctl = orig_compat_ifioctl;
+       if_43_hook_unset();
 }
 #endif /* defined(COMPAT_43) */
diff -r d1fbb2b451b6 -r 80a3f0a05b06 sys/kern/compat_stub.c
--- a/sys/kern/compat_stub.c    Fri Sep 21 02:53:00 2018 +0000
+++ b/sys/kern/compat_stub.c    Fri Sep 21 02:56:22 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.c,v 1.1.2.21 2018/09/20 07:34:10 pgoyette Exp $        */
+/* $NetBSD: compat_stub.c,v 1.1.2.22 2018/09/21 02:56:22 pgoyette Exp $        */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -139,6 +139,11 @@
 struct if_43_hook_t if_43_hook;
 
 /*
+ * if43_20 compatability
+ */
+struct if43_20_hook_t if43_20_hook;
+
+/*
  * upic_syscalls_40 compatability
  */
 struct uipc_syscalls_40_hook_t uipc_syscalls_40_hook;
@@ -148,8 +153,6 @@
  */
 struct uipc_syscalls_50_hook_t uipc_syscalls_50_hook;
 
-/*XXX PRG */int (*if43_20_cvtcmd)(int) = (void *)enosys;
-
 /*
  * rtsock 14 compatability
  */
diff -r d1fbb2b451b6 -r 80a3f0a05b06 sys/net/if.c
--- a/sys/net/if.c      Fri Sep 21 02:53:00 2018 +0000
+++ b/sys/net/if.c      Fri Sep 21 02:56:22 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.419.2.12 2018/09/20 09:23:22 pgoyette Exp $   */
+/*     $NetBSD: if.c,v 1.419.2.13 2018/09/21 02:56:22 pgoyette Exp $   */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.419.2.12 2018/09/20 09:23:22 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.419.2.13 2018/09/21 02:56:22 pgoyette Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -243,11 +243,6 @@
 
 static void if_sysctl_setup(struct sysctllog **);
 
-/* Compatibility vector functions */
-u_long (*vec_compat_cvtcmd)(u_long) = NULL;
-int (*vec_compat_ifioctl)(struct socket *, u_long, u_long, void *,
-       struct lwp *) = NULL;
-
 static int
 if_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
     void *arg0, void *arg1, void *arg2, void *arg3)
@@ -3119,6 +3114,18 @@
 MODULE_CALL_HOOK(uipc_syscalls_50_hook, f,
     (struct lwp *l, int cmd, void *data), (l, cmd, data), enosys());
 
+MODULE_CALL_HOOK_DECL(if_43_hook, f1,
+    (u_long *ncmd, u_long ocmd), (ncmd, ocmd), enosys());
+MODULE_CALL_HOOK(if_43_hook, f1,
+    (u_long *ncmd, u_long ocmd), (ncmd, ocmd), enosys());
+
+MODULE_CALL_HOOK_DECL(if_43_hook, f2,
+    (struct socket *so, u_long ocmd, u_long cmd, void *data, struct lwp *l),
+    (so, ocmd, cmd, data, l), enosys());
+MODULE_CALL_HOOK(if_43_hook, f2,
+    (struct socket *so, u_long ocmd, u_long cmd, void *data, struct lwp *l),
+    (so, ocmd, cmd, data, l), enosys());
+
 /*
  * Interface ioctls.
  */
@@ -3128,14 +3135,10 @@
        struct ifnet *ifp;
        struct ifreq *ifr;
        int error = 0;
-#if defined(COMPAT_OSOCK) || defined(COMPAT_OIFREQ)
        u_long ocmd = cmd;
-#endif
        short oif_flags;
-#ifdef COMPAT_OIFREQ
        struct ifreq ifrb;
        struct oifreq *oifr = NULL;
-#endif
        int r;
        struct psref psref;
        int bound;
@@ -3157,16 +3160,13 @@
        }
 
        ifr = data;
-#ifdef COMPAT_OIFREQ
-       if (vec_compat_cvtcmd) {
-               cmd = (*vec_compat_cvtcmd)(cmd);
+       if (if_43_hook_f1_call(&cmd, ocmd) != ENOSYS) {
                if (cmd != ocmd) {
                        oifr = data;
                        data = ifr = &ifrb;
                        ifreqo2n(oifr, ifr);
                }
        }
-#endif
 
        switch (cmd) {
        case SIOCIFCREATE:
@@ -3259,11 +3259,8 @@
                error = EOPNOTSUPP;
        else {
                KERNEL_LOCK_IF_IFP_MPSAFE(ifp);
-#ifdef COMPAT_OSOCK
-               if (vec_compat_ifioctl != NULL)
-                       error = (*vec_compat_ifioctl)(so, ocmd, cmd, data, l);
-               else
-#endif
+               error = if_43_hook_f2_call(so, ocmd, cmd, data, l);
+               if (error == ENOSYS)
                        error = (*so->so_proto->pr_usrreqs->pr_ioctl)(so,
                            cmd, data, ifp);
                KERNEL_UNLOCK_IF_IFP_MPSAFE(ifp);
@@ -3276,10 +3273,8 @@
                        splx(s);
                }
        }
-#ifdef COMPAT_OIFREQ
        if (cmd != ocmd)
                ifreqn2o(oifr, ifr);
-#endif
 
        IFNET_UNLOCK(ifp);
        KERNEL_UNLOCK_UNLESS_IFP_MPSAFE(ifp);
@@ -3414,13 +3409,11 @@
 ifreq_setaddr(u_long cmd, struct ifreq *ifr, const struct sockaddr *sa)
 {
        uint8_t len = sizeof(ifr->ifr_ifru.ifru_space);
-#ifdef COMPAT_OIFREQ
        struct ifreq ifrb;
        struct oifreq *oifr = NULL;
        u_long ocmd = cmd;
 
-       if (vec_compat_cvtcmd) {
-               cmd = (*vec_compat_cvtcmd)(cmd);
+       if (if_43_hook_f1_call(&cmd, ocmd) != ENOSYS) {
                if (cmd != ocmd) {
                        oifr = (struct oifreq *)(void *)ifr;
                        ifr = &ifrb;
@@ -3429,17 +3422,14 @@
                }



Home | Main Index | Thread Index | Old Index