gpt4 book ai didi

wdk - 错误LNK2001 : unresolved external symbol _fltused in wdk

转载 作者:行者123 更新时间:2023-11-30 17:32:47 26 4
gpt4 key购买 nike

我正在尝试在 C 代码中定义一个 double 据类型变量,该变量将在 Windows 内核中使用。代码可以编译,但在链接时出错。我尝试在源文件中使用 libcntpr.lib 并在代码中定义 __fltused 变量,但无济于事。如果有人能帮助我了解如何使用它,我将非常感激。

最佳答案

不知道是否仍然适用于当前的 WDK,但 Walter Oney 阻止了在驱动程序中使用浮点内容 here .

The problem is worse than just finding the right library, unfortunately. The C compiler's floating point support assumes that it will be operating in a an application environment where you can initialize the coprocessor, install some exception handlers, and then blast away. It also assumes that the operating system will take care of saving and restoring each thread's coprocessor context as required by all the thread context switches that occur from then on.

These assumptions aren't usually true in a driver. Furthermore, the runtime library support for coprocessor exceptions can't work because there's a whole bunch of missing infrastructure.

What you basically need to do is write your code in such a way that you initialize the coprocessor each time you want to use it (don't forget KeSaveFloatingPointState and KeRestoreFloatingPointState). Set things up so that the coprocessor will never generate an exception, too. Then you can simply define the symbol __fltused somewhere to satisfy the linker. (All that symbol usually does is drag in the runtime support. You don't want that support becuase, as I said, it won't work in kernel mode.) You'll undoubtedly need some assembly language code for the initialization steps.

If you have a system thread that will be doing all your floating point math, you can initialize the coprocesor once at the start of the thread. The system will save and restore your state as necessary from then on.

Don't forget that you can only do floating point at IRQL < DISPATCH_LEVEL.

There's FINIT, among other things. If you're rusty on coprocessor programming, my advice would be to tell your management that this is a specialized problem that will require a good deal of study to solve. Then fly off to Martinique for a week or so (after hurricane season, that is) to perform the study in an appropriate environment.

Seriously, if you're unfamiliar with FINIT and other math coprocessor instructions, this is probably not something you should be incorporating into your driver.

还有来自 Microsoft 的有趣读物:C++ for Kernel Mode Drivers: Pros and Cons

On x86 systems, the floating point and multimedia units are not available in kernel mode unless specifically requested. Trying to use them improperly may or may not cause a floating-point fault at raised IRQL (which will crash the system), but it could cause silent data corruption in random processes. Improper use can also cause data corruption in other processes; such problems are often difficult to debug.

关于wdk - 错误LNK2001 : unresolved external symbol _fltused in wdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23998641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com