blob: 98ac5b8990cfcb86518ef2f297326b95ce29be3d [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 - architecture dependent code (MAC OS X)
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> Felix Gröbert
7 * <groebert@google.com>
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +00008 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +00009 * Copyright 2010-2015 by Google Inc. All Rights Reserved.
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000010 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License. You may obtain
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000013 * a copy of the License at
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000014 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000015 * http://www.apache.org/licenses/LICENSE-2.0
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000016 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000017 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
20 * implied. See the License for the specific language governing
21 * permissions and limitations under the License.
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000022 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000023 */
robert.swiecki3bb518c2010-10-14 00:48:24 +000024
robert.swiecki@gmail.comba85c3e2015-02-02 14:55:16 +000025#include "common.h"
26#include "arch.h"
27
robert.swiecki3bb518c2010-10-14 00:48:24 +000028#include <ctype.h>
groebert@google.comb857deb2010-10-21 19:09:29 +000029#include <dirent.h>
robert.swiecki@gmail.comba85c3e2015-02-02 14:55:16 +000030#include <errno.h>
groebert@google.comb857deb2010-10-21 19:09:29 +000031#include <fcntl.h>
robert.swiecki@gmail.comba85c3e2015-02-02 14:55:16 +000032#include <signal.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include <sys/cdefs.h>
37#include <sys/mman.h>
Jagger8f94f5b2016-04-02 02:11:10 +020038#include <sys/stat.h>
robert.swiecki@gmail.comba85c3e2015-02-02 14:55:16 +000039#include <sys/time.h>
40#include <sys/types.h>
41#include <sys/wait.h>
42#include <sys/resource.h>
43#include <time.h>
44#include <unistd.h>
robert.swiecki3bb518c2010-10-14 00:48:24 +000045
groebert@google.comb857deb2010-10-21 19:09:29 +000046#include "files.h"
Jagger3db1d952016-03-10 02:02:46 +010047#include "log.h"
48#include "sancov.h"
Robert Swiecki559801c2016-03-31 19:15:47 +020049#include "subproc.h"
Jagger3db1d952016-03-10 02:02:46 +010050#include "util.h"
robert.swiecki3bb518c2010-10-14 00:48:24 +000051
groebert@google.com1bd4c212013-06-19 11:13:56 +000052#include <servers/bootstrap.h>
53#include <mach/mach.h>
54#include <mach/mach_vm.h>
55#include <mach/mach_types.h>
56#include <mach/i386/thread_status.h>
57#include <mach/task_info.h>
58#include <pthread.h>
59
60#include "mach_exc.h"
61#include "mach_excServer.h"
62
63#import <Foundation/Foundation.h>
64
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000065/*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000066 * Interface to third_party/CrashReport_*.o
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000067 */
groebert@google.com43216c82015-02-13 11:11:38 +000068/* *INDENT-OFF* */
robert.swiecki@gmail.com4be26672015-03-05 03:36:50 +000069@interface CrashReport : NSObject - (id) initWithTask:(task_t)
70 task exceptionType:(exception_type_t)
71 anExceptionType exceptionCode:(mach_exception_data_t)
72 anExceptionCode exceptionCodeCount:(mach_msg_type_number_t)
73 anExceptionCodeCount thread:(thread_t)
74 thread threadStateFlavor:(thread_state_flavor_t)
75 aThreadStateFlavor threadState:(thread_state_data_t)
76 aThreadState threadStateCount:(mach_msg_type_number_t) aThreadStateCount;
groebert@google.com1bd4c212013-06-19 11:13:56 +000077@end
groebert@google.com43216c82015-02-13 11:11:38 +000078/* *INDENT-ON* */
79
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000080/*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000081 * Global to have exception port available in the collection thread
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000082 */
groebert@google.com1bd4c212013-06-19 11:13:56 +000083static mach_port_t g_exception_port = MACH_PORT_NULL;
84
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000085/*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000086 * From xnu/bsd/sys/proc_internal.h
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000087 */
groebert@google.comc659c0e2015-02-13 11:17:00 +000088#define PID_MAX 99999
groebert@google.com43216c82015-02-13 11:11:38 +000089
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000090/*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000091 * Global to store crash info in exception handler thread
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000092 */
groebert@google.comc659c0e2015-02-13 11:17:00 +000093fuzzer_t g_fuzzer_crash_information[PID_MAX + 1];
groebert@google.com43216c82015-02-13 11:11:38 +000094
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000095/*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +000096 * Global to have a unique service name for each honggfuzz process
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +000097 */
groebert@google.com76afff92013-06-20 14:43:41 +000098char g_service_name[256];
groebert@google.com16610ee2013-06-19 13:06:12 +000099
robert.swiecki3bb518c2010-10-14 00:48:24 +0000100struct {
101 bool important;
102 const char *descr;
103} arch_sigs[NSIG];
104
robert.swiecki@gmail.comc6d28752014-01-08 12:02:37 +0000105__attribute__ ((constructor))
106void arch_initSigs(void)
robert.swiecki3bb518c2010-10-14 00:48:24 +0000107{
108 for (int x = 0; x < NSIG; x++)
109 arch_sigs[x].important = false;
110
111 arch_sigs[SIGILL].important = true;
112 arch_sigs[SIGILL].descr = "SIGILL";
113 arch_sigs[SIGFPE].important = true;
114 arch_sigs[SIGFPE].descr = "SIGFPE";
115 arch_sigs[SIGSEGV].important = true;
116 arch_sigs[SIGSEGV].descr = "SIGSEGV";
117 arch_sigs[SIGBUS].important = true;
118 arch_sigs[SIGBUS].descr = "SIGBUS";
119 arch_sigs[SIGABRT].important = true;
120 arch_sigs[SIGABRT].descr = "SIGABRT";
121}
122
groebert@google.com1bd4c212013-06-19 11:13:56 +0000123const char *exception_to_string(int exception)
groebert@google.comb857deb2010-10-21 19:09:29 +0000124{
groebert@google.com1bd4c212013-06-19 11:13:56 +0000125 switch (exception) {
126 case EXC_BAD_ACCESS:
127 return "EXC_BAD_ACCESS";
128 case EXC_BAD_INSTRUCTION:
129 return "EXC_BAD_INSTRUCTION";
130 case EXC_ARITHMETIC:
131 return "EXC_ARITHMETIC";
132 case EXC_EMULATION:
133 return "EXC_EMULATION";
134 case EXC_SOFTWARE:
135 return "EXC_SOFTWARE";
136 case EXC_BREAKPOINT:
137 return "EXC_BREAKPOINT";
138 case EXC_SYSCALL:
139 return "EXC_SYSCALL";
140 case EXC_MACH_SYSCALL:
141 return "EXC_MACH_SYSCALL";
142 case EXC_RPC_ALERT:
143 return "EXC_RPC_ALERT";
144 case EXC_CRASH:
145 return "EXC_CRASH";
groebert@google.comb857deb2010-10-21 19:09:29 +0000146 }
groebert@google.com1bd4c212013-06-19 11:13:56 +0000147 return "UNKNOWN";
groebert@google.comb857deb2010-10-21 19:09:29 +0000148}
149
150/*
robert.swiecki3bb518c2010-10-14 00:48:24 +0000151 * Returns true if a process exited (so, presumably, we can delete an input
152 * file)
153 */
robert.swiecki@gmail.com751f6862015-02-11 15:03:26 +0000154static bool arch_analyzeSignal(honggfuzz_t * hfuzz, int status, fuzzer_t * fuzzer)
robert.swiecki3bb518c2010-10-14 00:48:24 +0000155{
156 /*
157 * Resumed by delivery of SIGCONT
158 */
159 if (WIFCONTINUED(status)) {
160 return false;
161 }
162
Jagger3db1d952016-03-10 02:02:46 +0100163 if (WIFEXITED(status) || WIFSIGNALED(status)) {
164 sancov_Analyze(hfuzz, fuzzer);
165 }
166
robert.swiecki3bb518c2010-10-14 00:48:24 +0000167 /*
168 * Boring, the process just exited
169 */
170 if (WIFEXITED(status)) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200171 LOG_D("Process (pid %d) exited normally with status %d", fuzzer->pid, WEXITSTATUS(status));
robert.swiecki3bb518c2010-10-14 00:48:24 +0000172 return true;
173 }
174
175 /*
176 * Shouldn't really happen, but, well..
177 */
178 if (!WIFSIGNALED(status)) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200179 LOG_E("Process (pid %d) exited with the following status %d, please report that as a bug",
180 fuzzer->pid, status);
robert.swiecki3bb518c2010-10-14 00:48:24 +0000181 return true;
182 }
183
184 int termsig = WTERMSIG(status);
Robert Swieckic8c32db2015-10-09 18:06:22 +0200185 LOG_D("Process (pid %d) killed by signal %d '%s'", fuzzer->pid, termsig, strsignal(termsig));
robert.swiecki3bb518c2010-10-14 00:48:24 +0000186 if (!arch_sigs[termsig].important) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200187 LOG_D("It's not that important signal, skipping");
robert.swiecki3bb518c2010-10-14 00:48:24 +0000188 return true;
189 }
190
groebert@google.com1bd4c212013-06-19 11:13:56 +0000191 /*
192 * Signal is interesting
193 */
Anestis Bechtsoudisce34c302016-04-30 11:42:29 +0300194 /*
195 * Increase crashes counter presented by ASCII display
196 */
197 ATOMIC_POST_INC(hfuzz->crashesCnt);
groebert@google.comb857deb2010-10-21 19:09:29 +0000198
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000199 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000200 * Get data from exception handler
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000201 */
groebert@google.com43216c82015-02-13 11:11:38 +0000202 fuzzer->pc = g_fuzzer_crash_information[fuzzer->pid].pc;
203 fuzzer->exception = g_fuzzer_crash_information[fuzzer->pid].exception;
204 fuzzer->access = g_fuzzer_crash_information[fuzzer->pid].access;
205 fuzzer->backtrace = g_fuzzer_crash_information[fuzzer->pid].backtrace;
206
Anestis Bechtsoudisce34c302016-04-30 11:42:29 +0300207 /*
208 * Check if stackhash is blacklisted
209 */
210 if (hfuzz->blacklist
211 && (fastArray64Search(hfuzz->blacklist, hfuzz->blacklistCnt, fuzzer->backtrace) != -1)) {
212 LOG_I("Blacklisted stack hash '%" PRIx64 "', skipping", fuzzer->backtrace);
213 ATOMIC_POST_INC(hfuzz->blCrashesCnt);
214 return true;
215 }
216
Anestis Bechtsoudis46ea10e2015-11-07 18:16:25 +0200217 /* If dry run mode, copy file with same name into workspace */
Robert Swiecki7084e652016-03-14 19:47:00 +0100218 if (hfuzz->origFlipRate == 0.0L && hfuzz->useVerifier) {
Anestis Bechtsoudis4e170502015-11-07 22:44:19 +0200219 snprintf(fuzzer->crashFileName, sizeof(fuzzer->crashFileName), "%s/%s",
220 hfuzz->workDir, fuzzer->origFileName);
Anestis Bechtsoudis46ea10e2015-11-07 18:16:25 +0200221 } else if (hfuzz->saveUnique) {
Anestis Bechtsoudis4a3c8e82015-11-07 18:59:14 +0200222 snprintf(fuzzer->crashFileName, sizeof(fuzzer->crashFileName),
223 "%s/%s.%s.PC.%.16llx.STACK.%.16llx.ADDR.%.16llx.%s",
Anestis Bechtsoudisd9680532015-09-06 17:37:05 +0300224 hfuzz->workDir, arch_sigs[termsig].descr,
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000225 exception_to_string(fuzzer->exception), fuzzer->pc,
Anestis Bechtsoudis4a3c8e82015-11-07 18:59:14 +0200226 fuzzer->backtrace, fuzzer->access, hfuzz->fileExtn);
groebert@google.comb857deb2010-10-21 19:09:29 +0000227 } else {
groebert@google.com1bd4c212013-06-19 11:13:56 +0000228 char localtmstr[PATH_MAX];
Robert Swiecki81c6a0d2015-09-08 15:43:20 +0200229 util_getLocalTime("%F.%H.%M.%S", localtmstr, sizeof(localtmstr), time(NULL));
groebert@google.com1bd4c212013-06-19 11:13:56 +0000230
Anestis Bechtsoudis4a3c8e82015-11-07 18:59:14 +0200231 snprintf(fuzzer->crashFileName, sizeof(fuzzer->crashFileName),
232 "%s/%s.%s.PC.%.16llx.STACK.%.16llx.ADDR.%.16llx.TIME.%s.PID.%.5d.%s",
Anestis Bechtsoudisd9680532015-09-06 17:37:05 +0300233 hfuzz->workDir, arch_sigs[termsig].descr,
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000234 exception_to_string(fuzzer->exception), fuzzer->pc,
Anestis Bechtsoudis4a3c8e82015-11-07 18:59:14 +0200235 fuzzer->backtrace, fuzzer->access, localtmstr, fuzzer->pid, hfuzz->fileExtn);
groebert@google.com1bd4c212013-06-19 11:13:56 +0000236 }
237
Anestis Bechtsoudisce34c302016-04-30 11:42:29 +0300238 if (files_exists(fuzzer->crashFileName)) {
239 LOG_I("It seems that '%s' already exists, skipping", fuzzer->crashFileName);
240 // Clear filename so that verifier can understand we hit a duplicate
241 memset(fuzzer->crashFileName, 0, sizeof(fuzzer->crashFileName));
Anestis Bechtsoudisd59af692015-09-21 15:15:05 +0300242 return true;
243 }
244
Jagger1d743382016-04-02 02:09:41 +0200245 if (files_writeBufToFile
246 (fuzzer->crashFileName, fuzzer->dynamicFile, fuzzer->dynamicFileSz,
247 O_CREAT | O_EXCL | O_WRONLY) == false) {
248 LOG_E("Couldn't copy '%s' to '%s'", fuzzer->fileName, fuzzer->crashFileName);
249 return true;
robert.swiecki3bb518c2010-10-14 00:48:24 +0000250 }
groebert@google.comb857deb2010-10-21 19:09:29 +0000251
Jagger1d743382016-04-02 02:09:41 +0200252 LOG_I("Ok, that's interesting, saved '%s' as '%s'", fuzzer->fileName, fuzzer->crashFileName);
253
254 ATOMIC_POST_INC(hfuzz->uniqueCrashesCnt);
255 /* If unique crash found, reset dynFile counter */
256 ATOMIC_CLEAR(hfuzz->dynFileIterExpire);
257
robert.swiecki3bb518c2010-10-14 00:48:24 +0000258 return true;
259}
260
Robert Swiecki12800cd2016-03-31 15:38:10 +0200261pid_t arch_fork(honggfuzz_t * hfuzz UNUSED, fuzzer_t * fuzzer UNUSED)
Robert Swiecki1df61a92015-10-08 17:26:06 +0200262{
263 return fork();
Robert Swiecki1df61a92015-10-08 17:26:06 +0200264}
265
robert.swiecki3bb518c2010-10-14 00:48:24 +0000266bool arch_launchChild(honggfuzz_t * hfuzz, char *fileName)
267{
robert.swiecki3bb518c2010-10-14 00:48:24 +0000268#define ARGS_MAX 512
269 char *args[ARGS_MAX + 2];
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300270 char argData[PATH_MAX] = { 0 };
robert.swiecki3bb518c2010-10-14 00:48:24 +0000271 int x;
272
273 for (x = 0; x < ARGS_MAX && hfuzz->cmdline[x]; x++) {
robert.swiecki@gmail.coma0d87142015-02-14 13:11:18 +0000274 if (!hfuzz->fuzzStdin && strcmp(hfuzz->cmdline[x], _HF_FILE_PLACEHOLDER) == 0) {
robert.swiecki3bb518c2010-10-14 00:48:24 +0000275 args[x] = fileName;
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300276 } else if (!hfuzz->fuzzStdin && strstr(hfuzz->cmdline[x], _HF_FILE_PLACEHOLDER)) {
277 const char *off = strstr(hfuzz->cmdline[x], _HF_FILE_PLACEHOLDER);
Jagger400fd8f2015-08-16 10:50:55 +0200278 snprintf(argData, PATH_MAX, "%.*s%s", (int)(off - hfuzz->cmdline[x]), hfuzz->cmdline[x],
279 fileName);
Anestis Bechtsoudisc1f6faa2015-07-31 05:32:19 +0300280 args[x] = argData;
robert.swiecki3bb518c2010-10-14 00:48:24 +0000281 } else {
282 args[x] = hfuzz->cmdline[x];
283 }
284 }
285
286 args[x++] = NULL;
287
Robert Swieckic8c32db2015-10-09 18:06:22 +0200288 LOG_D("Launching '%s' on file '%s'", args[0], fileName);
robert.swiecki3bb518c2010-10-14 00:48:24 +0000289
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000290 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000291 * Get child's bootstrap port.
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000292 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000293 mach_port_t child_bootstrap = MACH_PORT_NULL;
294 if (task_get_bootstrap_port(mach_task_self(), &child_bootstrap) != KERN_SUCCESS) {
295 return false;
296 }
297
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000298 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000299 * Get exception port.
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000300 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000301 mach_port_t exception_port = MACH_PORT_NULL;
302
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000303 if (bootstrap_look_up(child_bootstrap, g_service_name, &exception_port)
robert.swiecki@gmail.com62e34ae2015-03-05 03:39:32 +0000304 != KERN_SUCCESS) {
groebert@google.com1bd4c212013-06-19 11:13:56 +0000305 return false;
306 }
307
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000308 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000309 * Here we register the exception port in the child
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000310 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000311 if (task_set_exception_ports(mach_task_self(),
312 EXC_MASK_CRASH,
313 exception_port,
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000314 EXCEPTION_STATE_IDENTITY |
315 MACH_EXCEPTION_CODES, MACHINE_THREAD_STATE) != KERN_SUCCESS) {
groebert@google.com1bd4c212013-06-19 11:13:56 +0000316 return false;
317 }
318
robert.swiecki3bb518c2010-10-14 00:48:24 +0000319 execvp(args[0], args);
robert.swiecki3bb518c2010-10-14 00:48:24 +0000320 return false;
321}
322
tlogic@gmail.com854c4a12015-04-17 05:52:17 +0000323static void arch_checkTimeLimit(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
324{
325 if (!hfuzz->tmOut) {
326 return;
327 }
328 int64_t curMillis = util_timeNowMillis();
329 int64_t diffMillis = curMillis - fuzzer->timeStartedMillis;
330 if (diffMillis > ((hfuzz->tmOut + 2) * 1000)) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200331 LOG_W("PID %d took too much time (limit %ld s). Sending SIGKILL",
332 fuzzer->pid, hfuzz->tmOut);
tlogic@gmail.com854c4a12015-04-17 05:52:17 +0000333 kill(fuzzer->pid, SIGKILL);
334 }
335}
336
robert.swiecki@gmail.com751f6862015-02-11 15:03:26 +0000337void arch_reapChild(honggfuzz_t * hfuzz, fuzzer_t * fuzzer)
robert.swiecki3bb518c2010-10-14 00:48:24 +0000338{
groebert@google.com06d93802013-09-16 12:06:40 +0000339 /*
Anestis Bechtsoudis51c9bb12015-08-26 14:46:21 +0300340 * First check manually if we have expired children
groebert@google.com06d93802013-09-16 12:06:40 +0000341 */
tlogic@gmail.com854c4a12015-04-17 05:52:17 +0000342 arch_checkTimeLimit(hfuzz, fuzzer);
groebert@google.com06d93802013-09-16 12:06:40 +0000343
344 /*
robert.swiecki@gmail.com751f6862015-02-11 15:03:26 +0000345 * Now check for signals using wait4
groebert@google.com06d93802013-09-16 12:06:40 +0000346 */
tlogic@gmail.com854c4a12015-04-17 05:52:17 +0000347 int options = WUNTRACED;
348 if (hfuzz->tmOut) {
robert.swiecki@gmail.com394d95e2015-04-20 22:15:13 +0000349 options |= WNOHANG;
tlogic@gmail.com854c4a12015-04-17 05:52:17 +0000350 }
robert.swiecki@gmail.com751f6862015-02-11 15:03:26 +0000351
robert.swiecki@gmail.com65cfa1c2015-02-11 15:59:28 +0000352 for (;;) {
353 int status = 0;
tlogic@gmail.com854c4a12015-04-17 05:52:17 +0000354 while (wait4(fuzzer->pid, &status, options, NULL) != fuzzer->pid) {
355 if (hfuzz->tmOut) {
robert.swiecki@gmail.com394d95e2015-04-20 22:15:13 +0000356 arch_checkTimeLimit(hfuzz, fuzzer);
357 usleep(0.20 * 1000000);
tlogic@gmail.com854c4a12015-04-17 05:52:17 +0000358 }
359 }
Robert Swiecki559801c2016-03-31 19:15:47 +0200360
361 char strStatus[4096];
362 LOG_D("Process (pid %d) came back with status: %s", fuzzer->pid,
Robert Swiecki9f9968a2016-04-01 14:39:51 +0200363 subproc_StatusToStr(status, strStatus, sizeof(strStatus)));
robert.swiecki3bb518c2010-10-14 00:48:24 +0000364
groebert@google.com43216c82015-02-13 11:11:38 +0000365 if (arch_analyzeSignal(hfuzz, status, fuzzer)) {
robert.swiecki@gmail.com65cfa1c2015-02-11 15:59:28 +0000366 return;
367 }
robert.swiecki3bb518c2010-10-14 00:48:24 +0000368 }
robert.swiecki@gmail.com751f6862015-02-11 15:03:26 +0000369}
robert.swiecki28cba5c2011-06-22 01:38:55 +0000370
groebert@google.com1bd4c212013-06-19 11:13:56 +0000371void *wait_for_exception()
372{
373 while (1) {
374 mach_msg_server_once(mach_exc_server, 4096, g_exception_port, MACH_MSG_OPTION_NONE);
375 }
376}
377
378/*
379 * Called once before fuzzing starts. Prepare mach ports for attaching crash reporter.
380 */
robert.swiecki@gmail.com6d6f7562015-02-17 22:18:51 +0000381bool arch_archInit(honggfuzz_t * hfuzz)
robert.swiecki28cba5c2011-06-22 01:38:55 +0000382{
groebert@google.com1bd4c212013-06-19 11:13:56 +0000383 char plist[PATH_MAX];
robert.swiecki@gmail.combb5d2642015-02-25 20:00:00 +0000384 snprintf(plist, sizeof(plist), "/Users/%s/Library/Preferences/com.apple.DebugSymbols.plist",
385 getlogin());
groebert@google.com1bd4c212013-06-19 11:13:56 +0000386
387 if (files_exists(plist)) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200388 LOG_W
389 ("honggfuzz won't work if DBGShellCommands are set in ~/Library/Preferences/com.apple.DebugSymbols.plist");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000390 }
391
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000392 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000393 * Allocate exception port.
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000394 */
robert.swiecki@gmail.combb5d2642015-02-25 20:00:00 +0000395 if (mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &g_exception_port) !=
robert.swiecki@gmail.com62e34ae2015-03-05 03:39:32 +0000396 KERN_SUCCESS) {
groebert@google.com1bd4c212013-06-19 11:13:56 +0000397 return false;
398 }
399
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000400 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000401 * Insert exception receive port.
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000402 */
403 if (mach_port_insert_right
robert.swiecki@gmail.com62e34ae2015-03-05 03:39:32 +0000404 (mach_task_self(), g_exception_port, g_exception_port,
405 MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS) {
groebert@google.com1bd4c212013-06-19 11:13:56 +0000406 return false;
407 }
408
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000409 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000410 * Get bootstrap port.
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000411 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000412 mach_port_t bootstrap = MACH_PORT_NULL;
413 if (task_get_bootstrap_port(mach_task_self(), &bootstrap) != KERN_SUCCESS) {
414 return false;
415 }
416
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000417 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000418 * Generate and register exception port service.
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000419 */
robert.swiecki@gmail.combb5d2642015-02-25 20:00:00 +0000420 snprintf(g_service_name, sizeof(g_service_name), "com.google.code.honggfuzz.%d",
tlogic@gmail.com479f0f92015-04-15 18:03:16 +0000421 (int)util_rndGet(0, 999999));
groebert@google.com76afff92013-06-20 14:43:41 +0000422 if (bootstrap_check_in(bootstrap, g_service_name, &g_exception_port) != KERN_SUCCESS) {
groebert@google.com1bd4c212013-06-19 11:13:56 +0000423 return false;
424 }
425
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000426 /*
427 * Create a collection thread to catch the exceptions from the
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000428 * children
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000429 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000430 pthread_t exception_thread;
431
432 if (pthread_create(&exception_thread, NULL, wait_for_exception, 0)) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200433 LOG_F("Parent: could not create thread to wait for child's exception");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000434 return false;
435 }
436
437 if (pthread_detach(exception_thread)) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200438 LOG_F("Parent: could not detach thread to wait for child's exception");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000439 return false;
440 }
441
robert.swiecki28cba5c2011-06-22 01:38:55 +0000442 return true;
443}
groebert@google.com1bd4c212013-06-19 11:13:56 +0000444
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000445/*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000446 * Write the crash report to DEBUG
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000447 */
448void
449write_crash_report(thread_port_t thread,
450 task_port_t task,
451 exception_type_t exception,
452 mach_exception_data_t code,
453 mach_msg_type_number_t code_count,
454 int *flavor, thread_state_t in_state, mach_msg_type_number_t in_state_count)
groebert@google.com1bd4c212013-06-19 11:13:56 +0000455{
456
457 NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];
458 CrashReport *_crashReport = nil;
459
robert.swiecki@gmail.com4be26672015-03-05 03:36:50 +0000460 /* *INDENT-OFF* */
groebert@google.com43216c82015-02-13 11:11:38 +0000461 _crashReport = [[CrashReport alloc] initWithTask:task
robert.swiecki@gmail.com4be26672015-03-05 03:36:50 +0000462 exceptionType:exception
463 exceptionCode:code
464 exceptionCodeCount:code_count
465 thread:thread
466 threadStateFlavor:*flavor
467 threadState:(thread_state_t)in_state
468 threadStateCount:in_state_count];
469 /* *INDENT-OFF* */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000470
471 NSString *crashDescription =[_crashReport description];
472 char *description = (char *)[crashDescription UTF8String];
473
Robert Swieckic8c32db2015-10-09 18:06:22 +0200474 LOG_D("CrashReport: %s", description);
groebert@google.com1bd4c212013-06-19 11:13:56 +0000475
476 [_crashReport release];
477 [pool drain];
478}
479
480/* Hash the callstack in an unique way */
481uint64_t hash_callstack(thread_port_t thread,
482 task_port_t task,
483 exception_type_t exception,
484 mach_exception_data_t code,
485 mach_msg_type_number_t code_count,
groebert@google.com43216c82015-02-13 11:11:38 +0000486 int *flavor,
487 thread_state_t in_state,
488 mach_msg_type_number_t in_state_count) {
groebert@google.com1bd4c212013-06-19 11:13:56 +0000489
490 NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init];
491 CrashReport *_crashReport = nil;
492
robert.swiecki@gmail.com4be26672015-03-05 03:36:50 +0000493 /* *INDENT-OFF* */
groebert@google.com43216c82015-02-13 11:11:38 +0000494 _crashReport = [[CrashReport alloc] initWithTask:task
robert.swiecki@gmail.com4be26672015-03-05 03:36:50 +0000495 exceptionType:exception
496 exceptionCode:code
497 exceptionCodeCount:code_count
498 thread:thread
499 threadStateFlavor:*flavor
500 threadState:(thread_state_t)in_state
501 threadStateCount:in_state_count];
502 /* *INDENT-ON* */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000503
504 NSString *crashDescription =[_crashReport description];
505 char *description = (char *)[crashDescription UTF8String];
506
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000507 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000508 * The callstack begins with the following word
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000509 */
groebert@google.com06d93802013-09-16 12:06:40 +0000510 char *callstack = strstr(description, "Crashed:");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000511
512 if (callstack == NULL) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200513 LOG_F("Could not find callstack in crash report %s", description);
groebert@google.com1bd4c212013-06-19 11:13:56 +0000514 }
515
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000516 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000517 * Scroll forward to the next newline
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000518 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000519 char *callstack_start = strstr(callstack, "\n");
520
521 if (callstack_start == NULL) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200522 LOG_F("Could not find callstack start in crash report %s", description);
groebert@google.com1bd4c212013-06-19 11:13:56 +0000523 }
524
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000525 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000526 * Skip the newline
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000527 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000528 callstack_start++;
529
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000530 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000531 * Determine the end of the callstack
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000532 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000533 char *callstack_end = strstr(callstack, "\n\nThread");
534
535 if (callstack_end == NULL) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200536 LOG_F("Could not find callstack end in crash report %s", description);
groebert@google.com1bd4c212013-06-19 11:13:56 +0000537 }
538
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000539 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000540 * Make sure it's NULL-terminated
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000541 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000542 *callstack_end = '\0';
543
544 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000545 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000546 * For each line, we only take the last three nibbles from the
547 * address.
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000548 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000549 * Sample output:
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000550 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000551 * 0 libsystem_kernel.dylib 0x00007fff80514d46 __kill + 10 1
552 * libsystem_c.dylib 0x00007fff85731ec0 __abort + 193 2
553 * libsystem_c.dylib 0x00007fff85732d17 __stack_chk_fail + 195 3
554 * stack_buffer_overflow64-stripped 0x000000010339def5 0x10339d000 +
555 * 3829 4 ??? 0x4141414141414141 0 + 4702111234474983745
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000556 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000557 * 0 libsystem_kernel.dylib 0x00007fff80514d46 __kill + 10 1
558 * libsystem_c.dylib 0x00007fff85731ec0 __abort + 193 2
559 * libsystem_c.dylib 0x00007fff85732d17 __stack_chk_fail + 195 3
560 * stack_buffer_overflow64 0x0000000108f41ef5 main + 133 4 ???
561 * 0x4141414141414141 0 + 4702111234474983745
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000562 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000563 * 0 libsystem_kernel.dylib 0x940023ba __kill + 10 1
564 * libsystem_kernel.dylib 0x940014bc kill$UNIX2003 + 32 2
565 * libsystem_c.dylib 0x926f362e __abort + 246 3 libsystem_c.dylib
566 * 0x926c2b60 __chk_fail + 49 4 libsystem_c.dylib 0x926c2bf9
567 * __memset_chk + 53 5 stack_buffer_overflow32-stripped 0x00093ee5
568 * 0x93000 + 3813 6 libdyld.dylib 0x978c6725 start + 1
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000569 *
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000570 * 0 libsystem_kernel.dylib 0x940023ba __kill + 10 1
571 * libsystem_kernel.dylib 0x940014bc kill$UNIX2003 + 32 2
572 * libsystem_c.dylib 0x926f362e __abort + 246 3 libsystem_c.dylib
573 * 0x926c2b60 __chk_fail + 49 4 libsystem_c.dylib 0x926c2bf9
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000574 * __memset_chk + 53 5 stack_buffer_overflow32 0x0003cee5 main + 117 6
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000575 * libdyld.dylib 0x978c6725 start + 1
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000576 *
groebert@google.com1bd4c212013-06-19 11:13:56 +0000577 */
578
579 uint64_t hash = 0;
580 char *pos = callstack_start;
581
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000582 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000583 * Go through each line until we run out of lines
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000584 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000585 while (strstr(pos, "\t") != NULL) {
586 /*
587 * Format: dylib spaces tab address space symbol space plus space offset
588 * Scroll pos forward to the last three nibbles of the address.
589 */
590 if ((pos = strstr(pos, "\t")) == NULL)
591 break;
592 if ((pos = strstr(pos, " ")) == NULL)
593 break;
594 pos = pos - 3;
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000595 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000596 * Hash the last three nibbles
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000597 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000598 hash ^= util_hash(pos, 3);
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000599 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000600 * Scroll pos one forward to skip the current tab
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000601 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000602 pos++;
603 }
604
Anestis Bechtsoudisc9473322015-10-09 12:59:17 -0700605 LOG_D("Callstack hash %llu", hash);
groebert@google.com1bd4c212013-06-19 11:13:56 +0000606
607 [_crashReport release];
608 [pool drain];
609
610 return hash;
611}
612
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000613kern_return_t
614catch_mach_exception_raise(mach_port_t exception_port,
615 mach_port_t thread,
616 mach_port_t task,
robert.swiecki@gmail.combb5d2642015-02-25 20:00:00 +0000617 exception_type_t exception, mach_exception_data_t code,
618 mach_msg_type_number_t codeCnt)
groebert@google.comc659c0e2015-02-13 11:17:00 +0000619{
Robert Swieckic8c32db2015-10-09 18:06:22 +0200620 LOG_F("This function should never get called");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000621 return KERN_SUCCESS;
622}
623
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000624kern_return_t
625catch_mach_exception_raise_state(mach_port_t exception_port,
626 exception_type_t exception,
627 const mach_exception_data_t code,
628 mach_msg_type_number_t codeCnt,
629 int *flavor,
630 const thread_state_t old_state,
631 mach_msg_type_number_t old_stateCnt,
632 thread_state_t new_state, mach_msg_type_number_t * new_stateCnt)
groebert@google.comc659c0e2015-02-13 11:17:00 +0000633{
Robert Swieckic8c32db2015-10-09 18:06:22 +0200634 LOG_F("This function should never get called");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000635 return KERN_SUCCESS;
636}
637
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000638kern_return_t catch_mach_exception_raise_state_identity( __attribute__ ((unused))
robert.swiecki@gmail.com62e34ae2015-03-05 03:39:32 +0000639 exception_port_t exception_port,
640 thread_port_t thread,
641 task_port_t task,
642 exception_type_t exception,
643 mach_exception_data_t code,
644 mach_msg_type_number_t
645 code_count, int *flavor,
646 thread_state_t in_state,
647 mach_msg_type_number_t
648 in_state_count,
649 thread_state_t out_state,
650 mach_msg_type_number_t * out_state_count)
groebert@google.comc659c0e2015-02-13 11:17:00 +0000651{
groebert@google.com1bd4c212013-06-19 11:13:56 +0000652 if (exception != EXC_CRASH) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200653 LOG_F("Got non EXC_CRASH! This should not happen.");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000654 }
655
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000656 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000657 * We will save our results to the honggfuzz_t global
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000658 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000659 pid_t pid;
660 pid_for_task(task, &pid);
Robert Swieckic8c32db2015-10-09 18:06:22 +0200661 LOG_D("Crash of pid %d", pid);
groebert@google.com1bd4c212013-06-19 11:13:56 +0000662
groebert@google.com20e368f2015-02-13 14:19:25 +0000663 fuzzer_t *fuzzer = &g_fuzzer_crash_information[pid];
robert.swiecki@gmail.comc6d28752014-01-08 12:02:37 +0000664
groebert@google.com1bd4c212013-06-19 11:13:56 +0000665 /*
666 * Get program counter.
667 * Cast to void* in order to silence the alignment warnings
668 */
669
670 x86_thread_state_t *platform_in_state = ((x86_thread_state_t *) (void *)in_state);
671
672 if (x86_THREAD_STATE32 == platform_in_state->tsh.flavor) {
groebert@google.com20e368f2015-02-13 14:19:25 +0000673 fuzzer->pc = platform_in_state->uts.ts32.__eip;
groebert@google.com1bd4c212013-06-19 11:13:56 +0000674 } else {
groebert@google.com20e368f2015-02-13 14:19:25 +0000675 fuzzer->pc = platform_in_state->uts.ts64.__rip;
groebert@google.com1bd4c212013-06-19 11:13:56 +0000676 }
677
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000678 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000679 * Get the exception type
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000680 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000681
682 exception_type_t exception_type = ((code[0] >> 20) & 0x0F);
683
684 if (exception_type == 0) {
685 exception_type = EXC_CRASH;
686 }
687
groebert@google.com20e368f2015-02-13 14:19:25 +0000688 fuzzer->exception = exception_type;
groebert@google.com1bd4c212013-06-19 11:13:56 +0000689
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000690 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000691 * Get the access address.
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000692 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000693
694 mach_exception_data_type_t exception_data[2];
695 memcpy(exception_data, code, sizeof(exception_data));
696 exception_data[0] = (code[0] & ~(0x00000000FFF00000));
697 exception_data[1] = code[1];
698
699 mach_exception_data_type_t access_address = exception_data[1];
groebert@google.com20e368f2015-02-13 14:19:25 +0000700 fuzzer->access = (uint64_t) access_address;
groebert@google.com1bd4c212013-06-19 11:13:56 +0000701
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000702 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000703 * Get a hash of the callstack
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000704 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000705
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000706 uint64_t hash = hash_callstack(thread, task, exception, code, code_count, flavor,
707 in_state, in_state_count);
groebert@google.com1bd4c212013-06-19 11:13:56 +0000708
groebert@google.com20e368f2015-02-13 14:19:25 +0000709 fuzzer->backtrace = hash;
groebert@google.com1bd4c212013-06-19 11:13:56 +0000710
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000711 /*
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000712 * Cleanup
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000713 */
groebert@google.com1bd4c212013-06-19 11:13:56 +0000714
715 if (mach_port_deallocate(mach_task_self(), task) != KERN_SUCCESS) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200716 LOG_W("Exception Handler: Could not deallocate task");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000717 }
718
719 if (mach_port_deallocate(mach_task_self(), thread) != KERN_SUCCESS) {
Robert Swieckic8c32db2015-10-09 18:06:22 +0200720 LOG_W("Exception Handler: Could not deallocate thread");
groebert@google.com1bd4c212013-06-19 11:13:56 +0000721 }
722
robert.swiecki@gmail.com3b630b42015-02-16 10:53:53 +0000723 return KERN_SUCCESS; // KERN_SUCCESS indicates that this should
robert.swiecki@gmail.com772b33d2015-02-14 20:35:00 +0000724 // not be forwarded to other crash
725 // handlers
groebert@google.com1bd4c212013-06-19 11:13:56 +0000726}
Robert Swiecki0f937af2016-03-30 18:19:16 +0200727
Robert Swieckidecf14b2016-03-31 15:09:28 +0200728bool arch_archThreadInit(honggfuzz_t * hfuzz UNUSED, fuzzer_t * fuzzer UNUSED)
Robert Swiecki0f937af2016-03-30 18:19:16 +0200729{
730 return true;
731}