Skip to content

Commit

Permalink
Merge pull request AFLplusplus#1205 from yuawn/rename
Browse files Browse the repository at this point in the history
rename active_paths
  • Loading branch information
vanhauser-thc authored Dec 11, 2021
2 parents 74aa826 + 602eafc commit 5ec91ad
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 110 deletions.
2 changes: 1 addition & 1 deletion include/afl-fuzz.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ typedef struct afl_state {

double *alias_probability; /* alias weighted probabilities */
u32 * alias_table; /* alias weighted random lookup table */
u32 active_paths; /* enabled entries in the queue */
u32 active_items; /* enabled entries in the queue */

u8 *var_bytes; /* Bytes that appear to be variable */

Expand Down
49 changes: 27 additions & 22 deletions include/xxhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ XXH128_hashFromCanonical(const XXH128_canonical_t *src);
* These declarations should only be used with static linking.
* Never use them in association with dynamic linking!
*****************************************************************************
*/
*/

/*
* These definitions are only present to allow static allocation
Expand Down Expand Up @@ -1435,9 +1435,9 @@ XXH_PUBLIC_API XXH128_hash_t XXH128(const void *data, size_t len,
#define XXH_OLD_NAMES
#undef XXH_OLD_NAMES /* don't actually use, it is ugly. */
#endif /* XXH_DOXYGEN */
/*!
* @}
*/
/*!
* @}
*/

#ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command \
line for example */
Expand Down Expand Up @@ -1601,13 +1601,15 @@ static void *XXH_memcpy(void *dest, const void *src, size_t size) {
static_assert((c), m); \
\
} while (0)

#elif defined(__cplusplus) && (__cplusplus >= 201103L) /* C++11 */
#define XXH_STATIC_ASSERT_WITH_MESSAGE(c, m) \
do { \
\
static_assert((c), m); \
\
} while (0)

#else
#define XXH_STATIC_ASSERT_WITH_MESSAGE(c, m) \
do { \
Expand All @@ -1619,6 +1621,7 @@ static void *XXH_memcpy(void *dest, const void *src, size_t size) {
}; \
\
} while (0)

#endif
#define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c), #c)
#endif
Expand Down Expand Up @@ -1830,7 +1833,7 @@ static int XXH_isLittleEndian(void) {
return one.c[0];

}
\

#define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian()
#endif
#endif
Expand Down Expand Up @@ -2079,23 +2082,6 @@ static xxh_u32 XXH32_avalanche(xxh_u32 h32) {

#define XXH_get32bits(p) XXH_readLE32_align(p, align)

/*!
* @internal
* @brief Processes the last 0-15 bytes of @p ptr.
*
* There may be up to 15 bytes remaining to consume from the input.
* This final stage will digest them to ensure that all input bytes are present
* in the final mix.
*
* @param h32 The hash to finalize.
* @param ptr The pointer to the remaining input.
* @param len The remaining length, modulo 16.
* @param align Whether @p ptr is aligned.
* @return The finalized hash.
*/
static xxh_u32 XXH32_finalize(xxh_u32 h32, const xxh_u8 *ptr, size_t len,
XXH_alignment align) {
\
#define XXH_PROCESS1 \
do { \
\
Expand All @@ -2113,6 +2099,23 @@ static xxh_u32 XXH32_finalize(xxh_u32 h32, const xxh_u8 *ptr, size_t len,
\
} while (0)

/*!
* @internal
* @brief Processes the last 0-15 bytes of @p ptr.
*
* There may be up to 15 bytes remaining to consume from the input.
* This final stage will digest them to ensure that all input bytes are present
* in the final mix.
*
* @param h32 The hash to finalize.
* @param ptr The pointer to the remaining input.
* @param len The remaining length, modulo 16.
* @param align Whether @p ptr is aligned.
* @return The finalized hash.
*/
static xxh_u32 XXH32_finalize(xxh_u32 h32, const xxh_u8 *ptr, size_t len,
XXH_alignment align) {

/* Compact rerolled version */
if (XXH_REROLL) {

Expand Down Expand Up @@ -3385,6 +3388,7 @@ enum XXH_VECTOR_TYPE /* fake enum */ {
(outHi) = vget_high_u32(vreinterpretq_u32_u64(in)); \
\
} while (0)

#else
#define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \
do { \
Expand All @@ -3393,6 +3397,7 @@ enum XXH_VECTOR_TYPE /* fake enum */ {
(outHi) = vshrn_n_u64((in), 32); \
\
} while (0)

#endif
#endif /* XXH_VECTOR == XXH_NEON */

Expand Down
97 changes: 54 additions & 43 deletions instrumentation/split-compares-pass.so.cc
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
// BUG FIXME TODO: u64 does not work for > 64 bit ... e.g. 80 and 128 bit
if (sizeInBits > 64) { continue; }

IntegerType *intType = IntegerType::get(C, op_size);
IntegerType * intType = IntegerType::get(C, op_size);
const unsigned int precision = sizeInBits == 32 ? 24
: sizeInBits == 64 ? 53
: sizeInBits == 128 ? 113
Expand Down Expand Up @@ -916,13 +916,14 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
/* create the integers from floats directly */
Instruction *bpre_op0, *bpre_op1;
bpre_op0 = CastInst::Create(Instruction::BitCast, op0,
IntegerType::get(C, op_size));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), bpre_op0);
IntegerType::get(C, op_size));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
bpre_op0);

bpre_op1 = CastInst::Create(Instruction::BitCast, op1,
IntegerType::get(C, op_size));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), bpre_op1);

IntegerType::get(C, op_size));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
bpre_op1);

