async_win.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /* This must be the first #include file */
  10. #include "../async_local.h"
  11. #ifdef ASYNC_WIN
  12. # include <windows.h>
  13. # include "internal/cryptlib.h"
  14. int ASYNC_is_capable(void)
  15. {
  16. return 1;
  17. }
  18. int ASYNC_set_mem_functions(ASYNC_stack_alloc_fn alloc_fn,
  19. ASYNC_stack_free_fn free_fn)
  20. {
  21. return 0;
  22. }
  23. void ASYNC_get_mem_functions(ASYNC_stack_alloc_fn *alloc_fn,
  24. ASYNC_stack_free_fn *free_fn)
  25. {
  26. if (alloc_fn != NULL)
  27. *alloc_fn = NULL;
  28. if (free_fn != NULL)
  29. *free_fn = NULL;
  30. }
  31. void async_local_cleanup(void)
  32. {
  33. async_ctx *ctx = async_get_ctx();
  34. if (ctx != NULL) {
  35. async_fibre *fibre = &ctx->dispatcher;
  36. if (fibre != NULL && fibre->fibre != NULL && fibre->converted) {
  37. ConvertFiberToThread();
  38. fibre->fibre = NULL;
  39. }
  40. }
  41. }
  42. int async_fibre_init_dispatcher(async_fibre *fibre)
  43. {
  44. # if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600
  45. fibre->fibre = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH);
  46. # else
  47. fibre->fibre = ConvertThreadToFiber(NULL);
  48. # endif
  49. if (fibre->fibre == NULL) {
  50. fibre->converted = 0;
  51. fibre->fibre = GetCurrentFiber();
  52. if (fibre->fibre == NULL)
  53. return 0;
  54. } else {
  55. fibre->converted = 1;
  56. }
  57. return 1;
  58. }
  59. VOID CALLBACK async_start_func_win(PVOID unused)
  60. {
  61. async_start_func();
  62. }
  63. #endif