为什么ucrtbase会导出_CxxThrowException?

Why does ucrtbase export _CxxThrowException?

为什么 ucrtbase.dllvcruntime140.dll 根据 Dependency Walker 导出的一些函数重叠?

免责声明:我目前纯粹出于学术兴趣。

我目前正在尝试了解 Microsoft Visual-C++ CRT 相关 DLL 文件的布局。在此处查找 UCRT 信息和一般文件:

简而言之,对于普通的 C++ 应用程序,您在运行时具有这些(顶层)DLL 依赖项:

从该信息中可以突出显示的是:

来自博客条目:

... split the CRT into two logical parts: The VCRuntime, which contained the compiler support functionality required for things like process startup and exception handling ...

并来自 MSDN 页面:

The vcruntime library contains Visual C++ CRT implementation-specific code, such as exception handling and debugging support, runtime checks and type information, implementation details and certain extended library functions. This library is specific to the version of the compiler used.

在使用 Dependency Walker, I noticed that both the ucrt and the vcruntime export the function _CxxThrowException 浏览 DLL 时。如果您曾经查看过 vc++ 堆栈跟踪,那么这个函数就是老熟人了:

Builds the exception record and calls the runtime environment to start processing the exception.

我很惊讶地发现这个是从 ucrtbase.dll 导出的,因为 - 正如上面的两个引号所表明的 - 我本以为 这台机器坚定地属于编译器特定方面的事情。

在撰写本文时,我注意到了一些其他的重叠:极少数标准 C 库函数(memcpy、...、strstr、...)也是从 vcruntime140.dll 导出,尽管我原以为它们只生活在 ucrtbase.

那么这是怎么回事,我可以从中学到什么?

通用 CRT (ucrtbase.dll) 包含 VCRuntime 的私有副本,供 Windows 操作系统组件使用。 VCRuntime 的这个私有副本是操作系统的内部实现细节,可能随时更改(即,没有任何应用程序兼容性保证。

在任何情况下都不要使用通用 CRT 的这些导出。 (Windows SDK 中没有库为这些导出提供可链接的符号,因此不可能不小心使用它们。)