-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add support for Windows Secure Hot-Patching #138972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This verifies that we correctly handle a -fms-secure-hotpatch-functions-file argument that points | ||
// to a missing file. | ||
// | ||
// RUN: not %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-secure-hotpatch-functions-file=%S/this-file-is-intentionally-missing-do-not-create-it.txt /Fo%t.obj %s 2>&1 | FileCheck %s | ||
// CHECK: failed to open hotpatch functions file | ||
|
||
void this_might_have_side_effects(); | ||
|
||
int __declspec(noinline) this_gets_hotpatched() { | ||
this_might_have_side_effects(); | ||
return 42; | ||
} | ||
|
||
int __declspec(noinline) this_does_not_get_hotpatched() { | ||
return this_gets_hotpatched() + 100; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// This verifies that hotpatch function attributes are correctly propagated when compiling directly to OBJ, | ||
// and that name mangling works as expected. | ||
// | ||
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-secure-hotpatch-functions-list=?this_gets_hotpatched@@YAHXZ /Fo%t.obj %s | ||
// RUN: llvm-readobj --codeview %t.obj | FileCheck %s | ||
|
||
void this_might_have_side_effects(); | ||
|
||
int __declspec(noinline) this_gets_hotpatched() { | ||
this_might_have_side_effects(); | ||
return 42; | ||
} | ||
|
||
// CHECK: Kind: S_HOTPATCHFUNC (0x1169) | ||
// CHECK-NEXT: Function: this_gets_hotpatched | ||
// CHECK-NEXT: Name: ?this_gets_hotpatched@@YAHXZ | ||
|
||
extern "C" int __declspec(noinline) this_does_not_get_hotpatched() { | ||
return this_gets_hotpatched() + 100; | ||
} | ||
|
||
// CHECK-NOT: S_HOTPATCHFUNC |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This verifies that hotpatch function attributes are correctly propagated through LLVM IR when compiling with LTO. | ||
// | ||
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-secure-hotpatch-functions-list=this_gets_hotpatched -flto /Fo%t.bc %s | ||
// RUN: llvm-dis %t.bc -o - | FileCheck %s | ||
// | ||
// CHECK: ; Function Attrs: marked_for_windows_hot_patching mustprogress nofree noinline norecurse nosync nounwind sspstrong willreturn memory(none) uwtable | ||
// CHECK-NEXT: define dso_local noundef i32 @this_gets_hotpatched() local_unnamed_addr #0 !dbg !13 { | ||
// | ||
// CHECK: ; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind sspstrong willreturn memory(none) uwtable | ||
// CHECK-NEXT: define dso_local noundef i32 @this_does_not_get_hotpatched() local_unnamed_addr #1 !dbg !19 { | ||
|
||
int __declspec(noinline) this_gets_hotpatched() { | ||
return 42; | ||
} | ||
|
||
int __declspec(noinline) this_does_not_get_hotpatched() { | ||
return this_gets_hotpatched() + 100; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This verifies that hotpatch function attributes are correctly propagated when compiling directly to OBJ. | ||
// | ||
// RUN: echo this_gets_hotpatched > %t.patch-functions.txt | ||
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-secure-hotpatch-functions-file=%t.patch-functions.txt /Fo%t.obj %s | ||
// RUN: llvm-readobj --codeview %t.obj | FileCheck %s | ||
|
||
void this_might_have_side_effects(); | ||
|
||
int __declspec(noinline) this_gets_hotpatched() { | ||
this_might_have_side_effects(); | ||
return 42; | ||
} | ||
|
||
// CHECK: Kind: S_HOTPATCHFUNC (0x1169) | ||
// CHECK-NEXT: Function: this_gets_hotpatched | ||
|
||
int __declspec(noinline) this_does_not_get_hotpatched() { | ||
return this_gets_hotpatched() + 100; | ||
} | ||
|
||
// CHECK-NOT: S_HOTPATCHFUNC |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,21 @@ class CallerSym : public SymbolRecord { | |
uint32_t RecordOffset = 0; | ||
}; | ||
|
||
class HotPatchFuncSym : public SymbolRecord { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity (related to my other questions), historically Windows updates only deliver binaries (DLLs, EXEs), not PDBs. PDBs are usually fetched by users when debugging, through the Microsoft symbol server. Then how is the kernel gonna find this record if the PDB isn't there by default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our hot-patch tools read PDBs and then generate metadata that is placed into the final DLL/SYS/EXE, into a COFF section that is reserved for this purpose. The PDBs are not distributed with the hot-patch, and are not needed by the OS that is installing the hot-patch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Would that tooling remain proprietary, or is it something that will be open-sourced as well, for example for NT drivers developpers? |
||
public: | ||
explicit HotPatchFuncSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {} | ||
HotPatchFuncSym(uint32_t RecordOffset) | ||
: SymbolRecord(SymbolRecordKind::HotPatchFuncSym), | ||
RecordOffset(RecordOffset) {} | ||
|
||
// This is an ItemID in the IPI stream, which points to an LF_FUNC_ID or | ||
// LF_MFUNC_ID record. | ||
TypeIndex Function; | ||
StringRef Name; | ||
|
||
uint32_t RecordOffset = 0; | ||
}; | ||
|
||
struct DecodedAnnotation { | ||
StringRef Name; | ||
ArrayRef<uint8_t> Bytes; | ||
|
Uh oh!
There was an error while loading. Please reload this page.