github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/executor/executor_fuchsia.h (about) 1 // Copyright 2017 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 #include <errno.h> 5 #include <pthread.h> 6 #include <stdlib.h> 7 #include <string.h> 8 #include <sys/mman.h> 9 #include <unistd.h> 10 #include <zircon/status.h> 11 #include <zircon/syscalls.h> 12 13 #include "nocover.h" 14 15 static void os_init(int argc, char** argv, void* data, size_t data_size) 16 { 17 zx_status_t status = syz_mmap((size_t)data, data_size); 18 if (status != ZX_OK) 19 failmsg("mmap of data segment failed", "status=%s (%d)", zx_status_get_string(status), status); 20 } 21 22 static intptr_t execute_syscall(const call_t* c, intptr_t a[kMaxArgs]) 23 { 24 intptr_t res = c->call(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]); 25 if (strncmp(c->name, "zx_", 3) == 0) { 26 // Convert zircon error convention to the libc convention that executor expects. 27 // The following calls return arbitrary integers instead of error codes. 28 if (res == ZX_OK || 29 !strcmp(c->name, "zx_debuglog_read") || 30 !strcmp(c->name, "zx_clock_get") || 31 !strcmp(c->name, "zx_clock_get_monotonic") || 32 !strcmp(c->name, "zx_deadline_after") || 33 !strcmp(c->name, "zx_ticks_get")) 34 return 0; 35 errno = (-res) & 0x7f; 36 return -1; 37 } 38 // We cast libc functions to signature returning intptr_t, 39 // as the result int -1 is returned as 0x00000000ffffffff rather than full -1. 40 if (res == 0xffffffff) 41 res = (intptr_t)-1; 42 return res; 43 }