* [PATCH v2] ioctl: remove obsolete ioctl definitions and dead code that used them
@ 2024-08-21 22:47 Kris Van Hees
2024-08-22 0:11 ` Eugene Loh
0 siblings, 1 reply; 3+ messages in thread
From: Kris Van Hees @ 2024-08-21 22:47 UTC (permalink / raw)
To: dtrace, dtrace-devel
Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
---
include/dtrace/dif.h | 5 +-
include/dtrace/dif_defines.h | 5 +-
include/dtrace/ioctl.h | 23 -----
libdtrace/dt_options.c | 61 -----------
libdtrace/dt_probe.c | 132 ------------------------
libdtrace/dt_work.c | 5 -
runtest.sh | 61 ++---------
test/utils/.gitignore | 2 -
test/utils/Build | 2 +-
test/utils/baddof.c | 191 -----------------------------------
test/utils/badioctl.c | 129 -----------------------
11 files changed, 13 insertions(+), 603 deletions(-)
delete mode 100644 test/utils/baddof.c
delete mode 100644 test/utils/badioctl.c
diff --git a/include/dtrace/dif.h b/include/dtrace/dif.h
index 191aa73c..576bda2c 100644
--- a/include/dtrace/dif.h
+++ b/include/dtrace/dif.h
@@ -19,10 +19,7 @@
/*
* The following definitions describe the DTrace Intermediate Format (DIF), a a
* RISC-like instruction set and program encoding used to represent predicates
- * and actions that can be bound to DTrace probes. The constants below defining
- * the number of available registers are suggested minimums; the compiler should
- * use DTRACEIOC_CONF to dynamically obtain the number of registers provided by
- * the current DTrace implementation.
+ * and actions that can be bound to DTrace probes.
*/
/*
diff --git a/include/dtrace/dif_defines.h b/include/dtrace/dif_defines.h
index d88b3b2e..c8c1d961 100644
--- a/include/dtrace/dif_defines.h
+++ b/include/dtrace/dif_defines.h
@@ -19,9 +19,8 @@
* The following definitions describe the DTrace Intermediate Format (DIF), a a
* RISC-like instruction set and program encoding used to represent predicates
* and actions that can be bound to DTrace probes. The constants below defining
- * the number of available registers are suggested minimums; the compiler should
- * use DTRACEIOC_CONF to dynamically obtain the number of registers provided by
- * the current DTrace implementation.
+ * the number of available registers are dependent on the underlying BPF
+ * implementation.
*/
#define DIF_VERSION_1 1
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_options.c b/libdtrace/dt_options.c
index 2f7917a0..ec53358b 100644
--- a/libdtrace/dt_options.c
+++ b/libdtrace/dt_options.c
@@ -1030,67 +1030,6 @@ dt_opt_bufresize(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
return 0;
}
-int
-dt_options_load(dtrace_hdl_t *dtp)
-{
-#ifdef FIXME
- dof_hdr_t hdr, *dof;
- dof_sec_t *sec = NULL; /* gcc -Wmaybe-uninitialized */
- size_t offs;
- int i;
-
- /*
- * To load the option values, we need to ask the kernel to provide its
- * DOF, which we'll sift through to look for OPTDESC sections.
- */
- memset(&hdr, 0, sizeof(dof_hdr_t));
- hdr.dofh_loadsz = sizeof(dof_hdr_t);
-
- if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &hdr) == -1)
- return dt_set_errno(dtp, errno);
-
- if (hdr.dofh_loadsz < sizeof(dof_hdr_t))
- return dt_set_errno(dtp, EINVAL);
-
- dof = alloca(hdr.dofh_loadsz);
- memset(dof, 0, sizeof(dof_hdr_t));
- dof->dofh_loadsz = hdr.dofh_loadsz;
-
- for (i = 0; i < DTRACEOPT_MAX; i++)
- dtp->dt_options[i] = DTRACEOPT_UNSET;
-
- if (dt_ioctl(dtp, DTRACEIOC_DOFGET, dof) == -1)
- return dt_set_errno(dtp, errno);
-
- /* FIXME: can we get a zero-section DOF back? */
-
- for (i = 0; i < dof->dofh_secnum; i++) {
- sec = (dof_sec_t *)(uintptr_t)((uintptr_t)dof +
- dof->dofh_secoff + i * dof->dofh_secsize);
-
- if (sec->dofs_type != DOF_SECT_OPTDESC)
- continue;
-
- break;
- }
-
- for (offs = 0; offs < sec->dofs_size; offs += sec->dofs_entsize) {
- dof_optdesc_t *opt = (dof_optdesc_t *)(uintptr_t)
- ((uintptr_t)dof + sec->dofs_offset + offs);
-
- if (opt->dofo_strtab != DOF_SECIDX_NONE)
- continue;
-
- if (opt->dofo_option >= DTRACEOPT_MAX)
- continue;
-
- dtp->dt_options[opt->dofo_option] = opt->dofo_value;
- }
-#endif
-
- return 0;
-}
-
/*ARGSUSED*/
static int
dt_opt_preallocate(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
diff --git a/libdtrace/dt_probe.c b/libdtrace/dt_probe.c
index 0b53121a..14ea134f 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/libdtrace/dt_work.c b/libdtrace/dt_work.c
index 13483301..c98bbfb9 100644
--- a/libdtrace/dt_work.c
+++ b/libdtrace/dt_work.c
@@ -319,11 +319,6 @@ dtrace_go(dtrace_hdl_t *dtp, uint_t cflags)
if (dt_state_get_activity(dtp) == DT_ACTIVITY_STOPPED)
dt_state_set_activity(dtp, DT_ACTIVITY_DRAINING);
-#if 0
- if (dt_options_load(dtp) == -1)
- return dt_set_errno(dtp, errno);
-#endif
-
return 0;
}
diff --git a/runtest.sh b/runtest.sh
index 0fe98a99..c720a8c9 100755
--- a/runtest.sh
+++ b/runtest.sh
@@ -247,7 +247,6 @@ Options:
or with a timeout, but have no expected results,
as the expected results. (Only useful if
--no-comparison is not specified.)
- --[no-]baddof: Run corrupt-DOF tests.
--[no-]use-installed: Use an installed dtrace rather than a copy in the
source tree.
--quiet: Only show unexpected output (FAILs and XPASSes).
@@ -267,7 +266,6 @@ exit 0
CAPTURE_EXPECTED=${DTRACE_TEST_CAPTURE_EXPECTED:+t}
OVERWRITE_RESULTS=
NOEXEC=${DTRACE_TEST_NO_EXECUTE:+t}
-NOBADDOF=${DTRACE_TEST_BADDOF:-t}
USE_INSTALLED=${DTRACE_TEST_USE_INSTALLED:+t}
VALGRIND=${DTRACE_TEST_VALGRIND:+t}
COMPARISON=t
@@ -303,8 +301,6 @@ while [[ $# -gt 0 ]]; do
--no-comparison) COMPARISON=;;
--valgrind) VALGRIND=t;;
--no-valgrind) VALGRIND=;;
- --baddof) NOBADDOF=;;
- --no-baddof) NOBADDOF=t;;
--use-installed) USE_INSTALLED=t;;
--no-use-installed) USE_INSTALLED=;;
--timeout=*) TIMEOUT="$(printf -- $1 | cut -d= -f2-)";;
@@ -641,56 +637,17 @@ done
# Initialize test coverage.
-if [[ -n $NOBADDOF ]]; then
- for name in build*; do
- if [[ -n "$(echo $name/*.gcno)" ]]; then
- rm -rf $logdir/coverage
- mkdir -p $logdir/coverage
- lcov --zerocounters --directory $name --quiet
- lcov --capture --base-directory . --directory $name --initial \
- --quiet -o $logdir/coverage/initial.lcov 2>/dev/null
- fi
- done
-fi
-
-load_modules
-
-if [[ -z $NOBADDOF ]]; then
- # Run DOF-corruption tests instead.
-
- test/utils/badioctl > /dev/null 2> $tmpdir/badioctl.err &
- declare ioctlpid=$!
-
- ZAPTHESE+=($ioctlpid)
- for _test in $(if [[ $ONLY_TESTS ]]; then
- echo $TESTS | sed 's,\.r$,\.d,g; s,\.r ,.d ,g'
- else
- for name in $TESTSUITES; do
- find test/$name -name "*.d" | sort -u
- done
- fi); do
-
- if ! run_with_timeout $TIMEOUT test/utils/baddof $_test > /dev/null 2> $tmpdir/baddof.err; then
- out "$_test: FAIL (bad DOF)"
- fi
- if [[ -s $tmpdir/baddof.err ]]; then
- sum "baddof stderr:"
- tee -a < $tmpdir/baddof.err $LOGFILE >> $SUMFILE
- fi
- done
-
- if [[ "$(ps -p $ioctlpid -o ppid=)" -eq $BASHPID ]]; then
- kill -$TIMEOUTSIG -- $ioctlpid >/dev/null 2>&1
- fi
- if [[ -s $tmpdir/badioctl.err ]]; then
- sum "badioctl stderr:"
- tee -a < $tmpdir/badioctl.err $LOGFILE >> $SUMFILE
+for name in build*; do
+ if [[ -n "$(echo $name/*.gcno)" ]]; then
+ rm -rf $logdir/coverage
+ mkdir -p $logdir/coverage
+ lcov --zerocounters --directory $name --quiet
+ lcov --capture --base-directory . --directory $name --initial \
+ --quiet -o $logdir/coverage/initial.lcov 2>/dev/null
fi
- # equivalent of unset "ZAPTHESE[-1]" on bash < 4.3
- unset "ZAPTHESE[$((${#ZAPTHESE[@]}-1))]"
- exit 0
-fi
+done
+load_modules
# Export some variables so triggers and .sh scripts can get at them.
export _test _pid dt_flags
diff --git a/test/utils/.gitignore b/test/utils/.gitignore
index 7c25cb18..4d52db48 100644
--- a/test/utils/.gitignore
+++ b/test/utils/.gitignore
@@ -1,6 +1,4 @@
# In-place built executables
-baddof
-badioctl
workload_kernel
workload_user
print-stack-layout
diff --git a/test/utils/Build b/test/utils/Build
index 1398822b..10f4e726 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 = 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;
-}
diff --git a/test/utils/badioctl.c b/test/utils/badioctl.c
deleted file mode 100644
index 8a5c286c..00000000
--- a/test/utils/badioctl.c
+++ /dev/null
@@ -1,129 +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 <sys/mman.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-
-#define DTRACEIOC (('d' << 24) | ('t' << 16) | ('r' << 8))
-#define DTRACEIOC_MAX 17
-
-void
-fatal(char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
-
- fprintf(stderr, "%s: ", "badioctl");
- vfprintf(stderr, fmt, ap);
-
- if (fmt[strlen(fmt) - 1] != '\n')
- fprintf(stderr, ": %s\n", strerror(errno));
-
- exit(1);
-}
-
-void
-badioctl(pid_t parent)
-{
- int fd = -1, random, ps = sysconf(_SC_PAGESIZE);
- int i = 0;
- caddr_t addr;
- struct timeval now, last = {0};
-
- if ((random = open("/dev/urandom", O_RDONLY)) == -1)
- fatal("couldn't open /dev/urandom");
-
- if ((addr = mmap(0, ps, PROT_READ | PROT_WRITE,
- MAP_ANON | MAP_PRIVATE, -1, 0)) == (caddr_t)-1)
- fatal("mmap");
-
- for (;;) {
- unsigned int ioc;
-
- gettimeofday(&now, NULL);
- if (now.tv_sec > last.tv_sec) {
- if (kill(parent, 0) == -1 && errno == ESRCH) {
- /*
- * Our parent died. We will kill ourselves in
- * sympathy.
- */
- exit(0);
- }
-
- /*
- * Once a second, we'll reopen the device.
- */
- if (fd != -1)
- close(fd);
-
- fd = open("/dev/dtrace/dtrace", O_RDONLY);
-
- if (fd == -1)
- fatal("couldn't open DTrace pseudo device");
-
- last = now;
- }
-
-
- if ((i++ % 1000) == 0) {
- /*
- * Every thousand iterations, change our random gunk.
- */
- read(random, addr, ps);
- }
-
- read(random, &ioc, sizeof(ioc));
- ioc %= DTRACEIOC_MAX;
- ioc++;
- ioctl(fd, DTRACEIOC | ioc, addr);
- }
-}
-
-int
-main()
-{
- pid_t child, parent = getpid();
- int status;
-
- for (;;) {
- if ((child = fork()) == 0)
- badioctl(parent);
-
- while (waitpid(child, &status, WEXITED) != child)
- continue;
-
- if (WIFEXITED(status)) {
- /*
- * Our child exited by design -- we'll exit with
- * the same status code.
- */
- exit(WEXITSTATUS(status));
- }
-
- /*
- * Our child died on a signal. Respawn it.
- */
- printf("badioctl: child died on signal %d; respawning.\n",
- WTERMSIG(status));
- fflush(stdout);
- }
-
- /* NOTREACHED */
- return 0;
-}
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] ioctl: remove obsolete ioctl definitions and dead code that used them
2024-08-21 22:47 [PATCH v2] ioctl: remove obsolete ioctl definitions and dead code that used them Kris Van Hees
@ 2024-08-22 0:11 ` Eugene Loh
2024-08-22 0:56 ` Kris Van Hees
0 siblings, 1 reply; 3+ messages in thread
From: Eugene Loh @ 2024-08-22 0:11 UTC (permalink / raw)
To: dtrace, dtrace-devel
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
though maybe dt_options_load() should still be removed from dt_impl.h.
On 8/21/24 18:47, Kris Van Hees wrote:
> Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
> ---
> include/dtrace/dif.h | 5 +-
> include/dtrace/dif_defines.h | 5 +-
> include/dtrace/ioctl.h | 23 -----
> libdtrace/dt_options.c | 61 -----------
> libdtrace/dt_probe.c | 132 ------------------------
> libdtrace/dt_work.c | 5 -
> runtest.sh | 61 ++---------
> test/utils/.gitignore | 2 -
> test/utils/Build | 2 +-
> test/utils/baddof.c | 191 -----------------------------------
> test/utils/badioctl.c | 129 -----------------------
> 11 files changed, 13 insertions(+), 603 deletions(-)
> delete mode 100644 test/utils/baddof.c
> delete mode 100644 test/utils/badioctl.c
>
> diff --git a/include/dtrace/dif.h b/include/dtrace/dif.h
> index 191aa73c..576bda2c 100644
> --- a/include/dtrace/dif.h
> +++ b/include/dtrace/dif.h
> @@ -19,10 +19,7 @@
> /*
> * The following definitions describe the DTrace Intermediate Format (DIF), a a
> * RISC-like instruction set and program encoding used to represent predicates
> - * and actions that can be bound to DTrace probes. The constants below defining
> - * the number of available registers are suggested minimums; the compiler should
> - * use DTRACEIOC_CONF to dynamically obtain the number of registers provided by
> - * the current DTrace implementation.
> + * and actions that can be bound to DTrace probes.
> */
>
> /*
> diff --git a/include/dtrace/dif_defines.h b/include/dtrace/dif_defines.h
> index d88b3b2e..c8c1d961 100644
> --- a/include/dtrace/dif_defines.h
> +++ b/include/dtrace/dif_defines.h
> @@ -19,9 +19,8 @@
> * The following definitions describe the DTrace Intermediate Format (DIF), a a
> * RISC-like instruction set and program encoding used to represent predicates
> * and actions that can be bound to DTrace probes. The constants below defining
> - * the number of available registers are suggested minimums; the compiler should
> - * use DTRACEIOC_CONF to dynamically obtain the number of registers provided by
> - * the current DTrace implementation.
> + * the number of available registers are dependent on the underlying BPF
> + * implementation.
> */
>
> #define DIF_VERSION_1 1
> 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_options.c b/libdtrace/dt_options.c
> index 2f7917a0..ec53358b 100644
> --- a/libdtrace/dt_options.c
> +++ b/libdtrace/dt_options.c
> @@ -1030,67 +1030,6 @@ dt_opt_bufresize(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
> return 0;
> }
>
> -int
> -dt_options_load(dtrace_hdl_t *dtp)
> -{
> -#ifdef FIXME
> - dof_hdr_t hdr, *dof;
> - dof_sec_t *sec = NULL; /* gcc -Wmaybe-uninitialized */
> - size_t offs;
> - int i;
> -
> - /*
> - * To load the option values, we need to ask the kernel to provide its
> - * DOF, which we'll sift through to look for OPTDESC sections.
> - */
> - memset(&hdr, 0, sizeof(dof_hdr_t));
> - hdr.dofh_loadsz = sizeof(dof_hdr_t);
> -
> - if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &hdr) == -1)
> - return dt_set_errno(dtp, errno);
> -
> - if (hdr.dofh_loadsz < sizeof(dof_hdr_t))
> - return dt_set_errno(dtp, EINVAL);
> -
> - dof = alloca(hdr.dofh_loadsz);
> - memset(dof, 0, sizeof(dof_hdr_t));
> - dof->dofh_loadsz = hdr.dofh_loadsz;
> -
> - for (i = 0; i < DTRACEOPT_MAX; i++)
> - dtp->dt_options[i] = DTRACEOPT_UNSET;
> -
> - if (dt_ioctl(dtp, DTRACEIOC_DOFGET, dof) == -1)
> - return dt_set_errno(dtp, errno);
> -
> - /* FIXME: can we get a zero-section DOF back? */
> -
> - for (i = 0; i < dof->dofh_secnum; i++) {
> - sec = (dof_sec_t *)(uintptr_t)((uintptr_t)dof +
> - dof->dofh_secoff + i * dof->dofh_secsize);
> -
> - if (sec->dofs_type != DOF_SECT_OPTDESC)
> - continue;
> -
> - break;
> - }
> -
> - for (offs = 0; offs < sec->dofs_size; offs += sec->dofs_entsize) {
> - dof_optdesc_t *opt = (dof_optdesc_t *)(uintptr_t)
> - ((uintptr_t)dof + sec->dofs_offset + offs);
> -
> - if (opt->dofo_strtab != DOF_SECIDX_NONE)
> - continue;
> -
> - if (opt->dofo_option >= DTRACEOPT_MAX)
> - continue;
> -
> - dtp->dt_options[opt->dofo_option] = opt->dofo_value;
> - }
> -#endif
> -
> - return 0;
> -}
> -
> /*ARGSUSED*/
> static int
> dt_opt_preallocate(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
> diff --git a/libdtrace/dt_probe.c b/libdtrace/dt_probe.c
> index 0b53121a..14ea134f 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/libdtrace/dt_work.c b/libdtrace/dt_work.c
> index 13483301..c98bbfb9 100644
> --- a/libdtrace/dt_work.c
> +++ b/libdtrace/dt_work.c
> @@ -319,11 +319,6 @@ dtrace_go(dtrace_hdl_t *dtp, uint_t cflags)
> if (dt_state_get_activity(dtp) == DT_ACTIVITY_STOPPED)
> dt_state_set_activity(dtp, DT_ACTIVITY_DRAINING);
>
> -#if 0
> - if (dt_options_load(dtp) == -1)
> - return dt_set_errno(dtp, errno);
> -#endif
> -
> return 0;
> }
>
> diff --git a/runtest.sh b/runtest.sh
> index 0fe98a99..c720a8c9 100755
> --- a/runtest.sh
> +++ b/runtest.sh
> @@ -247,7 +247,6 @@ Options:
> or with a timeout, but have no expected results,
> as the expected results. (Only useful if
> --no-comparison is not specified.)
> - --[no-]baddof: Run corrupt-DOF tests.
> --[no-]use-installed: Use an installed dtrace rather than a copy in the
> source tree.
> --quiet: Only show unexpected output (FAILs and XPASSes).
> @@ -267,7 +266,6 @@ exit 0
> CAPTURE_EXPECTED=${DTRACE_TEST_CAPTURE_EXPECTED:+t}
> OVERWRITE_RESULTS=
> NOEXEC=${DTRACE_TEST_NO_EXECUTE:+t}
> -NOBADDOF=${DTRACE_TEST_BADDOF:-t}
> USE_INSTALLED=${DTRACE_TEST_USE_INSTALLED:+t}
> VALGRIND=${DTRACE_TEST_VALGRIND:+t}
> COMPARISON=t
> @@ -303,8 +301,6 @@ while [[ $# -gt 0 ]]; do
> --no-comparison) COMPARISON=;;
> --valgrind) VALGRIND=t;;
> --no-valgrind) VALGRIND=;;
> - --baddof) NOBADDOF=;;
> - --no-baddof) NOBADDOF=t;;
> --use-installed) USE_INSTALLED=t;;
> --no-use-installed) USE_INSTALLED=;;
> --timeout=*) TIMEOUT="$(printf -- $1 | cut -d= -f2-)";;
> @@ -641,56 +637,17 @@ done
>
> # Initialize test coverage.
>
> -if [[ -n $NOBADDOF ]]; then
> - for name in build*; do
> - if [[ -n "$(echo $name/*.gcno)" ]]; then
> - rm -rf $logdir/coverage
> - mkdir -p $logdir/coverage
> - lcov --zerocounters --directory $name --quiet
> - lcov --capture --base-directory . --directory $name --initial \
> - --quiet -o $logdir/coverage/initial.lcov 2>/dev/null
> - fi
> - done
> -fi
> -
> -load_modules
> -
> -if [[ -z $NOBADDOF ]]; then
> - # Run DOF-corruption tests instead.
> -
> - test/utils/badioctl > /dev/null 2> $tmpdir/badioctl.err &
> - declare ioctlpid=$!
> -
> - ZAPTHESE+=($ioctlpid)
> - for _test in $(if [[ $ONLY_TESTS ]]; then
> - echo $TESTS | sed 's,\.r$,\.d,g; s,\.r ,.d ,g'
> - else
> - for name in $TESTSUITES; do
> - find test/$name -name "*.d" | sort -u
> - done
> - fi); do
> -
> - if ! run_with_timeout $TIMEOUT test/utils/baddof $_test > /dev/null 2> $tmpdir/baddof.err; then
> - out "$_test: FAIL (bad DOF)"
> - fi
> - if [[ -s $tmpdir/baddof.err ]]; then
> - sum "baddof stderr:"
> - tee -a < $tmpdir/baddof.err $LOGFILE >> $SUMFILE
> - fi
> - done
> -
> - if [[ "$(ps -p $ioctlpid -o ppid=)" -eq $BASHPID ]]; then
> - kill -$TIMEOUTSIG -- $ioctlpid >/dev/null 2>&1
> - fi
> - if [[ -s $tmpdir/badioctl.err ]]; then
> - sum "badioctl stderr:"
> - tee -a < $tmpdir/badioctl.err $LOGFILE >> $SUMFILE
> +for name in build*; do
> + if [[ -n "$(echo $name/*.gcno)" ]]; then
> + rm -rf $logdir/coverage
> + mkdir -p $logdir/coverage
> + lcov --zerocounters --directory $name --quiet
> + lcov --capture --base-directory . --directory $name --initial \
> + --quiet -o $logdir/coverage/initial.lcov 2>/dev/null
> fi
> - # equivalent of unset "ZAPTHESE[-1]" on bash < 4.3
> - unset "ZAPTHESE[$((${#ZAPTHESE[@]}-1))]"
> - exit 0
> -fi
> +done
>
> +load_modules
>
> # Export some variables so triggers and .sh scripts can get at them.
> export _test _pid dt_flags
> diff --git a/test/utils/.gitignore b/test/utils/.gitignore
> index 7c25cb18..4d52db48 100644
> --- a/test/utils/.gitignore
> +++ b/test/utils/.gitignore
> @@ -1,6 +1,4 @@
> # In-place built executables
> -baddof
> -badioctl
> workload_kernel
> workload_user
> print-stack-layout
> diff --git a/test/utils/Build b/test/utils/Build
> index 1398822b..10f4e726 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 = 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;
> -}
> diff --git a/test/utils/badioctl.c b/test/utils/badioctl.c
> deleted file mode 100644
> index 8a5c286c..00000000
> --- a/test/utils/badioctl.c
> +++ /dev/null
> @@ -1,129 +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 <sys/mman.h>
> -#include <sys/wait.h>
> -#include <sys/time.h>
> -#include <stdio.h>
> -#include <stdlib.h>
> -#include <fcntl.h>
> -#include <stdarg.h>
> -#include <string.h>
> -#include <errno.h>
> -#include <unistd.h>
> -
> -#define DTRACEIOC (('d' << 24) | ('t' << 16) | ('r' << 8))
> -#define DTRACEIOC_MAX 17
> -
> -void
> -fatal(char *fmt, ...)
> -{
> - va_list ap;
> -
> - va_start(ap, fmt);
> -
> - fprintf(stderr, "%s: ", "badioctl");
> - vfprintf(stderr, fmt, ap);
> -
> - if (fmt[strlen(fmt) - 1] != '\n')
> - fprintf(stderr, ": %s\n", strerror(errno));
> -
> - exit(1);
> -}
> -
> -void
> -badioctl(pid_t parent)
> -{
> - int fd = -1, random, ps = sysconf(_SC_PAGESIZE);
> - int i = 0;
> - caddr_t addr;
> - struct timeval now, last = {0};
> -
> - if ((random = open("/dev/urandom", O_RDONLY)) == -1)
> - fatal("couldn't open /dev/urandom");
> -
> - if ((addr = mmap(0, ps, PROT_READ | PROT_WRITE,
> - MAP_ANON | MAP_PRIVATE, -1, 0)) == (caddr_t)-1)
> - fatal("mmap");
> -
> - for (;;) {
> - unsigned int ioc;
> -
> - gettimeofday(&now, NULL);
> - if (now.tv_sec > last.tv_sec) {
> - if (kill(parent, 0) == -1 && errno == ESRCH) {
> - /*
> - * Our parent died. We will kill ourselves in
> - * sympathy.
> - */
> - exit(0);
> - }
> -
> - /*
> - * Once a second, we'll reopen the device.
> - */
> - if (fd != -1)
> - close(fd);
> -
> - fd = open("/dev/dtrace/dtrace", O_RDONLY);
> -
> - if (fd == -1)
> - fatal("couldn't open DTrace pseudo device");
> -
> - last = now;
> - }
> -
> -
> - if ((i++ % 1000) == 0) {
> - /*
> - * Every thousand iterations, change our random gunk.
> - */
> - read(random, addr, ps);
> - }
> -
> - read(random, &ioc, sizeof(ioc));
> - ioc %= DTRACEIOC_MAX;
> - ioc++;
> - ioctl(fd, DTRACEIOC | ioc, addr);
> - }
> -}
> -
> -int
> -main()
> -{
> - pid_t child, parent = getpid();
> - int status;
> -
> - for (;;) {
> - if ((child = fork()) == 0)
> - badioctl(parent);
> -
> - while (waitpid(child, &status, WEXITED) != child)
> - continue;
> -
> - if (WIFEXITED(status)) {
> - /*
> - * Our child exited by design -- we'll exit with
> - * the same status code.
> - */
> - exit(WEXITSTATUS(status));
> - }
> -
> - /*
> - * Our child died on a signal. Respawn it.
> - */
> - printf("badioctl: child died on signal %d; respawning.\n",
> - WTERMSIG(status));
> - fflush(stdout);
> - }
> -
> - /* NOTREACHED */
> - return 0;
> -}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] ioctl: remove obsolete ioctl definitions and dead code that used them
2024-08-22 0:11 ` Eugene Loh
@ 2024-08-22 0:56 ` Kris Van Hees
0 siblings, 0 replies; 3+ messages in thread
From: Kris Van Hees @ 2024-08-22 0:56 UTC (permalink / raw)
To: Eugene Loh; +Cc: dtrace, dtrace-devel
On Wed, Aug 21, 2024 at 08:11:40PM -0400, Eugene Loh wrote:
> Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
> though maybe dt_options_load() should still be removed from dt_impl.h.
Ah yes, will do. Thanks.
> On 8/21/24 18:47, Kris Van Hees wrote:
> > Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
> > ---
> > include/dtrace/dif.h | 5 +-
> > include/dtrace/dif_defines.h | 5 +-
> > include/dtrace/ioctl.h | 23 -----
> > libdtrace/dt_options.c | 61 -----------
> > libdtrace/dt_probe.c | 132 ------------------------
> > libdtrace/dt_work.c | 5 -
> > runtest.sh | 61 ++---------
> > test/utils/.gitignore | 2 -
> > test/utils/Build | 2 +-
> > test/utils/baddof.c | 191 -----------------------------------
> > test/utils/badioctl.c | 129 -----------------------
> > 11 files changed, 13 insertions(+), 603 deletions(-)
> > delete mode 100644 test/utils/baddof.c
> > delete mode 100644 test/utils/badioctl.c
> >
> > diff --git a/include/dtrace/dif.h b/include/dtrace/dif.h
> > index 191aa73c..576bda2c 100644
> > --- a/include/dtrace/dif.h
> > +++ b/include/dtrace/dif.h
> > @@ -19,10 +19,7 @@
> > /*
> > * The following definitions describe the DTrace Intermediate Format (DIF), a a
> > * RISC-like instruction set and program encoding used to represent predicates
> > - * and actions that can be bound to DTrace probes. The constants below defining
> > - * the number of available registers are suggested minimums; the compiler should
> > - * use DTRACEIOC_CONF to dynamically obtain the number of registers provided by
> > - * the current DTrace implementation.
> > + * and actions that can be bound to DTrace probes.
> > */
> > /*
> > diff --git a/include/dtrace/dif_defines.h b/include/dtrace/dif_defines.h
> > index d88b3b2e..c8c1d961 100644
> > --- a/include/dtrace/dif_defines.h
> > +++ b/include/dtrace/dif_defines.h
> > @@ -19,9 +19,8 @@
> > * The following definitions describe the DTrace Intermediate Format (DIF), a a
> > * RISC-like instruction set and program encoding used to represent predicates
> > * and actions that can be bound to DTrace probes. The constants below defining
> > - * the number of available registers are suggested minimums; the compiler should
> > - * use DTRACEIOC_CONF to dynamically obtain the number of registers provided by
> > - * the current DTrace implementation.
> > + * the number of available registers are dependent on the underlying BPF
> > + * implementation.
> > */
> > #define DIF_VERSION_1 1
> > 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_options.c b/libdtrace/dt_options.c
> > index 2f7917a0..ec53358b 100644
> > --- a/libdtrace/dt_options.c
> > +++ b/libdtrace/dt_options.c
> > @@ -1030,67 +1030,6 @@ dt_opt_bufresize(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
> > return 0;
> > }
> > -int
> > -dt_options_load(dtrace_hdl_t *dtp)
> > -{
> > -#ifdef FIXME
> > - dof_hdr_t hdr, *dof;
> > - dof_sec_t *sec = NULL; /* gcc -Wmaybe-uninitialized */
> > - size_t offs;
> > - int i;
> > -
> > - /*
> > - * To load the option values, we need to ask the kernel to provide its
> > - * DOF, which we'll sift through to look for OPTDESC sections.
> > - */
> > - memset(&hdr, 0, sizeof(dof_hdr_t));
> > - hdr.dofh_loadsz = sizeof(dof_hdr_t);
> > -
> > - if (dt_ioctl(dtp, DTRACEIOC_DOFGET, &hdr) == -1)
> > - return dt_set_errno(dtp, errno);
> > -
> > - if (hdr.dofh_loadsz < sizeof(dof_hdr_t))
> > - return dt_set_errno(dtp, EINVAL);
> > -
> > - dof = alloca(hdr.dofh_loadsz);
> > - memset(dof, 0, sizeof(dof_hdr_t));
> > - dof->dofh_loadsz = hdr.dofh_loadsz;
> > -
> > - for (i = 0; i < DTRACEOPT_MAX; i++)
> > - dtp->dt_options[i] = DTRACEOPT_UNSET;
> > -
> > - if (dt_ioctl(dtp, DTRACEIOC_DOFGET, dof) == -1)
> > - return dt_set_errno(dtp, errno);
> > -
> > - /* FIXME: can we get a zero-section DOF back? */
> > -
> > - for (i = 0; i < dof->dofh_secnum; i++) {
> > - sec = (dof_sec_t *)(uintptr_t)((uintptr_t)dof +
> > - dof->dofh_secoff + i * dof->dofh_secsize);
> > -
> > - if (sec->dofs_type != DOF_SECT_OPTDESC)
> > - continue;
> > -
> > - break;
> > - }
> > -
> > - for (offs = 0; offs < sec->dofs_size; offs += sec->dofs_entsize) {
> > - dof_optdesc_t *opt = (dof_optdesc_t *)(uintptr_t)
> > - ((uintptr_t)dof + sec->dofs_offset + offs);
> > -
> > - if (opt->dofo_strtab != DOF_SECIDX_NONE)
> > - continue;
> > -
> > - if (opt->dofo_option >= DTRACEOPT_MAX)
> > - continue;
> > -
> > - dtp->dt_options[opt->dofo_option] = opt->dofo_value;
> > - }
> > -#endif
> > -
> > - return 0;
> > -}
> > -
> > /*ARGSUSED*/
> > static int
> > dt_opt_preallocate(dtrace_hdl_t *dtp, const char *arg, uintptr_t option)
> > diff --git a/libdtrace/dt_probe.c b/libdtrace/dt_probe.c
> > index 0b53121a..14ea134f 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/libdtrace/dt_work.c b/libdtrace/dt_work.c
> > index 13483301..c98bbfb9 100644
> > --- a/libdtrace/dt_work.c
> > +++ b/libdtrace/dt_work.c
> > @@ -319,11 +319,6 @@ dtrace_go(dtrace_hdl_t *dtp, uint_t cflags)
> > if (dt_state_get_activity(dtp) == DT_ACTIVITY_STOPPED)
> > dt_state_set_activity(dtp, DT_ACTIVITY_DRAINING);
> > -#if 0
> > - if (dt_options_load(dtp) == -1)
> > - return dt_set_errno(dtp, errno);
> > -#endif
> > -
> > return 0;
> > }
> > diff --git a/runtest.sh b/runtest.sh
> > index 0fe98a99..c720a8c9 100755
> > --- a/runtest.sh
> > +++ b/runtest.sh
> > @@ -247,7 +247,6 @@ Options:
> > or with a timeout, but have no expected results,
> > as the expected results. (Only useful if
> > --no-comparison is not specified.)
> > - --[no-]baddof: Run corrupt-DOF tests.
> > --[no-]use-installed: Use an installed dtrace rather than a copy in the
> > source tree.
> > --quiet: Only show unexpected output (FAILs and XPASSes).
> > @@ -267,7 +266,6 @@ exit 0
> > CAPTURE_EXPECTED=${DTRACE_TEST_CAPTURE_EXPECTED:+t}
> > OVERWRITE_RESULTS=
> > NOEXEC=${DTRACE_TEST_NO_EXECUTE:+t}
> > -NOBADDOF=${DTRACE_TEST_BADDOF:-t}
> > USE_INSTALLED=${DTRACE_TEST_USE_INSTALLED:+t}
> > VALGRIND=${DTRACE_TEST_VALGRIND:+t}
> > COMPARISON=t
> > @@ -303,8 +301,6 @@ while [[ $# -gt 0 ]]; do
> > --no-comparison) COMPARISON=;;
> > --valgrind) VALGRIND=t;;
> > --no-valgrind) VALGRIND=;;
> > - --baddof) NOBADDOF=;;
> > - --no-baddof) NOBADDOF=t;;
> > --use-installed) USE_INSTALLED=t;;
> > --no-use-installed) USE_INSTALLED=;;
> > --timeout=*) TIMEOUT="$(printf -- $1 | cut -d= -f2-)";;
> > @@ -641,56 +637,17 @@ done
> > # Initialize test coverage.
> > -if [[ -n $NOBADDOF ]]; then
> > - for name in build*; do
> > - if [[ -n "$(echo $name/*.gcno)" ]]; then
> > - rm -rf $logdir/coverage
> > - mkdir -p $logdir/coverage
> > - lcov --zerocounters --directory $name --quiet
> > - lcov --capture --base-directory . --directory $name --initial \
> > - --quiet -o $logdir/coverage/initial.lcov 2>/dev/null
> > - fi
> > - done
> > -fi
> > -
> > -load_modules
> > -
> > -if [[ -z $NOBADDOF ]]; then
> > - # Run DOF-corruption tests instead.
> > -
> > - test/utils/badioctl > /dev/null 2> $tmpdir/badioctl.err &
> > - declare ioctlpid=$!
> > -
> > - ZAPTHESE+=($ioctlpid)
> > - for _test in $(if [[ $ONLY_TESTS ]]; then
> > - echo $TESTS | sed 's,\.r$,\.d,g; s,\.r ,.d ,g'
> > - else
> > - for name in $TESTSUITES; do
> > - find test/$name -name "*.d" | sort -u
> > - done
> > - fi); do
> > -
> > - if ! run_with_timeout $TIMEOUT test/utils/baddof $_test > /dev/null 2> $tmpdir/baddof.err; then
> > - out "$_test: FAIL (bad DOF)"
> > - fi
> > - if [[ -s $tmpdir/baddof.err ]]; then
> > - sum "baddof stderr:"
> > - tee -a < $tmpdir/baddof.err $LOGFILE >> $SUMFILE
> > - fi
> > - done
> > -
> > - if [[ "$(ps -p $ioctlpid -o ppid=)" -eq $BASHPID ]]; then
> > - kill -$TIMEOUTSIG -- $ioctlpid >/dev/null 2>&1
> > - fi
> > - if [[ -s $tmpdir/badioctl.err ]]; then
> > - sum "badioctl stderr:"
> > - tee -a < $tmpdir/badioctl.err $LOGFILE >> $SUMFILE
> > +for name in build*; do
> > + if [[ -n "$(echo $name/*.gcno)" ]]; then
> > + rm -rf $logdir/coverage
> > + mkdir -p $logdir/coverage
> > + lcov --zerocounters --directory $name --quiet
> > + lcov --capture --base-directory . --directory $name --initial \
> > + --quiet -o $logdir/coverage/initial.lcov 2>/dev/null
> > fi
> > - # equivalent of unset "ZAPTHESE[-1]" on bash < 4.3
> > - unset "ZAPTHESE[$((${#ZAPTHESE[@]}-1))]"
> > - exit 0
> > -fi
> > +done
> > +load_modules
> > # Export some variables so triggers and .sh scripts can get at them.
> > export _test _pid dt_flags
> > diff --git a/test/utils/.gitignore b/test/utils/.gitignore
> > index 7c25cb18..4d52db48 100644
> > --- a/test/utils/.gitignore
> > +++ b/test/utils/.gitignore
> > @@ -1,6 +1,4 @@
> > # In-place built executables
> > -baddof
> > -badioctl
> > workload_kernel
> > workload_user
> > print-stack-layout
> > diff --git a/test/utils/Build b/test/utils/Build
> > index 1398822b..10f4e726 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 = 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;
> > -}
> > diff --git a/test/utils/badioctl.c b/test/utils/badioctl.c
> > deleted file mode 100644
> > index 8a5c286c..00000000
> > --- a/test/utils/badioctl.c
> > +++ /dev/null
> > @@ -1,129 +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 <sys/mman.h>
> > -#include <sys/wait.h>
> > -#include <sys/time.h>
> > -#include <stdio.h>
> > -#include <stdlib.h>
> > -#include <fcntl.h>
> > -#include <stdarg.h>
> > -#include <string.h>
> > -#include <errno.h>
> > -#include <unistd.h>
> > -
> > -#define DTRACEIOC (('d' << 24) | ('t' << 16) | ('r' << 8))
> > -#define DTRACEIOC_MAX 17
> > -
> > -void
> > -fatal(char *fmt, ...)
> > -{
> > - va_list ap;
> > -
> > - va_start(ap, fmt);
> > -
> > - fprintf(stderr, "%s: ", "badioctl");
> > - vfprintf(stderr, fmt, ap);
> > -
> > - if (fmt[strlen(fmt) - 1] != '\n')
> > - fprintf(stderr, ": %s\n", strerror(errno));
> > -
> > - exit(1);
> > -}
> > -
> > -void
> > -badioctl(pid_t parent)
> > -{
> > - int fd = -1, random, ps = sysconf(_SC_PAGESIZE);
> > - int i = 0;
> > - caddr_t addr;
> > - struct timeval now, last = {0};
> > -
> > - if ((random = open("/dev/urandom", O_RDONLY)) == -1)
> > - fatal("couldn't open /dev/urandom");
> > -
> > - if ((addr = mmap(0, ps, PROT_READ | PROT_WRITE,
> > - MAP_ANON | MAP_PRIVATE, -1, 0)) == (caddr_t)-1)
> > - fatal("mmap");
> > -
> > - for (;;) {
> > - unsigned int ioc;
> > -
> > - gettimeofday(&now, NULL);
> > - if (now.tv_sec > last.tv_sec) {
> > - if (kill(parent, 0) == -1 && errno == ESRCH) {
> > - /*
> > - * Our parent died. We will kill ourselves in
> > - * sympathy.
> > - */
> > - exit(0);
> > - }
> > -
> > - /*
> > - * Once a second, we'll reopen the device.
> > - */
> > - if (fd != -1)
> > - close(fd);
> > -
> > - fd = open("/dev/dtrace/dtrace", O_RDONLY);
> > -
> > - if (fd == -1)
> > - fatal("couldn't open DTrace pseudo device");
> > -
> > - last = now;
> > - }
> > -
> > -
> > - if ((i++ % 1000) == 0) {
> > - /*
> > - * Every thousand iterations, change our random gunk.
> > - */
> > - read(random, addr, ps);
> > - }
> > -
> > - read(random, &ioc, sizeof(ioc));
> > - ioc %= DTRACEIOC_MAX;
> > - ioc++;
> > - ioctl(fd, DTRACEIOC | ioc, addr);
> > - }
> > -}
> > -
> > -int
> > -main()
> > -{
> > - pid_t child, parent = getpid();
> > - int status;
> > -
> > - for (;;) {
> > - if ((child = fork()) == 0)
> > - badioctl(parent);
> > -
> > - while (waitpid(child, &status, WEXITED) != child)
> > - continue;
> > -
> > - if (WIFEXITED(status)) {
> > - /*
> > - * Our child exited by design -- we'll exit with
> > - * the same status code.
> > - */
> > - exit(WEXITSTATUS(status));
> > - }
> > -
> > - /*
> > - * Our child died on a signal. Respawn it.
> > - */
> > - printf("badioctl: child died on signal %d; respawning.\n",
> > - WTERMSIG(status));
> > - fflush(stdout);
> > - }
> > -
> > - /* NOTREACHED */
> > - return 0;
> > -}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-22 0:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-21 22:47 [PATCH v2] ioctl: remove obsolete ioctl definitions and dead code that used them Kris Van Hees
2024-08-22 0:11 ` Eugene Loh
2024-08-22 0:56 ` Kris Van Hees
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox