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.7 开发驱动,必定会发生页故障, // 这在内核开发有点难以接受 // 但是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>(); } `
llvm-msvc-kernel-driver.zip
迫切希望你能解决这个问题,因为WDK工具编译我的驱动release版会搞死编译器,只能编译debug版本
有压缩文件的代码呀
` 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
if 0 //def clang
endif
ifdef clang
pragma data_seg()
endif
}
extern "C" NTSTATUS DriverEntry( IN PDRIVER_OBJECT driverObject, IN PUNICODE_STRING registryPath ) { test<128>(); } `