blob: 03eeed1da8aed1d4bb3e13203ed48d9f2e90692f [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.swiecki3bb518c2010-10-14 00:48:24 +000029#include <stdbool.h>
30#include <stdint.h>
robert.swiecki@gmail.comba85c3e2015-02-02 14:55:16 +000031#include <sys/param.h>
32#include <sys/types.h>
robert.swiecki3bb518c2010-10-14 00:48:24 +000033
34#define PROG_NAME "honggfuzz"
robert.swiecki@gmail.coma51662b2015-03-01 19:12:41 +000035#define PROG_VERSION "0.6rc"
robert.swiecki32b69c92015-02-26 14:56:36 +000036#define PROG_AUTHORS "Robert Swiecki <swiecki@google.com> et al.,\nCopyright 2010-2015 by Google Inc. All Rights Reserved."
robert.swiecki3bb518c2010-10-14 00:48:24 +000037
robert.swiecki@gmail.com64dc2a02015-02-17 22:21:30 +000038/* Name of the template which will be replaced with the proper name of the file */
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +000039#define _HF_FILE_PLACEHOLDER "___FILE___"
robert.swiecki@gmail.com64dc2a02015-02-17 22:21:30 +000040
41/* Default name of the report created with some architectures */
robert.swiecki@gmail.come7190b92015-02-14 23:05:42 +000042#define _HF_REPORT_FILE "HONGGFUZZ.REPORT.TXT"
robert.swiecki3bb518c2010-10-14 00:48:24 +000043
robert.swiecki@gmail.com64dc2a02015-02-17 22:21:30 +000044/* Default stack-size of created threads. Must be bigger then _HF_DYNAMIC_FILE_MAX_SZ */
robert.swiecki@gmail.com23b3a2f2015-03-01 03:40:12 +000045#define _HF_PTHREAD_STACKSIZE (1024 * 1024 * 8) /* 8MB */
robert.swiecki@gmail.com01b6dd42015-02-16 18:11:28 +000046
robert.swiecki@gmail.come7680522015-02-22 22:22:37 +000047/* Align to the upper-page boundary */
robert.swiecki87f7c7e2015-02-26 14:11:57 +000048#define _HF_PAGE_ALIGN_UP(x) (((size_t)x + (size_t)getpagesize() - (size_t)1) & ~((size_t)getpagesize() - (size_t)1))
robert.swiecki@gmail.come7680522015-02-22 22:22:37 +000049
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030050/* String buffer size for function names in stack traces produced from libunwind */
Jaggerd628a702015-08-23 12:59:37 +020051#define _HF_FUNC_NAME_SZ 256 // Should be alright for mangled C++ procs too
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030052
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000053typedef enum {
robert.swiecki@gmail.com81e26dc2015-03-03 04:26:04 +000054 _HF_DYNFILE_NONE = 0x0,
55 _HF_DYNFILE_INSTR_COUNT = 0x1,
56 _HF_DYNFILE_BRANCH_COUNT = 0x2,
robert.swiecki@gmail.com10e69b62015-03-08 02:21:56 +000057 _HF_DYNFILE_UNIQUE_BLOCK_COUNT = 0x8,
58 _HF_DYNFILE_UNIQUE_EDGE_COUNT = 0x10,
robert.swiecki2a953692015-03-16 19:33:37 +000059 _HF_DYNFILE_CUSTOM = 0x20,
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000060} dynFileMethod_t;
61
robert.swiecki3bb518c2010-10-14 00:48:24 +000062typedef struct {
Jaggerb409ee12015-09-09 02:02:32 +020063 uint64_t cpuInstrCnt;
64 uint64_t cpuBranchCnt;
65 uint64_t pcCnt;
66 uint64_t pathCnt;
67 uint64_t customCnt;
68} hwcnt_t;
69
70typedef struct {
robert.swiecki3bb518c2010-10-14 00:48:24 +000071 char **cmdline;
72 char *inputFile;
73 bool nullifyStdio;
74 bool fuzzStdin;
75 bool saveUnique;
Jagger0764ad72015-09-06 01:11:08 +020076 bool useScreen;
robert.swiecki3bb518c2010-10-14 00:48:24 +000077 char *fileExtn;
Anestis Bechtsoudisd9680532015-09-06 17:37:05 +030078 char *workDir;
robert.swiecki3bb518c2010-10-14 00:48:24 +000079 double flipRate;
robert.swiecki3bb518c2010-10-14 00:48:24 +000080 char *externalCommand;
robert.swiecki@gmail.com4f1124f2015-04-21 17:12:22 +000081 const char *dictionaryFile;
82 const char **dictionary;
robert.swiecki3bb518c2010-10-14 00:48:24 +000083 long tmOut;
Jaggerea39a8f2015-09-05 00:57:22 +020084 size_t dictionaryCnt;
85 size_t mutationsMax;
Jaggerea39a8f2015-09-05 00:57:22 +020086 size_t threadsMax;
87 size_t threadsFinished;
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +000088 size_t maxFileSz;
robert.swiecki3bb518c2010-10-14 00:48:24 +000089 void *ignoreAddr;
robert.swiecki@gmail.come7190b92015-02-14 23:05:42 +000090 char *reportFile;
Robert Swieckic578d642015-09-08 16:13:36 +020091 uint64_t asLimit;
robert.swiecki3bb518c2010-10-14 00:48:24 +000092 char **files;
93 int fileCnt;
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000094 pid_t pid;
95 char *envs[128];
robert.swiecki@gmail.com41d8e052015-02-19 01:10:41 +000096
Jagger630aa7f2015-09-06 02:53:51 +020097 time_t timeStart;
Jagger0764ad72015-09-06 01:11:08 +020098 size_t mutationsCnt;
99 size_t crashesCnt;
Anestis Bechtsoudisd7e8ed22015-09-10 18:29:34 +0300100 size_t uniqueCrashesCnt;
Jagger4b5281e2015-09-06 02:35:37 +0200101 size_t timeoutedCnt;
Jagger0764ad72015-09-06 01:11:08 +0200102
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +0000103 /* For the linux/ code */
robert.swiecki@gmail.comcd74cfc2015-02-19 16:37:49 +0000104 uint8_t *dynamicFileBest;
robert.swiecki@gmail.com6d6f7562015-02-17 22:18:51 +0000105 size_t dynamicFileBestSz;
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +0000106 dynFileMethod_t dynFileMethod;
Jaggerb409ee12015-09-09 02:02:32 +0200107 hwcnt_t hwCnts;
robert.swiecki@gmail.com684f60c2015-03-01 17:39:18 +0000108 uint64_t dynamicCutOffAddr;
robert.swiecki@gmail.com41d8e052015-02-19 01:10:41 +0000109 pthread_mutex_t dynamicFile_mutex;
Jaggerdbc4a152015-09-08 01:26:58 +0200110 bool disableRandomization;
111 bool msanReportUMRS;
robert.swiecki3bb518c2010-10-14 00:48:24 +0000112} honggfuzz_t;
113
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +0000114typedef struct fuzzer_t {
115 pid_t pid;
robert.swiecki@gmail.com3213a112015-03-12 01:42:02 +0000116 int64_t timeStartedMillis;
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +0000117 char origFileName[PATH_MAX];
118 char fileName[PATH_MAX];
119 uint64_t pc;
120 uint64_t backtrace;
121 uint64_t access;
122 int exception;
robert.swiecki@gmail.come7190b92015-02-14 23:05:42 +0000123 char report[8192];
robert.swiecki@gmail.comd4dd4df2015-02-18 00:50:12 +0000124
125 /* For linux/ code */
robert.swiecki@gmail.comcd74cfc2015-02-19 16:37:49 +0000126 uint8_t *dynamicFile;
Jaggerb409ee12015-09-09 02:02:32 +0200127 hwcnt_t hwCnts;
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +0000128 size_t dynamicFileSz;
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +0000129} fuzzer_t;
robert.swiecki3bb518c2010-10-14 00:48:24 +0000130
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300131#define _HF_MAX_FUNCS 80
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +0000132typedef struct {
133 void *pc;
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300134 char func[_HF_FUNC_NAME_SZ];
135 size_t line;
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +0000136} funcs_t;
137
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +0000138#define ARRAYSIZE(x) (sizeof(x) / sizeof(*x))
139
robert.swiecki3bb518c2010-10-14 00:48:24 +0000140#endif