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 <unistd.h>
9 #include <zircon/syscalls.h>
10
11 #include "nocover.h"
12
os_init(int argc,char ** argv,void * data,size_t data_size)13 static void os_init(int argc, char** argv, void* data, size_t data_size)
14 {
15 if (syz_mmap((size_t)data, data_size) != ZX_OK)
16 fail("mmap of data segment failed");
17 }
18
execute_syscall(const call_t * c,long a[kMaxArgs])19 static long execute_syscall(const call_t* c, long a[kMaxArgs])
20 {
21 long res = c->call(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
22 if (strncmp(c->name, "zx_", 3) == 0) {
23 // Convert zircon error convention to the libc convention that executor expects.
24 if (res == ZX_OK ||
25 !strcmp(c->name, "zx_log_read") ||
26 !strcmp(c->name, "zx_clock_get") ||
27 !strcmp(c->name, "zx_ticks_get"))
28 return 0;
29 errno = (-res) & 0x7f;
30 return -1;
31 }
32 // We cast libc functions to signature returning long,
33 // as the result int -1 is returned as 0x00000000ffffffff rather than full -1.
34 if (res == 0xffffffff)
35 res = (long)-1;
36 return res;
37 }
38