Source-Changes-HG archive

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

[src/pgoyette-compat]: src/sys/sys Split the HOOK-related macros out from the...



details:   https://anonhg.NetBSD.org/src/rev/d8156dd71555
branches:  pgoyette-compat
changeset: 830721:d8156dd71555
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Sep 18 03:32:35 2018 +0000

description:
Split the HOOK-related macros out from the declarations.

We'll need the macros for compat32, but won't want the declarations.

diffstat:

 sys/sys/compat_hook.h |  187 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sys/sys/compat_stub.h |  154 +----------------------------------------
 2 files changed, 189 insertions(+), 152 deletions(-)

diffs (truncated from 359 to 300 lines):

diff -r 8528aa7dd8d6 -r d8156dd71555 sys/sys/compat_hook.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/sys/compat_hook.h     Tue Sep 18 03:32:35 2018 +0000
@@ -0,0 +1,187 @@
+/* $NetBSD: compat_hook.h,v 1.1.2.1 2018/09/18 03:32:35 pgoyette Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Paul Goyette
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_COMPAT_HOOK_H
+#define _SYS_COMPAT_HOOK_H
+
+#include <sys/param.h> /* for COHERENCY_UNIT, for __cacheline_aligned */
+#include <sys/mutex.h>
+#include <sys/localcount.h>
+#include <sys/condvar.h>
+#include <sys/pserialize.h>
+#include <sys/atomic.h>
+
+/*
+ * Macros for creating MP-safe vectored function calls, where
+ * the function implementations are in modules which could be
+ * unloaded.
+ */
+
+#define COMPAT_HOOK(hook,args)                                 \
+extern struct hook ## _t {                                     \
+       kmutex_t                mtx;                            \
+       kcondvar_t              cv;                             \
+       struct localcount       lc;                             \
+       pserialize_t            psz;                            \
+        bool                   hooked;                         \
+       int                     (*f)args;                       \
+} hook __cacheline_aligned;
+
+#define COMPAT_HOOK2(hook,args1,args2)                         \
+extern struct hook ## _t {                                     \
+       kmutex_t                mtx;                            \
+       kcondvar_t              cv;                             \
+       struct localcount       lc;                             \
+       pserialize_t            psz;                            \
+        bool                   hooked;                         \
+       int                     (*f1)args1;                     \
+       int                     (*f2)args2;                     \
+} hook __cacheline_aligned;
+
+#define COMPAT_SET_HOOK(hook, waitchan, func)                  \
+static void hook ## _set(void);                                        \
+static void hook ## _set(void)                                 \
+{                                                              \
+                                                               \
+       KASSERT(!hook.hooked);                                  \
+                                                               \
+       hook.psz = pserialize_create();                         \
+       mutex_init(&hook.mtx, MUTEX_DEFAULT, IPL_NONE);         \
+       cv_init(&hook.cv, waitchan);                            \
+       localcount_init(&hook.lc);                              \
+       hook.f = func;                                          \
+                                                               \
+       /* Make sure it's initialized before anyone uses it */  \
+       membar_producer();                                      \
+                                                               \
+       /* Let them use it */                                   \
+       hook.hooked = true;                                     \
+}
+
+#define COMPAT_SET_HOOK2(hook, waitchan, func1, func2)         \
+static void hook ## _set(void);                                        \
+static void hook ## _set(void)                                 \
+{                                                              \
+                                                               \
+       KASSERT(!hook.hooked);                                  \
+                                                               \
+       hook.psz = pserialize_create();                         \
+       mutex_init(&hook.mtx, MUTEX_DEFAULT, IPL_NONE);         \
+       cv_init(&hook.cv, waitchan);                            \
+       localcount_init(&hook.lc);                              \
+       hook.f1 = func1;                                        \
+       hook.f2 = func2;                                        \
+                                                               \
+       /* Make sure it's initialized before anyone uses it */  \
+       membar_producer();                                      \
+                                                               \
+       /* Let them use it */                                   \
+       hook.hooked = true;                                     \
+}
+
+#define COMPAT_UNSET_HOOK(hook)                                        \
+static void (hook ## _unset)(void);                            \
+static void (hook ## _unset)(void)                             \
+{                                                              \
+                                                               \
+       KASSERT(kernconfig_is_held());                          \
+       KASSERT(hook.hooked);                                   \
+       KASSERT(hook.f);                                        \
+                                                               \
+       /* Prevent new localcount_acquire calls.  */            \
+       hook.hooked = false;                                    \
+                                                               \
+       /* Wait for existing localcount_acquire calls to drain.  */ \
+       pserialize_perform(hook.psz);                           \
+                                                               \
+       /* Wait for existing localcount references to drain.  */\
+       localcount_drain(&hook.lc, &hook.cv, &hook.mtx);        \
+                                                               \
+       localcount_fini(&hook.lc);                              \
+       cv_destroy(&hook.cv);                                   \
+       mutex_destroy(&hook.mtx);                               \
+       pserialize_destroy(hook.psz);                           \
+}
+
+#define COMPAT_UNSET_HOOK2(hook)                               \
+static void (hook ## _unset)(void);                            \
+static void (hook ## _unset)(void)                             \
+{                                                              \
+                                                               \
+       KASSERT(kernconfig_is_held());                          \
+       KASSERT(hook.hooked);                                   \
+       KASSERT(hook.f1);                                       \
+       KASSERT(hook.f2);                                       \
+                                                               \
+       /* Prevent new localcount_acquire calls.  */            \
+       hook.hooked = false;                                    \
+                                                               \
+       /* Wait for existing localcount_acquire calls to drain.  */ \
+       pserialize_perform(hook.psz);                           \
+                                                               \
+       /* Wait for existing localcount references to drain.  */\
+       localcount_drain(&hook.lc, &hook.cv, &hook.mtx);        \
+                                                               \
+       localcount_fini(&hook.lc);                              \
+       cv_destroy(&hook.cv);                                   \
+       mutex_destroy(&hook.mtx);                               \
+       pserialize_destroy(hook.psz);                           \
+}
+
+#define COMPAT_CALL_HOOK_DECL(hook, which, decl, args, default)        \
+int                                                            \
+hook ## _ ## which ## _call decl;
+#define COMPAT_CALL_HOOK(hook, which, decl, args, default)     \
+int                                                            \
+hook ## _ ## which ## _call decl                               \
+{                                                              \
+       bool hooked;                                            \
+       int error, s;                                           \
+                                                               \
+       s = pserialize_read_enter();                            \
+       hooked = hook.hooked;                                   \
+       if (hooked) {                                           \
+               membar_consumer();                              \
+               localcount_acquire(&hook.lc);                   \
+       }                                                       \
+       pserialize_read_exit(s);                                \
+                                                               \
+       if (hooked) {                                           \
+               error = (*hook.which)args;                      \
+               localcount_release(&hook.lc, &hook.cv,          \
+                   &hook.mtx);                                 \
+       } else {                                                \
+               error = default;                                \
+       }                                                       \
+       return error;                                           \
+}
+
+#endif /* _SYS_COMPAT_HOOK_H */
diff -r 8528aa7dd8d6 -r d8156dd71555 sys/sys/compat_stub.h
--- a/sys/sys/compat_stub.h     Tue Sep 18 01:15:57 2018 +0000
+++ b/sys/sys/compat_stub.h     Tue Sep 18 03:32:35 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_stub.h,v 1.1.2.24 2018/09/18 01:15:58 pgoyette Exp $        */
+/* $NetBSD: compat_stub.h,v 1.1.2.25 2018/09/18 03:32:35 pgoyette Exp $        */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,157 +32,7 @@
 #ifndef _SYS_COMPAT_STUB_H
 #define _SYS_COMPAT_STUB_H
 
-#include <sys/param.h> /* for COHERENCY_UNIT, for __cacheline_aligned */
-#include <sys/mutex.h>
-#include <sys/localcount.h>
-#include <sys/condvar.h>
-#include <sys/pserialize.h>
-#include <sys/atomic.h>
-
-/*
- * Macros for creating MP-safe vectored function calls, where
- * the function implementations are in modules which could be
- * unloaded.
- */
-
-#define COMPAT_HOOK(hook,args)                                 \
-extern struct hook ## _t {                                     \
-       kmutex_t                mtx;                            \
-       kcondvar_t              cv;                             \
-       struct localcount       lc;                             \
-       pserialize_t            psz;                            \
-        bool                   hooked;                         \
-       int                     (*f)args;                       \
-} hook __cacheline_aligned;
-
-#define COMPAT_HOOK2(hook,args1,args2)                         \
-extern struct hook ## _t {                                     \
-       kmutex_t                mtx;                            \
-       kcondvar_t              cv;                             \
-       struct localcount       lc;                             \
-       pserialize_t            psz;                            \
-        bool                   hooked;                         \
-       int                     (*f1)args1;                     \
-       int                     (*f2)args2;                     \
-} hook __cacheline_aligned;
-
-#define COMPAT_SET_HOOK(hook, waitchan, func)                  \
-static void hook ## _set(void);                                        \
-static void hook ## _set(void)                                 \
-{                                                              \
-                                                               \
-       KASSERT(!hook.hooked);                                  \
-                                                               \
-       hook.psz = pserialize_create();                         \
-       mutex_init(&hook.mtx, MUTEX_DEFAULT, IPL_NONE);         \
-       cv_init(&hook.cv, waitchan);                            \
-       localcount_init(&hook.lc);                              \
-       hook.f = func;                                          \
-                                                               \
-       /* Make sure it's initialized before anyone uses it */  \
-       membar_producer();                                      \
-                                                               \
-       /* Let them use it */                                   \
-       hook.hooked = true;                                     \
-}
-
-#define COMPAT_SET_HOOK2(hook, waitchan, func1, func2)         \
-static void hook ## _set(void);                                        \
-static void hook ## _set(void)                                 \
-{                                                              \
-                                                               \
-       KASSERT(!hook.hooked);                                  \
-                                                               \
-       hook.psz = pserialize_create();                         \
-       mutex_init(&hook.mtx, MUTEX_DEFAULT, IPL_NONE);         \
-       cv_init(&hook.cv, waitchan);                            \
-       localcount_init(&hook.lc);                              \
-       hook.f1 = func1;                                        \
-       hook.f2 = func2;                                        \
-                                                               \
-       /* Make sure it's initialized before anyone uses it */  \
-       membar_producer();                                      \
-                                                               \
-       /* Let them use it */                                   \
-       hook.hooked = true;                                     \
-}
-
-#define COMPAT_UNSET_HOOK(hook)                                        \
-static void (hook ## _unset)(void);                            \
-static void (hook ## _unset)(void)                             \
-{                                                              \
-                                                               \
-       KASSERT(kernconfig_is_held());                          \
-       KASSERT(hook.hooked);                                   \
-       KASSERT(hook.f);                                        \
-                                                               \
-       /* Prevent new localcount_acquire calls.  */            \
-       hook.hooked = false;                                    \
-                                                               \
-       /* Wait for existing localcount_acquire calls to drain.  */ \
-       pserialize_perform(hook.psz);                           \
-                                                               \
-       /* Wait for existing localcount references to drain.  */\
-       localcount_drain(&hook.lc, &hook.cv, &hook.mtx);        \
-                                                               \
-       localcount_fini(&hook.lc);                              \
-       cv_destroy(&hook.cv);                                   \
-       mutex_destroy(&hook.mtx);                               \



Home | Main Index | Thread Index | Old Index