发现问题:Visual Studio CRT 库:FLS_GETVALUE
今天,我在检查Visual Studio 2008和2010的CRT库的源代码时,发现mtdll.h文件中存在一个错误。问题出在宏 FLS_GETVALUE 上。在 x86 系统上,该宏直接调用 TlsGetValue,而不是调用分配给变量 gpFlsGetValue 的函数。
首先,这是一个问题,因为 FlsAlloc、FlsGetValue、FlsFree 和 FlsSetValue 并非在所有系统(Windows Vista+ 和 Windows Server 2003+)上都可用。这些函数的行为类似于 TlsAlloc、TlsGetValue、TlsFree 和 TlsSetValue,但支持 Fibers(一种用户线程)。因为我们应该更喜欢使用 Fls* 函数而不是 Tls 函数,所以 VS 的 C 运行时库会在进程或 dll 加载时检查 Fls 函数是否可用,并初始化 gpFls* 变量。如果 Fls* 不可用,CRT 将使用等效的 Tls* 函数初始化这些变量。
您不能直接在代码中使用宏 FLS_GETVALUE,因为它由运行时库内部使用。运行时使用此宏来初始化运行时库的每个线程数据。
我的问题是关于这个错误的影响。我知道 Fiber 没有广泛使用,但是如果您开发一个在使用 Fiber 的应用程序中使用的 DLL,会产生什么影响?此错误是否会导致应用程序崩溃或仅产生错误结果?此问题是否会导致 SQL Server 等广泛使用的应用程序出现问题?你怎么认为?这个错误会带来安全风险吗? IIS 或 ASP.Net 使用光纤是否会导致崩溃?
对于好奇的人,这里是 mtdll.h 中有问题的行的当前来源:
#define FLS_GETVALUE ((PFLS_GETVALUE_FUNCTION)TlsGetValue(__getvalueindex))
这里是宏 FLS_GETVALUE 的固定版本:
#define FLS_GETVALUE (((PFLS_GETVALUE_FUNCTION)DecodePointer(gpFlsGetValue))(__getvalueindex))
现在,我应该找到如何向 Microsoft 提交错误。
Today, I was checking source code of the CRT library of Visual Studio 2008 and 2010 and I found a bug into the file mtdll.h. The problem is with the macro FLS_GETVALUE. On x86 systems, this macro call directly TlsGetValue instead of making a call to the function assigned to the variable gpFlsGetValue.
First of all, it's a problem because FlsAlloc, FlsGetValue, FlsFree and FlsSetValue are not available on all system( Windows Vista+ and Windows Server 2003+). These functions behave like TlsAlloc, TlsGetValue, TlsFree and TlsSetValue but support Fibers(kind of user thread). Because we should prefer using Fls* functions instead of Tls functions, the C runtime library of VS check if the Fls functions are availables when the process or the dll is loaded and initialise the gpFls* variables. If the Fls* are not available, the CRT initialise these variables with the equivalent Tls* functions.
You cannot use the macro FLS_GETVALUE directly into your code because it's used internally by the runtime library. The runtime use this macro to initialise per thread data of the runtime library.
My question is about the impact of this bug. I know that fiber are not widely used, but if you develop a DLL that is used inside an application that use fiber, what can be the impact? Does this bug can cause a crash of the application or only produce false results? Does this problem can cause problem with widely used application like SQL Server? What do you think? Does this bug can be a security risk? Does IIS or ASP.Net use fiber that can cause a crash?
For curious people, here the current source of the problematic line in mtdll.h:
#define FLS_GETVALUE ((PFLS_GETVALUE_FUNCTION)TlsGetValue(__getvalueindex))
Here a fixed version of the macro FLS_GETVALUE :
#define FLS_GETVALUE (((PFLS_GETVALUE_FUNCTION)DecodePointer(gpFlsGetValue))(__getvalueindex))
For now, I should find how to submit a bug to Microsoft.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此不太确定。 CRT 处理 FlsGetValue 的方式似乎与其他 FLS 函数不同。看起来 CRT 在 TLS 中存储了一个指向 FlsGetValue 函数的指针(伪代码):
I'm not sure about that. The CRT seems to handle FlsGetValue differently from the other FLS functions. It looks like the CRT is storing a pointer to the FlsGetValue function in TLS (pseudo-code):