/* Check if any operand is NaN.
* If so, all comparisons except unequal (which yields true) yield false */
Expand All @@ -940,41 +941,41 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
/* Check op0 for NaN */
/* Shift left 1 Bit, ignore sign bit */
Instruction *nan_op0, *nan_op1;
nan_op0 = BinaryOperator::Create(
Instruction::Shl, bpre_op0,
ConstantInt::get(bpre_op0->getType(), 1));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), nan_op0);
nan_op0 = BinaryOperator::Create(Instruction::Shl, bpre_op0,
ConstantInt::get(bpre_op0->getType(), 1));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
nan_op0);

/* compare to NaN interval */
Instruction *is_op0_nan =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op0, ConstantInt::get(intType, NaN_lowend) );
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op0,
ConstantInt::get(intType, NaN_lowend));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
is_op0_nan);

/* Check op1 for NaN */
/* Shift right 1 Bit, ignore sign bit */
nan_op1 = BinaryOperator::Create(
Instruction::Shl, bpre_op1,
ConstantInt::get(bpre_op1->getType(), 1));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), nan_op1);
nan_op1 = BinaryOperator::Create(Instruction::Shl, bpre_op1,
ConstantInt::get(bpre_op1->getType(), 1));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
nan_op1);

/* compare to NaN interval */
Instruction *is_op1_nan =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op1, ConstantInt::get(intType, NaN_lowend) );
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op1,
ConstantInt::get(intType, NaN_lowend));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
is_op1_nan);

/* combine checks */
Instruction *is_nan = BinaryOperator::Create(
Instruction::Or, is_op0_nan, is_op1_nan);
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
is_nan);
Instruction *is_nan =
BinaryOperator::Create(Instruction::Or, is_op0_nan, is_op1_nan);
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), is_nan);

/* the result of the comparison, when at least one op is NaN
is true only for the "NOT EQUAL" predicates. */
bool NaNcmp_result =
FcmpInst->getPredicate() == CmpInst::FCMP_ONE ||
FcmpInst->getPredicate() == CmpInst::FCMP_UNE;
bool NaNcmp_result = FcmpInst->getPredicate() == CmpInst::FCMP_ONE ||
FcmpInst->getPredicate() == CmpInst::FCMP_UNE;

BasicBlock *nonan_bb =
BasicBlock::Create(C, "noNaN", end_bb->getParent(), end_bb);
Expand All @@ -989,24 +990,30 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
/*** now working in nonan_bb ***/

/* Treat -0.0 as equal to +0.0, that is for -0.0 make it +0.0 */
Instruction *b_op0, *b_op1;
Instruction *isMzero_op0, *isMzero_op1;
Instruction * b_op0, *b_op1;
Instruction * isMzero_op0, *isMzero_op1;
const unsigned long long MinusZero = 1UL << (sizeInBits - 1U);
const unsigned long long PlusZero = 0;

isMzero_op0 =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op0, ConstantInt::get(intType, MinusZero));
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op0);
isMzero_op0 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op0,
ConstantInt::get(intType, MinusZero));
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op0);

isMzero_op1 =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op1, ConstantInt::get(intType, MinusZero));
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op1);
isMzero_op1 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op1,
ConstantInt::get(intType, MinusZero));
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op1);

b_op0 = SelectInst::Create(isMzero_op0, ConstantInt::get(intType, PlusZero), bpre_op0);
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), b_op0);
b_op0 = SelectInst::Create(isMzero_op0, ConstantInt::get(intType, PlusZero),
bpre_op0);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), b_op0);

