robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 1 | /* |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 2 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 3 | * honggfuzz - core structures and macros |
| 4 | * ----------------------------------------- |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 5 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 6 | * Author: Robert Swiecki <swiecki@google.com> |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 7 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 8 | * Copyright 2010-2015 by Google Inc. All Rights Reserved. |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 9 | * |
| 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.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 12 | * a copy of the License at |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 13 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
robert.swiecki@gmail.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 15 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 16 | * 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.com | 3b630b4 | 2015-02-16 10:53:53 +0000 | [diff] [blame] | 21 | * |
robert.swiecki@gmail.com | 772b33d | 2015-02-14 20:35:00 +0000 | [diff] [blame] | 22 | */ |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 23 | |
| 24 | #ifndef _COMMON_H_ |
| 25 | #define _COMMON_H_ |
| 26 | |
robert.swiecki@gmail.com | ba85c3e | 2015-02-02 14:55:16 +0000 | [diff] [blame] | 27 | #include <limits.h> |
robert.swiecki@gmail.com | 41d8e05 | 2015-02-19 01:10:41 +0000 | [diff] [blame] | 28 | #include <pthread.h> |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 29 | #include <stdbool.h> |
| 30 | #include <stdint.h> |
robert.swiecki@gmail.com | ba85c3e | 2015-02-02 14:55:16 +0000 | [diff] [blame] | 31 | #include <sys/param.h> |
| 32 | #include <sys/types.h> |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 33 | |
| 34 | #define PROG_NAME "honggfuzz" |
robert.swiecki@gmail.com | a51662b | 2015-03-01 19:12:41 +0000 | [diff] [blame] | 35 | #define PROG_VERSION "0.6rc" |
robert.swiecki | 32b69c9 | 2015-02-26 14:56:36 +0000 | [diff] [blame] | 36 | #define PROG_AUTHORS "Robert Swiecki <swiecki@google.com> et al.,\nCopyright 2010-2015 by Google Inc. All Rights Reserved." |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 37 | |
robert.swiecki@gmail.com | 64dc2a0 | 2015-02-17 22:21:30 +0000 | [diff] [blame] | 38 | /* Name of the template which will be replaced with the proper name of the file */ |
robert.swiecki@gmail.com | a0d8714 | 2015-02-14 13:11:18 +0000 | [diff] [blame] | 39 | #define _HF_FILE_PLACEHOLDER "___FILE___" |
robert.swiecki@gmail.com | 64dc2a0 | 2015-02-17 22:21:30 +0000 | [diff] [blame] | 40 | |
| 41 | /* Default name of the report created with some architectures */ |
robert.swiecki@gmail.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 42 | #define _HF_REPORT_FILE "HONGGFUZZ.REPORT.TXT" |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 43 | |
robert.swiecki@gmail.com | 64dc2a0 | 2015-02-17 22:21:30 +0000 | [diff] [blame] | 44 | /* Default stack-size of created threads. Must be bigger then _HF_DYNAMIC_FILE_MAX_SZ */ |
robert.swiecki@gmail.com | 23b3a2f | 2015-03-01 03:40:12 +0000 | [diff] [blame] | 45 | #define _HF_PTHREAD_STACKSIZE (1024 * 1024 * 8) /* 8MB */ |
robert.swiecki@gmail.com | 01b6dd4 | 2015-02-16 18:11:28 +0000 | [diff] [blame] | 46 | |
robert.swiecki@gmail.com | e768052 | 2015-02-22 22:22:37 +0000 | [diff] [blame] | 47 | /* Align to the upper-page boundary */ |
robert.swiecki | 87f7c7e | 2015-02-26 14:11:57 +0000 | [diff] [blame] | 48 | #define _HF_PAGE_ALIGN_UP(x) (((size_t)x + (size_t)getpagesize() - (size_t)1) & ~((size_t)getpagesize() - (size_t)1)) |
robert.swiecki@gmail.com | e768052 | 2015-02-22 22:22:37 +0000 | [diff] [blame] | 49 | |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 50 | /* String buffer size for function names in stack traces produced from libunwind */ |
Jagger | d628a70 | 2015-08-23 12:59:37 +0200 | [diff] [blame] | 51 | #define _HF_FUNC_NAME_SZ 256 // Should be alright for mangled C++ procs too |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 52 | |
robert.swiecki@gmail.com | cac22fd | 2015-02-19 14:03:28 +0000 | [diff] [blame] | 53 | typedef enum { |
robert.swiecki@gmail.com | 81e26dc | 2015-03-03 04:26:04 +0000 | [diff] [blame] | 54 | _HF_DYNFILE_NONE = 0x0, |
| 55 | _HF_DYNFILE_INSTR_COUNT = 0x1, |
| 56 | _HF_DYNFILE_BRANCH_COUNT = 0x2, |
robert.swiecki@gmail.com | 10e69b6 | 2015-03-08 02:21:56 +0000 | [diff] [blame] | 57 | _HF_DYNFILE_UNIQUE_BLOCK_COUNT = 0x8, |
| 58 | _HF_DYNFILE_UNIQUE_EDGE_COUNT = 0x10, |
robert.swiecki | 2a95369 | 2015-03-16 19:33:37 +0000 | [diff] [blame] | 59 | _HF_DYNFILE_CUSTOM = 0x20, |
robert.swiecki@gmail.com | cac22fd | 2015-02-19 14:03:28 +0000 | [diff] [blame] | 60 | } dynFileMethod_t; |
| 61 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 62 | typedef struct { |
Jagger | b409ee1 | 2015-09-09 02:02:32 +0200 | [diff] [blame] | 63 | uint64_t cpuInstrCnt; |
| 64 | uint64_t cpuBranchCnt; |
| 65 | uint64_t pcCnt; |
| 66 | uint64_t pathCnt; |
| 67 | uint64_t customCnt; |
| 68 | } hwcnt_t; |
| 69 | |
| 70 | typedef struct { |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 71 | char **cmdline; |
| 72 | char *inputFile; |
| 73 | bool nullifyStdio; |
| 74 | bool fuzzStdin; |
| 75 | bool saveUnique; |
Jagger | 0764ad7 | 2015-09-06 01:11:08 +0200 | [diff] [blame] | 76 | bool useScreen; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 77 | char *fileExtn; |
Anestis Bechtsoudis | d968053 | 2015-09-06 17:37:05 +0300 | [diff] [blame] | 78 | char *workDir; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 79 | double flipRate; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 80 | char *externalCommand; |
robert.swiecki@gmail.com | 4f1124f | 2015-04-21 17:12:22 +0000 | [diff] [blame] | 81 | const char *dictionaryFile; |
| 82 | const char **dictionary; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 83 | long tmOut; |
Jagger | ea39a8f | 2015-09-05 00:57:22 +0200 | [diff] [blame] | 84 | size_t dictionaryCnt; |
| 85 | size_t mutationsMax; |
Jagger | ea39a8f | 2015-09-05 00:57:22 +0200 | [diff] [blame] | 86 | size_t threadsMax; |
| 87 | size_t threadsFinished; |
robert.swiecki@gmail.com | 4da86bf | 2015-02-22 14:24:58 +0000 | [diff] [blame] | 88 | size_t maxFileSz; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 89 | void *ignoreAddr; |
robert.swiecki@gmail.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 90 | char *reportFile; |
Robert Swiecki | c578d64 | 2015-09-08 16:13:36 +0200 | [diff] [blame] | 91 | uint64_t asLimit; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 92 | char **files; |
| 93 | int fileCnt; |
robert.swiecki@gmail.com | 15eca6f | 2015-03-04 03:31:36 +0000 | [diff] [blame] | 94 | pid_t pid; |
| 95 | char *envs[128]; |
robert.swiecki@gmail.com | 41d8e05 | 2015-02-19 01:10:41 +0000 | [diff] [blame] | 96 | |
Jagger | 630aa7f | 2015-09-06 02:53:51 +0200 | [diff] [blame] | 97 | time_t timeStart; |
Jagger | 0764ad7 | 2015-09-06 01:11:08 +0200 | [diff] [blame] | 98 | size_t mutationsCnt; |
| 99 | size_t crashesCnt; |
Anestis Bechtsoudis | d7e8ed2 | 2015-09-10 18:29:34 +0300 | [diff] [blame^] | 100 | size_t uniqueCrashesCnt; |
Jagger | 4b5281e | 2015-09-06 02:35:37 +0200 | [diff] [blame] | 101 | size_t timeoutedCnt; |
Jagger | 0764ad7 | 2015-09-06 01:11:08 +0200 | [diff] [blame] | 102 | |
robert.swiecki@gmail.com | cac22fd | 2015-02-19 14:03:28 +0000 | [diff] [blame] | 103 | /* For the linux/ code */ |
robert.swiecki@gmail.com | cd74cfc | 2015-02-19 16:37:49 +0000 | [diff] [blame] | 104 | uint8_t *dynamicFileBest; |
robert.swiecki@gmail.com | 6d6f756 | 2015-02-17 22:18:51 +0000 | [diff] [blame] | 105 | size_t dynamicFileBestSz; |
robert.swiecki@gmail.com | cac22fd | 2015-02-19 14:03:28 +0000 | [diff] [blame] | 106 | dynFileMethod_t dynFileMethod; |
Jagger | b409ee1 | 2015-09-09 02:02:32 +0200 | [diff] [blame] | 107 | hwcnt_t hwCnts; |
robert.swiecki@gmail.com | 684f60c | 2015-03-01 17:39:18 +0000 | [diff] [blame] | 108 | uint64_t dynamicCutOffAddr; |
robert.swiecki@gmail.com | 41d8e05 | 2015-02-19 01:10:41 +0000 | [diff] [blame] | 109 | pthread_mutex_t dynamicFile_mutex; |
Jagger | dbc4a15 | 2015-09-08 01:26:58 +0200 | [diff] [blame] | 110 | bool disableRandomization; |
| 111 | bool msanReportUMRS; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 112 | } honggfuzz_t; |
| 113 | |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 114 | typedef struct fuzzer_t { |
| 115 | pid_t pid; |
robert.swiecki@gmail.com | 3213a11 | 2015-03-12 01:42:02 +0000 | [diff] [blame] | 116 | int64_t timeStartedMillis; |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 117 | 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.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 123 | char report[8192]; |
robert.swiecki@gmail.com | d4dd4df | 2015-02-18 00:50:12 +0000 | [diff] [blame] | 124 | |
| 125 | /* For linux/ code */ |
robert.swiecki@gmail.com | cd74cfc | 2015-02-19 16:37:49 +0000 | [diff] [blame] | 126 | uint8_t *dynamicFile; |
Jagger | b409ee1 | 2015-09-09 02:02:32 +0200 | [diff] [blame] | 127 | hwcnt_t hwCnts; |
robert.swiecki@gmail.com | 4da86bf | 2015-02-22 14:24:58 +0000 | [diff] [blame] | 128 | size_t dynamicFileSz; |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 129 | } fuzzer_t; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 130 | |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 131 | #define _HF_MAX_FUNCS 80 |
robert.swiecki@gmail.com | a0d8714 | 2015-02-14 13:11:18 +0000 | [diff] [blame] | 132 | typedef struct { |
| 133 | void *pc; |
Anestis Bechtsoudis | cfc39fb | 2015-08-06 10:31:36 +0300 | [diff] [blame] | 134 | char func[_HF_FUNC_NAME_SZ]; |
| 135 | size_t line; |
robert.swiecki@gmail.com | a0d8714 | 2015-02-14 13:11:18 +0000 | [diff] [blame] | 136 | } funcs_t; |
| 137 | |
robert.swiecki@gmail.com | 4da86bf | 2015-02-22 14:24:58 +0000 | [diff] [blame] | 138 | #define ARRAYSIZE(x) (sizeof(x) / sizeof(*x)) |
| 139 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 140 | #endif |