Source-Changes-HG archive

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

[src/trunk]: src/external/cddl/osnet/dev/systrace - cleanup FreeBSD ifdefs



details:   https://anonhg.NetBSD.org/src/rev/9c77f1a76356
branches:  trunk
changeset: 336588:9c77f1a76356
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Mar 07 15:14:09 2015 +0000

description:
- cleanup FreeBSD ifdefs
- remove unused code
- adjust to NetBSD struct emul and types.

diffstat:

 external/cddl/osnet/dev/systrace/systrace.c |  226 +++++++--------------------
 1 files changed, 60 insertions(+), 166 deletions(-)

diffs (truncated from 354 to 300 lines):

diff -r 110d31a35446 -r 9c77f1a76356 external/cddl/osnet/dev/systrace/systrace.c
--- a/external/cddl/osnet/dev/systrace/systrace.c       Sat Mar 07 15:13:04 2015 +0000
+++ b/external/cddl/osnet/dev/systrace/systrace.c       Sat Mar 07 15:14:09 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: systrace.c,v 1.4 2014/01/12 17:49:30 riz Exp $ */
+/*     $NetBSD: systrace.c,v 1.5 2015/03/07 15:14:09 christos Exp $    */
 
 /*
  * CDDL HEADER START
@@ -38,9 +38,6 @@
 #include <sys/cpuvar.h>
 #include <sys/fcntl.h>
 #include <sys/filio.h>
-#ifdef __FreeBSD__
-#include <sys/kdb.h>
-#endif
 #include <sys/kernel.h>
 #include <sys/kmem.h>
 #include <sys/kthread.h>
@@ -53,44 +50,40 @@
 #include <sys/poll.h>
 #include <sys/proc.h>
 #include <sys/selinfo.h>
-#ifdef __FreeBSD__
-#include <sys/smp.h>
-#include <sys/sysproto.h>
-#include <sys/sysent.h>
-#endif
 #include <sys/syscallargs.h>
 #include <sys/uio.h>
 #include <sys/unistd.h>
 
 #include <sys/dtrace.h>
 
-#ifdef LINUX_SYSTRACE
-#include <linux.h>
-#include <linux_syscall.h>
-#include <linux_proto.h>
-#include <linux_syscallnames.c>
-#include <linux_systrace.c>
-extern struct sysent linux_sysent[];
-#define        DEVNAME         "dtrace/linsystrace"
-#define        PROVNAME        "linsyscall"
-#define        MAXSYSCALL      LINUX_SYS_MAXSYSCALL
-#define        SYSCALLNAMES    linux_syscallnames
-#define        SYSENT          linux_sysent
+#include "emultrace.h"
+
+#define        CONCAT(x,y)     __CONCAT(x,y)
+#define        STRING(s)       __STRING(s)
+
+#ifndef NATIVE
+extern const char      * const CONCAT(emulname,_syscallnames)[];
+extern         struct sysent   CONCAT(emulname,_sysent)[];
+#define        MODNAME         CONCAT(dtrace_syscall_,emulname)
+#define        MODDEP          "dtrace_syscall,compat_" STRING(emulname)
+#define        MAXSYSCALL      CONCAT(EMULNAME,_SYS_MAXSYSCALL)
+#define        SYSCALLNAMES    CONCAT(emulname,_syscallnames)
+#define        SYSENT          CONCAT(emulname,_sysent)
+#define        PROVNAME        STRING(emulname) "_syscall"
 #else
-/*
- * The syscall arguments are processed into a DTrace argument array
- * using a generated function. See sys/kern/makesyscalls.sh.
- */
-#include <sys/syscall.h>
-#include <kern/systrace_args.c>
 extern const char      * const syscallnames[];
-#define        DEVNAME         "dtrace/systrace"
-#define        PROVNAME        "syscall"
+#define        MODNAME         dtrace_syscall
+#define        MODDEP          "dtrace"
 #define        MAXSYSCALL      SYS_MAXSYSCALL
 #define        SYSCALLNAMES    syscallnames
 #define        SYSENT          sysent
+#define        PROVNAME        "syscall"
 #endif
 
+#define        MODCMD          CONCAT(MODNAME,_modcmd)
+#define EMUL           CONCAT(emul_,emulname)
+extern struct emul     EMUL;
+
 #define        SYSTRACE_ARTIFICIAL_FRAMES      1
 
 #define        SYSTRACE_SHIFT                  16
@@ -103,9 +96,6 @@
 #error 1 << SYSTRACE_SHIFT must exceed number of system calls
 #endif
 
-#ifdef __FreeBSD__
-static d_open_t        systrace_open;
-#endif
 static int     systrace_unload(void);
 static void    systrace_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *);
 static void    systrace_provide(void *, const dtrace_probedesc_t *);
@@ -114,23 +104,6 @@
 static void    systrace_disable(void *, dtrace_id_t, void *);
 static void    systrace_load(void *);
 
-#ifdef __FreeBSD__
-static struct cdevsw systrace_cdevsw = {
-       .d_version      = D_VERSION,
-       .d_open         = systrace_open,
-#ifdef LINUX_SYSTRACE
-       .d_name         = "linsystrace",
-#else
-       .d_name         = "systrace",
-#endif
-};
-#endif
-
-static union   {
-       const char      * const *p_constnames;
-       char            **pp_syscallnames;
-} uglyhack = { SYSCALLNAMES };
-
 static dtrace_pattr_t systrace_attr = {
 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
@@ -152,12 +125,8 @@
        systrace_destroy
 };
 
-#ifdef __FreeBSD__
-static struct cdev             *systrace_cdev;
-#endif
 static dtrace_provider_id_t    systrace_id;
 
-#if !defined(LINUX_SYSTRACE)
 /*
  * Probe callback function.
  *
@@ -166,48 +135,40 @@
  *       compat syscall from something like Linux.
  */
 static void
-systrace_probe(u_int32_t id, int sysnum, struct sysent *se, void *params)
+systrace_probe(uint32_t id, register_t sysnum, const struct sysent *se,
+    const void *params, const register_t *ret, int error)
 {
-       int             n_args  = 0;
-       union systrace_probe_args_un    uargs[SYS_MAXSYSARGS];
+       size_t          n_args  = 0;
+       uintptr_t       uargs[SYS_MAXSYSARGS];
 
-       /*
-        * Check if this syscall has an argument conversion function
-        * registered.
-        */
-       if (se->sy_systrace_args_func != NULL)
-               /*
-                * Convert the syscall parameters using the registered
-                * function.
-                */
-               (*se->sy_systrace_args_func)(sysnum, params, uargs, &n_args);
-       else
-               /*
-                * Use the built-in system call argument conversion
-                * function to translate the syscall structure fields
-                * into the array of 64-bit values that DTrace 
-                * expects.
-                */
+       memset(uargs, 0, sizeof(uargs));
+       if (params) {
+               /* entry syscall, convert params */
                systrace_args(sysnum, params, uargs, &n_args);
-
+       } else {
+               /* return syscall, set values (XXX: errno?) */
+               uargs[0] = ret[0];
+               uargs[1] = ret[1];
+               uargs[2] = error;
+       }
        /* Process the probe using the converted argments. */
-       dtrace_probe(id, uargs[0].u, uargs[1].u, uargs[2].u, uargs[3].u,
-               uargs[4].u);
+       /* XXX: fix for more arguments! */
+       dtrace_probe(id, uargs[0], uargs[1], uargs[2], uargs[3], uargs[4]);
 }
