github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/executor/common_kvm_syzos.h (about)

     1  // Copyright 2025 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  #ifndef EXECUTOR_COMMON_KVM_SYZOS_H
     5  #define EXECUTOR_COMMON_KVM_SYZOS_H
     6  
     7  // Common SYZOS definitions.
     8  
     9  // Prevent function inlining. This attribute is applied to every guest_handle_* function,
    10  // making sure they remain small so that the compiler does not attempt to be too clever
    11  // (e.g. generate switch tables).
    12  #define noinline __attribute__((noinline))
    13  
    14  // __no_stack_protector disables -fstack-protector which may introduce unwanted global accesses.
    15  // TODO(glider): once syz-env-old migrates to GCC>11 we can just use
    16  // __attribute__((no_stack_protector)).
    17  #if defined(__clang__)
    18  
    19  // Clang supports the no_stack_protector attribute.
    20  #define __no_stack_protector __attribute__((no_stack_protector))
    21  #define __addrspace_guest __attribute__((address_space(10)))
    22  
    23  #elif defined(__GNUC__)
    24  // The no_stack_protector attribute was introduced in GCC 11.1.
    25  #if __GNUC__ > 11
    26  #define __no_stack_protector __attribute__((no_stack_protector))
    27  #else
    28  // Fallback to the optimize attribute for older GCC versions.
    29  #define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
    30  #endif
    31  #define __addrspace_guest
    32  
    33  #else
    34  #define __no_stack_protector
    35  #define __addrspace_guest
    36  #endif
    37  
    38  // Disable optimizations for a particular function.
    39  #if defined(__clang__)
    40  #define __optnone __attribute__((optnone))
    41  #elif defined(__GNUC__)
    42  #define __optnone __attribute__((optimize("O0")))
    43  #else
    44  #define __optnone
    45  #endif
    46  
    47  // Host will map the code in this section into the guest address space.
    48  #define GUEST_CODE __attribute__((section("guest"))) __no_stack_protector __addrspace_guest
    49  
    50  // Start/end of the guest section.
    51  extern char *__start_guest, *__stop_guest;
    52  
    53  #endif // EXECUTOR_COMMON_KVM_SYZOS_H