blob: d67f861f7431e8ede07d97aa4a9368c5048f4032 [file] [log] [blame]
morehouse400262a2017-12-08 22:54:44 +00001//===- FuzzerUtilFuchsia.cpp - Misc utils for Fuchsia. --------------------===//
2//
chandlerc40284492019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
morehouse400262a2017-12-08 22:54:44 +00006//
7//===----------------------------------------------------------------------===//
8// Misc utils implementation using Fuchsia/Zircon APIs.
9//===----------------------------------------------------------------------===//
10#include "FuzzerDefs.h"
11
12#if LIBFUZZER_FUCHSIA
13
14#include "FuzzerInternal.h"
15#include "FuzzerUtil.h"
phoseked73fdf2019-05-22 16:36:35 +000016#include <cassert>
morehouse400262a2017-12-08 22:54:44 +000017#include <cerrno>
18#include <cinttypes>
19#include <cstdint>
morehouse400262a2017-12-08 22:54:44 +000020#include <fcntl.h>
phoseke7c6a592018-06-07 18:41:35 +000021#include <lib/fdio/spawn.h>
morehouse400262a2017-12-08 22:54:44 +000022#include <string>
phosek00c73322018-04-20 00:41:06 +000023#include <sys/select.h>
morehouse400262a2017-12-08 22:54:44 +000024#include <thread>
phosekf9123762018-02-07 08:22:58 +000025#include <unistd.h>
morehouse400262a2017-12-08 22:54:44 +000026#include <zircon/errors.h>
phosekf9123762018-02-07 08:22:58 +000027#include <zircon/process.h>
phoseke59ddd22018-07-18 19:20:47 +000028#include <zircon/sanitizer.h>
morehouse400262a2017-12-08 22:54:44 +000029#include <zircon/status.h>
30#include <zircon/syscalls.h>
phoseke59ddd22018-07-18 19:20:47 +000031#include <zircon/syscalls/debug.h>
32#include <zircon/syscalls/exception.h>
morehouse400262a2017-12-08 22:54:44 +000033#include <zircon/syscalls/port.h>
34#include <zircon/types.h>
morehouse400262a2017-12-08 22:54:44 +000035
36namespace fuzzer {
37
phoseke59ddd22018-07-18 19:20:47 +000038// Given that Fuchsia doesn't have the POSIX signals that libFuzzer was written
39// around, the general approach is to spin up dedicated threads to watch for
40// each requested condition (alarm, interrupt, crash). Of these, the crash
41// handler is the most involved, as it requires resuming the crashed thread in
42// order to invoke the sanitizers to get the needed state.
43
44// Forward declaration of assembly trampoline needed to resume crashed threads.
45// This appears to have external linkage to C++, which is why it's not in the
46// anonymous namespace. The assembly definition inside MakeTrampoline()
47// actually defines the symbol with internal linkage only.
48void CrashTrampolineAsm() __asm__("CrashTrampolineAsm");
49
morehouse400262a2017-12-08 22:54:44 +000050namespace {
51
52// A magic value for the Zircon exception port, chosen to spell 'FUZZING'
53// when interpreted as a byte sequence on little-endian platforms.
54const uint64_t kFuzzingCrash = 0x474e495a5a5546;
55
phoseke59ddd22018-07-18 19:20:47 +000056// Helper function to handle Zircon syscall failures.
57void ExitOnErr(zx_status_t Status, const char *Syscall) {
58 if (Status != ZX_OK) {
59 Printf("libFuzzer: %s failed: %s\n", Syscall,
60 _zx_status_get_string(Status));
61 exit(1);
62 }
63}
64
morehouse400262a2017-12-08 22:54:44 +000065void AlarmHandler(int Seconds) {
66 while (true) {
67 SleepSeconds(Seconds);
68 Fuzzer::StaticAlarmCallback();
69 }
70}
71
72void InterruptHandler() {
phosek1631e452018-04-19 14:01:46 +000073 fd_set readfds;
morehouse400262a2017-12-08 22:54:44 +000074 // Ctrl-C sends ETX in Zircon.
phosek1631e452018-04-19 14:01:46 +000075 do {
76 FD_ZERO(&readfds);
77 FD_SET(STDIN_FILENO, &readfds);
78 select(STDIN_FILENO + 1, &readfds, nullptr, nullptr, nullptr);
79 } while(!FD_ISSET(STDIN_FILENO, &readfds) || getchar() != 0x03);
morehouse400262a2017-12-08 22:54:44 +000080 Fuzzer::StaticInterruptCallback();
81}
82
phoseke59ddd22018-07-18 19:20:47 +000083// For the crash handler, we need to call Fuzzer::StaticCrashSignalCallback
84// without POSIX signal handlers. To achieve this, we use an assembly function
85// to add the necessary CFI unwinding information and a C function to bridge
86// from that back into C++.
87
88// FIXME: This works as a short-term solution, but this code really shouldn't be
89// architecture dependent. A better long term solution is to implement remote
90// unwinding and expose the necessary APIs through sanitizer_common and/or ASAN
91// to allow the exception handling thread to gather the crash state directly.
92//
93// Alternatively, Fuchsia may in future actually implement basic signal
94// handling for the machine trap signals.
95#if defined(__x86_64__)
96#define FOREACH_REGISTER(OP_REG, OP_NUM) \
97 OP_REG(rax) \
98 OP_REG(rbx) \
99 OP_REG(rcx) \
100 OP_REG(rdx) \
101 OP_REG(rsi) \
102 OP_REG(rdi) \
103 OP_REG(rbp) \
104 OP_REG(rsp) \
105 OP_REG(r8) \
106 OP_REG(r9) \
107 OP_REG(r10) \
108 OP_REG(r11) \
109 OP_REG(r12) \
110 OP_REG(r13) \
111 OP_REG(r14) \
112 OP_REG(r15) \
113 OP_REG(rip)
114
115#elif defined(__aarch64__)
116#define FOREACH_REGISTER(OP_REG, OP_NUM) \
117 OP_NUM(0) \
118 OP_NUM(1) \
119 OP_NUM(2) \
120 OP_NUM(3) \
121 OP_NUM(4) \
122 OP_NUM(5) \
123 OP_NUM(6) \
124 OP_NUM(7) \
125 OP_NUM(8) \
126 OP_NUM(9) \
127 OP_NUM(10) \
128 OP_NUM(11) \
129 OP_NUM(12) \
130 OP_NUM(13) \
131 OP_NUM(14) \
132 OP_NUM(15) \
133 OP_NUM(16) \
134 OP_NUM(17) \
135 OP_NUM(18) \
136 OP_NUM(19) \
137 OP_NUM(20) \
138 OP_NUM(21) \
139 OP_NUM(22) \
140 OP_NUM(23) \
141 OP_NUM(24) \
142 OP_NUM(25) \
143 OP_NUM(26) \
144 OP_NUM(27) \
145 OP_NUM(28) \
146 OP_NUM(29) \
147 OP_NUM(30) \
148 OP_REG(sp)
149
150#else
151#error "Unsupported architecture for fuzzing on Fuchsia"
152#endif
153
154// Produces a CFI directive for the named or numbered register.
155#define CFI_OFFSET_REG(reg) ".cfi_offset " #reg ", %c[" #reg "]\n"
156#define CFI_OFFSET_NUM(num) CFI_OFFSET_REG(r##num)
157
158// Produces an assembler input operand for the named or numbered register.
159#define ASM_OPERAND_REG(reg) \
160 [reg] "i"(offsetof(zx_thread_state_general_regs_t, reg)),
161#define ASM_OPERAND_NUM(num) \
162 [r##num] "i"(offsetof(zx_thread_state_general_regs_t, r[num])),
163
164// Trampoline to bridge from the assembly below to the static C++ crash
165// callback.
166__attribute__((noreturn))
167static void StaticCrashHandler() {
morehouse400262a2017-12-08 22:54:44 +0000168 Fuzzer::StaticCrashSignalCallback();
phoseke59ddd22018-07-18 19:20:47 +0000169 for (;;) {
170 _Exit(1);
171 }
172}
173
174// Creates the trampoline with the necessary CFI information to unwind through
175// to the crashing call stack. The attribute is necessary because the function
176// is never called; it's just a container around the assembly to allow it to
177// use operands for compile-time computed constants.
178__attribute__((used))
179void MakeTrampoline() {
180 __asm__(".cfi_endproc\n"
181 ".pushsection .text.CrashTrampolineAsm\n"
182 ".type CrashTrampolineAsm,STT_FUNC\n"
183"CrashTrampolineAsm:\n"
184 ".cfi_startproc simple\n"
185 ".cfi_signal_frame\n"
186#if defined(__x86_64__)
187 ".cfi_return_column rip\n"
188 ".cfi_def_cfa rsp, 0\n"
189 FOREACH_REGISTER(CFI_OFFSET_REG, CFI_OFFSET_NUM)
190 "call %c[StaticCrashHandler]\n"
191 "ud2\n"
192#elif defined(__aarch64__)
193 ".cfi_return_column 33\n"
194 ".cfi_def_cfa sp, 0\n"
195 ".cfi_offset 33, %c[pc]\n"
196 FOREACH_REGISTER(CFI_OFFSET_REG, CFI_OFFSET_NUM)
197 "bl %[StaticCrashHandler]\n"
198#else
199#error "Unsupported architecture for fuzzing on Fuchsia"
200#endif
201 ".cfi_endproc\n"
202 ".size CrashTrampolineAsm, . - CrashTrampolineAsm\n"
203 ".popsection\n"
204 ".cfi_startproc\n"
205 : // No outputs
206 : FOREACH_REGISTER(ASM_OPERAND_REG, ASM_OPERAND_NUM)
207#if defined(__aarch64__)
208 ASM_OPERAND_REG(pc)
209#endif
210 [StaticCrashHandler] "i" (StaticCrashHandler));
211}
212
213void CrashHandler(zx_handle_t *Event) {
214 // This structure is used to ensure we close handles to objects we create in
215 // this handler.
216 struct ScopedHandle {
217 ~ScopedHandle() { _zx_handle_close(Handle); }
218 zx_handle_t Handle = ZX_HANDLE_INVALID;
219 };
220
221 // Create and bind the exception port. We need to claim to be a "debugger" so
222 // the kernel will allow us to modify and resume dying threads (see below).
223 // Once the port is set, we can signal the main thread to continue and wait
224 // for the exception to arrive.
225 ScopedHandle Port;
226 ExitOnErr(_zx_port_create(0, &Port.Handle), "_zx_port_create");
227 zx_handle_t Self = _zx_process_self();
228
229 ExitOnErr(_zx_task_bind_exception_port(Self, Port.Handle, kFuzzingCrash,
230 ZX_EXCEPTION_PORT_DEBUGGER),
231 "_zx_task_bind_exception_port");
232
233 ExitOnErr(_zx_object_signal(*Event, 0, ZX_USER_SIGNAL_0),
234 "_zx_object_signal");
235
phoseked73fdf2019-05-22 16:36:35 +0000236 // This thread lives as long as the process in order to keep handling
237 // crashes. In practice, the first crashed thread to reach the end of the
238 // StaticCrashHandler will end the process.
239 while (true) {
240 zx_port_packet_t Packet;
241 ExitOnErr(_zx_port_wait(Port.Handle, ZX_TIME_INFINITE, &Packet),
242 "_zx_port_wait");
phoseke59ddd22018-07-18 19:20:47 +0000243
phoseked73fdf2019-05-22 16:36:35 +0000244 // Ignore informational synthetic exceptions.
245 assert(ZX_PKT_IS_EXCEPTION(Packet.type));
246 if (ZX_EXCP_THREAD_STARTING == Packet.type ||
247 ZX_EXCP_THREAD_EXITING == Packet.type ||
248 ZX_EXCP_PROCESS_STARTING == Packet.type) {
249 continue;
250 }
phoseke59ddd22018-07-18 19:20:47 +0000251
phoseked73fdf2019-05-22 16:36:35 +0000252 // At this point, we want to get the state of the crashing thread, but
253 // libFuzzer and the sanitizers assume this will happen from that same
254 // thread via a POSIX signal handler. "Resurrecting" the thread in the
255 // middle of the appropriate callback is as simple as forcibly setting the
256 // instruction pointer/program counter, provided we NEVER EVER return from
257 // that function (since otherwise our stack will not be valid).
258 ScopedHandle Thread;
259 ExitOnErr(_zx_object_get_child(Self, Packet.exception.tid,
260 ZX_RIGHT_SAME_RIGHTS, &Thread.Handle),
261 "_zx_object_get_child");
phoseke59ddd22018-07-18 19:20:47 +0000262
phoseked73fdf2019-05-22 16:36:35 +0000263 zx_thread_state_general_regs_t GeneralRegisters;
264 ExitOnErr(_zx_thread_read_state(Thread.Handle, ZX_THREAD_STATE_GENERAL_REGS,
265 &GeneralRegisters,
266 sizeof(GeneralRegisters)),
267 "_zx_thread_read_state");
268
269 // To unwind properly, we need to push the crashing thread's register state
270 // onto the stack and jump into a trampoline with CFI instructions on how
271 // to restore it.
phoseke59ddd22018-07-18 19:20:47 +0000272#if defined(__x86_64__)
phoseked73fdf2019-05-22 16:36:35 +0000273 uintptr_t StackPtr =
274 (GeneralRegisters.rsp - (128 + sizeof(GeneralRegisters))) &
275 -(uintptr_t)16;
276 __unsanitized_memcpy(reinterpret_cast<void *>(StackPtr), &GeneralRegisters,
277 sizeof(GeneralRegisters));
278 GeneralRegisters.rsp = StackPtr;
279 GeneralRegisters.rip = reinterpret_cast<zx_vaddr_t>(CrashTrampolineAsm);
phoseke59ddd22018-07-18 19:20:47 +0000280
281#elif defined(__aarch64__)
phoseked73fdf2019-05-22 16:36:35 +0000282 uintptr_t StackPtr =
283 (GeneralRegisters.sp - sizeof(GeneralRegisters)) & -(uintptr_t)16;
284 __unsanitized_memcpy(reinterpret_cast<void *>(StackPtr), &GeneralRegisters,
285 sizeof(GeneralRegisters));
286 GeneralRegisters.sp = StackPtr;
287 GeneralRegisters.pc = reinterpret_cast<zx_vaddr_t>(CrashTrampolineAsm);
phoseke59ddd22018-07-18 19:20:47 +0000288
289#else
290#error "Unsupported architecture for fuzzing on Fuchsia"
291#endif
292
phoseked73fdf2019-05-22 16:36:35 +0000293 // Now force the crashing thread's state.
294 ExitOnErr(
295 _zx_thread_write_state(Thread.Handle, ZX_THREAD_STATE_GENERAL_REGS,
296 &GeneralRegisters, sizeof(GeneralRegisters)),
297 "_zx_thread_write_state");
phoseke59ddd22018-07-18 19:20:47 +0000298
phoseked73fdf2019-05-22 16:36:35 +0000299 ExitOnErr(_zx_task_resume_from_exception(Thread.Handle, Port.Handle, 0),
300 "_zx_task_resume_from_exception");
301 }
morehouse400262a2017-12-08 22:54:44 +0000302}
303
304} // namespace
305
kccda168932019-01-31 00:09:43 +0000306bool Mprotect(void *Ptr, size_t Size, bool AllowReadWrite) {
307 return false; // UNIMPLEMENTED
308}
309
morehouse400262a2017-12-08 22:54:44 +0000310// Platform specific functions.
311void SetSignalHandler(const FuzzingOptions &Options) {
morehouse400262a2017-12-08 22:54:44 +0000312 // Set up alarm handler if needed.
313 if (Options.UnitTimeoutSec > 0) {
314 std::thread T(AlarmHandler, Options.UnitTimeoutSec / 2 + 1);
315 T.detach();
316 }
317
318 // Set up interrupt handler if needed.
319 if (Options.HandleInt || Options.HandleTerm) {
320 std::thread T(InterruptHandler);
321 T.detach();
322 }
323
324 // Early exit if no crash handler needed.
325 if (!Options.HandleSegv && !Options.HandleBus && !Options.HandleIll &&
326 !Options.HandleFpe && !Options.HandleAbrt)
327 return;
328
phoseke59ddd22018-07-18 19:20:47 +0000329 // Set up the crash handler and wait until it is ready before proceeding.
330 zx_handle_t Event;
331 ExitOnErr(_zx_event_create(0, &Event), "_zx_event_create");
morehouse400262a2017-12-08 22:54:44 +0000332
phoseke59ddd22018-07-18 19:20:47 +0000333 std::thread T(CrashHandler, &Event);
phosekd2551d62018-08-27 17:51:52 +0000334 zx_status_t Status =
335 _zx_object_wait_one(Event, ZX_USER_SIGNAL_0, ZX_TIME_INFINITE, nullptr);
phoseke59ddd22018-07-18 19:20:47 +0000336 _zx_handle_close(Event);
337 ExitOnErr(Status, "_zx_object_wait_one");
morehouse400262a2017-12-08 22:54:44 +0000338
morehouse400262a2017-12-08 22:54:44 +0000339 T.detach();
340}
341
342void SleepSeconds(int Seconds) {
phosekf9123762018-02-07 08:22:58 +0000343 _zx_nanosleep(_zx_deadline_after(ZX_SEC(Seconds)));
morehouse400262a2017-12-08 22:54:44 +0000344}
345
346unsigned long GetPid() {
347 zx_status_t rc;
348 zx_info_handle_basic_t Info;
phoseke81389f2018-05-26 01:02:34 +0000349 if ((rc = _zx_object_get_info(_zx_process_self(), ZX_INFO_HANDLE_BASIC, &Info,
phoseke59ddd22018-07-18 19:20:47 +0000350 sizeof(Info), NULL, NULL)) != ZX_OK) {
morehouse400262a2017-12-08 22:54:44 +0000351 Printf("libFuzzer: unable to get info about self: %s\n",
phoseke81389f2018-05-26 01:02:34 +0000352 _zx_status_get_string(rc));
morehouse400262a2017-12-08 22:54:44 +0000353 exit(1);
354 }
355 return Info.koid;
356}
357
358size_t GetPeakRSSMb() {
359 zx_status_t rc;
360 zx_info_task_stats_t Info;
phosekf9123762018-02-07 08:22:58 +0000361 if ((rc = _zx_object_get_info(_zx_process_self(), ZX_INFO_TASK_STATS, &Info,
phoseke59ddd22018-07-18 19:20:47 +0000362 sizeof(Info), NULL, NULL)) != ZX_OK) {
morehouse400262a2017-12-08 22:54:44 +0000363 Printf("libFuzzer: unable to get info about self: %s\n",
phosekf9123762018-02-07 08:22:58 +0000364 _zx_status_get_string(rc));
morehouse400262a2017-12-08 22:54:44 +0000365 exit(1);
366 }
367 return (Info.mem_private_bytes + Info.mem_shared_bytes) >> 20;
368}
369
phosekf9123762018-02-07 08:22:58 +0000370template <typename Fn>
371class RunOnDestruction {
372 public:
373 explicit RunOnDestruction(Fn fn) : fn_(fn) {}
374 ~RunOnDestruction() { fn_(); }
375
376 private:
377 Fn fn_;
378};
379
380template <typename Fn>
381RunOnDestruction<Fn> at_scope_exit(Fn fn) {
382 return RunOnDestruction<Fn>(fn);
383}
384
morehouse400262a2017-12-08 22:54:44 +0000385int ExecuteCommand(const Command &Cmd) {
386 zx_status_t rc;
387
388 // Convert arguments to C array
389 auto Args = Cmd.getArguments();
390 size_t Argc = Args.size();
391 assert(Argc != 0);
phosek4b9efd12018-06-02 01:17:10 +0000392 std::unique_ptr<const char *[]> Argv(new const char *[Argc + 1]);
morehouse400262a2017-12-08 22:54:44 +0000393 for (size_t i = 0; i < Argc; ++i)
394 Argv[i] = Args[i].c_str();
phosek4b9efd12018-06-02 01:17:10 +0000395 Argv[Argc] = nullptr;
morehouse400262a2017-12-08 22:54:44 +0000396
phosekca62a262018-10-02 17:21:04 +0000397 // Determine output. On Fuchsia, the fuzzer is typically run as a component
398 // that lacks a mutable working directory. Fortunately, when this is the case
399 // a mutable output directory must be specified using "-artifact_prefix=...",
400 // so write the log file(s) there.
morehouse400262a2017-12-08 22:54:44 +0000401 int FdOut = STDOUT_FILENO;
morehouse400262a2017-12-08 22:54:44 +0000402 if (Cmd.hasOutputFile()) {
phosekca62a262018-10-02 17:21:04 +0000403 std::string Path;
404 if (Cmd.hasFlag("artifact_prefix"))
405 Path = Cmd.getFlagValue("artifact_prefix") + "/" + Cmd.getOutputFile();
406 else
407 Path = Cmd.getOutputFile();
408 FdOut = open(Path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0);
phosekf9123762018-02-07 08:22:58 +0000409 if (FdOut == -1) {
phosekca62a262018-10-02 17:21:04 +0000410 Printf("libFuzzer: failed to open %s: %s\n", Path.c_str(),
morehouse400262a2017-12-08 22:54:44 +0000411 strerror(errno));
412 return ZX_ERR_IO;
413 }
morehouse400262a2017-12-08 22:54:44 +0000414 }
phosekca62a262018-10-02 17:21:04 +0000415 auto CloseFdOut = at_scope_exit([FdOut]() {
416 if (FdOut != STDOUT_FILENO)
417 close(FdOut);
418 });
morehouse400262a2017-12-08 22:54:44 +0000419
420 // Determine stderr
421 int FdErr = STDERR_FILENO;
422 if (Cmd.isOutAndErrCombined())
423 FdErr = FdOut;
424
425 // Clone the file descriptors into the new process
phosek4b9efd12018-06-02 01:17:10 +0000426 fdio_spawn_action_t SpawnAction[] = {
427 {
428 .action = FDIO_SPAWN_ACTION_CLONE_FD,
429 .fd =
430 {
431 .local_fd = STDIN_FILENO,
432 .target_fd = STDIN_FILENO,
433 },
434 },
435 {
436 .action = FDIO_SPAWN_ACTION_CLONE_FD,
437 .fd =
438 {
439 .local_fd = FdOut,
440 .target_fd = STDOUT_FILENO,
441 },
442 },
443 {
444 .action = FDIO_SPAWN_ACTION_CLONE_FD,
445 .fd =
446 {
447 .local_fd = FdErr,
448 .target_fd = STDERR_FILENO,
449 },
450 },
451 };
morehouse400262a2017-12-08 22:54:44 +0000452
phosek4b9efd12018-06-02 01:17:10 +0000453 // Start the process.
454 char ErrorMsg[FDIO_SPAWN_ERR_MSG_MAX_LENGTH];
morehouse400262a2017-12-08 22:54:44 +0000455 zx_handle_t ProcessHandle = ZX_HANDLE_INVALID;
phosek4b9efd12018-06-02 01:17:10 +0000456 rc = fdio_spawn_etc(
457 ZX_HANDLE_INVALID, FDIO_SPAWN_CLONE_ALL & (~FDIO_SPAWN_CLONE_STDIO),
458 Argv[0], Argv.get(), nullptr, 3, SpawnAction, &ProcessHandle, ErrorMsg);
459 if (rc != ZX_OK) {
morehouse400262a2017-12-08 22:54:44 +0000460 Printf("libFuzzer: failed to launch '%s': %s, %s\n", Argv[0], ErrorMsg,
phosekf9123762018-02-07 08:22:58 +0000461 _zx_status_get_string(rc));
morehouse400262a2017-12-08 22:54:44 +0000462 return rc;
463 }
phosekf9123762018-02-07 08:22:58 +0000464 auto CloseHandle = at_scope_exit([&]() { _zx_handle_close(ProcessHandle); });
morehouse400262a2017-12-08 22:54:44 +0000465
466 // Now join the process and return the exit status.
phosekf9123762018-02-07 08:22:58 +0000467 if ((rc = _zx_object_wait_one(ProcessHandle, ZX_PROCESS_TERMINATED,
phosekd2551d62018-08-27 17:51:52 +0000468 ZX_TIME_INFINITE, nullptr)) != ZX_OK) {
morehouse400262a2017-12-08 22:54:44 +0000469 Printf("libFuzzer: failed to join '%s': %s\n", Argv[0],
phosekf9123762018-02-07 08:22:58 +0000470 _zx_status_get_string(rc));
morehouse400262a2017-12-08 22:54:44 +0000471 return rc;
472 }
473
474 zx_info_process_t Info;
phosekf9123762018-02-07 08:22:58 +0000475 if ((rc = _zx_object_get_info(ProcessHandle, ZX_INFO_PROCESS, &Info,
476 sizeof(Info), nullptr, nullptr)) != ZX_OK) {
morehouse400262a2017-12-08 22:54:44 +0000477 Printf("libFuzzer: unable to get return code from '%s': %s\n", Argv[0],
phoseke81389f2018-05-26 01:02:34 +0000478 _zx_status_get_string(rc));
morehouse400262a2017-12-08 22:54:44 +0000479 return rc;
480 }
481
482 return Info.return_code;
483}
484
485const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt,
486 size_t PattLen) {
487 return memmem(Data, DataLen, Patt, PattLen);
488}
489
490} // namespace fuzzer
491
492#endif // LIBFUZZER_FUCHSIA