blob: 2183338bc6d7e5790cc79d593a6d0dc6f1cfed06 [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.coma51662b2015-03-01 19:12:41 +000036#define PROG_VERSION "0.6rc"
robert.swiecki32b69c92015-02-26 14:56:36 +000037#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 +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.com23b3a2f2015-03-01 03:40:12 +000046#define _HF_PTHREAD_STACKSIZE (1024 * 1024 * 8) /* 8MB */
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 */
robert.swiecki87f7c7e2015-02-26 14:11:57 +000049#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 +000050
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +030051/* String buffer size for function names in stack traces produced from libunwind */
52#define _HF_FUNC_NAME_SZ 256 //Should be alright for mangled C++ procs too
53
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000054typedef enum {
robert.swiecki@gmail.com81e26dc2015-03-03 04:26:04 +000055 _HF_DYNFILE_NONE = 0x0,
56 _HF_DYNFILE_INSTR_COUNT = 0x1,
57 _HF_DYNFILE_BRANCH_COUNT = 0x2,
robert.swiecki@gmail.com10e69b62015-03-08 02:21:56 +000058 _HF_DYNFILE_UNIQUE_BLOCK_COUNT = 0x8,
59 _HF_DYNFILE_UNIQUE_EDGE_COUNT = 0x10,
robert.swiecki2a953692015-03-16 19:33:37 +000060 _HF_DYNFILE_CUSTOM = 0x20,
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000061} dynFileMethod_t;
62
robert.swiecki3bb518c2010-10-14 00:48:24 +000063typedef struct {
64 char **cmdline;
65 char *inputFile;
66 bool nullifyStdio;
67 bool fuzzStdin;
68 bool saveUnique;
69 char *fileExtn;
70 double flipRate;
robert.swiecki3bb518c2010-10-14 00:48:24 +000071 char *externalCommand;
robert.swiecki@gmail.com4f1124f2015-04-21 17:12:22 +000072 const char *dictionaryFile;
73 const char **dictionary;
74 size_t dictionaryCnt;
robert.swiecki3bb518c2010-10-14 00:48:24 +000075 long tmOut;
groebert@google.com8e2f44a2013-03-15 13:54:18 +000076 long mutationsMax;
77 long mutationsCnt;
robert.swiecki3bb518c2010-10-14 00:48:24 +000078 long threadsMax;
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +000079 size_t maxFileSz;
robert.swiecki3bb518c2010-10-14 00:48:24 +000080 void *ignoreAddr;
robert.swiecki@gmail.come7190b92015-02-14 23:05:42 +000081 char *reportFile;
robert.swiecki3bb518c2010-10-14 00:48:24 +000082 unsigned long asLimit;
robert.swiecki3bb518c2010-10-14 00:48:24 +000083 char **files;
84 int fileCnt;
robert.swiecki@gmail.com9bc725e2015-02-13 12:40:06 +000085 sem_t *sem;
robert.swiecki@gmail.com15eca6f2015-03-04 03:31:36 +000086 pid_t pid;
87 char *envs[128];
robert.swiecki@gmail.com41d8e052015-02-19 01:10:41 +000088
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000089 /* For the linux/ code */
robert.swiecki@gmail.comcd74cfc2015-02-19 16:37:49 +000090 uint8_t *dynamicFileBest;
robert.swiecki@gmail.com6d6f7562015-02-17 22:18:51 +000091 size_t dynamicFileBestSz;
robert.swiecki@gmail.comcac22fd2015-02-19 14:03:28 +000092 dynFileMethod_t dynFileMethod;
robert.swiecki@gmail.comf845d4d2015-03-05 02:46:33 +000093 int64_t branchBestCnt[4];
robert.swiecki@gmail.com90f36e62015-03-01 15:13:54 +000094 int dynamicRegressionCnt;
robert.swiecki@gmail.com684f60c2015-03-01 17:39:18 +000095 uint64_t dynamicCutOffAddr;
robert.swiecki@gmail.com41d8e052015-02-19 01:10:41 +000096 pthread_mutex_t dynamicFile_mutex;
robert.swiecki3bb518c2010-10-14 00:48:24 +000097} honggfuzz_t;
98
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +000099typedef struct fuzzer_t {
100 pid_t pid;
robert.swiecki@gmail.com3213a112015-03-12 01:42:02 +0000101 int64_t timeStartedMillis;
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +0000102 char origFileName[PATH_MAX];
103 char fileName[PATH_MAX];
104 uint64_t pc;
105 uint64_t backtrace;
106 uint64_t access;
107 int exception;
robert.swiecki@gmail.come7190b92015-02-14 23:05:42 +0000108 char report[8192];
robert.swiecki@gmail.comd4dd4df2015-02-18 00:50:12 +0000109
110 /* For linux/ code */
robert.swiecki@gmail.comcd74cfc2015-02-19 16:37:49 +0000111 uint8_t *dynamicFile;
robert.swiecki@gmail.comf845d4d2015-03-05 02:46:33 +0000112 int64_t branchCnt[4];
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +0000113 size_t dynamicFileSz;
robert.swiecki@gmail.com882900b2015-02-11 13:56:22 +0000114} fuzzer_t;
robert.swiecki3bb518c2010-10-14 00:48:24 +0000115
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300116#define _HF_MAX_FUNCS 80
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +0000117typedef struct {
118 void *pc;
Anestis Bechtsoudiscfc39fb2015-08-06 10:31:36 +0300119 char func[_HF_FUNC_NAME_SZ];
120 size_t line;
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +0000121} funcs_t;
122
robert.swiecki@gmail.com4da86bf2015-02-22 14:24:58 +0000123#define ARRAYSIZE(x) (sizeof(x) / sizeof(*x))
124
robert.swiecki3bb518c2010-10-14 00:48:24 +0000125#endif