- cleanup FreeBSD ifdefs

- remove unused code
- adjust to NetBSD struct emul and types.
This commit is contained in:
christos 2015-03-07 15:14:09 +00:00
parent 17b686e266
commit c0342a4ea1
1 changed files with 60 additions and 166 deletions

View File

@ -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 @@ extern const char * const syscallnames[];
#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 int systrace_enable(void *, dtrace_id_t, void *);
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 @@ static dtrace_pops_t systrace_pops = {
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 @@ static dtrace_provider_id_t systrace_id;
* 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 @@ systrace_provide(void *arg, const dtrace_probedesc_t *desc)
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 @@ systrace_enable(void *arg, dtrace_id_t id, void *parg)
{
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 @@ systrace_disable(void *arg, dtrace_id_t id, void *parg)
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
EMUL.e_dtrace_syscall = NULL;
#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;
switch (type) {
case MOD_LOAD:
break;
case MOD_UNLOAD:
break;
case MOD_SHUTDOWN:
break;
default:
error = EOPNOTSUPP;
break;
}
return (error);
return error;
}
static int
systrace_open(struct cdev *dev __unused, int oflags __unused, int devtype __unused, struct thread *td __unused)
{
return (0);
}
SYSINIT(systrace_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, systrace_load, NULL);
SYSUNINIT(systrace_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, systrace_unload, NULL);
#ifdef LINUX_SYSTRACE
DEV_MODULE(linsystrace, systrace_modevent, NULL);
MODULE_VERSION(linsystrace, 1);
MODULE_DEPEND(linsystrace, linux, 1, 1, 1);
MODULE_DEPEND(linsystrace, systrace, 1, 1, 1);
MODULE_DEPEND(linsystrace, dtrace, 1, 1, 1);
MODULE_DEPEND(linsystrace, opensolaris, 1, 1, 1);
#else
DEV_MODULE(systrace, systrace_modevent, NULL);
MODULE_VERSION(systrace, 1);
MODULE_DEPEND(systrace, dtrace, 1, 1, 1);
MODULE_DEPEND(systrace, opensolaris, 1, 1, 1);
#endif
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
static int
systrace_modcmd(modcmd_t cmd, void *data)
MODCMD(modcmd_t cmd, void *data)
{
switch (cmd) {
case MODULE_CMD_INIT:
@ -371,14 +265,14 @@ systrace_modcmd(modcmd_t cmd, void *data)
return 0;
case MODULE_CMD_FINI:
systrace_unload();
return 0;
return systrace_unload();
case MODULE_CMD_AUTOUNLOAD:
return EBUSY;
default:
return ENOTTY;
}
}
MODULE(MODULE_CLASS_MISC, systrace, "dtrace");
#endif
MODULE(MODULE_CLASS_MISC, MODNAME, MODDEP)