Update copyright year
[openssl.git] / crypto / async / arch / async_win.c
1 /*
2  * Copyright 2015-2022 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
18 int ASYNC_is_capable(void)
19 {
20     return 1;
21 }
22
23 int ASYNC_set_mem_functions(ASYNC_stack_alloc_fn alloc_fn,
24                             ASYNC_stack_free_fn free_fn)
25 {
26     return 0;
27 }
28
29 void ASYNC_get_mem_functions(ASYNC_stack_alloc_fn *alloc_fn,
30                              ASYNC_stack_free_fn *free_fn)
31 {
32     if (alloc_fn != NULL)
33         *alloc_fn = NULL;
34     if (free_fn != NULL)
35         *free_fn = NULL;
36 }
37
38 void async_local_cleanup(void)
39 {
40     async_ctx *ctx = async_get_ctx();
41     if (ctx != NULL) {
42         async_fibre *fibre = &ctx->dispatcher;
43         if (fibre != NULL && fibre->fibre != NULL && fibre->converted) {
44             ConvertFiberToThread();
45             fibre->fibre = NULL;
46         }
47     }
48 }
49
50 int async_fibre_init_dispatcher(async_fibre *fibre)
51 {
52 # if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600
53     fibre->fibre = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH);
54 # else
55     fibre->fibre = ConvertThreadToFiber(NULL);
56 # endif
57     if (fibre->fibre == NULL) {
58         fibre->converted = 0;
59         fibre->fibre = GetCurrentFiber();
60         if (fibre->fibre == NULL)
61             return 0;
62     } else {
63         fibre->converted = 1;
64     }
65
66     return 1;
67 }
68
69 VOID CALLBACK async_start_func_win(PVOID unused)
70 {
71     async_start_func();
72 }
73
74 #endif