Closed fgmailbox closed 1 year ago
template < ULONG tag > class TestClass { int value = 0; public: TestClass(int value = 0) : value(value){}; };
template < ULONG tag > void test() {
static int cnt { [](int val) { return val; }(tag) }; int *p_cnt = &cnt; using TestClass = TestClass<tag>; // 以下用llvm-msvc-kernelmode 2.6 开发驱动,必定会发生页故障, //但是wdk驱动开发工具是不会发生的, static TestClass testClass1(tag+100); static TestClass testClass2(tag + 200); static TestClass testClass4 {[](int val) { return val; }(tag)};
static thread_local int thr_cnt = [](auto val) { return val; }(tag + 1000); int *p_thr_cnt = &thr_cnt; static thread_local int thr_cnt2 = tag + 1000; int *p_thr_cnt2 = &thr_cnt2; static thread_local TestClass testClass3(tag + 300);
}
extern "C" NTSTATUS DriverEntry( IN PDRIVER_OBJECT driverObject, IN PUNICODE_STRING registryPath ) { test<128>(); }
c++里面的自定义的静态类型初始化都会发生这样的问题
llvm-msvc-kernel-driver.cpp.txt
DriverTest2.zip
template < ULONG tag > class TestClass { int value = 0; public: TestClass(int value = 0) : value(value){}; };
template < ULONG tag > void test() {
ifdef clang
pragma data_seg(".data")
endif
ifdef clang
endif
ifdef clang
pragma data_seg()
endif
}
extern "C" NTSTATUS DriverEntry( IN PDRIVER_OBJECT driverObject, IN PUNICODE_STRING registryPath ) { test<128>(); }