Skip to content

Commit

Permalink
添加IsThreadAFiber、ConvertThreadToFiberEx。
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Jun 30, 2021
1 parent 02b29f9 commit 580184e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@
| [FlsFree](https://docs.microsoft.com/windows/win32/api/fibersapi/nf-fibersapi-flsfree) | 不存在时,使用Tls实现。警告,此函数请勿跨模块使用!!!
| [FlsGetValue](https://docs.microsoft.com/windows/win32/api/fibersapi/nf-fibersapi-flsgetvalue) | 不存在时,使用Tls实现。警告,此函数请勿跨模块使用!!!
| [FlsSetValue](https://docs.microsoft.com/windows/win32/api/fibersapi/nf-fibersapi-flssetvalue) | 不存在时,使用Tls实现。警告,此函数请勿跨模块使用!!!
| [IsThreadAFiber](https://docs.microsoft.com/windows/win32/api/fibersapi/nf-fibersapi-isthreadafiber) | 不存在时,调用 GetCurrentFiber。
| [ConvertThreadToFiberEx](https://docs.microsoft.com/windows/win32/api/winbase/nf-winbase-convertthreadtofiberex) | 不存在时,调用 ConvertThreadToFiber。
| [RoInitialize](https://docs.microsoft.com/windows/win32/api/roapi/nf-roapi-roinitialize) | 不存在时,调用 CoInitializeEx。
| [RoUninitialize](https://docs.microsoft.com/windows/win32/api/roapi/nf-roapi-rouninitialize) | 不存在时,调用 CoUninitialize。

52 changes: 52 additions & 0 deletions src/Thunks/api-ms-win-core-fibers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,5 +517,57 @@ namespace YY

}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN6)

//Minimum supported client Windows Vista [desktop apps | UWP apps]
//Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
__DEFINE_THUNK(
kernel32,
0,
BOOL,
WINAPI,
IsThreadAFiber,
VOID
)
{
if (const auto pIsThreadAFiber = try_get_IsThreadAFiber())
{
return pIsThreadAFiber();
}

//如果当前没有 Fiber,那么我们认为这不是一个纤程
auto pFiber = GetCurrentFiber();

//0x1e00 是一个魔幻数字,似乎所有NT系统都会这样,当前不是一个Fiber时,第一次会返回 0x1e00。
return pFiber != nullptr && pFiber != (void*)0x1e00;
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN6)

//Minimum supported client Windows Vista [desktop apps | UWP apps]
//Minimum supported server Windows Server 2008 [desktop apps | UWP apps]
__DEFINE_THUNK(
kernel32,
8,
LPVOID,
WINAPI,
ConvertThreadToFiberEx,
_In_opt_ LPVOID lpParameter,
_In_ DWORD dwFlags
)
{
if (const auto pConvertThreadToFiberEx = try_get_ConvertThreadToFiberEx())
{
return pConvertThreadToFiberEx(lpParameter, dwFlags);
}

//FIBER_FLAG_FLOAT_SWITCH 无法使用,不过似乎关系不大。一些boost基础设施中都不切换浮点状态。
return ConvertThreadToFiber(lpParameter);
}
#endif
}
}

0 comments on commit 580184e

Please sign in to comment.