b_op1 = SelectInst::Create(isMzero_op1, ConstantInt::get(intType, PlusZero), bpre_op1);
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), b_op1);
b_op1 = SelectInst::Create(isMzero_op1, ConstantInt::get(intType, PlusZero),
bpre_op1);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), b_op1);

/* isolate signs of value of floating point type */

Expand All @@ -1017,22 +1024,26 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
s_s0 =
BinaryOperator::Create(Instruction::LShr, b_op0,
ConstantInt::get(b_op0->getType(), op_size - 1));
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), s_s0);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), s_s0);
t_s0 = new TruncInst(s_s0, Int1Ty);
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), t_s0);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), t_s0);

s_s1 =
BinaryOperator::Create(Instruction::LShr, b_op1,
ConstantInt::get(b_op1->getType(), op_size - 1));
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), s_s1);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), s_s1);
t_s1 = new TruncInst(s_s1, Int1Ty);
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), t_s1);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), t_s1);

/* compare of the sign bits */
icmp_sign_bit =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_s0, t_s1);
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()),
icmp_sign_bit);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), icmp_sign_bit);

/* create a new basic block which is executed if the signedness bits are
* equal */
Expand Down Expand Up @@ -1440,8 +1451,8 @@ bool SplitComparesTransform::runOnModule(Module &M) {

if (!be_quiet && !debug) {

errs() << "Split-floatingpoint-compare-pass: " << count
<< " FP comparisons splitted\n";
errs() << "Split-floatingpoint-compare-pass: " << count
<< " FP comparisons splitted\n";

}

Expand Down
8 changes: 4 additions & 4 deletions src/afl-fuzz-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ void perform_dry_run(afl_state_t *afl) {

q->was_fuzzed = 1;
--afl->pending_not_fuzzed;
--afl->active_paths;
--afl->active_items;

}

Expand Down Expand Up @@ -1051,7 +1051,7 @@ void perform_dry_run(afl_state_t *afl) {

q->was_fuzzed = 1;
--afl->pending_not_fuzzed;
--afl->active_paths;
--afl->active_items;

}

Expand Down Expand Up @@ -1162,7 +1162,7 @@ void perform_dry_run(afl_state_t *afl) {

p->was_fuzzed = 1;
--afl->pending_not_fuzzed;
--afl->active_paths;
--afl->active_items;

}

Expand All @@ -1175,7 +1175,7 @@ void perform_dry_run(afl_state_t *afl) {

q->was_fuzzed = 1;
--afl->pending_not_fuzzed;
--afl->active_paths;
--afl->active_items;

}

Expand Down
4 changes: 2 additions & 2 deletions src/afl-fuzz-one.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ u8 fuzz_one_original(afl_state_t *afl) {
afl->queue_cur->perf_score = orig_perf = perf_score =
calculate_score(afl, afl->queue_cur);

if (unlikely(perf_score <= 0 && afl->active_paths > 1)) {
if (unlikely(perf_score <= 0 && afl->active_items > 1)) {

goto abandon_entry;

Expand Down Expand Up @@ -3064,7 +3064,7 @@ static u8 mopt_common_fuzzing(afl_state_t *afl, MOpt_globals_t MOpt_globals) {
else
orig_perf = perf_score = calculate_score(afl, afl->queue_cur);

if (unlikely(perf_score <= 0 && afl->active_paths > 1)) {
if (unlikely(perf_score <= 0 && afl->active_items > 1)) {

goto abandon_entry;

Expand Down
2 changes: 1 addition & 1 deletion src/afl-fuzz-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ void add_to_queue(afl_state_t *afl, u8 *fname, u32 len, u8 passed_det) {
if (likely(q->len > 4)) afl->ready_for_splicing_count++;

++afl->queued_items;
++afl->active_paths;
++afl->active_items;
++afl->pending_not_fuzzed;

afl->cycles_wo_finds = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/afl-fuzz-redqueen.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ static u8 colorization(afl_state_t *afl, u8 *buf, u32 len,

if (afl->colorize_success && afl->cmplog_lvl < 3 &&
(positions > CMPLOG_POSITIONS_MAX && len / positions == 1 &&
afl->active_paths / afl->colorize_success > CMPLOG_CORPUS_PERCENT)) {
afl->active_items / afl->colorize_success > CMPLOG_CORPUS_PERCENT)) {

#ifdef _DEBUG
fprintf(stderr, "Colorization unsatisfactory\n");
Expand Down
Loading

0 comments on commit 5ec91ad

Please sign in to comment.