Debian Codegraph @

mingw-w64-crt/cfguard/mingw_cfguard_support.c

raw
1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7 // This source file defines the function pointers required to support Control
8 // Flow Guard. They shall be included even if CFGuard is disabled when building
9 // mingw-w64-crt itself, to allow linking to objects/libraries compiled with
10 // CFGuard.
11
12 #if defined(__x86_64__)
13
14 // The target address is passed as a parameter in an arch-specific manner,
15 // however it is not specified how on x86_64 because __guard_dispatch_icall_fptr
16 // is used instead. My guess would be that it's passed on %rcx, but it doesn't
17 // really matter here because this is a no-op anyway.
18 static void __guard_check_icall_dummy(void) {}
19
20 // This is intentionally declared as _not_ a function pointer, so that the
21 // jmp instruction is not included as a valid call target for CFGuard.
22 extern void *__guard_dispatch_icall_dummy;
23
24 #elif defined(__i386__) || defined(__aarch64__) || defined(__arm__)
25
26 // The target address is passed via %ecx (x86), X15 (aarch64) or R0 (arm),
27 // but it doesn't really matter here because this is a no-op anyway.
28 static void __guard_check_icall_dummy(void) {}
29
30 #else
31 # error "CFGuard support is unimplemented for the current architecture."
32 #endif
33
34 // I am not sure about the `.00cfg` section. This is just an attempt to follow
35 // what VC runtime defines -- it places all the guard check function pointers
36 // inside this section. The MSVC linker appears to merge this section into
37 // `.rdata`, but LLD does not do this at the time of writing.
38 // This section should be readonly data. The only thing that modifies these
39 // pointers is the PE image loader.
40
41 __asm__(".section .00cfg,\"dr\"");
42
43 __attribute__(( section (".00cfg") ))
44 void *__guard_check_icall_fptr = &__guard_check_icall_dummy;
45
46 #if defined(__x86_64__)
47
48 __attribute__(( section (".00cfg") ))
49 void *__guard_dispatch_icall_fptr = &__guard_dispatch_icall_dummy;
50
51 #endif