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@gmail.com | e507cb6 | 2015-02-11 17:14:49 +0000 | [diff] [blame] | 29 | #include <semaphore.h> |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 30 | #include <stdbool.h> |
| 31 | #include <stdint.h> |
robert.swiecki@gmail.com | ba85c3e | 2015-02-02 14:55:16 +0000 | [diff] [blame] | 32 | #include <sys/param.h> |
| 33 | #include <sys/types.h> |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 34 | |
| 35 | #define PROG_NAME "honggfuzz" |
robert.swiecki@gmail.com | e68a71c | 2015-02-01 16:13:00 +0000 | [diff] [blame] | 36 | #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.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 38 | |
robert.swiecki@gmail.com | 64dc2a0 | 2015-02-17 22:21:30 +0000 | [diff] [blame] | 39 | /* 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] | 40 | #define _HF_FILE_PLACEHOLDER "___FILE___" |
robert.swiecki@gmail.com | 64dc2a0 | 2015-02-17 22:21:30 +0000 | [diff] [blame] | 41 | |
| 42 | /* Default name of the report created with some architectures */ |
robert.swiecki@gmail.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 43 | #define _HF_REPORT_FILE "HONGGFUZZ.REPORT.TXT" |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 44 | |
robert.swiecki@gmail.com | 64dc2a0 | 2015-02-17 22:21:30 +0000 | [diff] [blame] | 45 | /* Default stack-size of created threads. Must be bigger then _HF_DYNAMIC_FILE_MAX_SZ */ |
robert.swiecki@gmail.com | c471a9f | 2015-02-25 17:28:06 +0000 | [diff] [blame] | 46 | #define _HF_PTHREAD_STACKSIZE (1024 * 1024 * 4) /* 4MB */ |
robert.swiecki@gmail.com | 01b6dd4 | 2015-02-16 18:11:28 +0000 | [diff] [blame] | 47 | |
robert.swiecki@gmail.com | e768052 | 2015-02-22 22:22:37 +0000 | [diff] [blame] | 48 | /* 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.com | cac22fd | 2015-02-19 14:03:28 +0000 | [diff] [blame] | 51 | typedef enum { |
| 52 | _HF_DYNFILE_NONE = 0, |
| 53 | _HF_DYNFILE_INSTR_COUNT, |
| 54 | _HF_DYNFILE_BRANCH_COUNT, |
robert.swiecki@gmail.com | f987e55 | 2015-02-25 01:47:07 +0000 | [diff] [blame] | 55 | _HF_DYNFILE_UNIQUE_PC_COUNT, |
robert.swiecki@gmail.com | cac22fd | 2015-02-19 14:03:28 +0000 | [diff] [blame] | 56 | } dynFileMethod_t; |
| 57 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 58 | typedef struct { |
| 59 | char **cmdline; |
| 60 | char *inputFile; |
| 61 | bool nullifyStdio; |
| 62 | bool fuzzStdin; |
| 63 | bool saveUnique; |
| 64 | char *fileExtn; |
| 65 | double flipRate; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 66 | char *externalCommand; |
| 67 | long tmOut; |
groebert@google.com | 8e2f44a | 2013-03-15 13:54:18 +0000 | [diff] [blame] | 68 | long mutationsMax; |
| 69 | long mutationsCnt; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 70 | long threadsMax; |
robert.swiecki@gmail.com | 4da86bf | 2015-02-22 14:24:58 +0000 | [diff] [blame] | 71 | size_t maxFileSz; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 72 | void *ignoreAddr; |
robert.swiecki@gmail.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 73 | char *reportFile; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 74 | unsigned long asLimit; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 75 | char **files; |
| 76 | int fileCnt; |
robert.swiecki@gmail.com | 9bc725e | 2015-02-13 12:40:06 +0000 | [diff] [blame] | 77 | sem_t *sem; |
robert.swiecki@gmail.com | 341dd12 | 2015-02-18 13:05:20 +0000 | [diff] [blame] | 78 | int pid; |
robert.swiecki@gmail.com | 41d8e05 | 2015-02-19 01:10:41 +0000 | [diff] [blame] | 79 | |
robert.swiecki@gmail.com | cac22fd | 2015-02-19 14:03:28 +0000 | [diff] [blame] | 80 | /* For the linux/ code */ |
robert.swiecki@gmail.com | cd74cfc | 2015-02-19 16:37:49 +0000 | [diff] [blame] | 81 | uint8_t *dynamicFileBest; |
robert.swiecki@gmail.com | 6d6f756 | 2015-02-17 22:18:51 +0000 | [diff] [blame] | 82 | size_t dynamicFileBestSz; |
robert.swiecki@gmail.com | cac22fd | 2015-02-19 14:03:28 +0000 | [diff] [blame] | 83 | dynFileMethod_t dynFileMethod; |
robert.swiecki@gmail.com | 1aac753 | 2015-02-18 11:34:50 +0000 | [diff] [blame] | 84 | int64_t branchBestCnt; |
robert.swiecki@gmail.com | 41d8e05 | 2015-02-19 01:10:41 +0000 | [diff] [blame] | 85 | pthread_mutex_t dynamicFile_mutex; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 86 | } honggfuzz_t; |
| 87 | |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 88 | typedef 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.com | e7190b9 | 2015-02-14 23:05:42 +0000 | [diff] [blame] | 97 | char report[8192]; |
robert.swiecki@gmail.com | d4dd4df | 2015-02-18 00:50:12 +0000 | [diff] [blame] | 98 | |
| 99 | /* For linux/ code */ |
robert.swiecki@gmail.com | cd74cfc | 2015-02-19 16:37:49 +0000 | [diff] [blame] | 100 | uint8_t *dynamicFile; |
robert.swiecki@gmail.com | 1aac753 | 2015-02-18 11:34:50 +0000 | [diff] [blame] | 101 | int64_t branchCnt; |
robert.swiecki@gmail.com | 4da86bf | 2015-02-22 14:24:58 +0000 | [diff] [blame] | 102 | size_t dynamicFileSz; |
robert.swiecki@gmail.com | 882900b | 2015-02-11 13:56:22 +0000 | [diff] [blame] | 103 | } fuzzer_t; |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 104 | |
robert.swiecki@gmail.com | a0d8714 | 2015-02-14 13:11:18 +0000 | [diff] [blame] | 105 | #define _HF_MAX_FUNCS 200 |
| 106 | typedef struct { |
| 107 | void *pc; |
| 108 | char func[64]; |
robert.swiecki@gmail.com | 90e9911 | 2015-02-15 02:05:14 +0000 | [diff] [blame] | 109 | int line; |
robert.swiecki@gmail.com | a0d8714 | 2015-02-14 13:11:18 +0000 | [diff] [blame] | 110 | } funcs_t; |
| 111 | |
robert.swiecki@gmail.com | 4da86bf | 2015-02-22 14:24:58 +0000 | [diff] [blame] | 112 | #define ARRAYSIZE(x) (sizeof(x) / sizeof(*x)) |
| 113 | |
robert.swiecki | 3bb518c | 2010-10-14 00:48:24 +0000 | [diff] [blame] | 114 | #endif |