blob: 8e4c9088d8097b081f26426521f8ce0f90579d2e [file] [log] [blame]
robert.swiecki3bb518c2010-10-14 00:48:24 +00001/*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00002 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +00003 * honggfuzz - core structures and macros
4 * -----------------------------------------
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00005 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +00006 * Author: Robert Swiecki <swiecki@google.com>
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00007 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +00008 * Copyright 2010-2015 by Google Inc. All Rights Reserved.
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00009 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License. You may obtain
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000012 * a copy of the License at
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000013 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000014 * http://www.apache.org/licenses/LICENSE-2.0
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000015 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000016 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19 * implied. See the License for the specific language governing
20 * permissions and limitations under the License.
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000021 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000022 */
robert.swiecki3bb518c2010-10-14 00:48:24 +000023
24#ifndef _COMMON_H_
25#define _COMMON_H_
26
robert.swiecki@gmail.comba85c3e2015-02-02 14:55:16 +000027#include <limits.h>
robert.swiecki@gmail.com41d8e052015-02-19 01:10:41 +000028#include <pthread.h>
robert.swiecki@gmail.come507cb62015-02-11 17:14:49 +000029#include <semaphore.h>
robert.swiecki3bb518c2010-10-14 00:48:24 +000030#include <stdbool.h>
31#include <stdint.h>
robert.swiecki@gmail.comba85c3e2015-02-02 14:55:16 +000032#include <sys/param.h>
33#include <sys/types.h>
robert.swiecki3bb518c2010-10-14 00:48:24 +000034
35#define PROG_NAME "honggfuzz"
robert.swiecki@gmail.come68a71c2015-02-01 16:13:00 +000036#define PROG_VERSION "0.4"
37#define PROG_AUTHORS "Robert Swiecki <swiecki@google.com> and others, Copyright 2010-2015 by Google Inc. All Rights Reserved."
robert.swiecki3bb518c2010-10-14 00:48:24 +000038
robert.swiecki@gmail.com64dc2a02015-02-17 22:21:30 +000039/* Name of the template which will be replaced with the proper name of the file */
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +000040#define _HF_FILE_PLACEHOLDER "___FILE___"
robert.swiecki@gmail.com64dc2a02015-02-17 22:21:30 +000041
42/* Default name of the report created with some architectures */
robert.swiecki@gmail.come7190b92015-02-14 23:05:42 +000043#define _HF_REPORT_FILE "HONGGFUZZ.REPORT.TXT"
robert.swiecki3bb518c2010-10-14 00:48:24 +000044
robert.swiecki@gmail.com64dc2a02015-02-17 22:21:30 +000045/* Default stack-size of created threads. Must be bigger then _HF_DYNAMIC_FILE_MAX_SZ */
robert.swiecki@gmail.comc471a9f2015-02-25 17:28:06 +000046#define _HF_PTHREAD_STACKSIZE (1024 * 1024 * 4) /* 4MB */
robert.swiecki@gmail.com01b6dd42015-02-16 18:11:28 +000047
robert.swiecki@gmail.come7680522015-02-22 22:22:37 +000048/* Align to the upper-page boundary */
49#define _HF_PAGE_ALIGN_UP(x) (((size_t)x + (size_t)sysconf(_SC_PAGESIZE) - 1) & ~((size_t)sysconf(_SC_PAGESIZE) - 1))
50
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000051typedef enum {
52 _HF_DYNFILE_NONE = 0,
53 _HF_DYNFILE_INSTR_COUNT,
54 _HF_DYNFILE_BRANCH_COUNT,
robert.swiecki@gmail.comf987e552015-02-25 01:47:07 +000055 _HF_DYNFILE_UNIQUE_PC_COUNT,
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000056} dynFileMethod_t;
57
robert.swiecki3bb518c2010-10-14 00:48:24 +000058typedef struct {
59 char **cmdline;
60 char *inputFile;
61 bool nullifyStdio;
62 bool fuzzStdin;
63 bool saveUnique;
64 char *fileExtn;
65 double flipRate;
robert.swiecki3bb518c2010-10-14 00:48:24 +000066 char *externalCommand;
67 long tmOut;
groebert@google.com8e2f44a2013-03-15 13:54:18 +000068 long mutationsMax;
69 long mutationsCnt;
robert.swiecki3bb518c2010-10-14 00:48:24 +000070 long threadsMax;
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +000071 size_t maxFileSz;
robert.swiecki3bb518c2010-10-14 00:48:24 +000072 void *ignoreAddr;
robert.swiecki@gmail.come7190b92015-02-14 23:05:42 +000073 char *reportFile;
robert.swiecki3bb518c2010-10-14 00:48:24 +000074 unsigned long asLimit;
robert.swiecki3bb518c2010-10-14 00:48:24 +000075 char **files;
76 int fileCnt;
robert.swiecki@gmail.com9bc725e2015-02-13 12:40:06 +000077 sem_t *sem;
robert.swiecki@gmail.com341dd122015-02-18 13:05:20 +000078 int pid;
robert.swiecki@gmail.com41d8e052015-02-19 01:10:41 +000079
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000080 /* For the linux/ code */
robert.swiecki@gmail.comcd74cfc2015-02-19 16:37:49 +000081 uint8_t *dynamicFileBest;
robert.swiecki@gmail.com6d6f7562015-02-17 22:18:51 +000082 size_t dynamicFileBestSz;
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000083 dynFileMethod_t dynFileMethod;
robert.swiecki@gmail.com1aac7532015-02-18 11:34:50 +000084 int64_t branchBestCnt;
robert.swiecki@gmail.com41d8e052015-02-19 01:10:41 +000085 pthread_mutex_t dynamicFile_mutex;
robert.swiecki3bb518c2010-10-14 00:48:24 +000086} honggfuzz_t;
87
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +000088typedef struct fuzzer_t {
89 pid_t pid;
90 time_t timeStarted;
91 char origFileName[PATH_MAX];
92 char fileName[PATH_MAX];
93 uint64_t pc;
94 uint64_t backtrace;
95 uint64_t access;
96 int exception;
robert.swiecki@gmail.come7190b92015-02-14 23:05:42 +000097 char report[8192];
robert.swiecki@gmail.comd4dd4df2015-02-18 00:50:12 +000098
99 /* For linux/ code */
robert.swiecki@gmail.comcd74cfc2015-02-19 16:37:49 +0000100 uint8_t *dynamicFile;
robert.swiecki@gmail.com1aac7532015-02-18 11:34:50 +0000101 int64_t branchCnt;
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +0000102 size_t dynamicFileSz;
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +0000103} fuzzer_t;
robert.swiecki3bb518c2010-10-14 00:48:24 +0000104
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +0000105#define _HF_MAX_FUNCS 200
106typedef struct {
107 void *pc;
108 char func[64];
robert.swiecki@gmail.com90e99112015-02-15 02:05:14 +0000109 int line;
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +0000110} funcs_t;
111
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +0000112#define ARRAYSIZE(x) (sizeof(x) / sizeof(*x))
113
robert.swiecki3bb518c2010-10-14 00:48:24 +0000114#endif