baddof.c revision 4fe01614e64281d82c5a22f0050e55f1e0bdbdae
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <math.h>
#include <dtrace.h>
void
{
exit(1);
}
#define LEAP_DISTANCE 20
void
{
int bit, i;
unsigned char saved;
/*
* We are going iterate through, flipping one bit and attempting
* to enable.
*/
if ((bit % 100) == 0)
/*
* That failed -- restore the bit and drive on.
*/
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.
*/
if (ttl < 10000) {
continue;
}
if (new == -1)
fatal("couldn't open DTrace pseudo device");
}
ttl = 0;
}
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.
*/
}
/*
* Let's see if that managed to get us valid DOF...
*/
/*
* Success! This will be our new base for valid DOF.
*/
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--)
}
}
int
{
if (argc < 1)
fatal("expected D script as argument\n");
/*
* First, we need to compile our provided D into DOF.
*/
fatal("cannot open dtrace library: %s\n",
}
}
for (;;) {
/*
* Open another instance of the dtrace device.
*/
if (fd == -1)
fatal("couldn't open DTrace pseudo device");
}
/* NOTREACHED */
return (0);
}