1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci/* This must be the first #include file */ 11e1051a39Sopenharmony_ci#include "../async_local.h" 12e1051a39Sopenharmony_ci 13e1051a39Sopenharmony_ci#ifdef ASYNC_WIN 14e1051a39Sopenharmony_ci 15e1051a39Sopenharmony_ci# include <windows.h> 16e1051a39Sopenharmony_ci# include "internal/cryptlib.h" 17e1051a39Sopenharmony_ci 18e1051a39Sopenharmony_ciint ASYNC_is_capable(void) 19e1051a39Sopenharmony_ci{ 20e1051a39Sopenharmony_ci return 1; 21e1051a39Sopenharmony_ci} 22e1051a39Sopenharmony_ci 23e1051a39Sopenharmony_civoid async_local_cleanup(void) 24e1051a39Sopenharmony_ci{ 25e1051a39Sopenharmony_ci async_ctx *ctx = async_get_ctx(); 26e1051a39Sopenharmony_ci if (ctx != NULL) { 27e1051a39Sopenharmony_ci async_fibre *fibre = &ctx->dispatcher; 28e1051a39Sopenharmony_ci if (fibre != NULL && fibre->fibre != NULL && fibre->converted) { 29e1051a39Sopenharmony_ci ConvertFiberToThread(); 30e1051a39Sopenharmony_ci fibre->fibre = NULL; 31e1051a39Sopenharmony_ci } 32e1051a39Sopenharmony_ci } 33e1051a39Sopenharmony_ci} 34e1051a39Sopenharmony_ci 35e1051a39Sopenharmony_ciint async_fibre_init_dispatcher(async_fibre *fibre) 36e1051a39Sopenharmony_ci{ 37e1051a39Sopenharmony_ci# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 38e1051a39Sopenharmony_ci fibre->fibre = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH); 39e1051a39Sopenharmony_ci# else 40e1051a39Sopenharmony_ci fibre->fibre = ConvertThreadToFiber(NULL); 41e1051a39Sopenharmony_ci# endif 42e1051a39Sopenharmony_ci if (fibre->fibre == NULL) { 43e1051a39Sopenharmony_ci fibre->converted = 0; 44e1051a39Sopenharmony_ci fibre->fibre = GetCurrentFiber(); 45e1051a39Sopenharmony_ci if (fibre->fibre == NULL) 46e1051a39Sopenharmony_ci return 0; 47e1051a39Sopenharmony_ci } else { 48e1051a39Sopenharmony_ci fibre->converted = 1; 49e1051a39Sopenharmony_ci } 50e1051a39Sopenharmony_ci 51e1051a39Sopenharmony_ci return 1; 52e1051a39Sopenharmony_ci} 53e1051a39Sopenharmony_ci 54e1051a39Sopenharmony_ciVOID CALLBACK async_start_func_win(PVOID unused) 55e1051a39Sopenharmony_ci{ 56e1051a39Sopenharmony_ci async_start_func(); 57e1051a39Sopenharmony_ci} 58e1051a39Sopenharmony_ci 59e1051a39Sopenharmony_ci#endif 60