blob: 6dc75be36405a634bfbb8468f210544eba87f3b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Copyright 2025 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
#ifndef EXECUTOR_COMMON_KVM_SYZOS_H
#define EXECUTOR_COMMON_KVM_SYZOS_H
// Common SYZOS definitions.
// Prevent function inlining. This attribute is applied to every guest_handle_* function,
// making sure they remain small so that the compiler does not attempt to be too clever
// (e.g. generate switch tables).
#define noinline __attribute__((noinline))
// Force inlining as much as possible.
#define always_inline __attribute__((always_inline)) inline
// __no_stack_protector disables -fstack-protector which may introduce unwanted global accesses.
// TODO(glider): once syz-env-old migrates to GCC>11 we can just use
// __attribute__((no_stack_protector)).
#if defined(__clang__)
// Clang supports the no_stack_protector attribute.
#define __no_stack_protector __attribute__((no_stack_protector))
#define __addrspace_guest __attribute__((address_space(10)))
#elif defined(__GNUC__)
// The no_stack_protector attribute was introduced in GCC 11.1.
#if __GNUC__ > 11
#define __no_stack_protector __attribute__((no_stack_protector))
#else
// Fallback to the optimize attribute for older GCC versions.
#define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
#endif
#define __addrspace_guest
#else
#define __no_stack_protector
#define __addrspace_guest
#endif
// Disable optimizations for a particular function.
#if defined(__clang__)
#define __optnone __attribute__((optnone))
#elif defined(__GNUC__)
#define __optnone __attribute__((optimize("O0")))
#else
#define __optnone
#endif
// Host will map the code in this section into the guest address space.
#define GUEST_CODE __attribute__((section("guest"))) __no_stack_protector __addrspace_guest
// Start/end of the guest section.
extern char *__start_guest, *__stop_guest;
// Common SYZOS API call descriptors.
struct api_call_header {
uint64 call;
uint64 size;
};
struct api_call_1 {
struct api_call_header header;
uint64 arg;
};
struct api_call_2 {
struct api_call_header header;
uint64 args[2];
};
struct api_call_3 {
struct api_call_header header;
uint64 args[3];
};
struct api_call_5 {
struct api_call_header header;
uint64 args[5];
};
#endif // EXECUTOR_COMMON_KVM_SYZOS_H
|