-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18596 from ypsvlq/mingw
mingw-w64: add missing CRT sources
- Loading branch information
Showing
272 changed files
with
4,799 additions
and
11,735 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* This file has no copyright assigned and is placed in the Public Domain. | ||
* This file is part of the mingw-w64 runtime package. | ||
* No warranty is given; refer to the file DISCLAIMER.PD within this package. | ||
*/ | ||
|
||
// This source file defines the function pointers required to support Control | ||
// Flow Guard. They shall be included even if CFGuard is disabled when building | ||
// mingw-w64-crt itself, to allow linking to objects/libraries compiled with | ||
// CFGuard. | ||
|
||
#if defined(__x86_64__) | ||
|
||
// The target address is passed as a parameter in an arch-specific manner, | ||
// however it is not specified how on x86_64 because __guard_dispatch_icall_fptr | ||
// is used instead. My guess would be that it's passed on %rcx, but it doesn't | ||
// really matter here because this is a no-op anyway. | ||
static void __guard_check_icall_dummy(void) {} | ||
|
||
// When CFGuard is not active, directly tail-call the target address, which | ||
// is passed via %rax. | ||
__asm__( | ||
".globl __guard_dispatch_icall_dummy\n" | ||
"__guard_dispatch_icall_dummy:\n" | ||
" jmp *%rax\n" | ||
); | ||
|
||
// This is intentionally declared as _not_ a function pointer, so that the | ||
// jmp instruction is not included as a valid call target for CFGuard. | ||
extern void *__guard_dispatch_icall_dummy; | ||
|
||
#elif defined(__i386__) || defined(__aarch64__) || defined(__arm__) | ||
|
||
// The target address is passed via %ecx (x86), X15 (aarch64) or R0 (arm), | ||
// but it doesn't really matter here because this is a no-op anyway. | ||
static void __guard_check_icall_dummy(void) {} | ||
|
||
#else | ||
# error "CFGuard support is unimplemented for the current architecture." | ||
#endif | ||
|
||
// I am not sure about the `.00cfg` section. This is just an attempt to follow | ||
// what VC runtime defines -- it places all the guard check function pointers | ||
// inside this section. The MSVC linker appears to merge this section into | ||
// `.rdata`, but LLD does not do this at the time of writing. | ||
// This section should be readonly data. The only thing that modifies these | ||
// pointers is the PE image loader. | ||
|
||
__asm__(".section .00cfg,\"dr\""); | ||
|
||
__attribute__(( section (".00cfg") )) | ||
void *__guard_check_icall_fptr = &__guard_check_icall_dummy; | ||
|
||
#if defined(__x86_64__) | ||
|
||
__attribute__(( section (".00cfg") )) | ||
void *__guard_dispatch_icall_fptr = &__guard_dispatch_icall_dummy; | ||
|
||
#endif |
Oops, something went wrong.