-#endif
 
 static void
 systrace_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
 {
        int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
-
-       systrace_setargdesc(sysnum, desc->dtargd_ndx, desc->dtargd_native,
-           sizeof(desc->dtargd_native));
+       if (SYSTRACE_ISENTRY((uintptr_t)parg))
+               systrace_entry_setargdesc(sysnum, desc->dtargd_ndx, 
+                   desc->dtargd_native, sizeof(desc->dtargd_native));
+       else
+               systrace_return_setargdesc(sysnum, desc->dtargd_ndx, 
+                   desc->dtargd_native, sizeof(desc->dtargd_native));
 
        if (desc->dtargd_native[0] == '\0')
                desc->dtargd_ndx = DTRACE_ARGNONE;
-
-       return;
 }
 
 static void
@@ -220,15 +181,15 @@
 
        for (i = 0; i < MAXSYSCALL; i++) {
                if (dtrace_probe_lookup(systrace_id, NULL,
-                   uglyhack.pp_syscallnames[i], "entry") != 0)
+                   SYSCALLNAMES[i], "entry") != 0)
                        continue;
 
-               (void) dtrace_probe_create(systrace_id, NULL, uglyhack.pp_syscallnames[i],
-                   "entry", SYSTRACE_ARTIFICIAL_FRAMES,
-                   (void *)((uintptr_t)SYSTRACE_ENTRY(i)));
-               (void) dtrace_probe_create(systrace_id, NULL, uglyhack.pp_syscallnames[i],
-                   "return", SYSTRACE_ARTIFICIAL_FRAMES,
-                   (void *)((uintptr_t)SYSTRACE_RETURN(i)));
+               (void) dtrace_probe_create(systrace_id, NULL,
+                   SYSCALLNAMES[i], "entry", SYSTRACE_ARTIFICIAL_FRAMES,
+                   (void *)(intptr_t)SYSTRACE_ENTRY(i));
+               (void) dtrace_probe_create(systrace_id, NULL,
+                   SYSCALLNAMES[i], "return", SYSTRACE_ARTIFICIAL_FRAMES,
+                   (void *)(intptr_t)SYSTRACE_RETURN(i));
        }
 }
 
@@ -255,9 +216,6 @@
 {
        int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
 
-       if (SYSENT[sysnum].sy_systrace_args_func == NULL)
-               SYSENT[sysnum].sy_systrace_args_func = systrace_args;
-
        if (SYSTRACE_ISENTRY((uintptr_t)parg))
                SYSENT[sysnum].sy_entry = id;
        else
@@ -277,93 +235,29 @@
 static void
 systrace_load(void *dummy)
 {
-#ifdef __FreeBSD__
-       /* Create the /dev/dtrace/systrace entry. */
-       systrace_cdev = make_dev(&systrace_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
-          DEVNAME);
-#endif
-
        if (dtrace_register(PROVNAME, &systrace_attr, DTRACE_PRIV_USER,
            NULL, &systrace_pops, NULL, &systrace_id) != 0)
                return;
 
-#if !defined(LINUX_SYSTRACE)
-       systrace_probe_func = (systrace_probe_func_t)systrace_probe;
-#endif
+       EMUL.e_dtrace_syscall = systrace_probe;
 }
 
 
 static int
 systrace_unload()
 {
-       int error = 0;
+       int error;
 
        if ((error = dtrace_unregister(systrace_id)) != 0)
                return (error);
 
-#if !defined(LINUX_SYSTRACE)
-       systrace_probe_func = NULL;
-#endif
-
-#ifdef __FreeBSD__
-       destroy_dev(systrace_cdev);
-#endif
-
-       return (error);
-}
-
-#ifdef __FreeBSD__
-static int
-systrace_modevent(module_t mod __unused, int type, void *data __unused)
-{
-       int error = 0;
+       EMUL.e_dtrace_syscall = NULL;
 
-       switch (type) {
-       case MOD_LOAD:
-               break;
-
-       case MOD_UNLOAD:
-               break;
-
-       case MOD_SHUTDOWN:
-               break;
-
-       default:
-               error = EOPNOTSUPP;
-               break;
-
-       }
-       return (error);
+       return error;



Home | Main Index | Thread Index | Old Index