1 // Copyright 2018 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 // This file is shared between executor and csource package.
5
6 #include <stdlib.h>
7 #include <unistd.h>
8
9 #if SYZ_EXECUTOR || __NR_syz_mmap
10 #include <sys/mman.h>
11
12 // syz_mmap(addr vma, len len[addr])
syz_mmap(long a0,long a1)13 static long syz_mmap(long a0, long a1)
14 {
15 return (long)mmap((void*)a0, a1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0);
16 }
17 #endif
18
19 #if SYZ_EXECUTOR || __NR_syz_errno
20 #include <errno.h>
21
22 // syz_errno(v int32)
syz_errno(long v)23 static long syz_errno(long v)
24 {
25 errno = v;
26 return v == 0 ? 0 : -1;
27 }
28 #endif
29
30 #if SYZ_EXECUTOR || __NR_syz_compare
31 #include <errno.h>
32 #include <string.h>
33
34 // syz_compare(want ptr[in, string], want_len len[want], got ptr[in, compare_data], got_len len[got])
syz_compare(long want,long want_len,long got,long got_len)35 static long syz_compare(long want, long want_len, long got, long got_len)
36 {
37 if (want_len != got_len) {
38 debug("syz_compare: want_len=%lu got_len=%lu\n", want_len, got_len);
39 errno = EBADF;
40 return -1;
41 }
42 if (memcmp((void*)want, (void*)got, want_len)) {
43 debug("syz_compare: data differs\n");
44 errno = EINVAL;
45 return -1;
46 }
47 return 0;
48 }
49 #endif
50
51 #if SYZ_EXECUTOR || SYZ_SANDBOX_NONE
52 static void loop();
do_sandbox_none(void)53 static int do_sandbox_none(void)
54 {
55 loop();
56 doexit(0);
57 }
58 #endif
59
60 #if SYZ_EXECUTOR
61 #define do_sandbox_setuid() 0
62 #define do_sandbox_namespace() 0
63 #endif
64