[DTrace-devel] [PATCH] ioctl: remove obsolete ioctl definitions and ddead code that used them
Kris Van Hees
kris.van.hees at oracle.com
Wed Aug 21 17:27:07 UTC 2024
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
include/dtrace/ioctl.h | 23 -----
libdtrace/dt_probe.c | 132 ----------------------------
test/utils/Build | 2 +-
test/utils/baddof.c | 191 -----------------------------------------
4 files changed, 1 insertion(+), 347 deletions(-)
delete mode 100644 test/utils/baddof.c
diff --git a/include/dtrace/ioctl.h b/include/dtrace/ioctl.h
index a2a3a93b..2273453a 100644
--- a/include/dtrace/ioctl.h
+++ b/include/dtrace/ioctl.h
@@ -9,30 +9,7 @@
#define _DTRACE_IOCTL_H_
#include <linux/ioctl.h>
-#include <dtrace/arg.h>
-#include <dtrace/conf.h>
-#include <dtrace/dof.h>
-#include <dtrace/enabling.h>
#include <dtrace/helpers.h>
-#include <dtrace/metadesc.h>
-#include <dtrace/stability.h>
-#include <dtrace/status.h>
-
-#define DTRACEIOC 0xd4
-#define DTRACEIOC_PROVIDER _IOR(DTRACEIOC, 1, dtrace_providerdesc_t)
-#define DTRACEIOC_PROBES _IOR(DTRACEIOC, 2, dtrace_probedesc_t)
-#define DTRACEIOC_PROBEMATCH _IOR(DTRACEIOC, 5, dtrace_probedesc_t)
-#define DTRACEIOC_ENABLE _IOW(DTRACEIOC, 6, void *)
-#define DTRACEIOC_EPROBE _IOW(DTRACEIOC, 8, dtrace_eprobedesc_t)
-#define DTRACEIOC_PROBEARG _IOR(DTRACEIOC, 9, dtrace_argdesc_t)
-#define DTRACEIOC_CONF _IOR(DTRACEIOC, 10, dtrace_conf_t)
-#define DTRACEIOC_STATUS _IOR(DTRACEIOC, 11, dtrace_status_t)
-#define DTRACEIOC_GO _IOW(DTRACEIOC, 12, processorid_t)
-#define DTRACEIOC_STOP _IOW(DTRACEIOC, 13, processorid_t)
-#define DTRACEIOC_AGGDESC _IOR(DTRACEIOC, 15, dtrace_aggdesc_t)
-#define DTRACEIOC_FORMAT _IOR(DTRACEIOC, 16, dtrace_fmtdesc_t)
-#define DTRACEIOC_DOFGET _IOR(DTRACEIOC, 17, dof_hdr_t)
-#define DTRACEIOC_REPLICATE _IOR(DTRACEIOC, 18, void *)
#define DTRACEHIOC 0xd8
#define DTRACEHIOC_ADD _IOW(DTRACEHIOC, 1, dof_hdr_t)
diff --git a/libdtrace/dt_probe.c b/libdtrace/dt_probe.c
index e1099d75..a40b90a8 100644
--- a/libdtrace/dt_probe.c
+++ b/libdtrace/dt_probe.c
@@ -186,131 +186,6 @@ dt_probe_key(const dtrace_probedesc_t *pdp, char *s)
return s;
}
-/*
- * If a probe was discovered from the kernel, ask dtrace(7D) for a description
- * of each of its arguments, including native and translated types.
- */
-static dt_probe_t *
-dt_probe_discover(dt_provider_t *pvp, const dtrace_probedesc_t *pdp)
-{
-#ifdef FIXME
- dtrace_hdl_t *dtp = pvp->pv_hdl;
- char *name = dt_probe_key(pdp, alloca(dt_probe_keylen(pdp)));
-
- dt_node_t *xargs, *nargs;
- dt_ident_t *idp;
- dt_probe_t *prp;
-
- dtrace_typeinfo_t dtt;
- int i, nc, xc;
-
- int adc = _dtrace_argmax;
- dt_argdesc_t *adv = alloca(sizeof(dt_argdesc_t) * adc);
- dt_argdesc_t *adp = adv;
-
- assert(strcmp(pvp->desc.dtvd_name, pdp->prv) == 0);
- assert(pdp->id != DTRACE_IDNONE);
-
- dt_dprintf("discovering probe %s:%s id=%d\n",
- pvp->desc.dtvd_name, name, pdp->id);
-
- for (nc = -1, i = 0; i < adc; i++, adp++) {
- memset(adp, 0, sizeof(dt_argdesc_t));
- adp->ndx = i;
- adp->id = pdp->id;
-
- if (dt_ioctl(dtp, DTRACEIOC_PROBEARG, adp) != 0) {
- dt_set_errno(dtp, errno);
- return NULL;
- }
-
- if (adp->ndx == DTRACE_ARGNONE)
- break; /* all argument descs have been retrieved */
-
- nc = MAX(nc, adp->mapping);
- }
-
- xc = i;
- nc++;
-
- /*
- * Now that we have discovered the number of native and translated
- * arguments from the argument descriptions, allocate a new probe ident
- * and corresponding dt_probe_t and hash it into the provider.
- */
- xargs = dt_probe_alloc_args(pvp, xc);
- nargs = dt_probe_alloc_args(pvp, nc);
-
- if ((xc != 0 && xargs == NULL) || (nc != 0 && nargs == NULL))
- return NULL; /* dt_errno is set for us */
-
- idp = dt_ident_create(name, DT_IDENT_PROBE, DT_IDFLG_ORPHAN, pdp->id,
- _dtrace_defattr, 0, &dt_idops_probe, NULL,
- dtp->dt_gen);
-
- if (idp == NULL) {
- dt_set_errno(dtp, EDT_NOMEM);
- return NULL;
- }
-
- prp = dt_probe_create(dtp, idp, 2, nargs, nc, xargs, xc);
- if (prp == NULL) {
- dt_ident_destroy(idp);
- return NULL;
- }
-
- dt_probe_declare(pvp, prp);
-
- /*
- * Once our new dt_probe_t is fully constructed, iterate over the
- * cached argument descriptions and assign types to prp->nargv[]
- * and prp->xargv[] and assign mappings to prp->mapping[].
- */
- for (adp = adv, i = 0; i < xc; i++, adp++) {
- if (dtrace_type_strcompile(dtp,
- adp->native, &dtt) != 0) {
- dt_dprintf("failed to resolve input type %s "
- "for %s:%s arg #%d: %s\n", adp->native,
- pvp->desc.dtvd_name, name, i + 1,
- dtrace_errmsg(dtp, dtrace_errno(dtp)));
-
- dtt.dtt_object = NULL;
- dtt.dtt_ctfp = NULL;
- dtt.dtt_type = CTF_ERR;
- } else {
- dt_node_type_assign(prp->nargv[adp->mapping],
- dtt.dtt_ctfp, dtt.dtt_type);
- }
-
- if (dtt.dtt_type != CTF_ERR && (adp->xlate[0] == '\0' ||
- strcmp(adp->native, adp->xlate) == 0)) {
- dt_node_type_propagate(prp->nargv[
- adp->mapping], prp->xargv[i]);
- } else if (dtrace_type_strcompile(dtp,
- adp->xlate, &dtt) != 0) {
- dt_dprintf("failed to resolve output type %s "
- "for %s:%s arg #%d: %s\n", adp->xlate,
- pvp->desc.dtvd_name, name, i + 1,
- dtrace_errmsg(dtp, dtrace_errno(dtp)));
-
- dtt.dtt_object = NULL;
- dtt.dtt_ctfp = NULL;
- dtt.dtt_type = CTF_ERR;
- } else {
- dt_node_type_assign(prp->xargv[i],
- dtt.dtt_ctfp, dtt.dtt_type);
- }
-
- prp->mapping[i] = adp->mapping;
- prp->argv[i] = dtt;
- }
-
- return prp;
-#else
- return NULL;
-#endif
-}
-
/*
* Lookup a probe declaration based on a known provider and full or partially
* specified module, function, and name. If the probe is not known to us yet,
@@ -339,13 +214,6 @@ dt_probe_lookup2(dt_provider_t *pvp, const char *s)
if ((idp = dt_idhash_lookup(pvp->pv_probes, key)) != NULL)
return idp->di_data;
- /*
- * If the probe isn't known, use the probe description computed above
- * to ask dtrace(7D) to find the first matching probe.
- */
- if (dt_ioctl(dtp, DTRACEIOC_PROBEMATCH, &pd) == 0)
- return dt_probe_discover(pvp, &pd);
-
if (errno == ESRCH || errno == EBADF)
dt_set_errno(dtp, EDT_NOPROBE);
else
diff --git a/test/utils/Build b/test/utils/Build
index 1398822b..494806fe 100644
--- a/test/utils/Build
+++ b/test/utils/Build
@@ -3,7 +3,7 @@
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
-TEST_UTILS = baddof badioctl workload_kernel workload_user showUSDT print-stack-layout
+TEST_UTILS = badioctl workload_kernel workload_user showUSDT print-stack-layout
TEST_SCRIPTS = check_result.sh clean_probes.sh cpc_get_events.sh cpc_temp_skip_bug.sh perf_count_event.sh workload_analyze_loop.sh workload_get_iterations.sh
define test-util-template
diff --git a/test/utils/baddof.c b/test/utils/baddof.c
deleted file mode 100644
index 5f844625..00000000
--- a/test/utils/baddof.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <string.h>
-#include <dtrace.h>
-
-void
-fatal(char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
-
- fprintf(stderr, "%s: ", "baddof");
- vfprintf(stderr, fmt, ap);
-
- if (fmt[strlen(fmt) - 1] != '\n')
- fprintf(stderr, ": %s\n", strerror(errno));
-
- exit(1);
-}
-
-#define LEAP_DISTANCE 20
-
-void
-corrupt(int fd, unsigned char *buf, int len)
-{
- static int ttl, valid;
- int bit, i;
- unsigned char saved;
- int val[LEAP_DISTANCE], pos[LEAP_DISTANCE];
- int new, rv;
-
-again:
- printf("valid DOF #%d\n", valid++);
-
- /*
- * We are going iterate through, flipping one bit and attempting
- * to enable.
- */
- for (bit = 0; bit < len * 8; bit++) {
- saved = buf[bit / 8];
- buf[bit / 8] ^= (1 << (bit % 8));
-
- if ((bit % 100) == 0)
- printf("%d\n", bit);
-
- if ((rv = ioctl(fd, DTRACEIOC_ENABLE, buf)) == -1) {
- /*
- * That failed -- restore the bit and drive on.
- */
- buf[bit / 8] = saved;
- continue;
- }
-
- /*
- * That worked -- and it may have enabled probes. To keep
- * enabled probes down to a reasonable level, we'll close
- * and reopen pseudodevice if we have more than 10,000
- * probes enabled.
- */
- ttl += rv;
-
- if (ttl < 10000) {
- buf[bit / 8] = saved;
- continue;
- }
-
- printf("enabled %d probes; resetting device.\n", ttl);
- close(fd);
-
- new = open("/dev/dtrace/dtrace", O_RDWR);
-
- if (new == -1)
- fatal("couldn't open DTrace pseudo device");
-
- if (new != fd) {
- dup2(new, fd);
- close(new);
- }
-
- ttl = 0;
- buf[bit / 8] = saved;
- }
-
- for (;;) {
- /*
- * Now we want to get as many bits away as possible. We flip
- * bits randomly -- getting as far away as we can until we don't
- * seem to be making any progress.
- */
- for (i = 0; i < LEAP_DISTANCE; i++) {
- /*
- * Pick a random bit and corrupt it.
- */
- bit = lrand48() % (len * 8);
-
- val[i] = buf[bit / 8];
- pos[i] = bit / 8;
- buf[bit / 8] ^= (1 << (bit % 8));
- }
-
- /*
- * Let's see if that managed to get us valid DOF...
- */
- if ((rv = ioctl(fd, DTRACEIOC_ENABLE, buf)) > 0) {
- /*
- * Success! This will be our new base for valid DOF.
- */
- ttl += rv;
- goto again;
- }
-
- /*
- * No luck -- we'll restore those bits and try flipping a
- * different set. Note that this must be done in reverse
- * order...
- */
- for (i = LEAP_DISTANCE - 1; i >= 0; i--)
- buf[pos[i]] = val[i];
- }
-}
-
-int
-main(int argc, char **argv)
-{
- char *filename = argv[1];
- dtrace_hdl_t *dtp;
- dtrace_prog_t *pgp;
- int err, fd, len;
- FILE *fp;
- unsigned char *dof, *copy;
-
- if (argc < 1)
- fatal("expected D script as argument\n");
-
- if ((fp = fopen(filename, "r")) == NULL)
- fatal("couldn't open %s", filename);
-
- /*
- * First, we need to compile our provided D into DOF.
- */
- if ((dtp = dtrace_open(DTRACE_VERSION, 0, &err)) == NULL) {
- fatal("cannot open dtrace library: %s\n",
- dtrace_errmsg(NULL, err));
- }
-
- pgp = dtrace_program_fcompile(dtp, fp, 0, 0, NULL);
- fclose(fp);
-
- if (pgp == NULL) {
- fatal("failed to compile script %s: %s\n", filename,
- dtrace_errmsg(dtp, dtrace_errno(dtp)));
- }
-
- dof = dtrace_dof_create(dtp, pgp, 0);
- len = ((dof_hdr_t *)dof)->dofh_loadsz;
-
- if ((copy = malloc(len)) == NULL)
- fatal("could not allocate copy of %d bytes", len);
-
- for (;;) {
- memcpy(copy, dof, len);
- /*
- * Open another instance of the dtrace device.
- */
- fd = open("/dev/dtrace/dtrace", O_RDWR);
-
- if (fd == -1)
- fatal("couldn't open DTrace pseudo device");
-
- corrupt(fd, copy, len);
- close(fd);
- }
-
- /* NOTREACHED */
- return 0;
-}
--
2.45.2
More information about the DTrace-devel
mailing list