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